diff --git a/packages/kcms/src/team/service/entry.test.ts b/packages/kcms/src/team/service/entry.test.ts index f14e0b5e..6c0b449b 100644 --- a/packages/kcms/src/team/service/entry.test.ts +++ b/packages/kcms/src/team/service/entry.test.ts @@ -1,5 +1,5 @@ import { Option } from '@mikuroxina/mini-fn'; -import { describe, expect, it } from 'vitest'; +import { beforeEach, describe, expect, it } from 'vitest'; import { DummyMainMatchRepository } from '../../match/adaptor/dummy/mainMatchRepository'; import { DummyPreMatchRepository } from '../../match/adaptor/dummy/preMatchRepository'; import { GetMatchService } from '../../match/service/get'; @@ -9,11 +9,16 @@ import { EntryService } from './entry'; describe('EntryService', () => { const teamRepository = new DummyRepository([TestEntryData.NotEntered, TestEntryData.Entered]); - const preMatchRepository = new DummyPreMatchRepository(); - const mainMatchRepository = new DummyMainMatchRepository(); + const preMatchRepository = new DummyPreMatchRepository(undefined); + const mainMatchRepository = new DummyMainMatchRepository(undefined); const getMatchService = new GetMatchService(preMatchRepository, mainMatchRepository); const service = new EntryService(teamRepository, getMatchService); + beforeEach(() => { + preMatchRepository.clear([]); + mainMatchRepository.clear([]); + }); + it('エントリーできる', async () => { await service.enter(TestEntryData.NotEntered.getId()); @@ -29,4 +34,20 @@ describe('EntryService', () => { expect(Option.isNone(res)).toBe(false); expect(Option.unwrap(res).getIsEntered()).toBe(false); }); + + it('試合表生成後はエントリーできない', async () => { + await service.enter(TestEntryData.NotEntered.getId()); + + const res = await teamRepository.findByID(TestEntryData.NotEntered.getId()); + expect(Option.isNone(res)).toBe(false); + expect(Option.unwrap(res).getIsEntered()).toBe(false); + }); + + it('試合表生成後はエントリーをキャンセルできない', async () => { + await service.cancel(TestEntryData.Entered.getId()); + + const res = await teamRepository.findByID(TestEntryData.Entered.getId()); + expect(Option.isNone(res)).toBe(false); + expect(Option.unwrap(res).getIsEntered()).toBe(true); + }); }); diff --git a/packages/kcms/src/team/service/entry.ts b/packages/kcms/src/team/service/entry.ts index 7e98590f..86fbca33 100644 --- a/packages/kcms/src/team/service/entry.ts +++ b/packages/kcms/src/team/service/entry.ts @@ -21,8 +21,8 @@ export class EntryService { const teamRes = await this.teamRepository.findByID(teamID); const matchRes = await this.preMatch.findAllPreMatch(); - if (!Result.isErr(matchRes)) { - return Result.err(new Error('Cannot enter now')); + if (Result.isOk(matchRes) && matchRes.length > 0) { + return Result.err(new Error('modify entry')); } if (Option.isNone(teamRes)) { return Result.err(new Error('Team not found')); @@ -46,8 +46,8 @@ export class EntryService { const teamRes = await this.teamRepository.findByID(teamID); const matchRes = await this.preMatch.findAllPreMatch(); - if (!Result.isErr(matchRes)) { - return Result.err(new Error('Cannot enter now')); + if (Result.isOk(matchRes) && matchRes.length > 0) { + return Result.err(new Error('modify entry')); } if (Option.isNone(teamRes)) { return Result.err(new Error('Team not found'));