Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 도어락 비밀번호 조회 쿼리 구현 #68

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/app/application/infraBlue/query/ICacheQuery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { DoorLockPasswordView } from '@khlug/app/application/infraBlue/query/view/DoorLockPasswordView';

export const CacheQueryToken = Symbol('CacheQuery');

export interface ICacheQuery {
getDoorLockPassword: () => Promise<DoorLockPasswordView>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { IQuery } from '@nestjs/cqrs';

export class GetDoorLockPasswordQuery implements IQuery {}
Original file line number Diff line number Diff line change
@@ -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<ICacheQuery>;

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);
});
});
});
Original file line number Diff line number Diff line change
@@ -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<GetDoorLockPasswordQuery, GetDoorLockPasswordQueryResult>
{
constructor(
@Inject(CacheQueryToken)
private readonly cacheQuery: ICacheQuery,
) {}

async execute(): Promise<GetDoorLockPasswordQueryResult> {
const doorLockPasswordView = await this.cacheQuery.getDoorLockPassword();
return new GetDoorLockPasswordQueryResult(doorLockPasswordView);
}
}
Original file line number Diff line number Diff line change
@@ -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) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface DoorLockPasswordView {
master: string;
forJajudy: string;
forFacilityTeam: string;
}
Loading