diff --git a/packages/kcms/src/team/controller.ts b/packages/kcms/src/team/controller.ts index 67670e67..519cad29 100644 --- a/packages/kcms/src/team/controller.ts +++ b/packages/kcms/src/team/controller.ts @@ -1,5 +1,5 @@ import { TeamRepository } from './models/repository.js'; -import { CreateTeamService } from './service/entry.js'; +import { CreateTeamService } from './service/createTeam'; import { Result, Option } from '@mikuroxina/mini-fn'; import { FindEntryService } from './service/get.js'; import { DeleteEntryService } from './service/delete.js'; diff --git a/packages/kcms/src/team/service/entry.test.ts b/packages/kcms/src/team/service/createTeam.test.ts similarity index 68% rename from packages/kcms/src/team/service/entry.test.ts rename to packages/kcms/src/team/service/createTeam.test.ts index f013560c..a43a954d 100644 --- a/packages/kcms/src/team/service/entry.test.ts +++ b/packages/kcms/src/team/service/createTeam.test.ts @@ -2,7 +2,7 @@ import { afterEach, describe, expect, it } from 'vitest'; import { DummyRepository } from '../adaptor/dummyRepository.js'; import { Team, TeamID } from '../models/team.js'; import { Result } from '@mikuroxina/mini-fn'; -import { CreateTeamService } from './entry.js'; +import { CreateTeamService } from './createTeam'; import { TestEntryData } from '../../testData/entry.js'; import { SnowflakeIDGenerator } from '../../id/main.js'; @@ -17,7 +17,7 @@ describe('entryService', () => { repository.reset(); }); - it('エントリーできる', async () => { + it('参加登録できる', async () => { const data = TestEntryData['ElementaryMultiWalk']; const actual = await service.create({ teamName: data.getTeamName(), @@ -57,60 +57,41 @@ describe('entryService', () => { expect(result[1]).toStrictEqual(new Error('teamName Exists')); }); - it('オープン部門のメンバーは1人のみ', async () => { - const entry = Team.new({ - id: '123' as TeamID, - teamName: 'team1', - members: ['山田四十郎', '山田太郎'], - isMultiWalk: true, - category: 'Open', - }); - const actual = await service.create({ - teamName: entry.getTeamName(), - members: entry.getMembers(), - isMultiWalk: entry.getIsMultiWalk(), - category: entry.getCategory(), - }); - - expect(Result.isErr(actual)).toBe(true); - expect(actual[1]).toStrictEqual(new Error('too many members')); - }); - - it('小学生部門のメンバーは1または2人', async () => { - const entry = Team.new({ + it('メンバーが居ないチームは作れない', async () => { + const team = Team.new({ id: '123' as TeamID, teamName: 'team1', - members: ['山田四十郎', '山田太郎', '山田次郎'], + members: [], isMultiWalk: true, category: 'Elementary', }); const actual = await service.create({ - teamName: entry.getTeamName(), - members: entry.getMembers(), - isMultiWalk: entry.getIsMultiWalk(), - category: entry.getCategory(), + teamName: team.getTeamName(), + members: team.getMembers(), + isMultiWalk: team.getIsMultiWalk(), + category: team.getCategory(), }); expect(Result.isErr(actual)).toBe(true); - expect(actual[1]).toStrictEqual(new Error('too many members')); + expect(actual[1]).toStrictEqual(new Error('no member')); }); - it('メンバーが居ないチームは作れない', async () => { - const entry = Team.new({ + it('メンバーが3人以上のチームは作れない', async () => { + const team = Team.new({ id: '123' as TeamID, teamName: 'team1', - members: [], + members: ['A太郎', 'B太郎', 'C太郎'], isMultiWalk: true, category: 'Elementary', }); const actual = await service.create({ - teamName: entry.getTeamName(), - members: entry.getMembers(), - isMultiWalk: entry.getIsMultiWalk(), - category: entry.getCategory(), + teamName: team.getTeamName(), + members: team.getMembers(), + isMultiWalk: team.getIsMultiWalk(), + category: team.getCategory(), }); expect(Result.isErr(actual)).toBe(true); - expect(actual[1]).toStrictEqual(new Error('no member')); + expect(actual[1]).toStrictEqual(new Error('too many members')); }); }); diff --git a/packages/kcms/src/team/service/entry.ts b/packages/kcms/src/team/service/createTeam.ts similarity index 81% rename from packages/kcms/src/team/service/entry.ts rename to packages/kcms/src/team/service/createTeam.ts index 9999c342..4a0cacc3 100644 --- a/packages/kcms/src/team/service/entry.ts +++ b/packages/kcms/src/team/service/createTeam.ts @@ -12,6 +12,12 @@ export class CreateTeamService { this.idGenerator = idGenerator; } + /** + * チームを作成(参加登録)します\ + * - チーム名は重複できない + * - チームのメンバー数は最大2人 + * @param input {@link TeamCreateArgs} チームのデータ + */ async create( input: Omit ): Promise> { @@ -19,13 +25,6 @@ export class CreateTeamService { if (Result.isErr(id)) { return Result.err(id[1]); } - const createArgs: Omit = { - id: id[1], - teamName: input.teamName, - members: input.members, - isMultiWalk: input.isMultiWalk, - category: input.category, - }; // チーム名は重複できない if (await this.isExists(input.teamName)) { @@ -38,18 +37,18 @@ export class CreateTeamService { return Result.err(new Error('no member')); } - if (input.category === 'Open') { - // オープン部門->1人 - if (input.members.length > 1) { - return Result.err(new Error('too many members')); - } - } else { - // 小学生部門 -> 1 or 2人 - if (input.members.length > 2) { - return Result.err(new Error('too many members')); - } + // 最大は2人 + if (input.members.length > 2) { + return Result.err(new Error('too many members')); } + const createArgs: Omit = { + id: id[1], + teamName: input.teamName, + members: input.members, + isMultiWalk: input.isMultiWalk, + category: input.category, + }; const e = Team.new(createArgs); const res = await this.repository.create(e); if (Result.isErr(res)) { @@ -59,6 +58,9 @@ export class CreateTeamService { return Result.ok(res[1]); } + /** + * チーム名が存在するかを返す + */ private async isExists(teamName: string) { const res = await this.repository.findByTeamName(teamName); return Option.isSome(res);