diff --git a/packages/kcms/src/match/adaptor/controller/match.ts b/packages/kcms/src/match/adaptor/controller/match.ts index c75f40c9..e92dbe3e 100644 --- a/packages/kcms/src/match/adaptor/controller/match.ts +++ b/packages/kcms/src/match/adaptor/controller/match.ts @@ -2,7 +2,7 @@ import { z } from '@hono/zod-openapi'; import { Result } from '@mikuroxina/mini-fn'; import { DepartmentType, MatchType } from 'config'; import { Team, TeamID } from '../../../team/models/team'; -import { FetchTeamService } from '../../../team/service/get'; +import { FetchTeamService } from '../../../team/service/fetchTeam'; import { MainMatch, MainMatchID } from '../../model/main'; import { PreMatch, PreMatchID } from '../../model/pre'; import { FetchRunResultService } from '../../service/fetchRunResult'; diff --git a/packages/kcms/src/match/main.ts b/packages/kcms/src/match/main.ts index b5a12c02..59e166ad 100644 --- a/packages/kcms/src/match/main.ts +++ b/packages/kcms/src/match/main.ts @@ -7,7 +7,7 @@ import { errorToCode } from '../team/adaptor/errors'; import { DummyRepository } from '../team/adaptor/repository/dummyRepository'; import { PrismaTeamRepository } from '../team/adaptor/repository/prismaRepository'; import { TeamID } from '../team/models/team'; -import { FetchTeamService } from '../team/service/get'; +import { FetchTeamService } from '../team/service/fetchTeam'; import { MatchController } from './adaptor/controller/match'; import { DummyMainMatchRepository } from './adaptor/dummy/mainMatchRepository'; import { DummyPreMatchRepository } from './adaptor/dummy/preMatchRepository'; diff --git a/packages/kcms/src/match/service/generatePre.test.ts b/packages/kcms/src/match/service/generatePre.test.ts index c0bc5635..0bf223d0 100644 --- a/packages/kcms/src/match/service/generatePre.test.ts +++ b/packages/kcms/src/match/service/generatePre.test.ts @@ -4,7 +4,7 @@ import { describe, expect, it } from 'vitest'; import { SnowflakeIDGenerator } from '../../id/main'; import { DummyRepository } from '../../team/adaptor/repository/dummyRepository'; import { TeamID } from '../../team/models/team'; -import { FetchTeamService } from '../../team/service/get'; +import { FetchTeamService } from '../../team/service/fetchTeam'; import { testTeamData } from '../../testData/entry'; import { DummyPreMatchRepository } from '../adaptor/dummy/preMatchRepository'; import { GeneratePreMatchService } from './generatePre'; diff --git a/packages/kcms/src/match/service/generatePre.ts b/packages/kcms/src/match/service/generatePre.ts index d1fd7cfb..a53e511f 100644 --- a/packages/kcms/src/match/service/generatePre.ts +++ b/packages/kcms/src/match/service/generatePre.ts @@ -2,7 +2,7 @@ import { Result } from '@mikuroxina/mini-fn'; import { config, DepartmentType } from 'config'; import { SnowflakeIDGenerator } from '../../id/main'; import { Team } from '../../team/models/team'; -import { FetchTeamService } from '../../team/service/get'; +import { FetchTeamService } from '../../team/service/fetchTeam'; import { PreMatch } from '../model/pre'; import { PreMatchRepository } from '../model/repository'; diff --git a/packages/kcms/src/team/adaptor/controller/controller.ts b/packages/kcms/src/team/adaptor/controller/controller.ts index 02d3f934..cd553069 100644 --- a/packages/kcms/src/team/adaptor/controller/controller.ts +++ b/packages/kcms/src/team/adaptor/controller/controller.ts @@ -4,7 +4,7 @@ import { TeamID } from '../../models/team'; import { CreateTeamService } from '../../service/createTeam'; import { DeleteTeamService } from '../../service/delete'; import { EntryService } from '../../service/entry'; -import { FetchTeamService } from '../../service/get'; +import { FetchTeamService } from '../../service/fetchTeam'; import { GetTeamResponseSchema, GetTeamsResponseSchema, diff --git a/packages/kcms/src/team/main.ts b/packages/kcms/src/team/main.ts index c2d026ae..532c5b3f 100644 --- a/packages/kcms/src/team/main.ts +++ b/packages/kcms/src/team/main.ts @@ -27,7 +27,7 @@ import { GetMatchService } from '../match/service/get'; import { CreateTeamService } from './service/createTeam'; import { DeleteTeamService } from './service/delete'; import { EntryService } from './service/entry'; -import { FetchTeamService } from './service/get'; +import { FetchTeamService } from './service/fetchTeam'; export const teamHandler = new OpenAPIHono(); const isProduction = process.env.NODE_ENV === 'production'; diff --git a/packages/kcms/src/team/service/fetchTeam.test.ts b/packages/kcms/src/team/service/fetchTeam.test.ts index 4f2a48a3..3bf548a1 100644 --- a/packages/kcms/src/team/service/fetchTeam.test.ts +++ b/packages/kcms/src/team/service/fetchTeam.test.ts @@ -1,29 +1,49 @@ import { Result } from '@mikuroxina/mini-fn'; -import { describe, expect, it } from 'vitest'; -import { DummyRepository } from '../adaptor/repository/dummyRepository'; -import { Team, TeamID } from '../models/team'; -import { FetchTeamService } from './fetchTeam'; +import { afterEach, beforeEach, describe, expect, it } from 'vitest'; +import { TestEntryData } from '../../testData/entry.js'; +import { DummyRepository } from '../adaptor/repository/dummyRepository.js'; +import { TeamID } from '../models/team.js'; +import { FetchTeamService } from './fetchTeam.js'; describe('FetchTeamService', () => { - const teamData = Team.new({ - id: '7549586' as TeamID, - teamName: 'かに2', - members: ['メンバー3'], - robotType: 'wheel', - departmentType: 'elementary', - }); - const repository = new DummyRepository([teamData]); + const repository = new DummyRepository(); const service = new FetchTeamService(repository); - it('チーム取得ができる', async () => { - const teamRes = await service.handle('7549586' as TeamID); - expect(Result.isErr(teamRes)).toBe(false); - const team = Result.unwrap(teamRes); - expect(team).toStrictEqual(teamData); + const testEntryData = [TestEntryData['ElementaryMultiWalk'], TestEntryData['ElementaryWheel']]; + + beforeEach(() => { + testEntryData.map((d) => repository.create(d)); + }); + afterEach(() => { + repository.reset(); + }); + + it('すべて取得できる', async () => { + const actual = await service.findAll(); + + expect(Result.isOk(actual)).toBe(true); + expect(actual[1]).toStrictEqual(testEntryData); }); - it('チームがない場合はエラーを返す', async () => { - const teamRes = await service.handle('0' as TeamID); - expect(Result.isErr(teamRes)).toBe(true); + it('チーム名で取得できる', async () => { + const actual = await service.findByTeamName(testEntryData[0].getTeamName()); + expect(Result.isOk(actual)).toBe(true); + expect(actual[1]).toStrictEqual(testEntryData[0]); + }); + + it('チームIDで取得できる', async () => { + const actual = await service.findByID(testEntryData[0].getId()); + expect(Result.isOk(actual)).toBe(true); + expect(actual[1]).toStrictEqual(testEntryData[0]); + }); + + it('存在しないときはエラーを返す', async () => { + const actual = await service.findByID('0' as TeamID); + expect(Result.isErr(actual)).toBe(true); + expect(actual[1]).toStrictEqual(new Error('Not found')); + + const actual2 = await service.findByTeamName('team0'); + expect(Result.isErr(actual2)).toBe(true); + expect(actual2[1]).toStrictEqual(new Error('Not found')); }); }); diff --git a/packages/kcms/src/team/service/fetchTeam.ts b/packages/kcms/src/team/service/fetchTeam.ts index eea970bb..92574be3 100644 --- a/packages/kcms/src/team/service/fetchTeam.ts +++ b/packages/kcms/src/team/service/fetchTeam.ts @@ -1,6 +1,6 @@ import { Option, Result } from '@mikuroxina/mini-fn'; -import { TeamRepository } from '../models/repository'; -import { Team, TeamID } from '../models/team'; +import { TeamRepository } from '../models/repository.js'; +import { Team, TeamID } from '../models/team.js'; export class FetchTeamService { private readonly repository: TeamRepository; @@ -9,11 +9,25 @@ export class FetchTeamService { this.repository = repository; } - async handle(teamID: TeamID): Promise> { - const teamRes = await this.repository.findByID(teamID); - if (Option.isNone(teamRes)) { - return Result.err(new Error('Team not found')); + async findAll(): Promise> { + return await this.repository.findAll(); + } + + async findByID(id: TeamID): Promise> { + const res = await this.repository.findByID(id); + if (Option.isNone(res)) { + return Result.err(new Error('Not found')); } - return Result.ok(Option.unwrap(teamRes)); + + return Result.ok(Option.unwrap(res)); + } + + async findByTeamName(name: string): Promise> { + const res = await this.repository.findByTeamName(name); + if (Option.isNone(res)) { + return Result.err(new Error('Not found')); + } + + return Result.ok(Option.unwrap(res)); } } diff --git a/packages/kcms/src/team/service/get.test.ts b/packages/kcms/src/team/service/get.test.ts deleted file mode 100644 index 43e5e258..00000000 --- a/packages/kcms/src/team/service/get.test.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { Result } from '@mikuroxina/mini-fn'; -import { afterEach, beforeEach, describe, expect, it } from 'vitest'; -import { TestEntryData } from '../../testData/entry.js'; -import { DummyRepository } from '../adaptor/repository/dummyRepository'; -import { TeamID } from '../models/team'; -import { FetchTeamService } from './get.js'; - -describe('getEntryService', () => { - const repository = new DummyRepository(); - const service = new FetchTeamService(repository); - - const testEntryData = [TestEntryData['ElementaryMultiWalk'], TestEntryData['ElementaryWheel']]; - - beforeEach(() => { - testEntryData.map((d) => repository.create(d)); - }); - afterEach(() => { - repository.reset(); - }); - - it('すべて取得できる', async () => { - const actual = await service.findAll(); - - expect(Result.isOk(actual)).toBe(true); - expect(actual[1]).toStrictEqual(testEntryData); - }); - - it('チーム名で取得できる', async () => { - const actual = await service.findByTeamName(testEntryData[0].getTeamName()); - expect(Result.isOk(actual)).toBe(true); - expect(actual[1]).toStrictEqual(testEntryData[0]); - }); - - it('チームIDで取得できる', async () => { - const actual = await service.findByID(testEntryData[0].getId()); - expect(Result.isOk(actual)).toBe(true); - expect(actual[1]).toStrictEqual(testEntryData[0]); - }); - - it('存在しないときはエラーを返す', async () => { - const actual = await service.findByID('0' as TeamID); - expect(Result.isErr(actual)).toBe(true); - expect(actual[1]).toStrictEqual(new Error('Not found')); - - const actual2 = await service.findByTeamName('team0'); - expect(Result.isErr(actual2)).toBe(true); - expect(actual2[1]).toStrictEqual(new Error('Not found')); - }); -}); diff --git a/packages/kcms/src/team/service/get.ts b/packages/kcms/src/team/service/get.ts deleted file mode 100644 index 92574be3..00000000 --- a/packages/kcms/src/team/service/get.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { Option, Result } from '@mikuroxina/mini-fn'; -import { TeamRepository } from '../models/repository.js'; -import { Team, TeamID } from '../models/team.js'; - -export class FetchTeamService { - private readonly repository: TeamRepository; - - constructor(repository: TeamRepository) { - this.repository = repository; - } - - async findAll(): Promise> { - return await this.repository.findAll(); - } - - async findByID(id: TeamID): Promise> { - const res = await this.repository.findByID(id); - if (Option.isNone(res)) { - return Result.err(new Error('Not found')); - } - - return Result.ok(Option.unwrap(res)); - } - - async findByTeamName(name: string): Promise> { - const res = await this.repository.findByTeamName(name); - if (Option.isNone(res)) { - return Result.err(new Error('Not found')); - } - - return Result.ok(Option.unwrap(res)); - } -}