feat: Implement execution step serializer

This commit is contained in:
Faruk AYDIN
2024-03-06 17:10:06 +01:00
parent 3a9dfe339a
commit e40d6c5ef0
3 changed files with 66 additions and 0 deletions

View File

@@ -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;

View File

@@ -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
);
});
});

View File

@@ -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;