From 2d8faf849eeed1088ab34abef15d2c07bcaab94a Mon Sep 17 00:00:00 2001 From: Faruk AYDIN Date: Mon, 30 Sep 2024 17:22:04 +0300 Subject: [PATCH] test: Implement execution model tests --- .../__snapshots__/execution.test.js.snap | 33 ++++++++++++ packages/backend/src/models/execution.test.js | 52 +++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 packages/backend/src/models/__snapshots__/execution.test.js.snap create mode 100644 packages/backend/src/models/execution.test.js diff --git a/packages/backend/src/models/__snapshots__/execution.test.js.snap b/packages/backend/src/models/__snapshots__/execution.test.js.snap new file mode 100644 index 00000000..ba4d99cd --- /dev/null +++ b/packages/backend/src/models/__snapshots__/execution.test.js.snap @@ -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", +} +`; diff --git a/packages/backend/src/models/execution.test.js b/packages/backend/src/models/execution.test.js new file mode 100644 index 00000000..85917441 --- /dev/null +++ b/packages/backend/src/models/execution.test.js @@ -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); + }); +});