From b94831c1015d697b3a3e3dffe4ee195527b8264a Mon Sep 17 00:00:00 2001 From: Coalery Date: Wed, 9 Oct 2024 16:32:50 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=8F=84=EC=96=B4=EB=9D=BD=20=EB=B9=84?= =?UTF-8?q?=EB=B0=80=EB=B2=88=ED=98=B8=20=EC=A1=B0=ED=9A=8C=20=EC=BF=BC?= =?UTF-8?q?=EB=A6=AC=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../infraBlue/query/ICacheQuery.ts | 7 +++ .../GetDoorLockPasswordQuery.ts | 3 ++ .../GetDoorLockPasswordQueryHandler.spec.ts | 53 +++++++++++++++++++ .../GetDoorLockPasswordQueryHandler.ts | 25 +++++++++ .../GetDoorLockPasswordQueryResult.ts | 7 +++ .../query/view/DoorLockPasswordView.ts | 5 ++ 6 files changed, 100 insertions(+) create mode 100644 src/app/application/infraBlue/query/ICacheQuery.ts create mode 100644 src/app/application/infraBlue/query/getDoorLockPassword/GetDoorLockPasswordQuery.ts create mode 100644 src/app/application/infraBlue/query/getDoorLockPassword/GetDoorLockPasswordQueryHandler.spec.ts create mode 100644 src/app/application/infraBlue/query/getDoorLockPassword/GetDoorLockPasswordQueryHandler.ts create mode 100644 src/app/application/infraBlue/query/getDoorLockPassword/GetDoorLockPasswordQueryResult.ts create mode 100644 src/app/application/infraBlue/query/view/DoorLockPasswordView.ts 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; +}