-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(be): resolve client submission test error (#1774)
* fix(be): resolve client submission test error * fix(be): add to be equal
- Loading branch information
Showing
1 changed file
with
17 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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' | ||
|
@@ -48,6 +48,9 @@ const db = { | |
contestRecord: { | ||
findUniqueOrThrow: stub() | ||
}, | ||
user: { | ||
findFirst: stub() | ||
}, | ||
getPaginator: PrismaService.prototype.getPaginator | ||
} | ||
|
||
|
@@ -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') | ||
) | ||
|