-
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 #51 from DevKor-github/develop
Develop
- Loading branch information
Showing
9 changed files
with
219 additions
and
49 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
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 |
---|---|---|
@@ -1,23 +1,66 @@ | ||
version: "3.7" | ||
networks: | ||
t4y: | ||
driver: bridge | ||
blccu_network: | ||
external: true | ||
|
||
services: | ||
blccu-ecr: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
args: | ||
PLATFORM: linux/amd64 | ||
redis: | ||
image: redis:latest | ||
ports: | ||
- 3000:3000 | ||
env_file: | ||
- ./.env.prod | ||
# my-database: | ||
# image: "mysql:latest" | ||
# restart: always | ||
# env_file: | ||
# - ./.env.prod | ||
# environment: | ||
# MYSQL_DATABASE: 'mydocker' | ||
# MYSQL_ROOT_PASSWORD: 'root' | ||
# ports: | ||
# - 3306:3306 | ||
- '6379:6379' | ||
restart: always | ||
networks: | ||
- blccu_network | ||
# prometheus: | ||
# image: prom/prometheus | ||
# container_name: prometheus | ||
# volumes: | ||
# - ./prometheus/config:/etc/prometheus | ||
# - prometheus-data:/prometheus | ||
# ports: | ||
# - 9090:9090 | ||
# command: | ||
# - '--storage.tsdb.path=/prometheus' | ||
# - '--config.file=/etc/prometheus/prometheus.yaml' | ||
# restart: always | ||
# networks: | ||
# - t4y | ||
|
||
# grafana: | ||
# image: grafana/grafana | ||
# container_name: grafana | ||
# ports: | ||
# - 9000:3000 | ||
# volumes: | ||
# - grafana-data:/var/lib/grafana | ||
# - ./grafana/provisioning/:/etc/grafana/provisioning/ | ||
# restart: always | ||
# depends_on: | ||
# - prometheus | ||
# networks: | ||
# - t4y | ||
|
||
# volumes: | ||
# grafana-data: | ||
# prometheus-data: | ||
# blccu-ecr: | ||
# build: | ||
# context: . | ||
# dockerfile: Dockerfile | ||
# args: | ||
# PLATFORM: linux/amd64 | ||
# ports: | ||
# - 3000:3000 | ||
# env_file: | ||
# - ./.env.prod | ||
# my-database: | ||
# image: "mysql:latest" | ||
# restart: always | ||
# env_file: | ||
# - ./.env.prod | ||
# environment: | ||
# MYSQL_DATABASE: 'mydocker' | ||
# MYSQL_ROOT_PASSWORD: 'root' | ||
# ports: | ||
# - 3306:3306 |
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
143 changes: 143 additions & 0 deletions
143
src/APIs/agreements/__test__/agreements.service.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,143 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { AgreementsService } from '../agreements.service'; | ||
import { AgreementsRepository } from '../agreements.repository'; | ||
import { UsersValidateService } from '@/APIs/users/services/users-validate-service'; | ||
import { AgreementDto } from '../dtos/common/agreement.dto'; | ||
import { Agreement } from '../entities/agreement.entity'; | ||
import { plainToClass } from 'class-transformer'; | ||
import fs from 'fs'; | ||
import { AgreementType } from '@/common/enums/agreement-type.enum'; | ||
import { BlccuException } from '@/common/blccu-exception'; | ||
|
||
describe('AgreementsService', () => { | ||
let service: AgreementsService; | ||
let repo: AgreementsRepository; | ||
let usersValidateService: UsersValidateService; | ||
|
||
const agreementEntity: Agreement = { | ||
id: 1, | ||
user: null, | ||
userId: 1, | ||
agreementType: AgreementType.TERMS_OF_SERVICE, | ||
isAgreed: true, | ||
dateCreated: new Date(), | ||
dateUpdated: new Date(), | ||
dateDeleted: null, | ||
}; | ||
|
||
const agreementDto: AgreementDto = plainToClass( | ||
AgreementDto, | ||
agreementEntity, | ||
); | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [ | ||
AgreementsService, | ||
{ | ||
provide: AgreementsRepository, | ||
useValue: { | ||
save: jest.fn().mockResolvedValue(agreementEntity), | ||
findOne: jest.fn().mockResolvedValue(agreementEntity), | ||
find: jest.fn().mockResolvedValue([agreementEntity]), | ||
}, | ||
}, | ||
{ | ||
provide: UsersValidateService, | ||
useValue: { | ||
adminCheck: jest.fn(), | ||
}, | ||
}, | ||
], | ||
}).compile(); | ||
|
||
service = module.get<AgreementsService>(AgreementsService); | ||
repo = module.get<AgreementsRepository>(AgreementsRepository); | ||
usersValidateService = | ||
module.get<UsersValidateService>(UsersValidateService); | ||
}); | ||
|
||
it('adminCheck_ShouldCallAdminCheck_ValidUserId', async () => { | ||
const userId = 1; | ||
await service.adminCheck({ userId }); | ||
expect(usersValidateService.adminCheck).toHaveBeenCalledWith({ userId }); | ||
}); | ||
|
||
it('createAgreement_ShouldReturnAgreementDto_ValidInput', async () => { | ||
const result = await service.createAgreement({ | ||
userId: 1, | ||
agreementType: AgreementType.TERMS_OF_SERVICE, | ||
isAgreed: true, | ||
}); | ||
|
||
expect(result).toEqual(agreementDto); | ||
expect(repo.save).toHaveBeenCalledWith({ | ||
agreementType: AgreementType.TERMS_OF_SERVICE, | ||
isAgreed: true, | ||
userId: 1, | ||
}); | ||
}); | ||
|
||
it('findContract_ShouldReturnContractHtml_ValidAgreementType', async () => { | ||
const agreementType = AgreementType.TERMS_OF_SERVICE; | ||
const mockData = '<html>Contract Terms</html>'; | ||
|
||
jest.spyOn(fs.promises, 'readFile').mockResolvedValue(mockData); | ||
|
||
const result = await service.findContract({ agreementType }); | ||
|
||
expect(result).toBe(mockData); | ||
}); | ||
|
||
it('findAgreement_ShouldReturnAgreementDto_ValidAgreementId', async () => { | ||
const result = await service.findAgreement({ agreementId: 1 }); | ||
|
||
expect(result).toEqual(agreementDto); | ||
expect(repo.findOne).toHaveBeenCalledWith({ where: { id: 1 } }); | ||
}); | ||
|
||
it('existCheck_ShouldThrowBlccuException_AgreementNotFound', async () => { | ||
jest.spyOn(service, 'findAgreement').mockResolvedValue(null); | ||
|
||
await expect(service.existCheck({ agreementId: 1 })).rejects.toThrow( | ||
new BlccuException('AGREEMENT_NOT_FOUND'), | ||
); | ||
}); | ||
|
||
it('findAgreements_ShouldReturnAgreementDtoArray_ValidUserId', async () => { | ||
const result = await service.findAgreements({ userId: 1 }); | ||
|
||
expect(result).toEqual([agreementDto]); | ||
expect(repo.find).toHaveBeenCalledWith({ where: { user: { id: 1 } } }); | ||
}); | ||
|
||
it('patchAgreement_ShouldThrowBlccuException_NotTheOwner', async () => { | ||
const otherUserAgreement: Agreement = { ...agreementEntity, userId: 2 }; | ||
|
||
jest.spyOn(service, 'existCheck').mockResolvedValue(otherUserAgreement); | ||
|
||
await expect( | ||
service.patchAgreement({ | ||
userId: 1, | ||
agreementId: 1, | ||
isAgreed: true, | ||
}), | ||
).rejects.toThrow(new BlccuException('NOT_THE_OWNER')); | ||
}); | ||
|
||
it('patchAgreement_ShouldReturnUpdatedAgreement_ValidInput', async () => { | ||
const updatedAgreement: Agreement = { ...agreementEntity, isAgreed: true }; | ||
|
||
jest.spyOn(service, 'existCheck').mockResolvedValue(agreementEntity); | ||
jest.spyOn(repo, 'save').mockResolvedValue(updatedAgreement); | ||
|
||
const result = await service.patchAgreement({ | ||
userId: 1, | ||
agreementId: 1, | ||
isAgreed: true, | ||
}); | ||
|
||
expect(result).toEqual(plainToClass(AgreementDto, updatedAgreement)); | ||
expect(repo.save).toHaveBeenCalledWith(updatedAgreement); | ||
}); | ||
}); |
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
This file was deleted.
Oops, something went wrong.
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