-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix create trigger called twice (#3243)
* Fix create trigger called twice * Add Zapier update action * Add Zapier delete action * Update description * Add dropDown for ids
- Loading branch information
Showing
17 changed files
with
358 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { Bundle, ZObject } from 'zapier-platform-core'; | ||
|
||
import { findObjectNamesPluralKey } from '../triggers/find_object_names_plural'; | ||
import { listRecordIdsKey } from '../triggers/list_record_ids'; | ||
import { capitalize } from '../utils/capitalize'; | ||
import requestDb from '../utils/requestDb'; | ||
|
||
export const deleteRecordKey = 'delete_record'; | ||
|
||
const perform = async (z: ZObject, bundle: Bundle) => { | ||
const data = bundle.inputData; | ||
const nameSingular = data.nameSingular; | ||
const id = data.id; | ||
delete data.nameSingular; | ||
delete data.id; | ||
const query = ` | ||
mutation delete${capitalize(nameSingular)} { | ||
delete${capitalize(nameSingular)}( | ||
id: "${id}" | ||
) | ||
{id} | ||
}`; | ||
return await requestDb(z, bundle, query); | ||
}; | ||
|
||
export default { | ||
display: { | ||
description: 'Delete a Record in Twenty.', | ||
hidden: false, | ||
label: 'Delete Record', | ||
}, | ||
key: deleteRecordKey, | ||
noun: 'Record', | ||
operation: { | ||
inputFields: [ | ||
{ | ||
key: 'namePlural', | ||
label: 'Record Name', | ||
dynamic: `${findObjectNamesPluralKey}.namePlural`, | ||
required: true, | ||
altersDynamicFields: true, | ||
}, | ||
{ | ||
key: 'id', | ||
label: 'Id', | ||
type: 'string', | ||
dynamic: `${listRecordIdsKey}.id`, | ||
required: true, | ||
}, | ||
], | ||
sample: { | ||
id: '179ed459-79cf-41d9-ab85-96397fa8e936', | ||
}, | ||
perform, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { Bundle, ZObject } from 'zapier-platform-core'; | ||
|
||
import { findObjectNamesSingularKey } from '../triggers/find_object_names_singular'; | ||
import { capitalize } from '../utils/capitalize'; | ||
import { recordInputFields } from '../utils/creates/creates.utils'; | ||
import handleQueryParams from '../utils/handleQueryParams'; | ||
import requestDb from '../utils/requestDb'; | ||
|
||
export const updateRecordKey = 'update_record'; | ||
|
||
const perform = async (z: ZObject, bundle: Bundle) => { | ||
const data = bundle.inputData; | ||
const nameSingular = data.nameSingular; | ||
const id = data.id; | ||
delete data.nameSingular; | ||
delete data.id; | ||
const query = ` | ||
mutation update${capitalize(nameSingular)} { | ||
update${capitalize(nameSingular)}( | ||
data:{${handleQueryParams(data)}}, | ||
id: "${id}" | ||
) | ||
{id} | ||
}`; | ||
return await requestDb(z, bundle, query); | ||
}; | ||
|
||
const updateRecordInputFields = async (z: ZObject, bundle: Bundle) => { | ||
return recordInputFields(z, bundle, true); | ||
}; | ||
|
||
export default { | ||
display: { | ||
description: 'Update a Record in Twenty.', | ||
hidden: false, | ||
label: 'Update Record', | ||
}, | ||
key: updateRecordKey, | ||
noun: 'Record', | ||
operation: { | ||
inputFields: [ | ||
{ | ||
key: 'nameSingular', | ||
required: true, | ||
label: 'Record Name', | ||
dynamic: `${findObjectNamesSingularKey}.nameSingular`, | ||
altersDynamicFields: true, | ||
}, | ||
updateRecordInputFields, | ||
], | ||
sample: { | ||
id: '179ed459-79cf-41d9-ab85-96397fa8e936', | ||
}, | ||
perform, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 4 additions & 3 deletions
7
packages/twenty-zapier/src/test/creates/create_record.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
packages/twenty-zapier/src/test/creates/delete_record.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
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); | ||
}); | ||
}); |
50 changes: 50 additions & 0 deletions
50
packages/twenty-zapier/src/test/creates/update_record.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
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'); | ||
}); | ||
}); |
20 changes: 20 additions & 0 deletions
20
packages/twenty-zapier/src/test/triggers/list_record_ids.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { createAppTester, tools } from 'zapier-platform-core'; | ||
|
||
import App from '../../index'; | ||
import { listRecordIdsKey } from '../../triggers/list_record_ids'; | ||
import getBundle from '../../utils/getBundle'; | ||
tools.env.inject(); | ||
|
||
const appTester = createAppTester(App); | ||
describe('triggers.list_record_ids', () => { | ||
test('should run', async () => { | ||
const bundle = getBundle({ namePlural: 'companies' }); | ||
const result = await appTester( | ||
App.triggers[listRecordIdsKey].operation.perform, | ||
bundle, | ||
); | ||
expect(result).toBeDefined(); | ||
expect(result.length).toBeGreaterThan(1); | ||
expect(result[0].id).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.