Skip to content

Commit

Permalink
feat:テストの追加
Browse files Browse the repository at this point in the history
  • Loading branch information
speak-mentaiko committed Oct 21, 2024
1 parent db75b74 commit 92239f2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
27 changes: 24 additions & 3 deletions packages/kcms/src/team/service/entry.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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());

Expand All @@ -29,4 +34,20 @@ describe('EntryService', () => {
expect(Option.isNone(res)).toBe(false);
expect(Option.unwrap(res).getIsEntered()).toBe(false);

Check failure on line 35 in packages/kcms/src/team/service/entry.test.ts

View workflow job for this annotation

GitHub Actions / Build & Check (backend)

src/team/service/entry.test.ts > EntryService > エントリーをキャンセルできる

AssertionError: expected true to be false // Object.is equality - Expected + Received - false + true ❯ src/team/service/entry.test.ts:35:47
});

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);
});
});
8 changes: 4 additions & 4 deletions packages/kcms/src/team/service/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand All @@ -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'));
Expand Down

0 comments on commit 92239f2

Please sign in to comment.