Skip to content

Commit 37e3e34

Browse files
authored
Merge branch 'main' into fix/attachment-deletion
2 parents f6487e9 + 7fde494 commit 37e3e34

File tree

8 files changed

+131
-67
lines changed

8 files changed

+131
-67
lines changed

packages/twenty-server/src/modules/workflow/workflow-runner/workflow-run-queue/cron/jobs/workflow-run-enqueue.cron.job.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class WorkflowRunEnqueueJob {
7676

7777
// Using raw query to avoid storing repository in cache
7878
const workflowRuns = await mainDataSource.query(
79-
`SELECT * FROM ${schemaName}."workflowRun" WHERE status = '${WorkflowRunStatus.NOT_STARTED}' ORDER BY "createdAt" ASC`,
79+
`SELECT id FROM ${schemaName}."workflowRun" WHERE status = '${WorkflowRunStatus.NOT_STARTED}' ORDER BY "createdAt" ASC`,
8080
);
8181

8282
const workflowRunsToEnqueueCount = Math.min(

packages/twenty-zapier/package.json

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
{
22
"name": "twenty-zapier",
3-
"version": "2.0.1",
3+
"version": "2.0.2",
44
"description": "Effortlessly sync Twenty with 3000+ apps. Automate tasks, boost productivity, and supercharge your customer relationships!",
55
"main": "src/index.ts",
6-
"scripts": {
7-
"nx": "NX_DEFAULT_PROJECT=twenty-zapier node ../../node_modules/nx/bin/nx.js",
8-
"format": "prettier . --write \"!build\"",
9-
"test": "yarn build && jest --testTimeout 10000 --rootDir ./lib/test",
10-
"validate": "yarn build && zapier validate",
11-
"versions": "yarn build && zapier versions",
12-
"watch": "yarn clean && npx tsc --watch"
13-
},
146
"engines": {
157
"node": "^22.12.0",
168
"npm": "please-use-yarn",
@@ -21,8 +13,11 @@
2113
"convertedByCLIVersion": "15.4.1"
2214
},
2315
"dependencies": {
16+
"@sniptt/guards": "^0.2.0",
2417
"dotenv": "^16.4.5",
25-
"zapier-platform-core": "15.5.1"
18+
"libphonenumber-js": "^1.10.26",
19+
"zapier-platform-core": "15.5.1",
20+
"zod": "3.23.8"
2621
},
2722
"devDependencies": {
2823
"jest": "29.7.0",

packages/twenty-zapier/project.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,41 @@
1212
},
1313
"dependsOn": ["^build"]
1414
},
15+
"format": {
16+
"executor": "nx:run-commands",
17+
"options": {
18+
"cwd": "{projectRoot}",
19+
"commands": ["prettier . --write \"!build\""]
20+
}
21+
},
22+
"test": {
23+
"executor": "nx:run-commands",
24+
"options": {
25+
"cwd": "{projectRoot}",
26+
"commands": ["NODE_ENV=test && nx run twenty-zapier:build && jest --testTimeout 10000 --rootDir ./lib/test"]
27+
}
28+
},
29+
"validate": {
30+
"executor": "nx:run-commands",
31+
"options": {
32+
"cwd": "{projectRoot}",
33+
"commands": ["nx run twenty-zapier:build && zapier validate"]
34+
}
35+
},
36+
"versions": {
37+
"executor": "nx:run-commands",
38+
"options": {
39+
"cwd": "{projectRoot}",
40+
"commands": ["nx run twenty-zapier:build && zapier versions"]
41+
}
42+
},
43+
"watch":{
44+
"executor": "nx:run-commands",
45+
"options": {
46+
"cwd": "{projectRoot}",
47+
"commands": ["nx run twenty-zapier:clean && npx tsc --watch"]
48+
}
49+
},
1550
"clean": {
1651
"executor": "nx:run-commands",
1752
"options": {

packages/twenty-zapier/src/test/triggers/trigger_record.test.ts

Lines changed: 81 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,56 +10,68 @@ const appTester = createAppTester(App);
1010
describe('triggers.trigger_record.created', () => {
1111
test('should succeed to subscribe', async () => {
1212
const bundle = getBundle({});
13+
1314
bundle.inputData.nameSingular = 'company';
1415
bundle.inputData.operation = DatabaseEventAction.CREATED;
1516
bundle.targetUrl = 'https://test.com';
17+
1618
const result = await appTester(
1719
App.triggers[triggerRecordKey].operation.performSubscribe,
1820
bundle,
1921
);
22+
2023
expect(result).toBeDefined();
2124
expect(result.id).toBeDefined();
25+
2226
const checkDbResult = await appTester(
2327
(z: ZObject, bundle: Bundle) =>
2428
requestDb(
2529
z,
2630
bundle,
27-
`query webhook {webhooks(filter: {id: {eq: "${result.id}"}}){edges {node {id operations}}}}`,
31+
`query webhook {webhook(input: {id: "${result.id}"}){id operations}}`,
2832
),
2933
bundle,
3034
);
31-
expect(checkDbResult.data.webhooks.edges[0].node.operations[0]).toEqual(
32-
'company.created',
33-
);
35+
36+
expect(checkDbResult.data.webhook.operations[0]).toEqual('company.created');
3437
});
38+
3539
test('should succeed to unsubscribe', async () => {
3640
const bundle = getBundle({});
41+
3742
bundle.inputData.nameSingular = 'company';
3843
bundle.inputData.operation = DatabaseEventAction.CREATED;
3944
bundle.targetUrl = 'https://test.com';
45+
4046
const result = await appTester(
4147
App.triggers[triggerRecordKey].operation.performSubscribe,
4248
bundle,
4349
);
50+
4451
const unsubscribeBundle = getBundle({});
52+
4553
unsubscribeBundle.subscribeData = { id: result.id };
54+
4655
const unsubscribeResult = await appTester(
4756
App.triggers[triggerRecordKey].operation.performUnsubscribe,
4857
unsubscribeBundle,
4958
);
59+
5060
expect(unsubscribeResult).toBeDefined();
5161
expect(unsubscribeResult.id).toEqual(result.id);
62+
5263
const checkDbResult = await appTester(
5364
(z: ZObject, bundle: Bundle) =>
54-
requestDb(
55-
z,
56-
bundle,
57-
`query webhook {webhooks(filter: {id: {eq: "${result.id}"}}){edges {node {id operations}}}}`,
58-
),
65+
requestDb(z, bundle, `query webhook {webhooks {id}}`),
5966
bundle,
6067
);
61-
expect(checkDbResult.data.webhooks.edges.length).toEqual(0);
68+
expect(
69+
// @ts-expect-error legacy noImplicitAny
70+
checkDbResult.data.webhooks.filter((webhook) => webhook.id === result.id)
71+
.length,
72+
).toEqual(0);
6273
});
74+
6375
test('should load company from webhook', async () => {
6476
const bundle = {
6577
cleanedRequest: {
@@ -77,91 +89,117 @@ describe('triggers.trigger_record.created', () => {
7789
},
7890
},
7991
};
92+
8093
const results = await appTester(
8194
App.triggers[triggerRecordKey].operation.perform,
8295
bundle,
8396
);
97+
8498
expect(results.length).toEqual(1);
99+
85100
const company = results[0];
101+
86102
expect(company.record.id).toEqual('d6ccb1d1-a90b-4822-a992-a0dd946592c9');
87103
});
88104
it('should load companies from list', async () => {
89105
const bundle = getBundle({});
106+
90107
bundle.inputData.nameSingular = 'company';
91108
bundle.inputData.operation = DatabaseEventAction.CREATED;
109+
92110
const results = await appTester(
93111
App.triggers[triggerRecordKey].operation.performList,
94112
bundle,
95113
);
114+
96115
expect(results.length).toBeGreaterThan(1);
116+
97117
const firstCompany = results[0];
118+
98119
expect(firstCompany.record).toBeDefined();
99120
});
100121
});
101122

102123
describe('triggers.trigger_record.update', () => {
103124
test('should succeed to subscribe', async () => {
104125
const bundle = getBundle({});
126+
105127
bundle.inputData.nameSingular = 'company';
106128
bundle.inputData.operation = DatabaseEventAction.UPDATED;
107129
bundle.targetUrl = 'https://test.com';
130+
108131
const result = await appTester(
109132
App.triggers[triggerRecordKey].operation.performSubscribe,
110133
bundle,
111134
);
135+
112136
expect(result).toBeDefined();
113137
expect(result.id).toBeDefined();
138+
114139
const checkDbResult = await appTester(
115140
(z: ZObject, bundle: Bundle) =>
116141
requestDb(
117142
z,
118143
bundle,
119-
`query webhook {webhooks(filter: {id: {eq: "${result.id}"}}){edges {node {id operations}}}}`,
144+
`query webhook {webhook(input: {id: "${result.id}"}){id operations}}`,
120145
),
121146
bundle,
122147
);
123-
expect(checkDbResult.data.webhooks.edges[0].node.operations[0]).toEqual(
148+
149+
expect(checkDbResult.data.webhooks.operations[0]).toEqual(
124150
'company.updated',
125151
);
126152
});
127153
test('should succeed to unsubscribe', async () => {
128154
const bundle = getBundle({});
155+
129156
bundle.inputData.nameSingular = 'company';
130157
bundle.inputData.operation = DatabaseEventAction.UPDATED;
131158
bundle.targetUrl = 'https://test.com';
159+
132160
const result = await appTester(
133161
App.triggers[triggerRecordKey].operation.performSubscribe,
134162
bundle,
135163
);
164+
136165
const unsubscribeBundle = getBundle({});
166+
137167
unsubscribeBundle.subscribeData = { id: result.id };
168+
138169
const unsubscribeResult = await appTester(
139170
App.triggers[triggerRecordKey].operation.performUnsubscribe,
140171
unsubscribeBundle,
141172
);
173+
142174
expect(unsubscribeResult).toBeDefined();
143175
expect(unsubscribeResult.id).toEqual(result.id);
176+
144177
const checkDbResult = await appTester(
145178
(z: ZObject, bundle: Bundle) =>
146-
requestDb(
147-
z,
148-
bundle,
149-
`query webhook {webhooks(filter: {id: {eq: "${result.id}"}}){edges {node {id operations}}}}`,
150-
),
179+
requestDb(z, bundle, `query webhook {webhooks {id}}`),
151180
bundle,
152181
);
153-
expect(checkDbResult.data.webhooks.edges.length).toEqual(0);
182+
expect(
183+
// @ts-expect-error legacy noImplicitAny
184+
checkDbResult.data.webhooks.filter((webhook) => webhook.id === result.id)
185+
.length,
186+
).toEqual(0);
154187
});
155188
it('should load companies from list', async () => {
156189
const bundle = getBundle({});
190+
157191
bundle.inputData.nameSingular = 'company';
158192
bundle.inputData.operation = DatabaseEventAction.UPDATED;
193+
159194
const results = await appTester(
160195
App.triggers[triggerRecordKey].operation.performList,
161196
bundle,
162197
);
198+
163199
expect(results.length).toBeGreaterThan(1);
200+
164201
const firstCompany = results[0];
202+
165203
expect(firstCompany.record).toBeDefined();
166204
expect(firstCompany.updatedFields).toBeDefined();
167205
});
@@ -170,66 +208,83 @@ describe('triggers.trigger_record.update', () => {
170208
describe('triggers.trigger_record.delete', () => {
171209
test('should succeed to subscribe', async () => {
172210
const bundle = getBundle({});
211+
173212
bundle.inputData.nameSingular = 'company';
174213
bundle.inputData.operation = DatabaseEventAction.DELETED;
175214
bundle.targetUrl = 'https://test.com';
215+
176216
const result = await appTester(
177217
App.triggers[triggerRecordKey].operation.performSubscribe,
178218
bundle,
179219
);
220+
180221
expect(result).toBeDefined();
181222
expect(result.id).toBeDefined();
223+
182224
const checkDbResult = await appTester(
183225
(z: ZObject, bundle: Bundle) =>
184226
requestDb(
185227
z,
186228
bundle,
187-
`query webhook {webhooks(filter: {id: {eq: "${result.id}"}}){edges {node {id operations}}}}`,
229+
`query webhook {webhook(input: {id: "${result.id}"}){id operations}}`,
188230
),
189231
bundle,
190232
);
191-
expect(checkDbResult.data.webhooks.edges[0].node.operations[0]).toEqual(
233+
234+
expect(checkDbResult.data.webhooks.operations[0]).toEqual(
192235
'company.deleted',
193236
);
194237
});
195238
test('should succeed to unsubscribe', async () => {
196239
const bundle = getBundle({});
240+
197241
bundle.inputData.nameSingular = 'company';
198242
bundle.inputData.operation = DatabaseEventAction.DELETED;
199243
bundle.targetUrl = 'https://test.com';
244+
200245
const result = await appTester(
201246
App.triggers[triggerRecordKey].operation.performSubscribe,
202247
bundle,
203248
);
249+
204250
const unsubscribeBundle = getBundle({});
251+
205252
unsubscribeBundle.subscribeData = { id: result.id };
253+
206254
const unsubscribeResult = await appTester(
207255
App.triggers[triggerRecordKey].operation.performUnsubscribe,
208256
unsubscribeBundle,
209257
);
258+
210259
expect(unsubscribeResult).toBeDefined();
211260
expect(unsubscribeResult.id).toEqual(result.id);
261+
212262
const checkDbResult = await appTester(
213263
(z: ZObject, bundle: Bundle) =>
214-
requestDb(
215-
z,
216-
bundle,
217-
`query webhook {webhooks(filter: {id: {eq: "${result.id}"}}){edges {node {id operations}}}}`,
218-
),
264+
requestDb(z, bundle, `query webhook {webhooks {id}}`),
219265
bundle,
220266
);
221-
expect(checkDbResult.data.webhooks.edges.length).toEqual(0);
267+
expect(
268+
// @ts-expect-error legacy noImplicitAny
269+
checkDbResult.data.webhooks.filter((webhook) => webhook.id === result.id)
270+
.length,
271+
).toEqual(0);
222272
});
223273
it('should load companies from list', async () => {
224274
const bundle = getBundle({});
275+
225276
bundle.inputData.nameSingular = 'company';
226277
bundle.inputData.operation = DatabaseEventAction.DELETED;
278+
227279
const results = await appTester(
228280
App.triggers[triggerRecordKey].operation.performList,
229281
bundle,
230282
);
283+
231284
expect(results.length).toBeGreaterThan(1);
285+
232286
const firstCompany = results[0];
287+
233288
expect(firstCompany).toBeDefined();
234289
expect(firstCompany.record.id).toBeDefined();
235290
expect(Object.keys(firstCompany).length).toEqual(1);

0 commit comments

Comments
 (0)