This commit is contained in:
tamaina
2023-05-22 04:50:18 +00:00
parent e689dcdd73
commit 86f4e206f4
10 changed files with 135 additions and 88 deletions

View File

@@ -1,5 +1,31 @@
import { enableFetchMocks } from 'jest-fetch-mock';
import { APIClient, isAPIError } from '../src/api';
import Ajv from 'ajv';
import { endpoints, getEndpointSchema } from '../src/endpoints';
import { Endpoints } from '@/endpoints.types';
describe('schemas', () => {
describe.each(Object.keys(endpoints))('validate schema of %s', async (key) => {
const ajv = new Ajv({
useDefaults: true,
});
ajv.addFormat('misskey:id', /^[a-zA-Z0-9]+$/);
const endpoint = (endpoints as any)[key] as unknown as Endpoints[keyof Endpoints];
test('each schemas', async () => {
for (const def of endpoint.defines) {
if (def.res === undefined) continue;
ajv.compile(def.req);
}
});
test('jointed schema (oneOf)', () => {
const req = getEndpointSchema('req', key as keyof Endpoints);
if (req) ajv.compile(req);
});
});
});
enableFetchMocks();

View File

@@ -0,0 +1,42 @@
{
"compilerOptions": {
"allowJs": true,
"noEmitOnError": false,
"noImplicitAny": true,
"noImplicitReturns": true,
"noUnusedParameters": false,
"noUnusedLocals": true,
"noFallthroughCasesInSwitch": true,
"declaration": false,
"sourceMap": true,
"target": "es2021",
"module": "es2020",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"removeComments": false,
"noLib": false,
"strict": true,
"strictNullChecks": true,
"strictPropertyInitialization": false,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"resolveJsonModule": true,
"isolatedModules": true,
"baseUrl": "./",
"paths": {
"@/*": ["../src/*"]
},
"typeRoots": [
"../node_modules/@types",
"../src/@types"
],
"lib": [
"esnext"
],
"types": ["jest", "node"]
},
"compileOnSave": false,
"include": [
"./**/*.ts",
]
}