mirror of
https://github.com/twentyhq/twenty.git
synced 2024-09-11 15:35:36 +03:00
parent
6653fb6ccd
commit
e2d93fa027
49
packages/twenty-zapier/src/creates/create_record.ts
Normal file
49
packages/twenty-zapier/src/creates/create_record.ts
Normal file
@ -0,0 +1,49 @@
|
||||
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';
|
||||
|
||||
const perform = async (z: ZObject, bundle: Bundle) => {
|
||||
const data = bundle.inputData;
|
||||
const nameSingular = data.nameSingular;
|
||||
delete data.nameSingular;
|
||||
const query = `
|
||||
mutation create${capitalize(nameSingular)} {
|
||||
create${capitalize(nameSingular)}(
|
||||
data:{${handleQueryParams(data)}}
|
||||
)
|
||||
{id}
|
||||
}`;
|
||||
return await requestDb(z, bundle, query);
|
||||
};
|
||||
|
||||
export const createRecordKey = 'create_record';
|
||||
|
||||
export default {
|
||||
display: {
|
||||
description: 'Create a Record in Twenty.',
|
||||
hidden: false,
|
||||
label: 'Create Record',
|
||||
},
|
||||
key: createRecordKey,
|
||||
noun: 'Record',
|
||||
operation: {
|
||||
inputFields: [
|
||||
{
|
||||
key: 'nameSingular',
|
||||
required: true,
|
||||
label: 'Record Name',
|
||||
dynamic: `${findObjectNamesSingularKey}.nameSingular`,
|
||||
altersDynamicFields: true,
|
||||
},
|
||||
recordInputFields,
|
||||
],
|
||||
sample: {
|
||||
id: '179ed459-79cf-41d9-ab85-96397fa8e936',
|
||||
},
|
||||
perform,
|
||||
},
|
||||
};
|
56
packages/twenty-zapier/src/creates/delete_record.ts
Normal file
56
packages/twenty-zapier/src/creates/delete_record.ts
Normal file
@ -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,
|
||||
},
|
||||
};
|
56
packages/twenty-zapier/src/creates/update_record.ts
Normal file
56
packages/twenty-zapier/src/creates/update_record.ts
Normal file
@ -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,
|
||||
},
|
||||
};
|
@ -4,7 +4,10 @@ import 'dotenv/config';
|
||||
|
||||
const { version } = require('../package.json');
|
||||
|
||||
import crudRecord, { crudRecordKey } from './creates/crud_record';
|
||||
import createRecord, { createRecordKey } from './creates/create_record';
|
||||
import crudRecord, { crudRecordKey } from './creates/create_record_2';
|
||||
import deleteRecord, { deleteRecordKey } from './creates/delete_record';
|
||||
import updateRecord, { updateRecordKey } from './creates/update_record';
|
||||
import findObjectNamesPlural, {
|
||||
findObjectNamesPluralKey,
|
||||
} from './triggers/find_object_names_plural';
|
||||
@ -24,6 +27,9 @@ export default {
|
||||
[triggerRecordKey]: triggerRecord,
|
||||
},
|
||||
creates: {
|
||||
[createRecordKey]: createRecord,
|
||||
[updateRecordKey]: updateRecord,
|
||||
[deleteRecordKey]: deleteRecord,
|
||||
[crudRecordKey]: crudRecord,
|
||||
},
|
||||
};
|
||||
|
@ -0,0 +1,70 @@
|
||||
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');
|
||||
});
|
||||
});
|
@ -1,6 +1,6 @@
|
||||
import { Bundle, createAppTester, tools, ZObject } from 'zapier-platform-core';
|
||||
|
||||
import { crudRecordKey } from '../../creates/crud_record';
|
||||
import { crudRecordKey } from '../../creates/create_record_2';
|
||||
import App from '../../index';
|
||||
import getBundle from '../../utils/getBundle';
|
||||
import requestDb from '../../utils/requestDb';
|
@ -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);
|
||||
});
|
||||
});
|
@ -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');
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user