Skip to content

Commit

Permalink
fix(template tests): small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
praveenkumarct committed Sep 25, 2024
1 parent 234c426 commit a605d65
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const errorMiddleware = (error, _req, res, _next) => {
.status(500)
.send(
isDevelopment
? { messge: error.message }
? { message: error.message }
: { message: 'Internal server error' }
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe('Testing router', () => {
message: 'Path not found.',
});
});

test('Post invalid body', async () => {
const response = await request(app).post('/event').send({
message: 'hello world',
Expand All @@ -25,6 +26,7 @@ describe('Testing router', () => {
message: 'Bad request: No customer id in the Pub/Sub message',
});
});

test('Post empty body', async () => {
const response = await request(app).post('/event');
expect(response.status).toBe(400);
Expand All @@ -33,6 +35,7 @@ describe('Testing router', () => {
});
});
});

describe('unexpected error', () => {
let postMock;

Expand All @@ -44,14 +47,15 @@ describe('unexpected error', () => {
readConfiguration.mockClear();
});

afterEach(() => {
// Restore the original implementation
postMock.mockRestore();
});
test('should handle errors thrown by post method', async () => {
// Call the route handler
const response = await request(app).post('/event');
expect(response.status).toBe(500);
expect(response.body).toEqual({ message: 'Internal server error' });
});

afterEach(() => {
// Restore the original implementation
postMock.mockRestore();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe('Testing router', () => {
message: 'Path not found.',
});
});

test('Post invalid body', async () => {
const response = await request(app).post('/service').send({
message: 'hello world',
Expand All @@ -25,6 +26,7 @@ describe('Testing router', () => {
message: 'Bad request - Missing body parameters.',
});
});

test('Post empty body', async () => {
const response = await request(app).post('/service');
expect(response.status).toBe(400);
Expand All @@ -33,6 +35,7 @@ describe('Testing router', () => {
});
});
});

describe('unexpected error', () => {
let postMock;

Expand All @@ -41,17 +44,17 @@ describe('unexpected error', () => {
postMock = jest.spyOn(serviceController, 'post').mockImplementation(() => {
throw new Error('Test error');
});
readConfiguration.mockClear();
});

afterEach(() => {
// Restore the original implementation
postMock.mockRestore();
});
test('should handle errors thrown by post method', async () => {
// Call the route handler
const response = await request(app).post('/service');
expect(response.status).toBe(500);
expect(response.body).toEqual({ message: 'Internal server error' });
});

afterEach(() => {
// Restore the original implementation
postMock.mockRestore();
});
});

0 comments on commit a605d65

Please sign in to comment.