Skip to content

Commit

Permalink
fix(be): resolve client submission test error (#1774)
Browse files Browse the repository at this point in the history
* fix(be): resolve client submission test error

* fix(be): add to be equal
  • Loading branch information
gyunseo authored Jul 4, 2024
1 parent 2906a7d commit 2e5a208
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions apps/backend/apps/client/src/submission/submission.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { NotFoundException } from '@nestjs/common'
import { ConfigService } from '@nestjs/config'
import { Test, type TestingModule } from '@nestjs/testing'
import { AmqpConnection } from '@golevelup/nestjs-rabbitmq'
import { Language, ResultStatus } from '@prisma/client'
import { Language, ResultStatus, type User } from '@prisma/client'
import { expect } from 'chai'
import { plainToInstance } from 'class-transformer'
import { TraceService } from 'nestjs-otel'
Expand Down Expand Up @@ -48,6 +48,9 @@ const db = {
contestRecord: {
findUniqueOrThrow: stub()
},
user: {
findFirst: stub()
},
getPaginator: PrismaService.prototype.getPaginator
}

Expand Down Expand Up @@ -415,20 +418,32 @@ describe('SubmissionService', () => {

describe('getContestSubmisssions', () => {
it('should return submissions', async () => {
const adminUser: User = {
id: 1,
username: 'username',
password: '1234',
role: 'Admin',
email: '[email protected]',
lastLogin: new Date(),
createTime: new Date(),
updateTime: new Date()
}
db.contestRecord.findUniqueOrThrow.resolves()
db.contestProblem.findFirstOrThrow.resolves()
db.submission.findMany.resolves(submissions)
db.user.findFirst.resolves(adminUser)

expect(
await service.getContestSubmissions({
problemId: problems[0].id,
contestId: 1,
userId: submissions[0].userId
})
)
).to.be.deep.equal({ data: submissions, total: 1 })
})

it('should throw exception if user is not registered to contest', async () => {
db.user.findFirst.resolves(null)
db.contestRecord.findUniqueOrThrow.rejects(
new NotFoundException('No contestRecord found error')
)
Expand Down

0 comments on commit 2e5a208

Please sign in to comment.