Skip to content

Commit

Permalink
Merge pull request #24 from CS3219-AY2425S1/glemen/#7-user-data-model
Browse files Browse the repository at this point in the history
[#7] Add user data model
  • Loading branch information
glemenneo authored Sep 18, 2024
2 parents df8556c + 3e5d0a5 commit 05f2e08
Show file tree
Hide file tree
Showing 20 changed files with 3,929 additions and 187 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
**/dist
**/coverage

**/*.log

**/.turbo
11 changes: 6 additions & 5 deletions backend/user-service/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { describe, expect, it } from '@jest/globals'
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', () => {
describe('GET /', () => {
it('should return 200 OK', async () => {
const response = await request(app).get('/')
expect(response.status).toBe(200)
})
})
})
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()
})
})
})
Loading

0 comments on commit 05f2e08

Please sign in to comment.