Skip to content

Commit

Permalink
[#7] test: repository test setup
Browse files Browse the repository at this point in the history
  • Loading branch information
glemenneo committed Sep 18, 2024
1 parent 3bfa665 commit 3e5d0a5
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions backend/user-service/__tests__/models/user.repository.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { MongoDBContainer, StartedMongoDBContainer } from '@testcontainers/mongodb'
import logger from '../../src/common/logger.util'
import connectToDatabase from '../../src/common/mongodb.util'
import { findOneUserByUsername } from '../../src/models/user.repository'

describe('UserRepository', () => {
let startedContainer: StartedMongoDBContainer

beforeAll(async () => {
const container: MongoDBContainer = new MongoDBContainer().withExposedPorts(27017)
startedContainer = await container.start()

const connectionString = `${startedContainer.getConnectionString()}?directConnection=true`
logger.info(`[Index Test] MongoDB container started on ${connectionString}`)

await connectToDatabase(connectionString)
}, 60000)

afterAll(async () => {
await startedContainer.stop()
logger.info(`[Index Test] MongoDB container stopped`)
})

describe('findOneUserByUsername', () => {
it('should return null when no user found', async () => {
const user = await findOneUserByUsername('')
expect(user).toBeNull()
})
})
})

0 comments on commit 3e5d0a5

Please sign in to comment.