feat: Extend step serializers to include execution steps
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
|
import executionStepSerializer from './execution-step.js';
|
||||||
|
|
||||||
const stepSerializer = (step) => {
|
const stepSerializer = (step) => {
|
||||||
return {
|
let stepData = {
|
||||||
id: step.id,
|
id: step.id,
|
||||||
type: step.type,
|
type: step.type,
|
||||||
key: step.key,
|
key: step.key,
|
||||||
@@ -10,6 +12,14 @@ const stepSerializer = (step) => {
|
|||||||
position: step.position,
|
position: step.position,
|
||||||
parameters: step.parameters,
|
parameters: step.parameters,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (step.executionSteps?.length > 0) {
|
||||||
|
stepData.executionSteps = step.executionSteps.map((executionStep) =>
|
||||||
|
executionStepSerializer(executionStep)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return stepData;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default stepSerializer;
|
export default stepSerializer;
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
import { describe, it, expect, beforeEach } from 'vitest';
|
import { describe, it, expect, beforeEach } from 'vitest';
|
||||||
import { createStep } from '../../test/factories/step';
|
import { createStep } from '../../test/factories/step';
|
||||||
|
import { createExecutionStep } from '../../test/factories/execution-step';
|
||||||
import stepSerializer from './step';
|
import stepSerializer from './step';
|
||||||
|
import executionStepSerializer from './execution-step';
|
||||||
|
|
||||||
describe('stepSerializer', () => {
|
describe('stepSerializer', () => {
|
||||||
let step;
|
let step;
|
||||||
@@ -24,4 +26,20 @@ describe('stepSerializer', () => {
|
|||||||
|
|
||||||
expect(stepSerializer(step)).toEqual(expectedPayload);
|
expect(stepSerializer(step)).toEqual(expectedPayload);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should return step data with the execution steps', async () => {
|
||||||
|
const executionStepOne = await createExecutionStep({ stepId: step.id });
|
||||||
|
const executionStepTwo = await createExecutionStep({ stepId: step.id });
|
||||||
|
|
||||||
|
step.executionSteps = [executionStepOne, executionStepTwo];
|
||||||
|
|
||||||
|
const expectedPayload = {
|
||||||
|
executionSteps: [
|
||||||
|
executionStepSerializer(executionStepOne),
|
||||||
|
executionStepSerializer(executionStepTwo),
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(stepSerializer(step)).toMatchObject(expectedPayload);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user