feat: Implement execution step serializer
This commit is contained in:
21
packages/backend/src/serializers/execution-step.js
Normal file
21
packages/backend/src/serializers/execution-step.js
Normal 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;
|
43
packages/backend/src/serializers/execution-step.test.js
Normal file
43
packages/backend/src/serializers/execution-step.test.js
Normal 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
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
@@ -10,6 +10,7 @@ import authSerializer from './auth.js';
|
|||||||
import triggerSerializer from './trigger.js';
|
import triggerSerializer from './trigger.js';
|
||||||
import actionSerializer from './action.js';
|
import actionSerializer from './action.js';
|
||||||
import executionSerializer from './execution.js';
|
import executionSerializer from './execution.js';
|
||||||
|
import executionStepSerializer from './execution-step.js';
|
||||||
|
|
||||||
const serializers = {
|
const serializers = {
|
||||||
User: userSerializer,
|
User: userSerializer,
|
||||||
@@ -24,6 +25,7 @@ const serializers = {
|
|||||||
Trigger: triggerSerializer,
|
Trigger: triggerSerializer,
|
||||||
Action: actionSerializer,
|
Action: actionSerializer,
|
||||||
Execution: executionSerializer,
|
Execution: executionSerializer,
|
||||||
|
ExecutionStep: executionStepSerializer,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default serializers;
|
export default serializers;
|
||||||
|
Reference in New Issue
Block a user