Merge pull request #2161 from automatisch/aut-1349-3
test(step): write tests for isTrigger, isAction, getWebhookUrl
This commit is contained in:
@@ -93,6 +93,14 @@ class Step extends Base {
|
||||
return `${appConfig.baseUrl}/apps/${this.appKey}/assets/favicon.svg`;
|
||||
}
|
||||
|
||||
get isTrigger() {
|
||||
return this.type === 'trigger';
|
||||
}
|
||||
|
||||
get isAction() {
|
||||
return this.type === 'action';
|
||||
}
|
||||
|
||||
async computeWebhookPath() {
|
||||
if (this.type === 'action') return null;
|
||||
|
||||
@@ -135,24 +143,6 @@ class Step extends Base {
|
||||
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() {
|
||||
if (!this.appKey) return null;
|
||||
|
||||
@@ -367,6 +357,16 @@ class Step extends Base {
|
||||
|
||||
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;
|
||||
|
@@ -126,4 +126,43 @@ describe('Step model', () => {
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user