Skip to content

Commit

Permalink
added tests to test app.js
Browse files Browse the repository at this point in the history
  • Loading branch information
gregory567 committed Aug 27, 2024
1 parent 02b5c0b commit e5e37d6
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test/todos.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,40 @@ describe('Todos API', () => {
expect(res.headers['access-control-allow-origin']).toBeUndefined();
});



test('should initialize PostHog with correct API key and host', () => {
const mockPostHog = jest.fn();
jest.mock('posthog-node', () => {
return {
PostHog: mockPostHog
};
});

// Reload the app module to apply the mock
delete require.cache[require.resolve('../app')];
require('../app');

expect(mockPostHog).toHaveBeenCalledWith(
'phc_xC1fBU65c02AaFCisiKximyPseHTHIUGSRwtQayUXs0',
{ host: 'https://eu.i.posthog.com' }
);
});


test('should return 404 for undefined routes', async () => {
const res = await request(app).get('/undefined-route');
expect(res.statusCode).toEqual(404);
});


test('should parse cookies correctly', async () => {
const res = await request(app)
.get('/todos')
.set('Cookie', 'test_cookie=test_value');

expect(res.statusCode).toEqual(200);
expect(res.headers['set-cookie']).toBeUndefined(); // Assuming no new cookies are set in this route
});

});

0 comments on commit e5e37d6

Please sign in to comment.