refactor: Use static method for IncompleteStepsError

This commit is contained in:
Faruk AYDIN
2024-10-30 14:33:52 +01:00
parent d38b0f088b
commit 5bdc5aed72
2 changed files with 5 additions and 5 deletions

View File

@@ -123,7 +123,7 @@ class Flow extends Base {
return lastExecutions.map((execution) => execution.internalId); return lastExecutions.map((execution) => execution.internalId);
} }
get IncompleteStepsError() { static get IncompleteStepsError() {
return new ValidationError({ return new ValidationError({
data: { data: {
flow: [ flow: [
@@ -310,7 +310,7 @@ class Flow extends Base {
const triggerStep = await this.getTriggerStep(); const triggerStep = await this.getTriggerStep();
if (triggerStep.status === 'incomplete') { if (triggerStep.status === 'incomplete') {
throw this.IncompleteStepsError; throw Flow.IncompleteStepsError;
} }
const trigger = await triggerStep.getTriggerCommand(); const trigger = await triggerStep.getTriggerCommand();

View File

@@ -142,6 +142,7 @@ describe('Flow model', () => {
describe('lastInternalIds', () => { describe('lastInternalIds', () => {
it('should return last internal IDs', async () => { it('should return last internal IDs', async () => {
const flow = await createFlow(); const flow = await createFlow();
const internalIds = [ const internalIds = [
await createExecution({ flowId: flow.id }), await createExecution({ flowId: flow.id }),
await createExecution({ flowId: flow.id }), await createExecution({ flowId: flow.id }),
@@ -155,6 +156,7 @@ describe('Flow model', () => {
const flow = new Flow(); const flow = new Flow();
const limitSpy = vi.fn().mockResolvedValue([]); const limitSpy = vi.fn().mockResolvedValue([]);
vi.spyOn(flow, '$relatedQuery').mockReturnValue({ vi.spyOn(flow, '$relatedQuery').mockReturnValue({
select: vi.fn().mockReturnThis(), select: vi.fn().mockReturnThis(),
orderBy: vi.fn().mockReturnThis(), orderBy: vi.fn().mockReturnThis(),
@@ -168,10 +170,8 @@ describe('Flow model', () => {
}); });
it('IncompleteStepsError should return validation error for incomplete steps', () => { it('IncompleteStepsError should return validation error for incomplete steps', () => {
const flow = new Flow();
expect(() => { expect(() => {
throw flow.IncompleteStepsError; throw Flow.IncompleteStepsError;
}).toThrowError( }).toThrowError(
'flow: All steps should be completed before updating flow status!' 'flow: All steps should be completed before updating flow status!'
); );