Skip to content

Commit

Permalink
chore: fix code styles
Browse files Browse the repository at this point in the history
  • Loading branch information
laminne committed Jul 6, 2024
1 parent d9a37af commit 53f8380
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 108 deletions.
8 changes: 4 additions & 4 deletions packages/kcms/src/entry/adaptor/json.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {EntryRepository} from '../repository.js';
import {Option, Result} from '@mikuroxina/mini-fn';
import {Entry, EntryCategory, EntryID} from '../entry.js';
import {readFile, writeFile} from 'node:fs/promises';
import { EntryRepository } from '../repository.js';
import { Option, Result } from '@mikuroxina/mini-fn';
import { Entry, EntryCategory, EntryID } from '../entry.js';
import { readFile, writeFile } from 'node:fs/promises';

interface JSONData {
entry: Array<EntryJSON>;
Expand Down
8 changes: 4 additions & 4 deletions packages/kcms/src/entry/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ export class Controller {
const unwrapped = Result.unwrap(res);
return Result.ok({
id: unwrapped.getId(),
teamName: unwrapped.getTeamName(),
members: unwrapped.getMembers(),
isMultiWalk: unwrapped.getIsMultiWalk(),
category: unwrapped.getCategory(),
teamName: unwrapped.getTeamName(),
members: unwrapped.getMembers(),
isMultiWalk: unwrapped.getIsMultiWalk(),
category: unwrapped.getCategory(),
});
}

Expand Down
194 changes: 97 additions & 97 deletions packages/kcms/src/entry/service/entry.test.ts
Original file line number Diff line number Diff line change
@@ -1,116 +1,116 @@
import {afterEach, describe, expect, it} from 'vitest';
import {DummyRepository} from '../adaptor/dummyRepository.js';
import {Entry, EntryID} from '../entry.js';
import {Result} from '@mikuroxina/mini-fn';
import {EntryService} from './entry.js';
import {TestEntryData} from '../../testData/entry.js';
import {SnowflakeIDGenerator} from '../../id/main.js';
import { afterEach, describe, expect, it } from 'vitest';
import { DummyRepository } from '../adaptor/dummyRepository.js';
import { Entry, EntryID } from '../entry.js';
import { Result } from '@mikuroxina/mini-fn';
import { EntryService } from './entry.js';
import { TestEntryData } from '../../testData/entry.js';
import { SnowflakeIDGenerator } from '../../id/main.js';

describe('entryService', () => {
const repository = new DummyRepository();
const service = new EntryService(
repository,
new SnowflakeIDGenerator(1, () => BigInt(new Date().getTime()))
);
const repository = new DummyRepository();
const service = new EntryService(
repository,
new SnowflakeIDGenerator(1, () => BigInt(new Date().getTime()))
);

afterEach(() => {
repository.reset();
afterEach(() => {
repository.reset();
});

it('エントリーできる', async () => {
const data = TestEntryData['ElementaryMultiWalk'];
const actual = await service.create({
teamName: data.getTeamName(),
members: data.getMembers(),
isMultiWalk: data.getIsMultiWalk(),
category: data.getCategory(),
});

it('エントリーできる', async () => {
const data = TestEntryData['ElementaryMultiWalk'];
const actual = await service.create({
teamName: data.getTeamName(),
members: data.getMembers(),
isMultiWalk: data.getIsMultiWalk(),
category: data.getCategory(),
});
expect(Result.isOk(actual)).toBe(true);
if (Result.isErr(actual)) {
return;
}

expect(Result.isOk(actual)).toBe(true);
if (Result.isErr(actual)) {
return;
}
expect(actual[1].getMembers()).toStrictEqual(['TestTaro1']);
expect(actual[1].getTeamName()).toBe('TestTeam1');
expect(actual[1].getIsMultiWalk()).toBe(true);
expect(actual[1].getCategory()).toBe('Elementary');
});

expect(actual[1].getMembers()).toStrictEqual(['TestTaro1']);
expect(actual[1].getTeamName()).toBe('TestTeam1');
expect(actual[1].getIsMultiWalk()).toBe(true);
expect(actual[1].getCategory()).toBe('Elementary');
it('チーム名が重複するときはエラー終了する', async () => {
const data = TestEntryData['ElementaryMultiWalk'];
const existsData = TestEntryData['ElementaryMultiWalkExists'];
await service.create({
teamName: data.getTeamName(),
members: data.getMembers(),
isMultiWalk: data.getIsMultiWalk(),
category: data.getCategory(),
});

it('チーム名が重複するときはエラー終了する', async () => {
const data = TestEntryData['ElementaryMultiWalk'];
const existsData = TestEntryData['ElementaryMultiWalkExists']
await service.create({
teamName: data.getTeamName(),
members: data.getMembers(),
isMultiWalk: data.getIsMultiWalk(),
category: data.getCategory(),
});
const result = await service.create({
teamName: existsData.getTeamName(),
members: existsData.getMembers(),
isMultiWalk: existsData.getIsMultiWalk(),
category: existsData.getCategory()
});

expect(Result.isErr(result)).toBe(true);
expect(result[1]).toStrictEqual(new Error('teamName Exists'));
const result = await service.create({
teamName: existsData.getTeamName(),
members: existsData.getMembers(),
isMultiWalk: existsData.getIsMultiWalk(),
category: existsData.getCategory(),
});

it('オープン部門のメンバーは1人のみ', async () => {
const entry = Entry.new({
id: '123' as EntryID,
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(result)).toBe(true);
expect(result[1]).toStrictEqual(new Error('teamName Exists'));
});

expect(Result.isErr(actual)).toBe(true);
expect(actual[1]).toStrictEqual(new Error('too many members'));
it('オープン部門のメンバーは1人のみ', async () => {
const entry = Entry.new({
id: '123' as EntryID,
teamName: 'team1',
members: ['山田四十郎', '山田太郎'],
isMultiWalk: true,
category: 'Open',
});
const actual = await service.create({
teamName: entry.getTeamName(),
members: entry.getMembers(),
isMultiWalk: entry.getIsMultiWalk(),
category: entry.getCategory(),
});

it('小学生部門のメンバーは1または2人', async () => {
const entry = Entry.new({
id: '123' as EntryID,
teamName: 'team1',
members: ['山田四十郎', '山田太郎', '山田次郎'],
isMultiWalk: true,
category: 'Elementary',
});
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'));
});

expect(Result.isErr(actual)).toBe(true);
expect(actual[1]).toStrictEqual(new Error('too many members'));
it('小学生部門のメンバーは1または2人', async () => {
const entry = Entry.new({
id: '123' as EntryID,
teamName: 'team1',
members: ['山田四十郎', '山田太郎', '山田次郎'],
isMultiWalk: true,
category: 'Elementary',
});
const actual = await service.create({
teamName: entry.getTeamName(),
members: entry.getMembers(),
isMultiWalk: entry.getIsMultiWalk(),
category: entry.getCategory(),
});

it('メンバーが居ないチームは作れない', async () => {
const entry = Entry.new({
id: '123' as EntryID,
teamName: 'team1',
members: [],
isMultiWalk: true,
category: 'Elementary',
});
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'));
});

expect(Result.isErr(actual)).toBe(true);
expect(actual[1]).toStrictEqual(new Error('no member'));
it('メンバーが居ないチームは作れない', async () => {
const entry = Entry.new({
id: '123' as EntryID,
teamName: 'team1',
members: [],
isMultiWalk: true,
category: 'Elementary',
});
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('no member'));
});
});
8 changes: 7 additions & 1 deletion packages/kcms/src/entry/service/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ export class EntryDTO {
}

public static fromDomain(d: Entry): EntryDTO {
return new EntryDTO(d.getId(), d.getTeamName(), d.getMembers(), d.getIsMultiWalk(), d.getCategory());
return new EntryDTO(
d.getId(),
d.getTeamName(),
d.getMembers(),
d.getIsMultiWalk(),
d.getCategory()
);
}

public toToDomain(): Entry {
Expand Down
2 changes: 1 addition & 1 deletion packages/kcms/src/match/service/generateFinal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('GenerateFinal1st', () => {
Result.unwrap(actual).map((v, i) => {
expect(expected[i]).toStrictEqual({
left: v.getTeams().left!.getId(),
right: v.getTeams().right!.getId()
right: v.getTeams().right!.getId(),
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/kcms/src/match/service/generateRanking.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TournamentRank } from './generateFinal.js';
import { Result } from '@mikuroxina/mini-fn';
import {isMatchResultPair, MatchResultPair} from '../match.js';
import { isMatchResultPair, MatchResultPair } from '../match.js';
import { MatchRepository } from './repository.js';

export class GenerateRankingService {
Expand Down

0 comments on commit 53f8380

Please sign in to comment.