From ca786fd80a1f2dee332842db11cdc11d3c0e6790 Mon Sep 17 00:00:00 2001 From: dahyeon Date: Sat, 25 Jul 2026 01:01:57 -0700 Subject: [PATCH] fix(dakao): hide started matches from schedule --- .../dakao/handlers/match-list.handler.spec.ts | 27 ++++++++ .../dakao/handlers/match-list.handler.ts | 2 + docs/specs/dakao-upcoming-match-list.md | 67 +++++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 docs/specs/dakao-upcoming-match-list.md diff --git a/apps/api/src/modules/dakao/handlers/match-list.handler.spec.ts b/apps/api/src/modules/dakao/handlers/match-list.handler.spec.ts index 855b25a6..4d796724 100644 --- a/apps/api/src/modules/dakao/handlers/match-list.handler.spec.ts +++ b/apps/api/src/modules/dakao/handlers/match-list.handler.spec.ts @@ -22,6 +22,33 @@ function makeHandler(params: { } describe('MatchListHandler', () => { + afterEach(() => { + jest.useRealTimers(); + }); + + it('queries only matches scheduled at or after command processing time', async () => { + const now = new Date('2026-07-25T07:30:00.000Z'); + jest.useFakeTimers().setSystemTime(now); + const communityId = objectId('111111111111111111111111'); + const list = jest.fn().mockResolvedValue([]); + const handler = makeHandler({ + matchService: { list }, + }); + + await handler.handle({ + communityId, + senderUserId: 'kakao-user-1', + senderNickname: '프리리', + }); + + expect(list).toHaveBeenCalledWith({ + communityId, + status: 'recruiting', + scheduledFrom: now, + limit: 10, + }); + }); + it('prints short codes, compact KST dates, and short links', async () => { const match = { _id: objectId('333333333333333333333333'), diff --git a/apps/api/src/modules/dakao/handlers/match-list.handler.ts b/apps/api/src/modules/dakao/handlers/match-list.handler.ts index 438c8fdc..e712ed94 100644 --- a/apps/api/src/modules/dakao/handlers/match-list.handler.ts +++ b/apps/api/src/modules/dakao/handlers/match-list.handler.ts @@ -19,9 +19,11 @@ export class MatchListHandler { senderUserId: string; senderNickname: string; }): Promise { + const scheduledFrom = new Date(); const matches = await this.matchService.list({ communityId: params.communityId, status: 'recruiting', + scheduledFrom, limit: 10, }); diff --git a/docs/specs/dakao-upcoming-match-list.md b/docs/specs/dakao-upcoming-match-list.md new file mode 100644 index 00000000..a9124011 --- /dev/null +++ b/docs/specs/dakao-upcoming-match-list.md @@ -0,0 +1,67 @@ +# Spec: Dakao Upcoming Internal Match List + +## Objective + +When a user sends `!내전 일정`, return only recruiting matches whose scheduled +start is not earlier than the command processing time. Matches that have already +started must not consume the ten-result query limit or appear in the response. + +## Approved Product Decisions + +- Capture the command processing time once before querying matches. +- Exclude `scheduledAt < now`. +- Include `scheduledAt === now` and future matches. +- Apply the boundary only to the Dakao `!내전 일정` command. +- Preserve the existing recruiting status, result limit, ordering, formatting, + short-code generation, and short-link behavior. + +## Commands + +- Focused test: + `pnpm --filter api exec jest src/modules/dakao/handlers/match-list.handler.spec.ts --runInBand` +- API lint: + `pnpm --filter api exec eslint "{src,apps,libs,test}/**/*.ts" --max-warnings=0` +- API build: `pnpm --filter api build` + +## Project Structure + +- `apps/api/src/modules/dakao/handlers/match-list.handler.ts` owns the command + query and response formatting. +- `apps/api/src/modules/dakao/handlers/match-list.handler.spec.ts` verifies the + command boundary and presentation. +- `apps/api/src/modules/match/match.service.ts` translates `scheduledFrom` into a + MongoDB `$gte` filter. + +## Code Style + +Pass the captured boundary through the existing list contract: + +```ts +const scheduledFrom = new Date(); +await matchService.list({ communityId, scheduledFrom }); +``` + +## Testing Strategy + +- Freeze the system clock in the handler unit test. +- Assert that the exact frozen time is passed as `scheduledFrom`. +- Rely on the existing `MatchService` test that verifies `scheduledFrom` becomes + `{ scheduledAt: { $gte: scheduledFrom } }`. +- Run the focused handler test, full API lint, and API build. + +## Boundaries + +- Always: filter before applying the result limit and use one captured time. +- Ask first: change ordering, statuses, limit, or response wording. +- Never: hide the requirement with an ESLint exception or filter only after the + limited database query. + +## Success Criteria + +- A match scheduled before command processing time is not queried. +- A match scheduled exactly at command processing time remains eligible. +- Existing command formatting and link tests continue to pass. + +## Open Questions + +None. -- 2.54.0