@@ -10,56 +10,68 @@ const appTester = createAppTester(App);
10
10
describe ( 'triggers.trigger_record.created' , ( ) => {
11
11
test ( 'should succeed to subscribe' , async ( ) => {
12
12
const bundle = getBundle ( { } ) ;
13
+
13
14
bundle . inputData . nameSingular = 'company' ;
14
15
bundle . inputData . operation = DatabaseEventAction . CREATED ;
15
16
bundle . targetUrl = 'https://test.com' ;
17
+
16
18
const result = await appTester (
17
19
App . triggers [ triggerRecordKey ] . operation . performSubscribe ,
18
20
bundle ,
19
21
) ;
22
+
20
23
expect ( result ) . toBeDefined ( ) ;
21
24
expect ( result . id ) . toBeDefined ( ) ;
25
+
22
26
const checkDbResult = await appTester (
23
27
( z : ZObject , bundle : Bundle ) =>
24
28
requestDb (
25
29
z ,
26
30
bundle ,
27
- `query webhook {webhooks(filter : {id: {eq: "${ result . id } "}}){edges {node { id operations}} }}` ,
31
+ `query webhook {webhook(input : {id: "${ result . id } "}){ id operations}}` ,
28
32
) ,
29
33
bundle ,
30
34
) ;
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' ) ;
34
37
} ) ;
38
+
35
39
test ( 'should succeed to unsubscribe' , async ( ) => {
36
40
const bundle = getBundle ( { } ) ;
41
+
37
42
bundle . inputData . nameSingular = 'company' ;
38
43
bundle . inputData . operation = DatabaseEventAction . CREATED ;
39
44
bundle . targetUrl = 'https://test.com' ;
45
+
40
46
const result = await appTester (
41
47
App . triggers [ triggerRecordKey ] . operation . performSubscribe ,
42
48
bundle ,
43
49
) ;
50
+
44
51
const unsubscribeBundle = getBundle ( { } ) ;
52
+
45
53
unsubscribeBundle . subscribeData = { id : result . id } ;
54
+
46
55
const unsubscribeResult = await appTester (
47
56
App . triggers [ triggerRecordKey ] . operation . performUnsubscribe ,
48
57
unsubscribeBundle ,
49
58
) ;
59
+
50
60
expect ( unsubscribeResult ) . toBeDefined ( ) ;
51
61
expect ( unsubscribeResult . id ) . toEqual ( result . id ) ;
62
+
52
63
const checkDbResult = await appTester (
53
64
( 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}}` ) ,
59
66
bundle ,
60
67
) ;
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 ) ;
62
73
} ) ;
74
+
63
75
test ( 'should load company from webhook' , async ( ) => {
64
76
const bundle = {
65
77
cleanedRequest : {
@@ -77,91 +89,117 @@ describe('triggers.trigger_record.created', () => {
77
89
} ,
78
90
} ,
79
91
} ;
92
+
80
93
const results = await appTester (
81
94
App . triggers [ triggerRecordKey ] . operation . perform ,
82
95
bundle ,
83
96
) ;
97
+
84
98
expect ( results . length ) . toEqual ( 1 ) ;
99
+
85
100
const company = results [ 0 ] ;
101
+
86
102
expect ( company . record . id ) . toEqual ( 'd6ccb1d1-a90b-4822-a992-a0dd946592c9' ) ;
87
103
} ) ;
88
104
it ( 'should load companies from list' , async ( ) => {
89
105
const bundle = getBundle ( { } ) ;
106
+
90
107
bundle . inputData . nameSingular = 'company' ;
91
108
bundle . inputData . operation = DatabaseEventAction . CREATED ;
109
+
92
110
const results = await appTester (
93
111
App . triggers [ triggerRecordKey ] . operation . performList ,
94
112
bundle ,
95
113
) ;
114
+
96
115
expect ( results . length ) . toBeGreaterThan ( 1 ) ;
116
+
97
117
const firstCompany = results [ 0 ] ;
118
+
98
119
expect ( firstCompany . record ) . toBeDefined ( ) ;
99
120
} ) ;
100
121
} ) ;
101
122
102
123
describe ( 'triggers.trigger_record.update' , ( ) => {
103
124
test ( 'should succeed to subscribe' , async ( ) => {
104
125
const bundle = getBundle ( { } ) ;
126
+
105
127
bundle . inputData . nameSingular = 'company' ;
106
128
bundle . inputData . operation = DatabaseEventAction . UPDATED ;
107
129
bundle . targetUrl = 'https://test.com' ;
130
+
108
131
const result = await appTester (
109
132
App . triggers [ triggerRecordKey ] . operation . performSubscribe ,
110
133
bundle ,
111
134
) ;
135
+
112
136
expect ( result ) . toBeDefined ( ) ;
113
137
expect ( result . id ) . toBeDefined ( ) ;
138
+
114
139
const checkDbResult = await appTester (
115
140
( z : ZObject , bundle : Bundle ) =>
116
141
requestDb (
117
142
z ,
118
143
bundle ,
119
- `query webhook {webhooks(filter : {id: {eq: "${ result . id } "}}){edges {node { id operations}} }}` ,
144
+ `query webhook {webhook(input : {id: "${ result . id } "}){ id operations}}` ,
120
145
) ,
121
146
bundle ,
122
147
) ;
123
- expect ( checkDbResult . data . webhooks . edges [ 0 ] . node . operations [ 0 ] ) . toEqual (
148
+
149
+ expect ( checkDbResult . data . webhooks . operations [ 0 ] ) . toEqual (
124
150
'company.updated' ,
125
151
) ;
126
152
} ) ;
127
153
test ( 'should succeed to unsubscribe' , async ( ) => {
128
154
const bundle = getBundle ( { } ) ;
155
+
129
156
bundle . inputData . nameSingular = 'company' ;
130
157
bundle . inputData . operation = DatabaseEventAction . UPDATED ;
131
158
bundle . targetUrl = 'https://test.com' ;
159
+
132
160
const result = await appTester (
133
161
App . triggers [ triggerRecordKey ] . operation . performSubscribe ,
134
162
bundle ,
135
163
) ;
164
+
136
165
const unsubscribeBundle = getBundle ( { } ) ;
166
+
137
167
unsubscribeBundle . subscribeData = { id : result . id } ;
168
+
138
169
const unsubscribeResult = await appTester (
139
170
App . triggers [ triggerRecordKey ] . operation . performUnsubscribe ,
140
171
unsubscribeBundle ,
141
172
) ;
173
+
142
174
expect ( unsubscribeResult ) . toBeDefined ( ) ;
143
175
expect ( unsubscribeResult . id ) . toEqual ( result . id ) ;
176
+
144
177
const checkDbResult = await appTester (
145
178
( 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}}` ) ,
151
180
bundle ,
152
181
) ;
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 ) ;
154
187
} ) ;
155
188
it ( 'should load companies from list' , async ( ) => {
156
189
const bundle = getBundle ( { } ) ;
190
+
157
191
bundle . inputData . nameSingular = 'company' ;
158
192
bundle . inputData . operation = DatabaseEventAction . UPDATED ;
193
+
159
194
const results = await appTester (
160
195
App . triggers [ triggerRecordKey ] . operation . performList ,
161
196
bundle ,
162
197
) ;
198
+
163
199
expect ( results . length ) . toBeGreaterThan ( 1 ) ;
200
+
164
201
const firstCompany = results [ 0 ] ;
202
+
165
203
expect ( firstCompany . record ) . toBeDefined ( ) ;
166
204
expect ( firstCompany . updatedFields ) . toBeDefined ( ) ;
167
205
} ) ;
@@ -170,66 +208,83 @@ describe('triggers.trigger_record.update', () => {
170
208
describe ( 'triggers.trigger_record.delete' , ( ) => {
171
209
test ( 'should succeed to subscribe' , async ( ) => {
172
210
const bundle = getBundle ( { } ) ;
211
+
173
212
bundle . inputData . nameSingular = 'company' ;
174
213
bundle . inputData . operation = DatabaseEventAction . DELETED ;
175
214
bundle . targetUrl = 'https://test.com' ;
215
+
176
216
const result = await appTester (
177
217
App . triggers [ triggerRecordKey ] . operation . performSubscribe ,
178
218
bundle ,
179
219
) ;
220
+
180
221
expect ( result ) . toBeDefined ( ) ;
181
222
expect ( result . id ) . toBeDefined ( ) ;
223
+
182
224
const checkDbResult = await appTester (
183
225
( z : ZObject , bundle : Bundle ) =>
184
226
requestDb (
185
227
z ,
186
228
bundle ,
187
- `query webhook {webhooks(filter : {id: {eq: "${ result . id } "}}){edges {node { id operations}} }}` ,
229
+ `query webhook {webhook(input : {id: "${ result . id } "}){ id operations}}` ,
188
230
) ,
189
231
bundle ,
190
232
) ;
191
- expect ( checkDbResult . data . webhooks . edges [ 0 ] . node . operations [ 0 ] ) . toEqual (
233
+
234
+ expect ( checkDbResult . data . webhooks . operations [ 0 ] ) . toEqual (
192
235
'company.deleted' ,
193
236
) ;
194
237
} ) ;
195
238
test ( 'should succeed to unsubscribe' , async ( ) => {
196
239
const bundle = getBundle ( { } ) ;
240
+
197
241
bundle . inputData . nameSingular = 'company' ;
198
242
bundle . inputData . operation = DatabaseEventAction . DELETED ;
199
243
bundle . targetUrl = 'https://test.com' ;
244
+
200
245
const result = await appTester (
201
246
App . triggers [ triggerRecordKey ] . operation . performSubscribe ,
202
247
bundle ,
203
248
) ;
249
+
204
250
const unsubscribeBundle = getBundle ( { } ) ;
251
+
205
252
unsubscribeBundle . subscribeData = { id : result . id } ;
253
+
206
254
const unsubscribeResult = await appTester (
207
255
App . triggers [ triggerRecordKey ] . operation . performUnsubscribe ,
208
256
unsubscribeBundle ,
209
257
) ;
258
+
210
259
expect ( unsubscribeResult ) . toBeDefined ( ) ;
211
260
expect ( unsubscribeResult . id ) . toEqual ( result . id ) ;
261
+
212
262
const checkDbResult = await appTester (
213
263
( 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}}` ) ,
219
265
bundle ,
220
266
) ;
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 ) ;
222
272
} ) ;
223
273
it ( 'should load companies from list' , async ( ) => {
224
274
const bundle = getBundle ( { } ) ;
275
+
225
276
bundle . inputData . nameSingular = 'company' ;
226
277
bundle . inputData . operation = DatabaseEventAction . DELETED ;
278
+
227
279
const results = await appTester (
228
280
App . triggers [ triggerRecordKey ] . operation . performList ,
229
281
bundle ,
230
282
) ;
283
+
231
284
expect ( results . length ) . toBeGreaterThan ( 1 ) ;
285
+
232
286
const firstCompany = results [ 0 ] ;
287
+
233
288
expect ( firstCompany ) . toBeDefined ( ) ;
234
289
expect ( firstCompany . record . id ) . toBeDefined ( ) ;
235
290
expect ( Object . keys ( firstCompany ) . length ) . toEqual ( 1 ) ;
0 commit comments