-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
workflows: Add mongodb server to jest workflow for database tests.
- Loading branch information
Showing
2 changed files
with
24 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
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 |
---|---|---|
@@ -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(); | ||
}); | ||
}); |