Skip to content

Commit

Permalink
[#7] feat: add mongodb test container to test
Browse files Browse the repository at this point in the history
  • Loading branch information
glemenneo committed Sep 18, 2024
1 parent 1594b43 commit 60e92be
Show file tree
Hide file tree
Showing 4 changed files with 2,566 additions and 65 deletions.
23 changes: 19 additions & 4 deletions backend/user-service/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
import { MongoDBContainer, StartedMongoDBContainer } from '@testcontainers/mongodb'
import request from 'supertest'
import app from '../src/index'

describe('GET /', () => {
it('should return 200 OK', async () => {
const response = await request(app).get('/')
expect(response.status).toBe(200)
describe('Index', () => {
let startedContainer: StartedMongoDBContainer

beforeAll(async () => {
const container: MongoDBContainer = new MongoDBContainer().withExposedPorts(27017)
startedContainer = await container.start()
process.env.DB_URL = `mongodb://${startedContainer.getHost()}:${startedContainer.getMappedPort(27017)}/user-service`
})

afterAll(async () => {
await startedContainer.stop()
})

describe('GET /', () => {
it('should return 200 OK', async () => {
const response = await request(app).get('/')
expect(response.status).toBe(200)
})
})
})
Loading

0 comments on commit 60e92be

Please sign in to comment.