Update validate-json.test.ts
This commit is contained in:
parent
da16da1496
commit
23add33145
@ -4,17 +4,7 @@ import path from "path";
|
|||||||
import { ScriptSchema, type Script } from "@/app/json-editor/_schemas/schemas";
|
import { ScriptSchema, type Script } from "@/app/json-editor/_schemas/schemas";
|
||||||
import { Metadata } from "@/lib/types";
|
import { Metadata } from "@/lib/types";
|
||||||
|
|
||||||
const publicJsonPath = path.join(process.cwd(), 'public/json');
|
const jsonDir = "public/json";
|
||||||
const getJsonDirectory = async () => {
|
|
||||||
if (!(await fs.stat(publicJsonPath).catch(() => null))) {
|
|
||||||
throw new Error(`JSON path file not found: ${publicJsonPath}`);
|
|
||||||
}
|
|
||||||
const jsonPath = (await fs.readFile(publicJsonPath, "utf-8")).trim();
|
|
||||||
return path.resolve(process.cwd(), jsonPath);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
const jsonDir = await getJsonDirectory();
|
|
||||||
const metadataFileName = "metadata.json";
|
const metadataFileName = "metadata.json";
|
||||||
const encoding = "utf-8";
|
const encoding = "utf-8";
|
||||||
|
|
||||||
@ -25,7 +15,7 @@ describe.each(fileNames)("%s", async (fileName) => {
|
|||||||
let script: Script;
|
let script: Script;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const filePath = path.resolve(jsonDir, fileName);
|
const filePath = path.resolve(jsonDir, fileName);
|
||||||
const fileContent = await fs.readFile(filePath, encoding)
|
const fileContent = await fs.readFile(filePath, encoding)
|
||||||
script = JSON.parse(fileContent);
|
script = JSON.parse(fileContent);
|
||||||
})
|
})
|
||||||
@ -46,7 +36,7 @@ describe(`${metadataFileName}`, async () => {
|
|||||||
let metadata: Metadata;
|
let metadata: Metadata;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const filePath = path.resolve(jsonDir, metadataFileName);
|
const filePath = path.resolve(jsonDir, metadataFileName);
|
||||||
const fileContent = await fs.readFile(filePath, encoding)
|
const fileContent = await fs.readFile(filePath, encoding)
|
||||||
metadata = JSON.parse(fileContent);
|
metadata = JSON.parse(fileContent);
|
||||||
})
|
})
|
||||||
@ -55,9 +45,9 @@ describe(`${metadataFileName}`, async () => {
|
|||||||
// TODO: create zod schema for metadata. Move zod schemas to /lib/types.ts
|
// TODO: create zod schema for metadata. Move zod schemas to /lib/types.ts
|
||||||
assert(metadata.categories.length > 0);
|
assert(metadata.categories.length > 0);
|
||||||
metadata.categories.forEach((category) => {
|
metadata.categories.forEach((category) => {
|
||||||
assert.isString(category.name)
|
assert.isString(category.name)
|
||||||
assert.isNumber(category.id)
|
assert.isNumber(category.id)
|
||||||
assert.isNumber(category.sort_order)
|
assert.isNumber(category.sort_order)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user