refactor(core): Reorganize webhook related components under src/webhooks (no-changelog) (#10296)

This commit is contained in:
Tomi Turtiainen
2024-08-07 11:23:44 +03:00
committed by GitHub
parent 2a8f1753e8
commit c8d322a9ba
23 changed files with 118 additions and 104 deletions

View File

@@ -0,0 +1,81 @@
import { mock } from 'jest-mock-extended';
import { WaitingWebhooks } from '@/webhooks/WaitingWebhooks';
import { ConflictError } from '@/errors/response-errors/conflict.error';
import { NotFoundError } from '@/errors/response-errors/not-found.error';
import type { IExecutionResponse } from '@/Interfaces';
import type express from 'express';
import type { ExecutionRepository } from '@/databases/repositories/execution.repository';
import type { WaitingWebhookRequest } from '@/webhooks/webhook.types';
describe('WaitingWebhooks', () => {
const executionRepository = mock<ExecutionRepository>();
const waitingWebhooks = new WaitingWebhooks(mock(), mock(), executionRepository);
beforeEach(() => {
jest.restoreAllMocks();
});
it('should throw NotFoundError if there is no execution to resume', async () => {
/**
* Arrange
*/
executionRepository.findSingleExecution.mockResolvedValue(undefined);
/**
* Act
*/
const promise = waitingWebhooks.executeWebhook(
mock<WaitingWebhookRequest>(),
mock<express.Response>(),
);
/**
* Assert
*/
await expect(promise).rejects.toThrowError(NotFoundError);
});
it('should throw ConflictError if the execution to resume is already running', async () => {
/**
* Arrange
*/
executionRepository.findSingleExecution.mockResolvedValue(
mock<IExecutionResponse>({ status: 'running' }),
);
/**
* Act
*/
const promise = waitingWebhooks.executeWebhook(
mock<WaitingWebhookRequest>(),
mock<express.Response>(),
);
/**
* Assert
*/
await expect(promise).rejects.toThrowError(ConflictError);
});
it('should throw ConflictError if the execution to resume already finished', async () => {
/**
* Arrange
*/
executionRepository.findSingleExecution.mockResolvedValue(
mock<IExecutionResponse>({ finished: true }),
);
/**
* Act
*/
const promise = waitingWebhooks.executeWebhook(
mock<WaitingWebhookRequest>(),
mock<express.Response>(),
);
/**
* Assert
*/
await expect(promise).rejects.toThrowError(ConflictError);
});
});