Skip to content

Commit

Permalink
workflows: Add mongodb server to jest workflow for database tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
kuv2707 committed Jun 8, 2024
1 parent dec586d commit 7bc3d56
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/jest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ jobs:
with:
node-version: '20'

- name: Use MongoDB in Github Actions
uses: supercharge/[email protected]


- name: Install backend dependencies
working-directory: ./backend
run: npm install
Expand Down
20 changes: 20 additions & 0 deletions backend/tests/database.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import mongoose from 'mongoose';

describe('DB connection test', () => {
beforeAll(async () => {
await mongoose
.connect('mongodb://localhost:27017/users')
.then(() => console.log('DB connected'));
}, 30000);
it('should insert a user into collection', async () => {
const users = mongoose.connection.collection('users');
const mockUser = { name: 'user1234', password: 'pass1' };
await users.insertOne(mockUser);

const insertedUser = await users.findOne({ name: 'user1234' });
expect(insertedUser).toEqual(mockUser);
});
afterAll(async () => {
await mongoose.connection.close();
});
});

0 comments on commit 7bc3d56

Please sign in to comment.