From 2e5a208436dc464964e9e25ad13969431715b82a Mon Sep 17 00:00:00 2001 From: Gyunseo Lee Date: Thu, 4 Jul 2024 20:46:32 +0900 Subject: [PATCH] fix(be): resolve client submission test error (#1774) * fix(be): resolve client submission test error * fix(be): add to be equal --- .../src/submission/submission.service.spec.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/apps/backend/apps/client/src/submission/submission.service.spec.ts b/apps/backend/apps/client/src/submission/submission.service.spec.ts index 444d45cb0a..cc4597a36c 100644 --- a/apps/backend/apps/client/src/submission/submission.service.spec.ts +++ b/apps/backend/apps/client/src/submission/submission.service.spec.ts @@ -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,9 +418,20 @@ describe('SubmissionService', () => { describe('getContestSubmisssions', () => { it('should return submissions', async () => { + const adminUser: User = { + id: 1, + username: 'username', + password: '1234', + role: 'Admin', + email: 'test@test.com', + 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({ @@ -425,10 +439,11 @@ describe('SubmissionService', () => { 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') )