test(step): write tests for isTrigger, isAction, getWebhookUrl

This commit is contained in:
Ali BARIN
2024-11-01 12:38:09 +00:00
parent 1cb5b780d2
commit 87bfff07db
2 changed files with 57 additions and 18 deletions

View File

@@ -93,6 +93,14 @@ class Step extends Base {
return `${appConfig.baseUrl}/apps/${this.appKey}/assets/favicon.svg`; return `${appConfig.baseUrl}/apps/${this.appKey}/assets/favicon.svg`;
} }
get isTrigger() {
return this.type === 'trigger';
}
get isAction() {
return this.type === 'action';
}
async computeWebhookPath() { async computeWebhookPath() {
if (this.type === 'action') return null; if (this.type === 'action') return null;
@@ -135,24 +143,6 @@ class Step extends Base {
return webhookUrl; return webhookUrl;
} }
async $afterInsert(queryContext) {
await super.$afterInsert(queryContext);
Telemetry.stepCreated(this);
}
async $afterUpdate(opt, queryContext) {
await super.$afterUpdate(opt, queryContext);
Telemetry.stepUpdated(this);
}
get isTrigger() {
return this.type === 'trigger';
}
get isAction() {
return this.type === 'action';
}
async getApp() { async getApp() {
if (!this.appKey) return null; if (!this.appKey) return null;
@@ -367,6 +357,16 @@ class Step extends Base {
return updatedStep; return updatedStep;
} }
async $afterInsert(queryContext) {
await super.$afterInsert(queryContext);
Telemetry.stepCreated(this);
}
async $afterUpdate(opt, queryContext) {
await super.$afterUpdate(opt, queryContext);
Telemetry.stepUpdated(this);
}
} }
export default Step; export default Step;

View File

@@ -126,4 +126,43 @@ describe('Step model', () => {
expect(step.iconUrl).toBe(null); expect(step.iconUrl).toBe(null);
}); });
}); });
it('isTrigger should return true when step type is trigger', () => {
const step = new Step();
step.type = 'trigger';
expect(step.isTrigger).toBe(true);
});
it('isAction should return true when step type is action', () => {
const step = new Step();
step.type = 'action';
expect(step.isAction).toBe(true);
});
describe.todo('computeWebhookPath');
describe('getWebhookUrl', () => {
it('should return absolute webhook URL when step type is trigger', async () => {
const step = new Step();
step.type = 'trigger';
vi.spyOn(step, 'computeWebhookPath').mockResolvedValue('/webhook-path');
vi.spyOn(appConfig, 'webhookUrl', 'get').mockReturnValue(
'https://automatisch.io'
);
expect(await step.getWebhookUrl()).toBe(
'https://automatisch.io/webhook-path'
);
});
it('should return undefined when step type is action', async () => {
const step = new Step();
step.type = 'action';
expect(await step.getWebhookUrl()).toBe(undefined);
});
});
}); });