Skip to content

Commit

Permalink
chore(dashboard): update create mock object from schema signature
Browse files Browse the repository at this point in the history
  • Loading branch information
djabarovgeorge committed Dec 8, 2024
1 parent 1ba4b5a commit 848fe15
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,10 @@ export class GeneratePreviewUsecase {
return finalPayload;
}

const examplePayloadSchema = createMockObjectFromSchema(
{
type: 'object',
properties: { payload: workflow.payloadSchema },
},
true
);
const examplePayloadSchema = createMockObjectFromSchema({
type: 'object',
properties: { payload: workflow.payloadSchema },
});

if (!examplePayloadSchema || Object.keys(examplePayloadSchema).length === 0) {
return finalPayload;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export const TestWorkflowTabs = ({ testData }: { testData: WorkflowTestDataRespo
const { workflow } = useFetchWorkflow({
workflowSlug,
});
const to = useMemo(() => createMockObjectFromSchema(testData.to, true), [testData]);
const payload = useMemo(() => createMockObjectFromSchema(testData.payload, true), [testData]);
const to = useMemo(() => createMockObjectFromSchema(testData.to), [testData]);
const payload = useMemo(() => createMockObjectFromSchema(testData.payload), [testData]);
const form = useForm<TestWorkflowFormType>({
mode: 'onSubmit',
resolver: zodResolver(buildDynamicFormSchema({ to: testData?.to ?? {} })),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import { JSONSchemaDto } from '../../dto';
*/
export function createMockObjectFromSchema(
schema: JSONSchemaDto,
safe = true,
path = '',
depth = 0
depth = 0,
safe = true
): Record<string, unknown> {
const MAX_DEPTH = 10;
if (depth >= MAX_DEPTH) {
Expand Down Expand Up @@ -48,7 +48,7 @@ export function createMockObjectFromSchema(
if (definition.default) {
acc[key] = definition.default;
} else if (definition.type === 'object' && definition.properties) {
acc[key] = createMockObjectFromSchema(definition, safe, currentPath, depth + 1);
acc[key] = createMockObjectFromSchema(definition, currentPath, depth + 1);
} else {
acc[key] = `{{${currentPath}}}`;
}
Expand Down

0 comments on commit 848fe15

Please sign in to comment.