2248 zapier integration implement typeorm eventsubscribers (#3122)
* Add new queue to twenty-server * Add triggers to zapier * Rename webhook operation * Use find one or fail * Use logger * Fix typescript templating * Add dedicated call webhook job * Update logging * Fix error handling
This commit is contained in:
@ -0,0 +1,19 @@
|
||||
import { createAppTester, tools } from 'zapier-platform-core';
|
||||
import getBundle from '../../utils/getBundle';
|
||||
import App from '../../index';
|
||||
import { findObjectNamesPluralKey } from '../../triggers/find_object_names_plural';
|
||||
tools.env.inject();
|
||||
|
||||
const appTester = createAppTester(App);
|
||||
describe('triggers.find_object_names_plural', () => {
|
||||
test('should run', async () => {
|
||||
const bundle = getBundle({});
|
||||
const result = await appTester(
|
||||
App.triggers[findObjectNamesPluralKey].operation.perform,
|
||||
bundle,
|
||||
);
|
||||
expect(result).toBeDefined();
|
||||
expect(result.length).toBeGreaterThan(1);
|
||||
expect(result[0].namePlural).toBeDefined();
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,19 @@
|
||||
import { createAppTester, tools } from 'zapier-platform-core';
|
||||
import getBundle from '../../utils/getBundle';
|
||||
import App from '../../index';
|
||||
import { findObjectNamesSingularKey } from '../../triggers/find_object_names_singular';
|
||||
tools.env.inject();
|
||||
|
||||
const appTester = createAppTester(App);
|
||||
describe('triggers.find_object_names_singular', () => {
|
||||
test('should run', async () => {
|
||||
const bundle = getBundle({});
|
||||
const result = await appTester(
|
||||
App.triggers[findObjectNamesSingularKey].operation.perform,
|
||||
bundle,
|
||||
);
|
||||
expect(result).toBeDefined();
|
||||
expect(result.length).toBeGreaterThan(1);
|
||||
expect(result[0].nameSingular).toBeDefined();
|
||||
});
|
||||
});
|
||||
@ -1,17 +0,0 @@
|
||||
import { createAppTester } from "zapier-platform-core";
|
||||
import getBundle from '../../utils/getBundle';
|
||||
import App from '../../index';
|
||||
|
||||
const appTester = createAppTester(App);
|
||||
describe('triggers.find_objects', () => {
|
||||
test('should run', async () => {
|
||||
const bundle = getBundle({});
|
||||
const result = await appTester(
|
||||
App.triggers.find_objects.operation.perform,
|
||||
bundle,
|
||||
);
|
||||
expect(result).toBeDefined();
|
||||
expect(result.length).toBeGreaterThan(1)
|
||||
expect(result[0].nameSingular).toBeDefined()
|
||||
})
|
||||
})
|
||||
@ -0,0 +1,93 @@
|
||||
import { Bundle, createAppTester, ZObject } from 'zapier-platform-core';
|
||||
import App from '../../index';
|
||||
import getBundle from '../../utils/getBundle';
|
||||
import requestDb from '../../utils/requestDb';
|
||||
import { triggerRecordCreatedKey } from '../../triggers/trigger_record_created';
|
||||
const appTester = createAppTester(App);
|
||||
|
||||
describe('triggers.trigger_record_created', () => {
|
||||
test('should succeed to subscribe', async () => {
|
||||
const bundle = getBundle({});
|
||||
bundle.inputData.namePlural = 'companies';
|
||||
bundle.targetUrl = 'https://test.com';
|
||||
const result = await appTester(
|
||||
App.triggers[triggerRecordCreatedKey].operation.performSubscribe,
|
||||
bundle,
|
||||
);
|
||||
expect(result).toBeDefined();
|
||||
expect(result.id).toBeDefined();
|
||||
const checkDbResult = await appTester(
|
||||
(z: ZObject, bundle: Bundle) =>
|
||||
requestDb(
|
||||
z,
|
||||
bundle,
|
||||
`query webhook {webhooks(filter: {id: {eq: "${result.id}"}}){edges {node {id operation}}}}`,
|
||||
),
|
||||
bundle,
|
||||
);
|
||||
expect(checkDbResult.data.webhooks.edges[0].node.operation).toEqual(
|
||||
'create.companies',
|
||||
);
|
||||
});
|
||||
test('should succeed to unsubscribe', async () => {
|
||||
const bundle = getBundle({});
|
||||
bundle.inputData.namePlural = 'companies';
|
||||
bundle.targetUrl = 'https://test.com';
|
||||
const result = await appTester(
|
||||
App.triggers[triggerRecordCreatedKey].operation.performSubscribe,
|
||||
bundle,
|
||||
);
|
||||
const unsubscribeBundle = getBundle({});
|
||||
unsubscribeBundle.subscribeData = { id: result.id };
|
||||
const unsubscribeResult = await appTester(
|
||||
App.triggers[triggerRecordCreatedKey].operation.performUnsubscribe,
|
||||
unsubscribeBundle,
|
||||
);
|
||||
expect(unsubscribeResult).toBeDefined();
|
||||
expect(unsubscribeResult.id).toEqual(result.id);
|
||||
const checkDbResult = await appTester(
|
||||
(z: ZObject, bundle: Bundle) =>
|
||||
requestDb(
|
||||
z,
|
||||
bundle,
|
||||
`query webhook {webhooks(filter: {id: {eq: "${result.id}"}}){edges {node {id operation}}}}`,
|
||||
),
|
||||
bundle,
|
||||
);
|
||||
expect(checkDbResult.data.webhooks.edges.length).toEqual(0);
|
||||
});
|
||||
test('should load company from webhook', async () => {
|
||||
const bundle = {
|
||||
cleanedRequest: {
|
||||
id: 'd6ccb1d1-a90b-4822-a992-a0dd946592c9',
|
||||
name: '',
|
||||
domainName: '',
|
||||
createdAt: '2023-10-19 10:10:12.490',
|
||||
address: '',
|
||||
employees: null,
|
||||
linkedinUrl: null,
|
||||
xUrl: null,
|
||||
annualRecurringRevenue: null,
|
||||
idealCustomerProfile: false,
|
||||
},
|
||||
};
|
||||
const results = await appTester(
|
||||
App.triggers[triggerRecordCreatedKey].operation.perform,
|
||||
bundle,
|
||||
);
|
||||
expect(results.length).toEqual(1);
|
||||
const company = results[0];
|
||||
expect(company.id).toEqual('d6ccb1d1-a90b-4822-a992-a0dd946592c9');
|
||||
});
|
||||
it('should load companies from list', async () => {
|
||||
const bundle = getBundle({});
|
||||
bundle.inputData.namePlural = 'companies';
|
||||
const results = await appTester(
|
||||
App.triggers[triggerRecordCreatedKey].operation.performList,
|
||||
bundle,
|
||||
);
|
||||
expect(results.length).toBeGreaterThan(1);
|
||||
const firstCompany = results[0];
|
||||
expect(firstCompany).toBeDefined();
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,95 @@
|
||||
import { Bundle, createAppTester, ZObject } from 'zapier-platform-core';
|
||||
import App from '../../index';
|
||||
import getBundle from '../../utils/getBundle';
|
||||
import requestDb from '../../utils/requestDb';
|
||||
import { triggerRecordDeletedKey } from '../../triggers/trigger_record_deleted';
|
||||
const appTester = createAppTester(App);
|
||||
|
||||
describe('triggers.trigger_record_deleted', () => {
|
||||
test('should succeed to subscribe', async () => {
|
||||
const bundle = getBundle({});
|
||||
bundle.inputData.namePlural = 'companies';
|
||||
bundle.targetUrl = 'https://test.com';
|
||||
const result = await appTester(
|
||||
App.triggers[triggerRecordDeletedKey].operation.performSubscribe,
|
||||
bundle,
|
||||
);
|
||||
expect(result).toBeDefined();
|
||||
expect(result.id).toBeDefined();
|
||||
const checkDbResult = await appTester(
|
||||
(z: ZObject, bundle: Bundle) =>
|
||||
requestDb(
|
||||
z,
|
||||
bundle,
|
||||
`query webhook {webhooks(filter: {id: {eq: "${result.id}"}}){edges {node {id operation}}}}`,
|
||||
),
|
||||
bundle,
|
||||
);
|
||||
expect(checkDbResult.data.webhooks.edges[0].node.operation).toEqual(
|
||||
'delete.companies',
|
||||
);
|
||||
});
|
||||
test('should succeed to unsubscribe', async () => {
|
||||
const bundle = getBundle({});
|
||||
bundle.inputData.namePlural = 'companies';
|
||||
bundle.targetUrl = 'https://test.com';
|
||||
const result = await appTester(
|
||||
App.triggers[triggerRecordDeletedKey].operation.performSubscribe,
|
||||
bundle,
|
||||
);
|
||||
const unsubscribeBundle = getBundle({});
|
||||
unsubscribeBundle.subscribeData = { id: result.id };
|
||||
const unsubscribeResult = await appTester(
|
||||
App.triggers[triggerRecordDeletedKey].operation.performUnsubscribe,
|
||||
unsubscribeBundle,
|
||||
);
|
||||
expect(unsubscribeResult).toBeDefined();
|
||||
expect(unsubscribeResult.id).toEqual(result.id);
|
||||
const checkDbResult = await appTester(
|
||||
(z: ZObject, bundle: Bundle) =>
|
||||
requestDb(
|
||||
z,
|
||||
bundle,
|
||||
`query webhook {webhooks(filter: {id: {eq: "${result.id}"}}){edges {node {id operation}}}}`,
|
||||
),
|
||||
bundle,
|
||||
);
|
||||
expect(checkDbResult.data.webhooks.edges.length).toEqual(0);
|
||||
});
|
||||
test('should load company from webhook', async () => {
|
||||
const bundle = {
|
||||
cleanedRequest: {
|
||||
id: 'd6ccb1d1-a90b-4822-a992-a0dd946592c9',
|
||||
name: '',
|
||||
domainName: '',
|
||||
createdAt: '2023-10-19 10:10:12.490',
|
||||
address: '',
|
||||
employees: null,
|
||||
linkedinUrl: null,
|
||||
xUrl: null,
|
||||
annualRecurringRevenue: null,
|
||||
idealCustomerProfile: false,
|
||||
},
|
||||
};
|
||||
const results = await appTester(
|
||||
App.triggers[triggerRecordDeletedKey].operation.perform,
|
||||
bundle,
|
||||
);
|
||||
expect(results.length).toEqual(1);
|
||||
const company = results[0];
|
||||
expect(company.id).toEqual('d6ccb1d1-a90b-4822-a992-a0dd946592c9');
|
||||
});
|
||||
it('should load companies from list', async () => {
|
||||
const bundle = getBundle({});
|
||||
bundle.inputData.namePlural = 'companies';
|
||||
const results = await appTester(
|
||||
App.triggers[triggerRecordDeletedKey].operation.performList,
|
||||
bundle,
|
||||
);
|
||||
expect(results.length).toBeGreaterThan(1);
|
||||
const firstCompany = results[0];
|
||||
expect(firstCompany).toBeDefined();
|
||||
expect(firstCompany.id).toBeDefined();
|
||||
expect(Object.keys(firstCompany).length).toEqual(1);
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,93 @@
|
||||
import { Bundle, createAppTester, ZObject } from 'zapier-platform-core';
|
||||
import App from '../../index';
|
||||
import getBundle from '../../utils/getBundle';
|
||||
import requestDb from '../../utils/requestDb';
|
||||
import { triggerRecordUpdatedKey } from '../../triggers/trigger_record_updated';
|
||||
const appTester = createAppTester(App);
|
||||
|
||||
describe('triggers.trigger_record_updated', () => {
|
||||
test('should succeed to subscribe', async () => {
|
||||
const bundle = getBundle({});
|
||||
bundle.inputData.namePlural = 'companies';
|
||||
bundle.targetUrl = 'https://test.com';
|
||||
const result = await appTester(
|
||||
App.triggers[triggerRecordUpdatedKey].operation.performSubscribe,
|
||||
bundle,
|
||||
);
|
||||
expect(result).toBeDefined();
|
||||
expect(result.id).toBeDefined();
|
||||
const checkDbResult = await appTester(
|
||||
(z: ZObject, bundle: Bundle) =>
|
||||
requestDb(
|
||||
z,
|
||||
bundle,
|
||||
`query webhook {webhooks(filter: {id: {eq: "${result.id}"}}){edges {node {id operation}}}}`,
|
||||
),
|
||||
bundle,
|
||||
);
|
||||
expect(checkDbResult.data.webhooks.edges[0].node.operation).toEqual(
|
||||
'update.companies',
|
||||
);
|
||||
});
|
||||
test('should succeed to unsubscribe', async () => {
|
||||
const bundle = getBundle({});
|
||||
bundle.inputData.namePlural = 'companies';
|
||||
bundle.targetUrl = 'https://test.com';
|
||||
const result = await appTester(
|
||||
App.triggers[triggerRecordUpdatedKey].operation.performSubscribe,
|
||||
bundle,
|
||||
);
|
||||
const unsubscribeBundle = getBundle({});
|
||||
unsubscribeBundle.subscribeData = { id: result.id };
|
||||
const unsubscribeResult = await appTester(
|
||||
App.triggers[triggerRecordUpdatedKey].operation.performUnsubscribe,
|
||||
unsubscribeBundle,
|
||||
);
|
||||
expect(unsubscribeResult).toBeDefined();
|
||||
expect(unsubscribeResult.id).toEqual(result.id);
|
||||
const checkDbResult = await appTester(
|
||||
(z: ZObject, bundle: Bundle) =>
|
||||
requestDb(
|
||||
z,
|
||||
bundle,
|
||||
`query webhook {webhooks(filter: {id: {eq: "${result.id}"}}){edges {node {id operation}}}}`,
|
||||
),
|
||||
bundle,
|
||||
);
|
||||
expect(checkDbResult.data.webhooks.edges.length).toEqual(0);
|
||||
});
|
||||
test('should load company from webhook', async () => {
|
||||
const bundle = {
|
||||
cleanedRequest: {
|
||||
id: 'd6ccb1d1-a90b-4822-a992-a0dd946592c9',
|
||||
name: '',
|
||||
domainName: '',
|
||||
createdAt: '2023-10-19 10:10:12.490',
|
||||
address: '',
|
||||
employees: null,
|
||||
linkedinUrl: null,
|
||||
xUrl: null,
|
||||
annualRecurringRevenue: null,
|
||||
idealCustomerProfile: false,
|
||||
},
|
||||
};
|
||||
const results = await appTester(
|
||||
App.triggers[triggerRecordUpdatedKey].operation.perform,
|
||||
bundle,
|
||||
);
|
||||
expect(results.length).toEqual(1);
|
||||
const company = results[0];
|
||||
expect(company.id).toEqual('d6ccb1d1-a90b-4822-a992-a0dd946592c9');
|
||||
});
|
||||
it('should load companies from list', async () => {
|
||||
const bundle = getBundle({});
|
||||
bundle.inputData.namePlural = 'companies';
|
||||
const results = await appTester(
|
||||
App.triggers[triggerRecordUpdatedKey].operation.performList,
|
||||
bundle,
|
||||
);
|
||||
expect(results.length).toBeGreaterThan(1);
|
||||
const firstCompany = results[0];
|
||||
expect(firstCompany).toBeDefined();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user