clan-core/pkgs/webview-ui/app/mock.ts

28 lines
677 B
TypeScript
Raw Normal View History

2024-05-29 14:40:20 +00:00
import { JSONSchemaFaker } from "json-schema-faker";
import { schema } from "./api/index";
2024-06-08 13:24:13 +00:00
import { OperationNames } from "./src/api";
2024-05-29 14:40:20 +00:00
const faker = JSONSchemaFaker;
faker.option({
alwaysFakeOptionals: true,
2024-06-11 14:28:02 +00:00
useExamplesValue: true,
2024-05-29 14:40:20 +00:00
});
const getFakeResponse = (method: OperationNames, data: any) => {
const fakeData = faker.generate(schema.properties[method].properties.return);
2024-06-15 09:32:42 +00:00
const { op_key } = data;
2024-06-11 14:28:02 +00:00
if (method === "open_file") {
return {
status: "success",
data: "/path/to/clan",
2024-06-15 09:32:42 +00:00
op_key,
2024-06-11 14:28:02 +00:00
};
}
2024-06-15 09:32:42 +00:00
// @ts-expect-error: fakeData is guaranteed to always be some object
return { ...fakeData, op_key };
2024-05-29 14:40:20 +00:00
};
export { getFakeResponse };