Skip to content

Commit

Permalink
Cleanup step after all tests are run to clear the database.
Browse files Browse the repository at this point in the history
  • Loading branch information
louissullivan4 committed Jan 2, 2024
1 parent b5f9d65 commit 3a278a0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
13 changes: 5 additions & 8 deletions test/integration/apiEndpointTests.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const request = require('supertest');
const createApp = require('../../src/server');
const clearDatabase = require('../../src/utils/clearDatabase');

const app = createApp(true);
describe('API Endpoints', () => {
it('should create a new user', (done) => {
const app = createApp(true);

request(app)
.post('/auth/signup')
.send({ username: 'testuser', password: 'password123' })
Expand All @@ -16,8 +16,6 @@ describe('API Endpoints', () => {
});

it('should not create a new user because they already exist', (done) => {
const app = createApp(true);

request(app)
.post('/auth/signup')
.send({ username: 'testuser', password: 'password123' })
Expand All @@ -29,8 +27,6 @@ describe('API Endpoints', () => {
});

it('should not create a new user because they already exist', (done) => {
const app = createApp(true);

request(app)
.post('/auth/signup')
.send({ username: 'testuser', password: 'password123' })
Expand All @@ -43,8 +39,6 @@ describe('API Endpoints', () => {


it ('should return 404 for unknown endpoints', (done) => {
const app = createApp(true);

request(app)
.get('/unknown')
.expect(404)
Expand All @@ -54,4 +48,7 @@ describe('API Endpoints', () => {
});
});

afterAll(async () => {
await clearDatabase();
});
});
4 changes: 3 additions & 1 deletion test/unit/modelTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ describe('User Model', () => {
expect(user.username).toBe('testUser');
expect(user.password).toBe('password123');
});
clearDatabase("User");
afterAll(async () => {
await clearDatabase();
});
});

0 comments on commit 3a278a0

Please sign in to comment.