-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(namingRule): change test code namingRule
- Loading branch information
1 parent
c25e866
commit f596850
Showing
5 changed files
with
219 additions
and
113 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
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
58 changes: 58 additions & 0 deletions
58
src/APIs/agreements/__test__/agreements.controller.spec.ts
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { AgreementsService } from '../agreements.service'; | ||
import { AgreementDto } from '../dtos/common/agreement.dto'; | ||
import { | ||
MockService, | ||
MockServiceFactory, | ||
TEST_DATE_FIELDS, | ||
} from '@/utils/test.utils'; | ||
import { AgreementType } from '@/common/enums/agreement-type.enum'; | ||
import { AgreementsController } from '../agreements.controller'; | ||
import { AgreementCreateRequestDto } from '../dtos/request/agreement-create-request.dto'; | ||
import { Request } from 'express'; | ||
|
||
describe('AgreementsService', () => { | ||
let ctrl_agreements: AgreementsController; | ||
let svc_agreements: MockService<AgreementsService>; | ||
let dto_agreement: AgreementDto; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [AgreementsController], | ||
providers: [ | ||
{ | ||
provide: AgreementsService, | ||
useValue: MockServiceFactory.getMockService(AgreementsService), | ||
}, | ||
], | ||
}).compile(); | ||
ctrl_agreements = module.get<AgreementsController>(AgreementsController); | ||
svc_agreements = | ||
module.get<MockService<AgreementsService>>(AgreementsService); | ||
dto_agreement = { | ||
id: 1, | ||
userId: 1, | ||
agreementType: AgreementType.TERMS_OF_SERVICE, | ||
isAgreed: true, | ||
...TEST_DATE_FIELDS, | ||
}; | ||
}); | ||
|
||
describe('agree', () => { | ||
it('should return AgreementDto with valid input', async () => { | ||
const req = { user: { userId: 1 } } as Request; | ||
const dto: AgreementCreateRequestDto = { | ||
agreementType: AgreementType.TERMS_OF_SERVICE, | ||
isAgreed: true, | ||
}; | ||
svc_agreements.createAgreement.mockResolvedValue(dto_agreement); | ||
|
||
const result = await ctrl_agreements.agree(req, dto); | ||
expect(result).toEqual(dto_agreement); | ||
expect(svc_agreements.createAgreement).toHaveBeenCalledWith({ | ||
...dto, | ||
userId: 1, | ||
}); | ||
}); | ||
}); | ||
}); |
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
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