Skip to content

Commit

Permalink
chore: update authorization middleware and getDeveloper controller #627
Browse files Browse the repository at this point in the history
  • Loading branch information
davydocsurg committed Nov 26, 2023
1 parent b8c1138 commit da7ca47
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 30 deletions.
14 changes: 2 additions & 12 deletions __tests__/developers.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createDeveloper, getExample, getExamples, getWord, getWords } from './shared/commands';
import { createDeveloper, getDeveloper, getExample, getExamples, getWord, getWords } from './shared/commands';
import { developerData, malformedDeveloperData, wordId, exampleId } from './__mocks__/documentData';

describe('Developers', () => {
Expand Down Expand Up @@ -106,17 +106,7 @@ describe('Developers', () => {
const developerDetails = await getDeveloper({ apiKey: developerRes.body.apiKey });
expect(developerDetails.status).toEqual(200);
expect(developerDetails.body.developer).toMatchObject({
usage: expect.objectContaining({
date: expect.any(String),
count: expect.any(Number),
}),
name: expect.any(String),
apiKey: expect.any(String),
email: expect.any(String),
password: expect.any(String),
createdAt: expect.any(String),
updatedAt: expect.any(String),
id: expect.any(String),
...developerRes.body.developer,
});
});

Expand Down
39 changes: 23 additions & 16 deletions __tests__/shared/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,25 @@ export const getExamplesV2 = (query = {}, options = {}) =>
.query(query)
.set('X-API-Key', options.apiKey || FALLBACK_API_KEY);

/* Searches for Nsibidi characters using the data in MongoDB V1 */
/* Searches for Nsibidi characters using the data in MongoDB V1 */
export const getNsibidiCharacter = (id, query = {}, options = {}) =>
server
.get(`${API_ROUTE}/nsibidi/${id}`)
.query(query)
.set('X-API-Key', options.apiKey || FALLBACK_API_KEY);
server
.get(`${API_ROUTE}/nsibidi/${id}`)
.query(query)
.set('X-API-Key', options.apiKey || FALLBACK_API_KEY);

/* Searches for Nsibidi characters using the data in MongoDB V2 */
export const getNsibidiCharacterV2 = (id, query = {}, options = {}) =>
server
.get(`${API_ROUTE_V2}/nsibidi/${id}`)
.query(query)
.set('X-API-Key', options.apiKey || FALLBACK_API_KEY);
server
.get(`${API_ROUTE_V2}/nsibidi/${id}`)
.query(query)
.set('X-API-Key', options.apiKey || FALLBACK_API_KEY);

export const getNsibidiCharactersV2 = (query = {}, options = {}) =>
server
.get(`${API_ROUTE_V2}/nsibidi`)
.query(query)
.set('X-API-Key', options.apiKey || FALLBACK_API_KEY);
server
.get(`${API_ROUTE_V2}/nsibidi`)
.query(query)
.set('X-API-Key', options.apiKey || FALLBACK_API_KEY);

/* Hits the POST /populate route to seed the local MongoDB database */
export const populateAPI = () => server.post(`${TEST_ROUTE}/populate`);
Expand All @@ -94,6 +94,13 @@ export const searchMockedTerm = (term) => {
return resultsFromDictionarySearch(regexTerm, term, mockedData);
};

/* fetch developer details */
export const getDeveloper = (id, options = {}) =>
server.get(`${API_ROUTE}/developers/${id}`).set('X-API-Key', options.apiKey || FALLBACK_API_KEY);
/* Fetch developer details */
export const getDeveloper = (options = {}) =>
server.get(`${API_ROUTE}/developers/account`).set('X-API-Key', options.apiKey || FALLBACK_API_KEY);

/** Login a developer */
export const loginDeveloper = (data) => server.post(`${API_ROUTE}/login`).send(data);

/** Logout a developer */
export const logoutDeveloper = (options = {}) =>
server.post(`${API_ROUTE}/logout`).set('Authorization', `Bearer ${options.token || ''}`);
3 changes: 2 additions & 1 deletion jest.frontend.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Frontend Jest Config
module.exports = {
displayName: 'igbo_api',
testMatch: ['./**/__tests__/**/*.test.tsx'],
Expand All @@ -9,7 +10,7 @@ module.exports = {
'^[./a-zA-Z0-9$_-]+\\.(svg|gif|png|less|css)$': '<rootDir>/src/__data__/assetStub.ts',
},
transform: {
'^.+\\.(js|ts|tsx)$': 'ts-jest',
'^.+\\.(js|ts|tsx)$': ['ts-jest', { tsconfig: './tsconfig.test.json' }],
},
setupFilesAfterEnv: ['./src/__tests__/shared/script.ts'],
};
2 changes: 1 addition & 1 deletion src/routers/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import rateLimit from 'express-rate-limit';
import { MiddleWare } from '../types';
import { getWords, getWord } from '../controllers/words';
import { getExamples, getExample } from '../controllers/examples';
import { getDeveloper, postDeveloper } from '../controllers/developers/developers';
import { getDeveloper, postDeveloper } from '../controllers/developers';
import { getStats } from '../controllers/stats';
import validId from '../middleware/validId';
import validateDeveloperBody from '../middleware/validateDeveloperBody';
Expand Down

0 comments on commit da7ca47

Please sign in to comment.