test: Implement execution model tests

This commit is contained in:
Faruk AYDIN
2024-09-30 17:22:04 +03:00
parent c9de9fa185
commit 2d8faf849e
2 changed files with 85 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`Execution model > jsonSchema should have correct validations 1`] = `
{
"properties": {
"createdAt": {
"type": "string",
},
"deletedAt": {
"type": "string",
},
"flowId": {
"format": "uuid",
"type": "string",
},
"id": {
"format": "uuid",
"type": "string",
},
"internalId": {
"type": "string",
},
"testRun": {
"default": false,
"type": "boolean",
},
"updatedAt": {
"type": "string",
},
},
"type": "object",
}
`;

View File

@@ -0,0 +1,52 @@
import { vi, describe, it, expect } from 'vitest';
import Execution from './execution';
import ExecutionStep from './execution-step';
import Flow from './flow';
import Base from './base';
import Telemetry from '../helpers/telemetry/index';
import { createExecution } from '../../test/factories/execution';
describe('Execution model', () => {
it('tableName should return correct name', () => {
expect(Execution.tableName).toBe('executions');
});
it('jsonSchema should have correct validations', () => {
expect(Execution.jsonSchema).toMatchSnapshot();
});
it('relationMappings should return correct associations', () => {
const relationMappings = Execution.relationMappings();
const expectedRelations = {
executionSteps: {
join: {
from: 'executions.id',
to: 'execution_steps.execution_id',
},
modelClass: ExecutionStep,
relation: Base.HasManyRelation,
},
flow: {
join: {
from: 'executions.flow_id',
to: 'flows.id',
},
modelClass: Flow,
relation: Base.BelongsToOneRelation,
},
};
expect(relationMappings).toStrictEqual(expectedRelations);
});
it('$afterInsert should call Telemetry.executionCreated', async () => {
const telemetryExecutionCreatedSpy = vi
.spyOn(Telemetry, 'executionCreated')
.mockImplementation(() => {});
const execution = await createExecution();
expect(telemetryExecutionCreatedSpy).toHaveBeenCalledWith(execution);
});
});