-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implementing order tracking and order managment issue
implementing order tracking and order managment issue implementing order tracking and order managment issue implementing order tracking and order managment issue adding documentation and tests writing tests
- Loading branch information
Showing
72 changed files
with
2,260 additions
and
970 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,47 @@ | ||
import { Request, Response } from 'express'; | ||
import { CustomError, errorHandler } from '../middlewares/errorHandler' | ||
import { CustomError, errorHandler } from '../middlewares/errorHandler'; | ||
|
||
describe('CustomError', () => { | ||
it('should create a CustomError object with statusCode and status properties', () => { | ||
const message = 'Test error message'; | ||
const statusCode = 404; | ||
const customError = new CustomError(message, statusCode); | ||
expect(customError.message).toBe(message); | ||
expect(customError.statusCode).toBe(statusCode); | ||
expect(customError.status).toBe('fail'); | ||
}); | ||
it('should create a CustomError object with statusCode and status properties', () => { | ||
const message = 'Test error message'; | ||
const statusCode = 404; | ||
const customError = new CustomError(message, statusCode); | ||
expect(customError.message).toBe(message); | ||
expect(customError.statusCode).toBe(statusCode); | ||
expect(customError.status).toBe('fail'); | ||
}); | ||
}); | ||
|
||
describe('errorHandler', () => { | ||
it('should send correct response with status code and message', () => { | ||
const err = new CustomError('Test error message', 404); | ||
const req = {} as Request; | ||
const res = { | ||
status: jest.fn().mockReturnThis(), | ||
json: jest.fn(), | ||
} as unknown as Response; | ||
const next = jest.fn(); | ||
errorHandler(err, req, res, next); | ||
expect(res.status).toHaveBeenCalledWith(404); | ||
expect(res.json).toHaveBeenCalledWith({ | ||
status: 404, | ||
message: 'Test error message', | ||
}); | ||
describe('errorHandler', () => { | ||
it('should send correct response with status code and message', () => { | ||
const err = new CustomError('Test error message', 404); | ||
const req = {} as Request; | ||
const res = { | ||
status: jest.fn().mockReturnThis(), | ||
json: jest.fn(), | ||
} as unknown as Response; | ||
const next = jest.fn(); | ||
errorHandler(err, req, res, next); | ||
expect(res.status).toHaveBeenCalledWith(404); | ||
expect(res.json).toHaveBeenCalledWith({ | ||
status: 404, | ||
message: 'Test error message', | ||
}); | ||
it('should handle errors with status code 500', () => { | ||
const err = new CustomError('something went wrong', 500); | ||
const req = {} as Request; | ||
const res = { | ||
status: jest.fn().mockReturnThis(), | ||
json: jest.fn(), | ||
} as unknown as Response; | ||
const next = jest.fn(); | ||
errorHandler(err, req, res, next); | ||
}); | ||
it('should handle errors with status code 500', () => { | ||
const err = new CustomError('something went wrong', 500); | ||
const req = {} as Request; | ||
const res = { | ||
status: jest.fn().mockReturnThis(), | ||
json: jest.fn(), | ||
} as unknown as Response; | ||
const next = jest.fn(); | ||
errorHandler(err, req, res, next); | ||
|
||
expect(res.status).toHaveBeenCalledWith(500); | ||
expect(res.json).toHaveBeenCalledWith({ | ||
status: 500, | ||
message: 'something went wrong', | ||
}); | ||
expect(res.status).toHaveBeenCalledWith(500); | ||
expect(res.json).toHaveBeenCalledWith({ | ||
status: 500, | ||
message: 'something went wrong', | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.