Improve webhook (#3459)
* Add trigger record * Merge triggers * Merge creates * Fix libraries * Fix create merged key * Rename file * Remove list Record Ids * Revert "Rename file" This reverts commit 2e72e05793ced4553eec8d9f890d31beae594c85. * Revert "Revert "Rename file"" This reverts commit e2d93fa02716093df6d4d6029af9cc324c06f06b. * Revert "Remove list Record Ids" This reverts commit 6653fb6ccd4307e3958b70923505034d92cf43bb. * Remove namePlural field * Use name singular for webhooks * Send webhook metadata * Extract resource from zapier webhook * Fix package.json * Fix package.json * Update payload * Fix package.json * Update payload * Update payload * Rename file * Use wildcard in webhook events * Fix nameSingular * Code review returns * Code review returns
This commit is contained in:
@ -1,70 +0,0 @@
|
||||
import { Bundle, createAppTester, tools, ZObject } from 'zapier-platform-core';
|
||||
|
||||
import { createRecordKey } from '../../creates/create_record';
|
||||
import App from '../../index';
|
||||
import getBundle from '../../utils/getBundle';
|
||||
import requestDb from '../../utils/requestDb';
|
||||
const appTester = createAppTester(App);
|
||||
tools.env.inject();
|
||||
|
||||
describe('creates.create_company', () => {
|
||||
test('should run to create a Company Record', async () => {
|
||||
const bundle = getBundle({
|
||||
nameSingular: 'Company',
|
||||
name: 'Company Name',
|
||||
address: 'Company Address',
|
||||
domainName: 'Company Domain Name',
|
||||
linkedinLink: { url: '/linkedin_url', label: 'Test linkedinUrl' },
|
||||
xLink: { url: '/x_url', label: 'Test xUrl' },
|
||||
annualRecurringRevenue: {
|
||||
amountMicros: 100000000000,
|
||||
currencyCode: 'USD',
|
||||
},
|
||||
idealCustomerProfile: true,
|
||||
employees: 25,
|
||||
});
|
||||
const result = await appTester(
|
||||
App.creates[createRecordKey].operation.perform,
|
||||
bundle,
|
||||
);
|
||||
expect(result).toBeDefined();
|
||||
expect(result.data?.createCompany?.id).toBeDefined();
|
||||
const checkDbResult = await appTester(
|
||||
(z: ZObject, bundle: Bundle) =>
|
||||
requestDb(
|
||||
z,
|
||||
bundle,
|
||||
`query findCompany {company(filter: {id: {eq: "${result.data.createCompany.id}"}}){id annualRecurringRevenue{amountMicros currencyCode}}}`,
|
||||
),
|
||||
bundle,
|
||||
);
|
||||
expect(
|
||||
checkDbResult.data.company.annualRecurringRevenue.amountMicros,
|
||||
).toEqual(100000000000);
|
||||
});
|
||||
test('should run to create a Person Record', async () => {
|
||||
const bundle = getBundle({
|
||||
nameSingular: 'Person',
|
||||
name: { firstName: 'John', lastName: 'Doe' },
|
||||
email: 'johndoe@gmail.com',
|
||||
phone: '+33610203040',
|
||||
city: 'Paris',
|
||||
});
|
||||
const result = await appTester(
|
||||
App.creates[createRecordKey].operation.perform,
|
||||
bundle,
|
||||
);
|
||||
expect(result).toBeDefined();
|
||||
expect(result.data?.createPerson?.id).toBeDefined();
|
||||
const checkDbResult = await appTester(
|
||||
(z: ZObject, bundle: Bundle) =>
|
||||
requestDb(
|
||||
z,
|
||||
bundle,
|
||||
`query findPerson {person(filter: {id: {eq: "${result.data.createPerson.id}"}}){phone}}`,
|
||||
),
|
||||
bundle,
|
||||
);
|
||||
expect(checkDbResult.data.person.phone).toEqual('+33610203040');
|
||||
});
|
||||
});
|
||||
158
packages/twenty-zapier/src/test/creates/crud_record.test.ts
Normal file
158
packages/twenty-zapier/src/test/creates/crud_record.test.ts
Normal file
@ -0,0 +1,158 @@
|
||||
import { Bundle, createAppTester, tools, ZObject } from 'zapier-platform-core';
|
||||
|
||||
import { crudRecordKey } from '../../creates/crud_record';
|
||||
import App from '../../index';
|
||||
import getBundle from '../../utils/getBundle';
|
||||
import requestDb from '../../utils/requestDb';
|
||||
import { Operation } from '../../utils/triggers/triggers.utils';
|
||||
const appTester = createAppTester(App);
|
||||
tools.env.inject();
|
||||
|
||||
describe('creates.create_company', () => {
|
||||
test('should run to create a Company Record', async () => {
|
||||
const bundle = getBundle({
|
||||
nameSingular: 'Company',
|
||||
crudZapierOperation: Operation.create,
|
||||
name: 'Company Name',
|
||||
address: 'Company Address',
|
||||
domainName: 'Company Domain Name',
|
||||
linkedinLink: { url: '/linkedin_url', label: 'Test linkedinUrl' },
|
||||
xLink: { url: '/x_url', label: 'Test xUrl' },
|
||||
annualRecurringRevenue: {
|
||||
amountMicros: 100000000000,
|
||||
currencyCode: 'USD',
|
||||
},
|
||||
idealCustomerProfile: true,
|
||||
employees: 25,
|
||||
});
|
||||
const result = await appTester(
|
||||
App.creates[crudRecordKey].operation.perform,
|
||||
bundle,
|
||||
);
|
||||
expect(result).toBeDefined();
|
||||
expect(result.data?.createCompany?.id).toBeDefined();
|
||||
const checkDbResult = await appTester(
|
||||
(z: ZObject, bundle: Bundle) =>
|
||||
requestDb(
|
||||
z,
|
||||
bundle,
|
||||
`query findCompany {company(filter: {id: {eq: "${result.data.createCompany.id}"}}){id annualRecurringRevenue{amountMicros currencyCode}}}`,
|
||||
),
|
||||
bundle,
|
||||
);
|
||||
expect(
|
||||
checkDbResult.data.company.annualRecurringRevenue.amountMicros,
|
||||
).toEqual(100000000000);
|
||||
});
|
||||
test('should run to create a Person Record', async () => {
|
||||
const bundle = getBundle({
|
||||
nameSingular: 'Person',
|
||||
crudZapierOperation: Operation.create,
|
||||
name: { firstName: 'John', lastName: 'Doe' },
|
||||
email: 'johndoe@gmail.com',
|
||||
phone: '+33610203040',
|
||||
city: 'Paris',
|
||||
});
|
||||
const result = await appTester(
|
||||
App.creates[crudRecordKey].operation.perform,
|
||||
bundle,
|
||||
);
|
||||
expect(result).toBeDefined();
|
||||
expect(result.data?.createPerson?.id).toBeDefined();
|
||||
const checkDbResult = await appTester(
|
||||
(z: ZObject, bundle: Bundle) =>
|
||||
requestDb(
|
||||
z,
|
||||
bundle,
|
||||
`query findPerson {person(filter: {id: {eq: "${result.data.createPerson.id}"}}){phone}}`,
|
||||
),
|
||||
bundle,
|
||||
);
|
||||
expect(checkDbResult.data.person.phone).toEqual('+33610203040');
|
||||
});
|
||||
});
|
||||
|
||||
describe('creates.update_company', () => {
|
||||
test('should run to update a Company record', async () => {
|
||||
const createBundle = getBundle({
|
||||
nameSingular: 'Company',
|
||||
crudZapierOperation: Operation.create,
|
||||
name: 'Company Name',
|
||||
employees: 25,
|
||||
});
|
||||
|
||||
const createResult = await appTester(
|
||||
App.creates[crudRecordKey].operation.perform,
|
||||
createBundle,
|
||||
);
|
||||
|
||||
const companyId = createResult.data?.createCompany?.id;
|
||||
|
||||
const updateBundle = getBundle({
|
||||
nameSingular: 'Company',
|
||||
crudZapierOperation: Operation.update,
|
||||
id: companyId,
|
||||
name: 'Updated Company Name',
|
||||
});
|
||||
|
||||
const updateResult = await appTester(
|
||||
App.creates[crudRecordKey].operation.perform,
|
||||
updateBundle,
|
||||
);
|
||||
|
||||
expect(updateResult).toBeDefined();
|
||||
expect(updateResult.data?.updateCompany?.id).toBeDefined();
|
||||
const checkDbResult = await appTester(
|
||||
(z: ZObject, bundle: Bundle) =>
|
||||
requestDb(
|
||||
z,
|
||||
bundle,
|
||||
`query findCompany {company(filter: {id: {eq: "${companyId}"}}){id name}}`,
|
||||
),
|
||||
updateBundle,
|
||||
);
|
||||
expect(checkDbResult.data.company.name).toEqual('Updated Company Name');
|
||||
});
|
||||
});
|
||||
|
||||
describe('creates.delete_company', () => {
|
||||
test('should run to delete a Company record', async () => {
|
||||
const createBundle = getBundle({
|
||||
nameSingular: 'Company',
|
||||
crudZapierOperation: Operation.create,
|
||||
name: 'Delete Company Name',
|
||||
employees: 25,
|
||||
});
|
||||
|
||||
const createResult = await appTester(
|
||||
App.creates[crudRecordKey].operation.perform,
|
||||
createBundle,
|
||||
);
|
||||
|
||||
const companyId = createResult.data?.createCompany?.id;
|
||||
|
||||
const deleteBundle = getBundle({
|
||||
nameSingular: 'Company',
|
||||
crudZapierOperation: Operation.delete,
|
||||
id: companyId,
|
||||
});
|
||||
|
||||
const deleteResult = await appTester(
|
||||
App.creates[crudRecordKey].operation.perform,
|
||||
deleteBundle,
|
||||
);
|
||||
|
||||
expect(deleteResult).toBeDefined();
|
||||
expect(deleteResult.data?.deleteCompany?.id).toBeDefined();
|
||||
const checkDbResult = await appTester(
|
||||
(z: ZObject, bundle: Bundle) =>
|
||||
requestDb(
|
||||
z,
|
||||
bundle,
|
||||
`query findCompanies {companies(filter: {id: {eq: "${companyId}"}}){edges{node{id}}}}`,
|
||||
),
|
||||
deleteBundle,
|
||||
);
|
||||
expect(checkDbResult.data.companies.edges.length).toEqual(0);
|
||||
});
|
||||
});
|
||||
@ -1,49 +0,0 @@
|
||||
import { Bundle, createAppTester, tools, ZObject } from 'zapier-platform-core';
|
||||
|
||||
import { createRecordKey } from '../../creates/create_record';
|
||||
import { deleteRecordKey } from '../../creates/delete_record';
|
||||
import App from '../../index';
|
||||
import getBundle from '../../utils/getBundle';
|
||||
import requestDb from '../../utils/requestDb';
|
||||
const appTester = createAppTester(App);
|
||||
|
||||
tools.env.inject();
|
||||
describe('creates.delete_company', () => {
|
||||
test('should run to delete a Company record', async () => {
|
||||
const createBundle = getBundle({
|
||||
nameSingular: 'Company',
|
||||
name: 'Delete Company Name',
|
||||
employees: 25,
|
||||
});
|
||||
|
||||
const createResult = await appTester(
|
||||
App.creates[createRecordKey].operation.perform,
|
||||
createBundle,
|
||||
);
|
||||
|
||||
const companyId = createResult.data?.createCompany?.id;
|
||||
|
||||
const deleteBundle = getBundle({
|
||||
nameSingular: 'Company',
|
||||
id: companyId,
|
||||
});
|
||||
|
||||
const deleteResult = await appTester(
|
||||
App.creates[deleteRecordKey].operation.perform,
|
||||
deleteBundle,
|
||||
);
|
||||
|
||||
expect(deleteResult).toBeDefined();
|
||||
expect(deleteResult.data?.deleteCompany?.id).toBeDefined();
|
||||
const checkDbResult = await appTester(
|
||||
(z: ZObject, bundle: Bundle) =>
|
||||
requestDb(
|
||||
z,
|
||||
bundle,
|
||||
`query findCompanies {companies(filter: {id: {eq: "${companyId}"}}){edges{node{id}}}}`,
|
||||
),
|
||||
deleteBundle,
|
||||
);
|
||||
expect(checkDbResult.data.companies.edges.length).toEqual(0);
|
||||
});
|
||||
});
|
||||
@ -1,50 +0,0 @@
|
||||
import { Bundle, createAppTester, tools, ZObject } from 'zapier-platform-core';
|
||||
|
||||
import { createRecordKey } from '../../creates/create_record';
|
||||
import { updateRecordKey } from '../../creates/update_record';
|
||||
import App from '../../index';
|
||||
import getBundle from '../../utils/getBundle';
|
||||
import requestDb from '../../utils/requestDb';
|
||||
const appTester = createAppTester(App);
|
||||
|
||||
tools.env.inject();
|
||||
describe('creates.update_company', () => {
|
||||
test('should run to update a Company record', async () => {
|
||||
const createBundle = getBundle({
|
||||
nameSingular: 'Company',
|
||||
name: 'Company Name',
|
||||
employees: 25,
|
||||
});
|
||||
|
||||
const createResult = await appTester(
|
||||
App.creates[createRecordKey].operation.perform,
|
||||
createBundle,
|
||||
);
|
||||
|
||||
const companyId = createResult.data?.createCompany?.id;
|
||||
|
||||
const updateBundle = getBundle({
|
||||
nameSingular: 'Company',
|
||||
id: companyId,
|
||||
name: 'Updated Company Name',
|
||||
});
|
||||
|
||||
const updateResult = await appTester(
|
||||
App.creates[updateRecordKey].operation.perform,
|
||||
updateBundle,
|
||||
);
|
||||
|
||||
expect(updateResult).toBeDefined();
|
||||
expect(updateResult.data?.updateCompany?.id).toBeDefined();
|
||||
const checkDbResult = await appTester(
|
||||
(z: ZObject, bundle: Bundle) =>
|
||||
requestDb(
|
||||
z,
|
||||
bundle,
|
||||
`query findCompany {company(filter: {id: {eq: "${companyId}"}}){id name}}`,
|
||||
),
|
||||
updateBundle,
|
||||
);
|
||||
expect(checkDbResult.data.company.name).toEqual('Updated Company Name');
|
||||
});
|
||||
});
|
||||
@ -1,19 +0,0 @@
|
||||
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();
|
||||
});
|
||||
});
|
||||
@ -8,7 +8,7 @@ tools.env.inject();
|
||||
const appTester = createAppTester(App);
|
||||
describe('triggers.list_record_ids', () => {
|
||||
test('should run', async () => {
|
||||
const bundle = getBundle({ namePlural: 'companies' });
|
||||
const bundle = getBundle({ nameSingular: 'company' });
|
||||
const result = await appTester(
|
||||
App.triggers[listRecordIdsKey].operation.perform,
|
||||
bundle,
|
||||
|
||||
235
packages/twenty-zapier/src/test/triggers/trigger_record.test.ts
Normal file
235
packages/twenty-zapier/src/test/triggers/trigger_record.test.ts
Normal file
@ -0,0 +1,235 @@
|
||||
import { Bundle, createAppTester, ZObject } from 'zapier-platform-core';
|
||||
|
||||
import App from '../../index';
|
||||
import { triggerRecordKey } from '../../triggers/trigger_record';
|
||||
import getBundle from '../../utils/getBundle';
|
||||
import requestDb from '../../utils/requestDb';
|
||||
const appTester = createAppTester(App);
|
||||
|
||||
describe('triggers.trigger_record.created', () => {
|
||||
test('should succeed to subscribe', async () => {
|
||||
const bundle = getBundle({});
|
||||
bundle.inputData.nameSingular = 'company';
|
||||
bundle.inputData.operation = 'create';
|
||||
bundle.targetUrl = 'https://test.com';
|
||||
const result = await appTester(
|
||||
App.triggers[triggerRecordKey].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.company',
|
||||
);
|
||||
});
|
||||
test('should succeed to unsubscribe', async () => {
|
||||
const bundle = getBundle({});
|
||||
bundle.inputData.nameSingular = 'company';
|
||||
bundle.inputData.operation = 'create';
|
||||
bundle.targetUrl = 'https://test.com';
|
||||
const result = await appTester(
|
||||
App.triggers[triggerRecordKey].operation.performSubscribe,
|
||||
bundle,
|
||||
);
|
||||
const unsubscribeBundle = getBundle({});
|
||||
unsubscribeBundle.subscribeData = { id: result.id };
|
||||
const unsubscribeResult = await appTester(
|
||||
App.triggers[triggerRecordKey].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: {
|
||||
record: {
|
||||
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[triggerRecordKey].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.nameSingular = 'company';
|
||||
bundle.inputData.operation = 'create';
|
||||
const results = await appTester(
|
||||
App.triggers[triggerRecordKey].operation.performList,
|
||||
bundle,
|
||||
);
|
||||
expect(results.length).toBeGreaterThan(1);
|
||||
const firstCompany = results[0];
|
||||
expect(firstCompany).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('triggers.trigger_record.update', () => {
|
||||
test('should succeed to subscribe', async () => {
|
||||
const bundle = getBundle({});
|
||||
bundle.inputData.nameSingular = 'company';
|
||||
bundle.inputData.operation = 'update';
|
||||
bundle.targetUrl = 'https://test.com';
|
||||
const result = await appTester(
|
||||
App.triggers[triggerRecordKey].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.company',
|
||||
);
|
||||
});
|
||||
test('should succeed to unsubscribe', async () => {
|
||||
const bundle = getBundle({});
|
||||
bundle.inputData.nameSingular = 'company';
|
||||
bundle.inputData.operation = 'update';
|
||||
bundle.targetUrl = 'https://test.com';
|
||||
const result = await appTester(
|
||||
App.triggers[triggerRecordKey].operation.performSubscribe,
|
||||
bundle,
|
||||
);
|
||||
const unsubscribeBundle = getBundle({});
|
||||
unsubscribeBundle.subscribeData = { id: result.id };
|
||||
const unsubscribeResult = await appTester(
|
||||
App.triggers[triggerRecordKey].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);
|
||||
});
|
||||
it('should load companies from list', async () => {
|
||||
const bundle = getBundle({});
|
||||
bundle.inputData.nameSingular = 'company';
|
||||
bundle.inputData.operation = 'update';
|
||||
const results = await appTester(
|
||||
App.triggers[triggerRecordKey].operation.performList,
|
||||
bundle,
|
||||
);
|
||||
expect(results.length).toBeGreaterThan(1);
|
||||
const firstCompany = results[0];
|
||||
expect(firstCompany).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('triggers.trigger_record.delete', () => {
|
||||
test('should succeed to subscribe', async () => {
|
||||
const bundle = getBundle({});
|
||||
bundle.inputData.nameSingular = 'company';
|
||||
bundle.inputData.operation = 'delete';
|
||||
bundle.targetUrl = 'https://test.com';
|
||||
const result = await appTester(
|
||||
App.triggers[triggerRecordKey].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.company',
|
||||
);
|
||||
});
|
||||
test('should succeed to unsubscribe', async () => {
|
||||
const bundle = getBundle({});
|
||||
bundle.inputData.nameSingular = 'company';
|
||||
bundle.inputData.operation = 'delete';
|
||||
bundle.targetUrl = 'https://test.com';
|
||||
const result = await appTester(
|
||||
App.triggers[triggerRecordKey].operation.performSubscribe,
|
||||
bundle,
|
||||
);
|
||||
const unsubscribeBundle = getBundle({});
|
||||
unsubscribeBundle.subscribeData = { id: result.id };
|
||||
const unsubscribeResult = await appTester(
|
||||
App.triggers[triggerRecordKey].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);
|
||||
});
|
||||
it('should load companies from list', async () => {
|
||||
const bundle = getBundle({});
|
||||
bundle.inputData.nameSingular = 'company';
|
||||
bundle.inputData.operation = 'delete';
|
||||
const results = await appTester(
|
||||
App.triggers[triggerRecordKey].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);
|
||||
});
|
||||
});
|
||||
@ -1,93 +0,0 @@
|
||||
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();
|
||||
});
|
||||
});
|
||||
@ -1,95 +0,0 @@
|
||||
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);
|
||||
});
|
||||
});
|
||||
@ -1,93 +0,0 @@
|
||||
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