Skip to content

Commit

Permalink
Merge branch 'main' into EngineInfoManagerのリファクタリング
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiroshiba authored Nov 7, 2024
2 parents d8013ae + 4689cf8 commit e903075
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 43 deletions.
43 changes: 21 additions & 22 deletions src/domain/defaultEngine/latetDefaultEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,46 @@

import { z } from "zod";

/** パッケージ(vvppやvvppp1ファイル)ごとのスキーマ */
const defaultEnginePackageSchema = z.object({
url: z.string(),
name: z.string(),
size: z.number(),
hash: z.string().optional(),
});

/** デバイスごとのスキーマ */
const defaultEngineDeviceSchema = z.object({
/** パッケージ情報のスキーマ */
const engineVariantSchema = z.object({
version: z.string(),
packages: z.array(defaultEnginePackageSchema),
packages: z
.object({
url: z.string(),
name: z.string(),
size: z.number(),
hash: z.string().optional(),
})
.array(),
});

/** デフォルトエンジンの更新情報のスキーマ */
const defaultEngineInfosSchema = z.object({
/** デフォルトエンジンの最新情報のスキーマ */
const latestDefaultEngineInfoSchema = z.object({
formatVersion: z.number(),
windows: z.object({
x64: z.object({
CPU: defaultEngineDeviceSchema,
"GPU/CPU": defaultEngineDeviceSchema,
CPU: engineVariantSchema,
"GPU/CPU": engineVariantSchema,
}),
}),
macos: z.object({
x64: z.object({
CPU: defaultEngineDeviceSchema,
CPU: engineVariantSchema,
}),
arm64: z.object({
CPU: defaultEngineDeviceSchema,
CPU: engineVariantSchema,
}),
}),
linux: z.object({
x64: z.object({
CPU: defaultEngineDeviceSchema,
"GPU/CPU": defaultEngineDeviceSchema,
CPU: engineVariantSchema,
"GPU/CPU": engineVariantSchema,
}),
}),
});

/** デフォルトエンジンの更新情報を取得する */
export const fetchDefaultEngineInfos = async (url: string) => {
/** デフォルトエンジンの最新情報を取得する */
export const fetchLatestDefaultEngineInfo = async (url: string) => {
const response = await fetch(url);
return defaultEngineInfosSchema.parse(await response.json());
return latestDefaultEngineInfoSchema.parse(await response.json());
};
21 changes: 0 additions & 21 deletions tests/unit/domain/defaultEngine/defaultEngine.node.spec.ts

This file was deleted.

16 changes: 16 additions & 0 deletions tests/unit/domain/defaultEngine/latetDefaultEngine.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import latestDefaultEngineInfos from "./latestDefaultEngineInfos.json";
import { fetchLatestDefaultEngineInfo } from "@/domain/defaultEngine/latetDefaultEngine";

test("fetchLatestDefaultEngineInfo", async () => {
// テスト用のjsonファイルでfetchをモックする
// 元ファイルは https://raw.githubusercontent.com/VOICEVOX/voicevox_blog/master/src/generateLatestDefaultEngineInfos.ts
const spy = vi
.spyOn(global, "fetch")
.mockResolvedValue(new Response(JSON.stringify(latestDefaultEngineInfos)));

// 読み込めることを確認
const infos = await fetchLatestDefaultEngineInfo("https://example.com/");
expect(infos.formatVersion).toBe(1);

spy.mockRestore();
});

0 comments on commit e903075

Please sign in to comment.