diff --git a/src/app/application/infraBlue/query/ICacheQuery.ts b/src/app/application/infraBlue/query/ICacheQuery.ts new file mode 100644 index 0000000..5ab87aa --- /dev/null +++ b/src/app/application/infraBlue/query/ICacheQuery.ts @@ -0,0 +1,7 @@ +import { DoorLockPasswordView } from '@khlug/app/application/infraBlue/query/view/DoorLockPasswordView'; + +export const CacheQueryToken = Symbol('CacheQuery'); + +export interface ICacheQuery { + getDoorLockPassword: () => Promise; +} diff --git a/src/app/application/infraBlue/query/getDoorLockPassword/GetDoorLockPasswordQuery.ts b/src/app/application/infraBlue/query/getDoorLockPassword/GetDoorLockPasswordQuery.ts new file mode 100644 index 0000000..37a3561 --- /dev/null +++ b/src/app/application/infraBlue/query/getDoorLockPassword/GetDoorLockPasswordQuery.ts @@ -0,0 +1,3 @@ +import { IQuery } from '@nestjs/cqrs'; + +export class GetDoorLockPasswordQuery implements IQuery {} diff --git a/src/app/application/infraBlue/query/getDoorLockPassword/GetDoorLockPasswordQueryHandler.spec.ts b/src/app/application/infraBlue/query/getDoorLockPassword/GetDoorLockPasswordQueryHandler.spec.ts new file mode 100644 index 0000000..00fc972 --- /dev/null +++ b/src/app/application/infraBlue/query/getDoorLockPassword/GetDoorLockPasswordQueryHandler.spec.ts @@ -0,0 +1,53 @@ +import { Test } from '@nestjs/testing'; +import { advanceTo, clear } from 'jest-date-mock'; + +import { GetDoorLockPasswordQueryHandler } from '@khlug/app/application/infraBlue/query/getDoorLockPassword/GetDoorLockPasswordQueryHandler'; +import { GetDoorLockPasswordQueryResult } from '@khlug/app/application/infraBlue/query/getDoorLockPassword/GetDoorLockPasswordQueryResult'; +import { + CacheQueryToken, + ICacheQuery, +} from '@khlug/app/application/infraBlue/query/ICacheQuery'; +import { DoorLockPasswordView } from '@khlug/app/application/infraBlue/query/view/DoorLockPasswordView'; + +describe('GetDoorLockPasswordQueryHandler', () => { + let handler: GetDoorLockPasswordQueryHandler; + let cacheQuery: jest.Mocked; + + beforeAll(() => advanceTo(new Date())); + + beforeEach(async () => { + advanceTo(new Date()); + + const testModule = await Test.createTestingModule({ + providers: [ + GetDoorLockPasswordQueryHandler, + { + provide: CacheQueryToken, + useValue: { getDoorLockPassword: jest.fn() }, + }, + ], + }).compile(); + + handler = testModule.get(GetDoorLockPasswordQueryHandler); + cacheQuery = testModule.get(CacheQueryToken); + }); + + afterEach(() => clear()); + + describe('execute', () => { + test('도어락 비밀번호 뷰를 반환해야 한다', async () => { + const view: DoorLockPasswordView = { + master: '1234', + forJajudy: '2345', + forFacilityTeam: '3456', + }; + + cacheQuery.getDoorLockPassword.mockResolvedValue(view); + + const result = await handler.execute(); + const expected = new GetDoorLockPasswordQueryResult(view); + + expect(result).toEqual(expected); + }); + }); +}); diff --git a/src/app/application/infraBlue/query/getDoorLockPassword/GetDoorLockPasswordQueryHandler.ts b/src/app/application/infraBlue/query/getDoorLockPassword/GetDoorLockPasswordQueryHandler.ts new file mode 100644 index 0000000..ac62a1a --- /dev/null +++ b/src/app/application/infraBlue/query/getDoorLockPassword/GetDoorLockPasswordQueryHandler.ts @@ -0,0 +1,25 @@ +import { Inject } from '@nestjs/common'; +import { IQueryHandler, QueryHandler } from '@nestjs/cqrs'; + +import { GetDoorLockPasswordQuery } from '@khlug/app/application/infraBlue/query/getDoorLockPassword/GetDoorLockPasswordQuery'; +import { GetDoorLockPasswordQueryResult } from '@khlug/app/application/infraBlue/query/getDoorLockPassword/GetDoorLockPasswordQueryResult'; +import { + CacheQueryToken, + ICacheQuery, +} from '@khlug/app/application/infraBlue/query/ICacheQuery'; + +@QueryHandler(GetDoorLockPasswordQuery) +export class GetDoorLockPasswordQueryHandler + implements + IQueryHandler +{ + constructor( + @Inject(CacheQueryToken) + private readonly cacheQuery: ICacheQuery, + ) {} + + async execute(): Promise { + const doorLockPasswordView = await this.cacheQuery.getDoorLockPassword(); + return new GetDoorLockPasswordQueryResult(doorLockPasswordView); + } +} diff --git a/src/app/application/infraBlue/query/getDoorLockPassword/GetDoorLockPasswordQueryResult.ts b/src/app/application/infraBlue/query/getDoorLockPassword/GetDoorLockPasswordQueryResult.ts new file mode 100644 index 0000000..716c9d0 --- /dev/null +++ b/src/app/application/infraBlue/query/getDoorLockPassword/GetDoorLockPasswordQueryResult.ts @@ -0,0 +1,7 @@ +import { IQueryResult } from '@nestjs/cqrs'; + +import { DoorLockPasswordView } from '@khlug/app/application/infraBlue/query/view/DoorLockPasswordView'; + +export class GetDoorLockPasswordQueryResult implements IQueryResult { + constructor(readonly view: DoorLockPasswordView) {} +} diff --git a/src/app/application/infraBlue/query/view/DoorLockPasswordView.ts b/src/app/application/infraBlue/query/view/DoorLockPasswordView.ts new file mode 100644 index 0000000..9986346 --- /dev/null +++ b/src/app/application/infraBlue/query/view/DoorLockPasswordView.ts @@ -0,0 +1,5 @@ +export interface DoorLockPasswordView { + master: string; + forJajudy: string; + forFacilityTeam: string; +}