Skip to content

Commit

Permalink
chore: update dependencies and rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
davydocsurg committed Nov 8, 2023
1 parent 7df18fe commit 82d5a89
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 258 deletions.
4 changes: 0 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ module.exports = {
node: true,
jest: true,
},
<<<<<<< HEAD
ignorePatterns: ['**/functions/*.js', '**/*.d.ts'],
=======
ignorePatterns: ['**/functions/*.js', '**/node_modules/'],
>>>>>>> 73fd51d (chore: set up jest frontend environment (#759))
// Prettier plugin should be the last to always override preceding plugins
extends: ['next', 'airbnb', 'plugin:cypress/recommended', 'prettier'],
parserOptions: {
Expand Down
29 changes: 0 additions & 29 deletions __tests__/__mocks__/documentData.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ const developerData = {
password: 'password',
};

<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> 404d4a7 (chore: create logout developer endpoint; add test #751 (#752))
// Generate a unique name using a UUID without hyphens
const generateUniqueName = () => uuid().replace(/-/g, '');

Expand Down Expand Up @@ -50,32 +46,13 @@ const anotherDeveloperData = {
name: generateUniqueName(),
email: generateUniqueEmail(),
password: generateUniquePassword(),
<<<<<<< HEAD
=======
const newDeveloperData = {
<<<<<<< HEAD
name: 'New Developer',
email: 'newdeveloper@example.com',
password: 'password',
>>>>>>> 03f15e6 (Fix create login endpoint (#748))
=======
name: `${uuid().replace(/-/g, '')}`,
email: `${uuid().replace(/-/g, '')}@testing.com`,
password: `${uuid()}`,
>>>>>>> 2b187a9 (Define the login business logic (#750))
=======
>>>>>>> 404d4a7 (chore: create logout developer endpoint; add test #751 (#752))
};

const malformedDeveloperData = {
email: 'developer@example.com',
password: 'password',
};

<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> 404d4a7 (chore: create logout developer endpoint; add test #751 (#752))
export {
wordId,
exampleId,
Expand All @@ -86,9 +63,3 @@ export {
anotherDeveloperData,
malformedDeveloperData,
};
<<<<<<< HEAD
=======
export { wordId, exampleId, developerData, newDeveloperData, malformedDeveloperData };
>>>>>>> 03f15e6 (Fix create login endpoint (#748))
=======
>>>>>>> 404d4a7 (chore: create logout developer endpoint; add test #751 (#752))
20 changes: 20 additions & 0 deletions __tests__/shared/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,26 @@ 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 */
export const getNsibidiCharacter = (id, query = {}, options = {}) =>
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);

export const getNsibidiCharactersV2 = (query = {}, options = {}) =>
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 Down
2 changes: 1 addition & 1 deletion jest.backend.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
displayName: 'igbo_api',
testMatch: ['**/__tests__/*.js', '**/__tests__/*.ts'],
testTimeout: 20000,
testTimeout: 50000,
testEnvironment: 'node',
moduleFileExtensions: ['ts', 'js', 'json'],
globalSetup: './testSetup.js',
Expand Down
8 changes: 0 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,8 @@
"@types/bcrypt": "^5.0.0",
"@types/compression": "^1.7.2",
"@types/express-rate-limit": "^6.0.0",
<<<<<<< HEAD
"@types/jest": "^29.5.6",
<<<<<<< HEAD
"@types/jsonwebtoken": "^9.0.2",
=======
=======
"@types/jest": "^29.5.4",
"@types/jsonwebtoken": "^9.0.2",
>>>>>>> 7a3f647 (Define the login business logic (#750))
>>>>>>> 2b187a9 (Define the login business logic (#750))
"@types/morgan": "^1.9.4",
"@types/node": "^20.3.0",
"@types/react": "^18.2.11",
Expand Down
20 changes: 10 additions & 10 deletions src/controllers/auth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Response } from 'express';
import jwt from 'jsonwebtoken';
import bcrypt from 'bcrypt';
import { Developer as DeveloperType, Express } from '../types';
import { Developer as DeveloperType, MiddleWare } from '../types';
import { isProduction, isTest } from '../config';
import { createDbConnection, handleCloseConnection } from '../services/database';
import { developerSchema } from '../models/Developer';
Expand Down Expand Up @@ -37,7 +37,7 @@ const signToken = (email: string) => {
* Creates and sends a JSON Web Token (JWT) to the client in a response.
*
* @param {DeveloperType} developer - The developer data to include in the JWT payload.
* @param {Express.Response} res - The Express response object to send the token in.
* @param {Response} res - The Express response object to send the token in.
* @returns {string} The signed JWT token.
* @throws {Error} If an error occurs during the token signing or sending process.
*/
Expand Down Expand Up @@ -76,13 +76,13 @@ const loginDeveloperWithEmailAndPassword = async (email: string, password: strin
/**
* Handles the login process for a developer.
*
* @param {Express.IgboAPIRequest} req - The Express request object.
* @param {Express.Response} res - The Express response object.
* @param {Express.NextFunction} next - The next middleware function.
* @param {IgboAPIRequest} req - The Express request object.
* @param {Response} res - The Express response object.
* @param {NextFunction} next - The next middleware function.
* @returns {Promise<void>} A Promise that resolves when the login process is complete.
* @throws {Error} If an error occurs during the login process.
*/
export const login: Express.MiddleWare = async (req, res, next) => {
export const login: MiddleWare = async (req, res, next) => {
try {
const { email, password } = req.body;

Expand All @@ -104,12 +104,12 @@ export const login: Express.MiddleWare = async (req, res, next) => {

/**
* Handles the logout process for a developer.
* @param {Express.IgboAPIRequest} req - The Express request object.
* @param {Express.Response} res - The Express response object.
* @param {Express.NextFunction} next - The next middleware function.
* @param {IgboAPIRequest} req - The Express request object.
* @param {Response} res - The Express response object.
* @param {NextFunction} next - The next middleware function.
* @returns {Promise<void>} A Promise that resolves when the logout process is complete.
*/
export const logout: Express.MiddleWare = async (req, res, next) => {
export const logout: MiddleWare = async (req, res, next) => {
try {
res.cookie('jwt', '', { expires: new Date(), httpOnly: true });

Expand Down
64 changes: 0 additions & 64 deletions src/controllers/developers/utils.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/controllers/utils/findDeveloper.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { compareSync } from 'bcrypt';
import { developerSchema } from '../../models/Developer';
import { createDbConnection } from '../../services/database';
import { DeveloperDocument, Express } from '../../types';
import { DeveloperDocument, MiddleWare } from '../../types';

export const handleRequest: Express.MiddleWare = (req) => {
export const handleRequest: MiddleWare = (req) => {
const { apiLimit } = req.query;
const apiToken = req.headers['X-API-Key'] || req.headers['x-api-key'];

Expand Down
4 changes: 2 additions & 2 deletions src/middleware/authenticate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import jwt from 'jsonwebtoken';
import { JWT_SECRET } from '../siteConstants';
import { Express } from '../types';
import { MiddleWare } from '../types';
import { createDbConnection, handleCloseConnection } from '../services/database';
import { developerSchema } from '../models/Developer';

Expand All @@ -10,7 +10,7 @@ interface DeveloperDataType {
exp?: number;
}

export const authenticate: Express.MiddleWare = async (req, res, next) => {
export const authenticate: MiddleWare = async (req, res, next) => {
let token: string | undefined;
// Check if token is set
if (req.headers.authorization && req.headers.authorization.startsWith('Bearer')) {
Expand Down
32 changes: 0 additions & 32 deletions src/middleware/validateApiKey.js

This file was deleted.

21 changes: 0 additions & 21 deletions src/services/firebase.js

This file was deleted.

Loading

0 comments on commit 82d5a89

Please sign in to comment.