diff --git a/packages/twenty-zapier/src/index.ts b/packages/twenty-zapier/src/index.ts index f6c0317db..49b875857 100644 --- a/packages/twenty-zapier/src/index.ts +++ b/packages/twenty-zapier/src/index.ts @@ -2,7 +2,6 @@ const { version } = require('../package.json'); import { version as platformVersion } from 'zapier-platform-core'; import createPerson from './creates/create_person'; import createCompany from './creates/create_company'; -import company from './triggers/company'; import authentication from './authentication'; import 'dotenv/config'; @@ -10,9 +9,6 @@ export default { version, platformVersion, authentication: authentication, - triggers: { - [company.key]: company, - }, creates: { [createPerson.key]: createPerson, [createCompany.key]: createCompany, diff --git a/packages/twenty-zapier/src/test/triggers/company.test.ts b/packages/twenty-zapier/src/test/triggers/company.test.ts deleted file mode 100644 index 15ac248cb..000000000 --- a/packages/twenty-zapier/src/test/triggers/company.test.ts +++ /dev/null @@ -1,89 +0,0 @@ -import { Bundle, createAppTester, ZObject } from 'zapier-platform-core'; -import App from '../../index'; -import getBundle from '../../utils/getBundle'; -import requestDb from '../../utils/requestDb'; -const appTester = createAppTester(App); - -describe('triggers.company', () => { - test('should succeed to subscribe', async () => { - const bundle = getBundle({}); - bundle.targetUrl = 'https://test.com'; - const result = await appTester( - App.triggers.company.operation.performSubscribe, - bundle, - ); - expect(result).toBeDefined(); - expect(result.id).toBeDefined(); - const checkDbResult = await appTester( - (z: ZObject, bundle: Bundle) => - requestDb( - z, - bundle, - `query webhook {webhook(filter: {id: {eq: "${result.id}"}}){id operation}}`, - ), - bundle, - ); - expect(checkDbResult.data.webhook.operation).toEqual( - 'company', - ); - }); - test('should succeed to unsubscribe', async () => { - const bundle = getBundle({}); - bundle.targetUrl = 'https://test.com'; - const result = await appTester( - App.triggers.company.operation.performSubscribe, - bundle, - ); - const unsubscribeBundle = getBundle({}); - unsubscribeBundle.subscribeData = { id: result.id }; - const unsubscribeResult = await appTester( - App.triggers.company.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 {webhook(filter: {id: {eq: "${result.id}"}}){id}}`, - ), - bundle, - ); - expect(checkDbResult.data.webhook).toEqual(null); - }); - 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.company.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({}); - const results = await appTester( - App.triggers.company.operation.performList, - bundle, - ); - expect(results.length).toBeGreaterThan(1); - const firstCompany = results[0]; - expect(firstCompany.node.id).toBeDefined(); - }); -}); diff --git a/packages/twenty-zapier/src/triggers/company.ts b/packages/twenty-zapier/src/triggers/company.ts deleted file mode 100644 index b106ae1fc..000000000 --- a/packages/twenty-zapier/src/triggers/company.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { Bundle, ZObject } from 'zapier-platform-core'; -import requestDb from '../utils/requestDb'; -import handleQueryParams from '../utils/handleQueryParams'; - -const performSubscribe = async (z: ZObject, bundle: Bundle) => { - const data = { targetUrl: bundle.targetUrl, operation: 'company' }; - const result = await requestDb( - z, - bundle, - `mutation createWebhook {createWebhook(data:{${handleQueryParams( - data, - )}}) {id}}`, - ); - return result.data.createWebhook; -}; -const performUnsubscribe = async (z: ZObject, bundle: Bundle) => { - const data = { id: bundle.subscribeData?.id }; - const result = await requestDb( - z, - bundle, - `mutation deleteWebhook {deleteWebhook(${handleQueryParams( - data, - )}) {id}}`, - ); - return result.data.deleteWebhook; -}; -const perform = (z: ZObject, bundle: Bundle) => { - return [bundle.cleanedRequest]; -}; -const performList = async (z: ZObject, bundle: Bundle) => { - const results = await requestDb( - z, - bundle, - `query company {companies {edges {node { - id - name - domainName - createdAt - address - employees - linkedinLink{label url} - xLink{label url} - annualRecurringRevenue{amountMicros currencyCode} - idealCustomerProfile - }}}}`, - ); - return results.data.companies.edges; -}; -export default { - key: 'company', - noun: 'Company', - display: { - label: 'New Company', - description: 'Triggers when a new company is created.', - }, - operation: { - inputFields: [], - type: 'hook', - performSubscribe, - performUnsubscribe, - perform, - performList, - sample: { - id: 'f75f6b2e-9442-4c72-aa95-47d8e5ec8cb3', - createdAt: '2023-10-19T07:37:25.306Z', - workspaceId: 'c8b070fc-c969-4ca5-837a-e7c3735734d2', - }, - outputFields: [ - { key: 'id', label: 'ID' }, - { key: 'createdAt', label: 'Created At' }, - { key: 'workspaceId', label: 'Workspace ID' }, - ], - }, -};