-
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.
Merge pull request #57 from DevKor-github/staging
Staging
- Loading branch information
Showing
12 changed files
with
574 additions
and
150 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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: PR Tests | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- staging | ||
- master | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: '21.7.2' | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Run tests | ||
run: npm test | ||
|
||
# - name: Upload test results | ||
# if: always() | ||
# uses: actions/upload-artifact@v2 | ||
# with: | ||
# name: test-results | ||
# path: test-results # Adjust the path according to your test results directory | ||
|
||
- name: Notify test results | ||
if: failure() | ||
run: echo "Tests failed!" |
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
114 changes: 114 additions & 0 deletions
114
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,114 @@ | ||
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'; | ||
import { AgreementPatchRequestDto } from '../dtos/request/agreement-patch-request.dto'; | ||
|
||
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, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('fetchAgreements', () => { | ||
it('should fetch agreements for the user', async () => { | ||
const req = { user: { userId: 1 } } as Request; | ||
svc_agreements.findAgreements.mockResolvedValue([dto_agreement]); | ||
|
||
const result = await ctrl_agreements.fetchAgreements(req); | ||
expect(result).toEqual([dto_agreement]); | ||
expect(svc_agreements.findAgreements).toHaveBeenCalledWith({ userId: 1 }); | ||
}); | ||
}); | ||
|
||
describe('fetchAgreementAdmin', () => { | ||
it('should fetch agreements for the target user as admin', async () => { | ||
const req = { user: { userId: 1 } } as Request; | ||
const targetUserKakaoId = 2; | ||
svc_agreements.adminCheck.mockResolvedValue(true); | ||
svc_agreements.findAgreements.mockResolvedValue([dto_agreement]); | ||
|
||
const result = await ctrl_agreements.fetchAgreementAdmin( | ||
req, | ||
targetUserKakaoId, | ||
); | ||
expect(result).toEqual([dto_agreement]); | ||
expect(svc_agreements.adminCheck).toHaveBeenCalledWith({ userId: 1 }); | ||
expect(svc_agreements.findAgreements).toHaveBeenCalledWith({ | ||
userId: targetUserKakaoId, | ||
}); | ||
}); | ||
}); | ||
describe('patchAgreement', () => { | ||
it('should patch an agreement', async () => { | ||
const req = { user: { userId: 1 } } as Request; | ||
const agreementId = 1; | ||
const patchAgreementInput: AgreementPatchRequestDto = { isAgreed: false }; | ||
const patchAgreementOutput: AgreementDto = { | ||
...dto_agreement, | ||
isAgreed: patchAgreementInput.isAgreed, | ||
}; | ||
svc_agreements.patchAgreement.mockResolvedValue(patchAgreementOutput); | ||
|
||
const result = await ctrl_agreements.patchAgreement( | ||
req, | ||
agreementId, | ||
patchAgreementInput, | ||
); | ||
expect(result).toEqual(patchAgreementOutput); | ||
expect(svc_agreements.patchAgreement).toHaveBeenCalledWith({ | ||
...patchAgreementInput, | ||
agreementId, | ||
userId: req.user.userId, | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.