diff --git a/.github/workflows/jest.yml b/.github/workflows/jest.yml index 697b05d..9c5f9dd 100644 --- a/.github/workflows/jest.yml +++ b/.github/workflows/jest.yml @@ -22,6 +22,10 @@ jobs: with: node-version: '20' + - name: Use MongoDB in Github Actions + uses: supercharge/mongodb-github-action@1.11.0 + + - name: Install backend dependencies working-directory: ./backend run: npm install diff --git a/backend/tests/database.test.ts b/backend/tests/database.test.ts new file mode 100644 index 0000000..536e695 --- /dev/null +++ b/backend/tests/database.test.ts @@ -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(); + }); +});