mirror of
https://github.com/twentyhq/twenty.git
synced 2024-11-22 11:43:34 +03:00
Rename file
This commit is contained in:
parent
ce079ddb02
commit
2e72e05793
@ -1,49 +0,0 @@
|
||||
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,
|
||||
},
|
||||
};
|
@ -1,56 +0,0 @@
|
||||
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,
|
||||
},
|
||||
};
|
@ -1,56 +0,0 @@
|
||||
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,10 +4,7 @@ import 'dotenv/config';
|
||||
|
||||
const { version } = require('../package.json');
|
||||
|
||||
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 crudRecord, { crudRecordKey } from './creates/crud_record';
|
||||
import findObjectNamesPlural, {
|
||||
findObjectNamesPluralKey,
|
||||
} from './triggers/find_object_names_plural';
|
||||
@ -29,9 +26,6 @@ export default {
|
||||
[triggerRecordKey]: triggerRecord,
|
||||
},
|
||||
creates: {
|
||||
[createRecordKey]: createRecord,
|
||||
[updateRecordKey]: updateRecord,
|
||||
[deleteRecordKey]: deleteRecord,
|
||||
[crudRecordKey]: crudRecord,
|
||||
},
|
||||
};
|
||||
|
@ -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');
|
||||
});
|
||||
});
|
@ -1,6 +1,6 @@
|
||||
import { Bundle, createAppTester, tools, ZObject } from 'zapier-platform-core';
|
||||
|
||||
import { crudRecordKey } from '../../creates/create_record_2';
|
||||
import { crudRecordKey } from '../../creates/crud_record';
|
||||
import App from '../../index';
|
||||
import getBundle from '../../utils/getBundle';
|
||||
import requestDb from '../../utils/requestDb';
|
@ -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');
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user