2023-02-09 06:59:01 -08:00
|
|
|
import { WorkflowPage, NDV, CredentialsModal } from '../pages';
|
2023-02-07 08:51:11 -08:00
|
|
|
import { v4 as uuid } from 'uuid';
|
|
|
|
import { cowBase64 } from '../support/binaryTestFiles';
|
2023-06-15 04:40:23 -07:00
|
|
|
import { BACKEND_BASE_URL } from '../constants';
|
2023-07-28 00:51:07 -07:00
|
|
|
import { getVisibleSelect } from '../utils';
|
2023-02-07 08:51:11 -08:00
|
|
|
|
|
|
|
const workflowPage = new WorkflowPage();
|
|
|
|
const ndv = new NDV();
|
|
|
|
const credentialsModal = new CredentialsModal();
|
|
|
|
|
|
|
|
const waitForWebhook = 500;
|
|
|
|
|
|
|
|
interface SimpleWebhookCallOptions {
|
|
|
|
method: string;
|
|
|
|
webhookPath: string;
|
|
|
|
responseCode?: number;
|
|
|
|
respondWith?: string;
|
|
|
|
executeNow?: boolean;
|
|
|
|
responseData?: string;
|
|
|
|
authentication?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const simpleWebhookCall = (options: SimpleWebhookCallOptions) => {
|
2023-02-09 06:59:01 -08:00
|
|
|
const {
|
2023-02-07 08:51:11 -08:00
|
|
|
authentication,
|
|
|
|
method,
|
|
|
|
webhookPath,
|
|
|
|
responseCode,
|
|
|
|
respondWith,
|
|
|
|
responseData,
|
|
|
|
executeNow = true,
|
2023-02-24 09:07:35 -08:00
|
|
|
} = options;
|
2023-02-07 08:51:11 -08:00
|
|
|
|
|
|
|
workflowPage.actions.addInitialNodeToCanvas('Webhook');
|
|
|
|
workflowPage.actions.openNode('Webhook');
|
|
|
|
|
|
|
|
cy.getByTestId('parameter-input-httpMethod').click();
|
2023-07-28 00:51:07 -07:00
|
|
|
getVisibleSelect().find('.option-headline').contains(method).click();
|
2023-02-07 08:51:11 -08:00
|
|
|
cy.getByTestId('parameter-input-path')
|
|
|
|
.find('.parameter-input')
|
|
|
|
.find('input')
|
|
|
|
.clear()
|
|
|
|
.type(webhookPath);
|
2023-02-09 06:59:01 -08:00
|
|
|
|
2023-02-07 08:51:11 -08:00
|
|
|
if (authentication) {
|
|
|
|
cy.getByTestId('parameter-input-authentication').click();
|
2023-07-28 00:51:07 -07:00
|
|
|
getVisibleSelect().find('.option-headline').contains(authentication).click();
|
2023-02-07 08:51:11 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (responseCode) {
|
|
|
|
cy.getByTestId('parameter-input-responseCode')
|
2023-02-24 09:07:35 -08:00
|
|
|
.find('.parameter-input')
|
|
|
|
.find('input')
|
|
|
|
.clear()
|
|
|
|
.type(responseCode.toString());
|
2023-02-07 08:51:11 -08:00
|
|
|
}
|
2023-02-09 06:59:01 -08:00
|
|
|
|
2023-02-07 08:51:11 -08:00
|
|
|
if (respondWith) {
|
|
|
|
cy.getByTestId('parameter-input-responseMode').click();
|
2023-07-28 00:51:07 -07:00
|
|
|
getVisibleSelect().find('.option-headline').contains(respondWith).click();
|
2023-02-07 08:51:11 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (responseData) {
|
|
|
|
cy.getByTestId('parameter-input-responseData').click();
|
2023-07-28 00:51:07 -07:00
|
|
|
getVisibleSelect().find('.option-headline').contains(responseData).click();
|
2023-02-07 08:51:11 -08:00
|
|
|
}
|
|
|
|
|
2023-02-09 06:59:01 -08:00
|
|
|
if (executeNow) {
|
2023-02-07 08:51:11 -08:00
|
|
|
ndv.actions.execute();
|
|
|
|
cy.wait(waitForWebhook);
|
|
|
|
|
2023-06-15 04:40:23 -07:00
|
|
|
cy.request(method, `${BACKEND_BASE_URL}/webhook-test/${webhookPath}`).then((response) => {
|
2023-02-07 08:51:11 -08:00
|
|
|
expect(response.status).to.eq(200);
|
|
|
|
ndv.getters.outputPanel().contains('headers');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('Webhook Trigger node', async () => {
|
2023-02-24 09:07:35 -08:00
|
|
|
beforeEach(() => {
|
2023-02-09 06:59:01 -08:00
|
|
|
workflowPage.actions.visit();
|
2023-02-07 08:51:11 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should listen for a GET request', () => {
|
2023-02-24 09:07:35 -08:00
|
|
|
simpleWebhookCall({ method: 'GET', webhookPath: uuid(), executeNow: true });
|
2023-02-07 08:51:11 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should listen for a POST request', () => {
|
2023-02-24 09:07:35 -08:00
|
|
|
simpleWebhookCall({ method: 'POST', webhookPath: uuid(), executeNow: true });
|
2023-02-07 08:51:11 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should listen for a DELETE request', () => {
|
2023-02-24 09:07:35 -08:00
|
|
|
simpleWebhookCall({ method: 'DELETE', webhookPath: uuid(), executeNow: true });
|
2023-02-07 08:51:11 -08:00
|
|
|
});
|
|
|
|
it('should listen for a HEAD request', () => {
|
2023-02-24 09:07:35 -08:00
|
|
|
simpleWebhookCall({ method: 'HEAD', webhookPath: uuid(), executeNow: true });
|
2023-02-07 08:51:11 -08:00
|
|
|
});
|
|
|
|
it('should listen for a PATCH request', () => {
|
2023-02-24 09:07:35 -08:00
|
|
|
simpleWebhookCall({ method: 'PATCH', webhookPath: uuid(), executeNow: true });
|
2023-02-07 08:51:11 -08:00
|
|
|
});
|
|
|
|
it('should listen for a PUT request', () => {
|
2023-02-24 09:07:35 -08:00
|
|
|
simpleWebhookCall({ method: 'PUT', webhookPath: uuid(), executeNow: true });
|
2023-02-07 08:51:11 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should listen for a GET request and respond with Respond to Webhook node', () => {
|
|
|
|
const webhookPath = uuid();
|
|
|
|
simpleWebhookCall({
|
|
|
|
method: 'GET',
|
|
|
|
webhookPath,
|
|
|
|
executeNow: false,
|
|
|
|
respondWith: 'Respond to Webhook',
|
|
|
|
});
|
|
|
|
|
|
|
|
ndv.getters.backToCanvas().click();
|
2023-02-09 06:59:01 -08:00
|
|
|
|
2023-02-07 08:51:11 -08:00
|
|
|
workflowPage.actions.addNodeToCanvas('Set');
|
|
|
|
workflowPage.actions.openNode('Set');
|
|
|
|
cy.get('.add-option').click();
|
2023-07-28 00:51:07 -07:00
|
|
|
getVisibleSelect().find('.el-select-dropdown__item').contains('Number').click();
|
2023-02-24 09:07:35 -08:00
|
|
|
cy.get('.fixed-collection-parameter')
|
|
|
|
.getByTestId('parameter-input-name')
|
|
|
|
.clear()
|
|
|
|
.type('MyValue');
|
2023-02-07 08:51:11 -08:00
|
|
|
cy.get('.fixed-collection-parameter').getByTestId('parameter-input-value').clear().type('1234');
|
2023-07-28 00:51:07 -07:00
|
|
|
ndv.getters.backToCanvas().click({ force: true });
|
2023-02-09 06:59:01 -08:00
|
|
|
|
2023-02-07 08:51:11 -08:00
|
|
|
workflowPage.actions.addNodeToCanvas('Respond to Webhook');
|
|
|
|
|
|
|
|
workflowPage.actions.executeWorkflow();
|
|
|
|
cy.wait(waitForWebhook);
|
2023-02-09 06:59:01 -08:00
|
|
|
|
2023-06-15 04:40:23 -07:00
|
|
|
cy.request('GET', `${BACKEND_BASE_URL}/webhook-test/${webhookPath}`).then((response) => {
|
2023-02-07 08:51:11 -08:00
|
|
|
expect(response.status).to.eq(200);
|
|
|
|
expect(response.body.MyValue).to.eq(1234);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should listen for a GET request and respond custom status code 201', () => {
|
|
|
|
const webhookPath = uuid();
|
|
|
|
simpleWebhookCall({
|
|
|
|
method: 'GET',
|
|
|
|
webhookPath,
|
|
|
|
executeNow: false,
|
|
|
|
responseCode: 201,
|
|
|
|
});
|
|
|
|
|
|
|
|
ndv.actions.execute();
|
|
|
|
cy.wait(waitForWebhook);
|
2023-02-09 06:59:01 -08:00
|
|
|
|
2023-06-15 04:40:23 -07:00
|
|
|
cy.request('GET', `${BACKEND_BASE_URL}/webhook-test/${webhookPath}`).then((response) => {
|
2023-02-07 08:51:11 -08:00
|
|
|
expect(response.status).to.eq(201);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should listen for a GET request and respond with last node', () => {
|
|
|
|
const webhookPath = uuid();
|
|
|
|
simpleWebhookCall({
|
|
|
|
method: 'GET',
|
|
|
|
webhookPath,
|
|
|
|
executeNow: false,
|
|
|
|
respondWith: 'Last Node',
|
|
|
|
});
|
|
|
|
ndv.getters.backToCanvas().click();
|
2023-02-09 06:59:01 -08:00
|
|
|
|
2023-02-07 08:51:11 -08:00
|
|
|
workflowPage.actions.addNodeToCanvas('Set');
|
|
|
|
workflowPage.actions.openNode('Set');
|
|
|
|
cy.get('.add-option').click();
|
2023-07-28 00:51:07 -07:00
|
|
|
getVisibleSelect().find('.el-select-dropdown__item').contains('Number').click();
|
2023-02-24 09:07:35 -08:00
|
|
|
cy.get('.fixed-collection-parameter')
|
|
|
|
.getByTestId('parameter-input-name')
|
2023-07-28 00:51:07 -07:00
|
|
|
.find('input')
|
2023-02-24 09:07:35 -08:00
|
|
|
.clear()
|
|
|
|
.type('MyValue');
|
2023-07-28 00:51:07 -07:00
|
|
|
cy.get('.fixed-collection-parameter')
|
|
|
|
.getByTestId('parameter-input-value')
|
|
|
|
.find('input')
|
|
|
|
.clear()
|
|
|
|
.type('1234');
|
|
|
|
ndv.getters.backToCanvas().click({ force: true });
|
2023-02-09 06:59:01 -08:00
|
|
|
|
2023-02-07 08:51:11 -08:00
|
|
|
workflowPage.actions.executeWorkflow();
|
|
|
|
cy.wait(waitForWebhook);
|
2023-02-09 06:59:01 -08:00
|
|
|
|
2023-06-15 04:40:23 -07:00
|
|
|
cy.request('GET', `${BACKEND_BASE_URL}/webhook-test/${webhookPath}`).then((response) => {
|
2023-02-07 08:51:11 -08:00
|
|
|
expect(response.status).to.eq(200);
|
|
|
|
expect(response.body.MyValue).to.eq(1234);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should listen for a GET request and respond with last node binary data', () => {
|
|
|
|
const webhookPath = uuid();
|
|
|
|
simpleWebhookCall({
|
|
|
|
method: 'GET',
|
|
|
|
webhookPath,
|
|
|
|
executeNow: false,
|
|
|
|
respondWith: 'Last Node',
|
|
|
|
responseData: 'First Entry Binary',
|
|
|
|
});
|
|
|
|
ndv.getters.backToCanvas().click();
|
2023-02-09 06:59:01 -08:00
|
|
|
|
2023-02-07 08:51:11 -08:00
|
|
|
workflowPage.actions.addNodeToCanvas('Set');
|
|
|
|
workflowPage.actions.openNode('Set');
|
|
|
|
cy.get('.add-option').click();
|
2023-07-28 00:51:07 -07:00
|
|
|
getVisibleSelect().find('.el-select-dropdown__item').contains('String').click();
|
2023-02-07 08:51:11 -08:00
|
|
|
cy.get('.fixed-collection-parameter').getByTestId('parameter-input-name').clear().type('data');
|
2023-02-24 09:07:35 -08:00
|
|
|
cy.get('.fixed-collection-parameter')
|
|
|
|
.getByTestId('parameter-input-value')
|
|
|
|
.clear()
|
|
|
|
.find('input')
|
|
|
|
.invoke('val', cowBase64)
|
|
|
|
.trigger('blur');
|
2023-02-07 08:51:11 -08:00
|
|
|
ndv.getters.backToCanvas().click();
|
2023-02-09 06:59:01 -08:00
|
|
|
|
2023-02-07 08:51:11 -08:00
|
|
|
workflowPage.actions.addNodeToCanvas('Move Binary Data');
|
|
|
|
workflowPage.actions.zoomToFit();
|
|
|
|
|
|
|
|
workflowPage.actions.openNode('Move Binary Data');
|
|
|
|
cy.getByTestId('parameter-input-mode').click();
|
2023-07-28 00:51:07 -07:00
|
|
|
getVisibleSelect().find('.option-headline').contains('JSON to Binary').click();
|
2023-02-07 08:51:11 -08:00
|
|
|
ndv.getters.backToCanvas().click();
|
2023-02-09 06:59:01 -08:00
|
|
|
|
2023-02-07 08:51:11 -08:00
|
|
|
workflowPage.actions.executeWorkflow();
|
|
|
|
cy.wait(waitForWebhook);
|
2023-02-09 06:59:01 -08:00
|
|
|
|
2023-06-15 04:40:23 -07:00
|
|
|
cy.request('GET', `${BACKEND_BASE_URL}/webhook-test/${webhookPath}`).then((response) => {
|
2023-02-07 08:51:11 -08:00
|
|
|
expect(response.status).to.eq(200);
|
|
|
|
expect(Object.keys(response.body).includes('data')).to.be.true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should listen for a GET request and respond with an empty body', () => {
|
|
|
|
const webhookPath = uuid();
|
|
|
|
simpleWebhookCall({
|
|
|
|
method: 'GET',
|
|
|
|
webhookPath,
|
|
|
|
executeNow: false,
|
|
|
|
respondWith: 'Last Node',
|
|
|
|
responseData: 'No Response Body',
|
|
|
|
});
|
|
|
|
ndv.actions.execute();
|
|
|
|
cy.wait(waitForWebhook);
|
2023-06-15 04:40:23 -07:00
|
|
|
cy.request('GET', `${BACKEND_BASE_URL}/webhook-test/${webhookPath}`).then((response) => {
|
2023-02-07 08:51:11 -08:00
|
|
|
expect(response.status).to.eq(200);
|
|
|
|
expect(response.body.MyValue).to.be.undefined;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should listen for a GET request with Basic Authentication', () => {
|
|
|
|
const webhookPath = uuid();
|
|
|
|
simpleWebhookCall({
|
|
|
|
method: 'GET',
|
|
|
|
webhookPath,
|
|
|
|
executeNow: false,
|
|
|
|
authentication: 'Basic Auth',
|
|
|
|
});
|
|
|
|
// add credentials
|
|
|
|
workflowPage.getters.nodeCredentialsSelect().click();
|
2023-07-28 00:51:07 -07:00
|
|
|
getVisibleSelect().find('li').last().click();
|
2023-02-07 08:51:11 -08:00
|
|
|
credentialsModal.getters.credentialsEditModal().should('be.visible');
|
|
|
|
credentialsModal.actions.fillCredentialsForm();
|
|
|
|
|
|
|
|
ndv.actions.execute();
|
|
|
|
cy.wait(waitForWebhook);
|
|
|
|
cy.request({
|
|
|
|
method: 'GET',
|
2023-06-15 04:40:23 -07:00
|
|
|
url: `${BACKEND_BASE_URL}/webhook-test/${webhookPath}`,
|
2023-02-07 08:51:11 -08:00
|
|
|
auth: {
|
2023-02-24 09:07:35 -08:00
|
|
|
user: 'username',
|
|
|
|
pass: 'password',
|
2023-02-07 08:51:11 -08:00
|
|
|
},
|
|
|
|
failOnStatusCode: false,
|
|
|
|
})
|
2023-02-24 09:07:35 -08:00
|
|
|
.then((response) => {
|
|
|
|
expect(response.status).to.eq(403);
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
cy.request({
|
|
|
|
method: 'GET',
|
2023-06-15 04:40:23 -07:00
|
|
|
url: `${BACKEND_BASE_URL}/webhook-test/${webhookPath}`,
|
2023-02-24 09:07:35 -08:00
|
|
|
auth: {
|
|
|
|
user: 'test',
|
|
|
|
pass: 'test',
|
|
|
|
},
|
|
|
|
failOnStatusCode: true,
|
|
|
|
}).then((response) => {
|
|
|
|
expect(response.status).to.eq(200);
|
|
|
|
});
|
2023-02-07 08:51:11 -08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should listen for a GET request with Header Authentication', () => {
|
|
|
|
const webhookPath = uuid();
|
|
|
|
simpleWebhookCall({
|
|
|
|
method: 'GET',
|
|
|
|
webhookPath,
|
|
|
|
executeNow: false,
|
|
|
|
authentication: 'Header Auth',
|
|
|
|
});
|
|
|
|
// add credentials
|
|
|
|
workflowPage.getters.nodeCredentialsSelect().click();
|
2023-07-28 00:51:07 -07:00
|
|
|
getVisibleSelect().find('li').last().click();
|
2023-02-07 08:51:11 -08:00
|
|
|
credentialsModal.getters.credentialsEditModal().should('be.visible');
|
|
|
|
credentialsModal.actions.fillCredentialsForm();
|
|
|
|
|
|
|
|
ndv.actions.execute();
|
|
|
|
cy.wait(waitForWebhook);
|
|
|
|
cy.request({
|
|
|
|
method: 'GET',
|
2023-06-15 04:40:23 -07:00
|
|
|
url: `${BACKEND_BASE_URL}/webhook-test/${webhookPath}`,
|
2023-02-07 08:51:11 -08:00
|
|
|
headers: {
|
|
|
|
test: 'wrong',
|
|
|
|
},
|
|
|
|
failOnStatusCode: false,
|
|
|
|
})
|
2023-02-24 09:07:35 -08:00
|
|
|
.then((response) => {
|
|
|
|
expect(response.status).to.eq(403);
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
cy.request({
|
|
|
|
method: 'GET',
|
2023-06-15 04:40:23 -07:00
|
|
|
url: `${BACKEND_BASE_URL}/webhook-test/${webhookPath}`,
|
2023-02-24 09:07:35 -08:00
|
|
|
headers: {
|
|
|
|
test: 'test',
|
|
|
|
},
|
|
|
|
failOnStatusCode: true,
|
|
|
|
}).then((response) => {
|
|
|
|
expect(response.status).to.eq(200);
|
|
|
|
});
|
2023-02-07 08:51:11 -08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|