Skip to content

Commit

Permalink
Change rules to fit existing codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
sphilipse committed Oct 7, 2022
1 parent d406c70 commit cd2cf85
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 56 deletions.
20 changes: 1 addition & 19 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1415,21 +1415,8 @@ module.exports = {
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'default',
format: ['camelCase'],
leadingUnderscore: 'allow',
trailingUnderscore: 'allow',
},
{
selector: 'default',
selector: 'variable',
modifiers: ['destructured'],
format: ['camelCase', 'snake_case'],
leadingUnderscore: 'allow',
trailingUnderscore: 'allow',
},
{
selector: 'default',
modifiers: ['requiresQuotes'],
format: null,
leadingUnderscore: 'allow',
trailingUnderscore: 'allow',
Expand All @@ -1440,11 +1427,6 @@ module.exports = {
leadingUnderscore: 'allow',
trailingUnderscore: 'allow',
},

{
selector: 'typeLike',
format: ['PascalCase'],
},
],
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('EnterpriseSearchRequestHandler', () => {
meta: { page: { total_results: 1 } },
};

EnterpriseSearchAPI.mockReturn(responseBody);
enterpriseSearchAPI.mockReturn(responseBody);

const requestHandler = enterpriseSearchRequestHandler.createRequest({
path: '/as/credentials/collection',
Expand All @@ -61,7 +61,7 @@ describe('EnterpriseSearchRequestHandler', () => {
},
});

EnterpriseSearchAPI.shouldHaveBeenCalledWith(
enterpriseSearchAPI.shouldHaveBeenCalledWith(
'http://localhost:3002/as/credentials/collection?type=indexed&pageIndex=1',
{ method: 'GET' }
);
Expand All @@ -80,12 +80,12 @@ describe('EnterpriseSearchRequestHandler', () => {
});

await makeAPICall(requestHandler, { route: { method: 'POST' } });
EnterpriseSearchAPI.shouldHaveBeenCalledWith('http://localhost:3002/api/example', {
enterpriseSearchAPI.shouldHaveBeenCalledWith('http://localhost:3002/api/example', {
method: 'POST',
});

await makeAPICall(requestHandler, { route: { method: 'DELETE' } });
EnterpriseSearchAPI.shouldHaveBeenCalledWith('http://localhost:3002/api/example', {
enterpriseSearchAPI.shouldHaveBeenCalledWith('http://localhost:3002/api/example', {
method: 'DELETE',
});
});
Expand All @@ -96,7 +96,7 @@ describe('EnterpriseSearchRequestHandler', () => {
});
await makeAPICall(requestHandler, { body: { bodacious: true } });

EnterpriseSearchAPI.shouldHaveBeenCalledWith('http://localhost:3002/api/example', {
enterpriseSearchAPI.shouldHaveBeenCalledWith('http://localhost:3002/api/example', {
body: '{"bodacious":true}',
});
});
Expand All @@ -107,7 +107,7 @@ describe('EnterpriseSearchRequestHandler', () => {
});
await makeAPICall(requestHandler, { body: Buffer.from('{"bodacious":true}') });

EnterpriseSearchAPI.shouldHaveBeenCalledWith('http://localhost:3002/api/example', {
enterpriseSearchAPI.shouldHaveBeenCalledWith('http://localhost:3002/api/example', {
body: '{"bodacious":true}',
});
});
Expand All @@ -118,7 +118,7 @@ describe('EnterpriseSearchRequestHandler', () => {
});
await makeAPICall(requestHandler, { query: { someQuery: false } });

EnterpriseSearchAPI.shouldHaveBeenCalledWith(
enterpriseSearchAPI.shouldHaveBeenCalledWith(
'http://localhost:3002/api/example?someQuery=false'
);
});
Expand All @@ -130,7 +130,7 @@ describe('EnterpriseSearchRequestHandler', () => {
});
await makeAPICall(requestHandler, { query: { someQuery: false } });

EnterpriseSearchAPI.shouldHaveBeenCalledWith(
enterpriseSearchAPI.shouldHaveBeenCalledWith(
'http://localhost:3002/api/example?someQuery=true'
);
});
Expand All @@ -141,7 +141,7 @@ describe('EnterpriseSearchRequestHandler', () => {
});
await makeAPICall(requestHandler, { query: { 'page[current]': 1 } });

EnterpriseSearchAPI.shouldHaveBeenCalledWith(
enterpriseSearchAPI.shouldHaveBeenCalledWith(
'http://localhost:3002/api/example?page%5Bcurrent%5D=1'
);
});
Expand All @@ -153,7 +153,7 @@ describe('EnterpriseSearchRequestHandler', () => {
});
await makeAPICall(requestHandler, { params: { example: 'hello', id: 'world' } });

EnterpriseSearchAPI.shouldHaveBeenCalledWith(
enterpriseSearchAPI.shouldHaveBeenCalledWith(
'http://localhost:3002/api/examples/hello/some/world'
);
});
Expand All @@ -164,7 +164,7 @@ describe('EnterpriseSearchRequestHandler', () => {
});
await makeAPICall(requestHandler, { params: { example: 'hello#@/$%^/&[]{}/";world' } });

EnterpriseSearchAPI.shouldHaveBeenCalledWith(
enterpriseSearchAPI.shouldHaveBeenCalledWith(
'http://localhost:3002/api/examples/hello%23%40%2F%24%25%5E%2F%26%5B%5D%7B%7D%2F%22%3Bworld'
);
});
Expand All @@ -173,14 +173,14 @@ describe('EnterpriseSearchRequestHandler', () => {

describe('response passing', () => {
it('returns the response status code from Enterprise Search', async () => {
EnterpriseSearchAPI.mockReturn({}, { status: 201 });
enterpriseSearchAPI.mockReturn({}, { status: 201 });

const requestHandler = enterpriseSearchRequestHandler.createRequest({
path: '/api/example',
});
await makeAPICall(requestHandler);

EnterpriseSearchAPI.shouldHaveBeenCalledWith('http://localhost:3002/api/example');
enterpriseSearchAPI.shouldHaveBeenCalledWith('http://localhost:3002/api/example');
expect(responseMock.custom).toHaveBeenCalledWith({
body: {},
statusCode: 201,
Expand All @@ -196,7 +196,7 @@ describe('EnterpriseSearchRequestHandler', () => {
regular: 'data',
};

EnterpriseSearchAPI.mockReturn(jsonWithSessionData, { headers: JSON_HEADER });
enterpriseSearchAPI.mockReturn(jsonWithSessionData, { headers: JSON_HEADER });

const requestHandler = enterpriseSearchRequestHandler.createRequest({ path: '/api/prep' });
await makeAPICall(requestHandler);
Expand All @@ -212,15 +212,15 @@ describe('EnterpriseSearchRequestHandler', () => {

it('passes back the response body as-is if hasJsonResponse is false', async () => {
const mockFile = new File(['mockFile'], 'mockFile.json');
EnterpriseSearchAPI.mockReturn(mockFile);
enterpriseSearchAPI.mockReturn(mockFile);

const requestHandler = enterpriseSearchRequestHandler.createRequest({
path: '/api/file',
hasJsonResponse: false,
});
await makeAPICall(requestHandler);

EnterpriseSearchAPI.shouldHaveBeenCalledWith('http://localhost:3002/api/file');
enterpriseSearchAPI.shouldHaveBeenCalledWith('http://localhost:3002/api/file');
expect(responseMock.custom).toHaveBeenCalledWith({
body: expect.any(Buffer), // Unfortunately Response() buffers the body so we can't actually inspect/equality assert on it
statusCode: 200,
Expand All @@ -233,13 +233,13 @@ describe('EnterpriseSearchRequestHandler', () => {
describe('error responses', () => {
describe('handleClientError()', () => {
afterEach(() => {
EnterpriseSearchAPI.shouldHaveBeenCalledWith('http://localhost:3002/api/4xx');
enterpriseSearchAPI.shouldHaveBeenCalledWith('http://localhost:3002/api/4xx');
expect(mockLogger.error).not.toHaveBeenCalled();
});

it('passes back json.error', async () => {
const error = 'some error message';
EnterpriseSearchAPI.mockReturn({ error }, { status: 404, headers: JSON_HEADER });
enterpriseSearchAPI.mockReturn({ error }, { status: 404, headers: JSON_HEADER });

const requestHandler = enterpriseSearchRequestHandler.createRequest({ path: '/api/4xx' });
await makeAPICall(requestHandler);
Expand All @@ -256,7 +256,7 @@ describe('EnterpriseSearchRequestHandler', () => {

it('passes back json.errors', async () => {
const errors = ['one', 'two', 'three'];
EnterpriseSearchAPI.mockReturn({ errors }, { status: 400, headers: JSON_HEADER });
enterpriseSearchAPI.mockReturn({ errors }, { status: 400, headers: JSON_HEADER });

const requestHandler = enterpriseSearchRequestHandler.createRequest({ path: '/api/4xx' });
await makeAPICall(requestHandler);
Expand All @@ -272,7 +272,7 @@ describe('EnterpriseSearchRequestHandler', () => {
});

it('handles empty json', async () => {
EnterpriseSearchAPI.mockReturn({}, { status: 400, headers: JSON_HEADER });
enterpriseSearchAPI.mockReturn({}, { status: 400, headers: JSON_HEADER });

const requestHandler = enterpriseSearchRequestHandler.createRequest({ path: '/api/4xx' });
await makeAPICall(requestHandler);
Expand All @@ -288,7 +288,7 @@ describe('EnterpriseSearchRequestHandler', () => {
});

it('handles invalid json', async () => {
EnterpriseSearchAPI.mockReturn('invalid' as any, { status: 400, headers: JSON_HEADER });
enterpriseSearchAPI.mockReturn('invalid' as any, { status: 400, headers: JSON_HEADER });

const requestHandler = enterpriseSearchRequestHandler.createRequest({ path: '/api/4xx' });
await makeAPICall(requestHandler);
Expand All @@ -304,7 +304,7 @@ describe('EnterpriseSearchRequestHandler', () => {
});

it('handles blank bodies', async () => {
EnterpriseSearchAPI.mockReturn(undefined as any, { status: 404 });
enterpriseSearchAPI.mockReturn(undefined as any, { status: 404 });

const requestHandler = enterpriseSearchRequestHandler.createRequest({ path: '/api/4xx' });
await makeAPICall(requestHandler);
Expand All @@ -321,11 +321,11 @@ describe('EnterpriseSearchRequestHandler', () => {
});

it('handleServerError()', async () => {
EnterpriseSearchAPI.mockReturn('something crashed!' as any, { status: 500 });
enterpriseSearchAPI.mockReturn('something crashed!' as any, { status: 500 });
const requestHandler = enterpriseSearchRequestHandler.createRequest({ path: '/api/5xx' });

await makeAPICall(requestHandler);
EnterpriseSearchAPI.shouldHaveBeenCalledWith('http://localhost:3002/api/5xx');
enterpriseSearchAPI.shouldHaveBeenCalledWith('http://localhost:3002/api/5xx');

expect(responseMock.customError).toHaveBeenCalledWith({
statusCode: 502,
Expand All @@ -338,14 +338,14 @@ describe('EnterpriseSearchRequestHandler', () => {
});

it('handleReadOnlyModeError()', async () => {
EnterpriseSearchAPI.mockReturn(
enterpriseSearchAPI.mockReturn(
{ errors: ['Read only mode'] },
{ status: 503, headers: { ...JSON_HEADER, [READ_ONLY_MODE_HEADER]: 'true' } }
);
const requestHandler = enterpriseSearchRequestHandler.createRequest({ path: '/api/503' });

await makeAPICall(requestHandler);
EnterpriseSearchAPI.shouldHaveBeenCalledWith('http://localhost:3002/api/503');
enterpriseSearchAPI.shouldHaveBeenCalledWith('http://localhost:3002/api/503');

expect(responseMock.customError).toHaveBeenCalledWith({
statusCode: 503,
Expand All @@ -358,14 +358,14 @@ describe('EnterpriseSearchRequestHandler', () => {
});

it('handleInvalidDataError()', async () => {
EnterpriseSearchAPI.mockReturn({ results: false });
enterpriseSearchAPI.mockReturn({ results: false });
const requestHandler = enterpriseSearchRequestHandler.createRequest({
path: '/api/invalid',
hasValidData: (body?: any) => Array.isArray(body?.results),
});

await makeAPICall(requestHandler);
EnterpriseSearchAPI.shouldHaveBeenCalledWith('http://localhost:3002/api/invalid');
enterpriseSearchAPI.shouldHaveBeenCalledWith('http://localhost:3002/api/invalid');

expect(responseMock.customError).toHaveBeenCalledWith({
statusCode: 502,
Expand All @@ -378,11 +378,11 @@ describe('EnterpriseSearchRequestHandler', () => {
});

it('handleConnectionError()', async () => {
EnterpriseSearchAPI.mockReturnError();
enterpriseSearchAPI.mockReturnError();
const requestHandler = enterpriseSearchRequestHandler.createRequest({ path: '/api/failed' });

await makeAPICall(requestHandler);
EnterpriseSearchAPI.shouldHaveBeenCalledWith('http://localhost:3002/api/failed');
enterpriseSearchAPI.shouldHaveBeenCalledWith('http://localhost:3002/api/failed');

expect(responseMock.customError).toHaveBeenCalledWith({
statusCode: 502,
Expand All @@ -399,7 +399,7 @@ describe('EnterpriseSearchRequestHandler', () => {
});
await makeAPICall(requestHandler);

EnterpriseSearchAPI.shouldHaveBeenCalledWith('http://localhost:3002/api/unauthenticated');
enterpriseSearchAPI.shouldHaveBeenCalledWith('http://localhost:3002/api/unauthenticated');
expect(responseMock.customError).toHaveBeenCalledWith({
statusCode: 502,
body: 'Cannot authenticate Enterprise Search user',
Expand All @@ -409,21 +409,21 @@ describe('EnterpriseSearchRequestHandler', () => {
});

it('errors when receiving a 401 response', async () => {
EnterpriseSearchAPI.mockReturn({}, { status: 401 });
enterpriseSearchAPI.mockReturn({}, { status: 401 });
});

it('errors when redirected to /login', async () => {
EnterpriseSearchAPI.mockReturn({}, { url: 'http://localhost:3002/login' });
enterpriseSearchAPI.mockReturn({}, { url: 'http://localhost:3002/login' });
});

it('errors when redirected to /ent/select', async () => {
EnterpriseSearchAPI.mockReturn({}, { url: 'http://localhost:3002/ent/select' });
enterpriseSearchAPI.mockReturn({}, { url: 'http://localhost:3002/ent/select' });
});
});
});

it('setResponseHeaders', async () => {
EnterpriseSearchAPI.mockReturn('anything' as any, {
enterpriseSearchAPI.mockReturn('anything' as any, {
headers: { [READ_ONLY_MODE_HEADER]: 'true' },
});
const requestHandler = enterpriseSearchRequestHandler.createRequest({ path: '/' });
Expand All @@ -449,7 +449,7 @@ describe('EnterpriseSearchRequestHandler', () => {
regular: 'data',
};

EnterpriseSearchAPI.mockReturn(sessionDataBody, { headers: JSON_HEADER });
enterpriseSearchAPI.mockReturn(sessionDataBody, { headers: JSON_HEADER });

const requestHandler = enterpriseSearchRequestHandler.createRequest({ path: '/' });
await makeAPICall(requestHandler);
Expand Down Expand Up @@ -477,7 +477,7 @@ const makeAPICall = (handler: Function, params = {}) => {
return handler(null, request, responseMock);
};

const EnterpriseSearchAPI = {
const enterpriseSearchAPI = {
shouldHaveBeenCalledWith(expectedUrl: string, expectedParams = {}) {
expect(fetchMock).toHaveBeenCalledWith(expectedUrl, {
headers: { Authorization: 'Basic 123', ...JSON_HEADER },
Expand Down

0 comments on commit cd2cf85

Please sign in to comment.