diff --git a/packages/backend/src/serializers/execution-step.js b/packages/backend/src/serializers/execution-step.js new file mode 100644 index 00000000..52d7a409 --- /dev/null +++ b/packages/backend/src/serializers/execution-step.js @@ -0,0 +1,21 @@ +import stepSerializer from './step.js'; + +const executionStepSerializer = (executionStep) => { + let executionStepData = { + id: executionStep.id, + dataIn: executionStep.dataIn, + dataOut: executionStep.dataOut, + errorDetails: executionStep.errorDetails, + status: executionStep.status, + createdAt: executionStep.createdAt.getTime(), + updatedAt: executionStep.updatedAt.getTime(), + }; + + if (executionStep.step) { + executionStepData.step = stepSerializer(executionStep.step); + } + + return executionStepData; +}; + +export default executionStepSerializer; diff --git a/packages/backend/src/serializers/execution-step.test.js b/packages/backend/src/serializers/execution-step.test.js new file mode 100644 index 00000000..037ccbcd --- /dev/null +++ b/packages/backend/src/serializers/execution-step.test.js @@ -0,0 +1,43 @@ +import { describe, it, expect, beforeEach } from 'vitest'; +import executionStepSerializer from './execution-step'; +import stepSerializer from './step'; +import { createExecutionStep } from '../../test/factories/execution-step'; +import { createStep } from '../../test/factories/step'; + +describe('executionStepSerializer', () => { + let executionStep, step; + + beforeEach(async () => { + step = await createStep(); + + executionStep = await createExecutionStep({ + stepId: step.id, + }); + }); + + it('should return the execution step data', async () => { + const expectedPayload = { + id: executionStep.id, + dataIn: executionStep.dataIn, + dataOut: executionStep.dataOut, + errorDetails: executionStep.errorDetails, + status: executionStep.status, + createdAt: executionStep.createdAt.getTime(), + updatedAt: executionStep.updatedAt.getTime(), + }; + + expect(executionStepSerializer(executionStep)).toEqual(expectedPayload); + }); + + it('should return the execution step data with the step', async () => { + executionStep.step = step; + + const expectedPayload = { + step: stepSerializer(step), + }; + + expect(executionStepSerializer(executionStep)).toMatchObject( + expectedPayload + ); + }); +}); diff --git a/packages/backend/src/serializers/index.js b/packages/backend/src/serializers/index.js index 4e42b160..c35be112 100644 --- a/packages/backend/src/serializers/index.js +++ b/packages/backend/src/serializers/index.js @@ -10,6 +10,7 @@ import authSerializer from './auth.js'; import triggerSerializer from './trigger.js'; import actionSerializer from './action.js'; import executionSerializer from './execution.js'; +import executionStepSerializer from './execution-step.js'; const serializers = { User: userSerializer, @@ -24,6 +25,7 @@ const serializers = { Trigger: triggerSerializer, Action: actionSerializer, Execution: executionSerializer, + ExecutionStep: executionStepSerializer, }; export default serializers;