@marcoappio/marco-config 2.0.427 → 2.0.428
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/types/AuthData.d.ts +4 -0
- package/dist/types/AuthData.d.ts.map +1 -0
- package/dist/types/AuthData.js +1 -0
- package/dist/types/Zero.d.ts +18 -0
- package/dist/types/Zero.d.ts.map +1 -1
- package/dist/types/Zero.js +5 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/zero/index.d.ts +176 -184
- package/dist/zero/index.d.ts.map +1 -1
- package/dist/zero/index.js +0 -7
- package/dist/zero/{mutators → mutatorSchemas}/account.d.ts +4 -33
- package/dist/zero/mutatorSchemas/account.d.ts.map +1 -0
- package/dist/zero/{mutators → mutatorSchemas}/account.js +4 -7
- package/dist/zero/{mutators → mutatorSchemas}/draft.d.ts +1 -1
- package/dist/zero/{mutators → mutatorSchemas}/draft.d.ts.map +1 -1
- package/dist/zero/{mutators → mutatorSchemas}/draft.js +1 -1
- package/dist/zero/mutatorSchemas/index.d.ts +5 -0
- package/dist/zero/mutatorSchemas/index.d.ts.map +1 -0
- package/dist/zero/mutatorSchemas/index.js +4 -0
- package/dist/zero/{mutators → mutatorSchemas}/thread.d.ts +13 -26
- package/dist/zero/mutatorSchemas/thread.d.ts.map +1 -0
- package/dist/zero/{mutators → mutatorSchemas}/thread.js +13 -24
- package/dist/zero/{mutators → mutatorSchemas}/user.d.ts +1 -7
- package/dist/zero/mutatorSchemas/user.d.ts.map +1 -0
- package/dist/zero/{mutators → mutatorSchemas}/user.js +1 -7
- package/dist/zero/mutators/accountMutators/accountMutators.d.ts +8 -0
- package/dist/zero/mutators/accountMutators/accountMutators.d.ts.map +1 -0
- package/dist/zero/mutators/accountMutators/accountMutators.js +112 -0
- package/dist/zero/mutators/accountMutators/accountMutators.test.d.ts +2 -0
- package/dist/zero/mutators/accountMutators/accountMutators.test.d.ts.map +1 -0
- package/dist/zero/mutators/accountMutators/accountMutators.test.js +390 -0
- package/dist/zero/mutators/accountMutators/index.d.ts +2 -0
- package/dist/zero/mutators/accountMutators/index.d.ts.map +1 -0
- package/dist/zero/mutators/accountMutators/index.js +1 -0
- package/dist/zero/mutators/draftMutators/draftMutators.d.ts +8 -0
- package/dist/zero/mutators/draftMutators/draftMutators.d.ts.map +1 -0
- package/dist/zero/mutators/draftMutators/draftMutators.js +162 -0
- package/dist/zero/mutators/draftMutators/draftMutators.test.d.ts +2 -0
- package/dist/zero/mutators/draftMutators/draftMutators.test.d.ts.map +1 -0
- package/dist/zero/mutators/draftMutators/draftMutators.test.js +390 -0
- package/dist/zero/mutators/draftMutators/index.d.ts +2 -0
- package/dist/zero/mutators/draftMutators/index.d.ts.map +1 -0
- package/dist/zero/mutators/draftMutators/index.js +1 -0
- package/dist/zero/mutators/index.d.ts +6566 -0
- package/dist/zero/mutators/index.d.ts.map +1 -0
- package/dist/zero/mutators/index.js +17 -0
- package/dist/zero/mutators/mutators.d.ts +29 -0
- package/dist/zero/mutators/mutators.d.ts.map +1 -0
- package/dist/zero/{mutators.js → mutators/mutators.js} +10 -15
- package/dist/zero/mutators/threadMutators/index.d.ts +2 -0
- package/dist/zero/mutators/threadMutators/index.d.ts.map +1 -0
- package/dist/zero/mutators/threadMutators/index.js +1 -0
- package/dist/zero/mutators/threadMutators/threadMutators.d.ts +8 -0
- package/dist/zero/mutators/threadMutators/threadMutators.d.ts.map +1 -0
- package/dist/zero/mutators/threadMutators/threadMutators.js +238 -0
- package/dist/zero/mutators/threadMutators/threadMutators.test.d.ts +2 -0
- package/dist/zero/mutators/threadMutators/threadMutators.test.d.ts.map +1 -0
- package/dist/zero/mutators/threadMutators/threadMutators.test.js +465 -0
- package/dist/zero/mutators/userMutators/index.d.ts +2 -0
- package/dist/zero/mutators/userMutators/index.d.ts.map +1 -0
- package/dist/zero/mutators/userMutators/index.js +1 -0
- package/dist/zero/mutators/userMutators/userMutators.d.ts +8 -0
- package/dist/zero/mutators/userMutators/userMutators.d.ts.map +1 -0
- package/dist/zero/mutators/userMutators/userMutators.js +37 -0
- package/dist/zero/mutators/userMutators/userMutators.test.d.ts +2 -0
- package/dist/zero/mutators/userMutators/userMutators.test.d.ts.map +1 -0
- package/dist/zero/mutators/userMutators/userMutators.test.js +123 -0
- package/dist/zero/queries/getAccounts.d.ts +29 -29
- package/dist/zero/queries/getContacts.d.ts +29 -29
- package/dist/zero/queries/getDrafts.d.ts +29 -29
- package/dist/zero/queries/getThreads.d.ts +29 -29
- package/dist/zero/queries/getUser.d.ts +29 -29
- package/dist/zero/queries/index.d.ts +29 -29
- package/dist/zero/schema.d.ts +29 -29
- package/package.json +1 -1
- package/dist/zero/mutators/account.d.ts.map +0 -1
- package/dist/zero/mutators/thread.d.ts.map +0 -1
- package/dist/zero/mutators/user.d.ts.map +0 -1
- package/dist/zero/mutators.d.ts +0 -412
- package/dist/zero/mutators.d.ts.map +0 -1
- package/dist/zero/mutators.test.d.ts +0 -2
- package/dist/zero/mutators.test.d.ts.map +0 -1
- package/dist/zero/mutators.test.js +0 -33
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
import { describe, expect, it, mock } from 'bun:test';
|
|
2
|
+
import { createMutators } from '../mutators';
|
|
3
|
+
describe('threadMutators', () => {
|
|
4
|
+
describe('addLabel', () => {
|
|
5
|
+
it('adds label to thread', async () => {
|
|
6
|
+
const threadRecord = {
|
|
7
|
+
accountId: 'test-account-id-1',
|
|
8
|
+
id: 'test-thread-id-1',
|
|
9
|
+
};
|
|
10
|
+
const labelRecord = {
|
|
11
|
+
accountId: 'test-account-id-1',
|
|
12
|
+
id: 'test-label-id-1',
|
|
13
|
+
path: 'Work',
|
|
14
|
+
};
|
|
15
|
+
const runThread = mock(async () => threadRecord);
|
|
16
|
+
const oneThread = mock(() => ({ run: runThread }));
|
|
17
|
+
const whereThread = mock(() => ({ one: oneThread }));
|
|
18
|
+
const runLabel = mock(async () => labelRecord);
|
|
19
|
+
const oneLabel = mock(() => ({ run: runLabel }));
|
|
20
|
+
const whereLabelPath = mock(() => ({ one: oneLabel }));
|
|
21
|
+
const whereLabelAccount = mock(() => ({ where: whereLabelPath }));
|
|
22
|
+
const runExisting = mock(async () => null);
|
|
23
|
+
const oneExisting = mock(() => ({ run: runExisting }));
|
|
24
|
+
const whereLabelId = mock(() => ({ one: oneExisting }));
|
|
25
|
+
const whereThreadLabel = mock(() => ({ where: whereLabelId }));
|
|
26
|
+
const threadLabelInsert = mock(async () => { });
|
|
27
|
+
const transaction = {
|
|
28
|
+
mutate: {
|
|
29
|
+
threadLabel: {
|
|
30
|
+
delete: mock(async () => { }),
|
|
31
|
+
insert: threadLabelInsert,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
query: {
|
|
35
|
+
accountLabel: {
|
|
36
|
+
where: whereLabelAccount,
|
|
37
|
+
},
|
|
38
|
+
thread: {
|
|
39
|
+
where: whereThread,
|
|
40
|
+
},
|
|
41
|
+
threadLabel: {
|
|
42
|
+
where: whereThreadLabel,
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
const mutators = createMutators();
|
|
47
|
+
await mutators.thread.addLabel(transaction, {
|
|
48
|
+
labelPath: 'Work',
|
|
49
|
+
threadIds: ['test-thread-id-1'],
|
|
50
|
+
});
|
|
51
|
+
expect(threadLabelInsert).toHaveBeenCalledWith({
|
|
52
|
+
labelId: 'test-label-id-1',
|
|
53
|
+
threadId: 'test-thread-id-1',
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
describe('delete', () => {
|
|
58
|
+
it('deletes threads', async () => {
|
|
59
|
+
const threadDelete = mock(async () => { });
|
|
60
|
+
const transaction = {
|
|
61
|
+
mutate: {
|
|
62
|
+
thread: {
|
|
63
|
+
delete: threadDelete,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
query: {},
|
|
67
|
+
};
|
|
68
|
+
const mutators = createMutators();
|
|
69
|
+
await mutators.thread.delete(transaction, {
|
|
70
|
+
threadIds: ['test-thread-id-1', 'test-thread-id-2'],
|
|
71
|
+
});
|
|
72
|
+
expect(threadDelete).toHaveBeenCalledTimes(2);
|
|
73
|
+
expect(threadDelete).toHaveBeenCalledWith({
|
|
74
|
+
id: 'test-thread-id-1',
|
|
75
|
+
});
|
|
76
|
+
expect(threadDelete).toHaveBeenCalledWith({
|
|
77
|
+
id: 'test-thread-id-2',
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
describe('removeLabel', () => {
|
|
82
|
+
it('removes label from thread', async () => {
|
|
83
|
+
const threadRecord = {
|
|
84
|
+
accountId: 'test-account-id-1',
|
|
85
|
+
id: 'test-thread-id-1',
|
|
86
|
+
};
|
|
87
|
+
const labelRecord = {
|
|
88
|
+
accountId: 'test-account-id-1',
|
|
89
|
+
id: 'test-label-id-1',
|
|
90
|
+
path: 'Work',
|
|
91
|
+
};
|
|
92
|
+
const existingRecord = {
|
|
93
|
+
labelId: 'test-label-id-1',
|
|
94
|
+
threadId: 'test-thread-id-1',
|
|
95
|
+
};
|
|
96
|
+
const runThread = mock(async () => threadRecord);
|
|
97
|
+
const oneThread = mock(() => ({ run: runThread }));
|
|
98
|
+
const whereThread = mock(() => ({ one: oneThread }));
|
|
99
|
+
const runLabel = mock(async () => labelRecord);
|
|
100
|
+
const oneLabel = mock(() => ({ run: runLabel }));
|
|
101
|
+
const whereLabelPath = mock(() => ({ one: oneLabel }));
|
|
102
|
+
const whereLabelAccount = mock(() => ({ where: whereLabelPath }));
|
|
103
|
+
const runExisting = mock(async () => existingRecord);
|
|
104
|
+
const oneExisting = mock(() => ({ run: runExisting }));
|
|
105
|
+
const whereLabelId = mock(() => ({ one: oneExisting }));
|
|
106
|
+
const whereThreadLabel = mock(() => ({ where: whereLabelId }));
|
|
107
|
+
const threadLabelDelete = mock(async () => { });
|
|
108
|
+
const transaction = {
|
|
109
|
+
mutate: {
|
|
110
|
+
threadLabel: {
|
|
111
|
+
delete: threadLabelDelete,
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
query: {
|
|
115
|
+
accountLabel: {
|
|
116
|
+
where: whereLabelAccount,
|
|
117
|
+
},
|
|
118
|
+
thread: {
|
|
119
|
+
where: whereThread,
|
|
120
|
+
},
|
|
121
|
+
threadLabel: {
|
|
122
|
+
where: whereThreadLabel,
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
const mutators = createMutators();
|
|
127
|
+
await mutators.thread.removeLabel(transaction, {
|
|
128
|
+
labelPath: 'Work',
|
|
129
|
+
threadIds: ['test-thread-id-1'],
|
|
130
|
+
});
|
|
131
|
+
expect(threadLabelDelete).toHaveBeenCalledWith({
|
|
132
|
+
labelId: 'test-label-id-1',
|
|
133
|
+
threadId: 'test-thread-id-1',
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
describe('requestAttachmentDownload', () => {
|
|
138
|
+
it('requests attachment download', async () => {
|
|
139
|
+
const attachmentRecord = {
|
|
140
|
+
id: 'test-attachment-id-1',
|
|
141
|
+
status: 'NOT_DOWNLOADED',
|
|
142
|
+
};
|
|
143
|
+
const run = mock(async () => attachmentRecord);
|
|
144
|
+
const one = mock(() => ({ run }));
|
|
145
|
+
const where = mock(() => ({ one }));
|
|
146
|
+
const attachmentUpdate = mock(async () => { });
|
|
147
|
+
const transaction = {
|
|
148
|
+
mutate: {
|
|
149
|
+
threadMessageAttachment: {
|
|
150
|
+
update: attachmentUpdate,
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
query: {
|
|
154
|
+
threadMessageAttachment: {
|
|
155
|
+
where,
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
const mutators = createMutators();
|
|
160
|
+
await mutators.thread.requestAttachmentDownload(transaction, {
|
|
161
|
+
attachmentId: 'test-attachment-id-1',
|
|
162
|
+
threadId: 'test-thread-id-1',
|
|
163
|
+
});
|
|
164
|
+
expect(attachmentUpdate).toHaveBeenCalledWith({
|
|
165
|
+
id: 'test-attachment-id-1',
|
|
166
|
+
status: 'DOWNLOAD_REQUESTED',
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
describe('setArchive', () => {
|
|
171
|
+
it('archives thread', async () => {
|
|
172
|
+
let labelQueryCount = 0;
|
|
173
|
+
let threadLabelQueryCount = 0;
|
|
174
|
+
const threadRecord = {
|
|
175
|
+
accountId: 'test-account-id-1',
|
|
176
|
+
id: 'test-thread-id-1',
|
|
177
|
+
};
|
|
178
|
+
const inboxLabel = {
|
|
179
|
+
accountId: 'test-account-id-1',
|
|
180
|
+
id: 'test-inbox-label-id',
|
|
181
|
+
specialUse: 'INBOX',
|
|
182
|
+
};
|
|
183
|
+
const archiveLabel = {
|
|
184
|
+
accountId: 'test-account-id-1',
|
|
185
|
+
id: 'test-archive-label-id',
|
|
186
|
+
specialUse: 'ARCHIVE',
|
|
187
|
+
};
|
|
188
|
+
const runThread = mock(async () => threadRecord);
|
|
189
|
+
const oneThread = mock(() => ({ run: runThread }));
|
|
190
|
+
const whereThread = mock(() => ({ one: oneThread }));
|
|
191
|
+
const runLabel = mock(async () => {
|
|
192
|
+
const result = labelQueryCount === 0 ? inboxLabel : archiveLabel;
|
|
193
|
+
labelQueryCount++;
|
|
194
|
+
return result;
|
|
195
|
+
});
|
|
196
|
+
const oneLabel = mock(() => ({ run: runLabel }));
|
|
197
|
+
const whereSpecialUse = mock(() => ({ one: oneLabel }));
|
|
198
|
+
const whereLabelAccount = mock(() => ({ where: whereSpecialUse }));
|
|
199
|
+
const runExisting = mock(async () => {
|
|
200
|
+
const result = threadLabelQueryCount === 0 ? { labelId: 'test-inbox-label-id' } : null;
|
|
201
|
+
threadLabelQueryCount++;
|
|
202
|
+
return result;
|
|
203
|
+
});
|
|
204
|
+
const oneExisting = mock(() => ({ run: runExisting }));
|
|
205
|
+
const whereLabel = mock(() => ({ one: oneExisting }));
|
|
206
|
+
const whereThreadLabel = mock(() => ({ where: whereLabel }));
|
|
207
|
+
const threadLabelDelete = mock(async () => { });
|
|
208
|
+
const threadLabelInsert = mock(async () => { });
|
|
209
|
+
const transaction = {
|
|
210
|
+
mutate: {
|
|
211
|
+
threadLabel: {
|
|
212
|
+
delete: threadLabelDelete,
|
|
213
|
+
insert: threadLabelInsert,
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
query: {
|
|
217
|
+
accountLabel: {
|
|
218
|
+
where: whereLabelAccount,
|
|
219
|
+
},
|
|
220
|
+
thread: {
|
|
221
|
+
where: whereThread,
|
|
222
|
+
},
|
|
223
|
+
threadLabel: {
|
|
224
|
+
where: whereThreadLabel,
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
};
|
|
228
|
+
const mutators = createMutators();
|
|
229
|
+
await mutators.thread.setArchive(transaction, {
|
|
230
|
+
threadIds: ['test-thread-id-1'],
|
|
231
|
+
});
|
|
232
|
+
expect(threadLabelDelete).toHaveBeenCalledWith({
|
|
233
|
+
labelId: 'test-inbox-label-id',
|
|
234
|
+
threadId: 'test-thread-id-1',
|
|
235
|
+
});
|
|
236
|
+
expect(threadLabelInsert).toHaveBeenCalledWith({
|
|
237
|
+
labelId: 'test-archive-label-id',
|
|
238
|
+
threadId: 'test-thread-id-1',
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
describe('setFlagged', () => {
|
|
243
|
+
it('sets thread flagged status', async () => {
|
|
244
|
+
const threadUpdate = mock(async () => { });
|
|
245
|
+
const transaction = {
|
|
246
|
+
mutate: {
|
|
247
|
+
thread: {
|
|
248
|
+
update: threadUpdate,
|
|
249
|
+
},
|
|
250
|
+
},
|
|
251
|
+
query: {},
|
|
252
|
+
};
|
|
253
|
+
const mutators = createMutators();
|
|
254
|
+
await mutators.thread.setFlagged(transaction, {
|
|
255
|
+
flagged: true,
|
|
256
|
+
threadId: 'test-thread-id-1',
|
|
257
|
+
});
|
|
258
|
+
expect(threadUpdate).toHaveBeenCalledWith({
|
|
259
|
+
flagged: true,
|
|
260
|
+
id: 'test-thread-id-1',
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
describe('setInbox', () => {
|
|
265
|
+
it('moves thread to inbox', async () => {
|
|
266
|
+
let labelQueryCount = 0;
|
|
267
|
+
let threadLabelQueryCount = 0;
|
|
268
|
+
const threadRecord = {
|
|
269
|
+
accountId: 'test-account-id-1',
|
|
270
|
+
id: 'test-thread-id-1',
|
|
271
|
+
};
|
|
272
|
+
const inboxLabel = {
|
|
273
|
+
accountId: 'test-account-id-1',
|
|
274
|
+
id: 'test-inbox-label-id',
|
|
275
|
+
specialUse: 'INBOX',
|
|
276
|
+
};
|
|
277
|
+
const archiveLabel = {
|
|
278
|
+
accountId: 'test-account-id-1',
|
|
279
|
+
id: 'test-archive-label-id',
|
|
280
|
+
specialUse: 'ARCHIVE',
|
|
281
|
+
};
|
|
282
|
+
const runThread = mock(async () => threadRecord);
|
|
283
|
+
const oneThread = mock(() => ({ run: runThread }));
|
|
284
|
+
const whereThread = mock(() => ({ one: oneThread }));
|
|
285
|
+
const runLabel = mock(async () => {
|
|
286
|
+
const result = labelQueryCount === 0 ? inboxLabel : archiveLabel;
|
|
287
|
+
labelQueryCount++;
|
|
288
|
+
return result;
|
|
289
|
+
});
|
|
290
|
+
const oneLabel = mock(() => ({ run: runLabel }));
|
|
291
|
+
const whereSpecialUse = mock(() => ({ one: oneLabel }));
|
|
292
|
+
const whereLabelAccount = mock(() => ({ where: whereSpecialUse }));
|
|
293
|
+
const runExisting = mock(async () => {
|
|
294
|
+
const result = threadLabelQueryCount === 0 ? { labelId: 'test-archive-label-id' } : null;
|
|
295
|
+
threadLabelQueryCount++;
|
|
296
|
+
return result;
|
|
297
|
+
});
|
|
298
|
+
const oneExisting = mock(() => ({ run: runExisting }));
|
|
299
|
+
const whereLabel = mock(() => ({ one: oneExisting }));
|
|
300
|
+
const whereThreadLabel = mock(() => ({ where: whereLabel }));
|
|
301
|
+
const threadLabelDelete = mock(async () => { });
|
|
302
|
+
const threadLabelInsert = mock(async () => { });
|
|
303
|
+
const transaction = {
|
|
304
|
+
mutate: {
|
|
305
|
+
threadLabel: {
|
|
306
|
+
delete: threadLabelDelete,
|
|
307
|
+
insert: threadLabelInsert,
|
|
308
|
+
},
|
|
309
|
+
},
|
|
310
|
+
query: {
|
|
311
|
+
accountLabel: {
|
|
312
|
+
where: whereLabelAccount,
|
|
313
|
+
},
|
|
314
|
+
thread: {
|
|
315
|
+
where: whereThread,
|
|
316
|
+
},
|
|
317
|
+
threadLabel: {
|
|
318
|
+
where: whereThreadLabel,
|
|
319
|
+
},
|
|
320
|
+
},
|
|
321
|
+
};
|
|
322
|
+
const mutators = createMutators();
|
|
323
|
+
await mutators.thread.setInbox(transaction, {
|
|
324
|
+
threadIds: ['test-thread-id-1'],
|
|
325
|
+
});
|
|
326
|
+
expect(threadLabelDelete).toHaveBeenCalledWith({
|
|
327
|
+
labelId: 'test-archive-label-id',
|
|
328
|
+
threadId: 'test-thread-id-1',
|
|
329
|
+
});
|
|
330
|
+
expect(threadLabelInsert).toHaveBeenCalledWith({
|
|
331
|
+
labelId: 'test-inbox-label-id',
|
|
332
|
+
threadId: 'test-thread-id-1',
|
|
333
|
+
});
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
describe('setSeen', () => {
|
|
337
|
+
it('sets thread seen status', async () => {
|
|
338
|
+
const threadUpdate = mock(async () => { });
|
|
339
|
+
const transaction = {
|
|
340
|
+
mutate: {
|
|
341
|
+
thread: {
|
|
342
|
+
update: threadUpdate,
|
|
343
|
+
},
|
|
344
|
+
},
|
|
345
|
+
query: {},
|
|
346
|
+
};
|
|
347
|
+
const mutators = createMutators();
|
|
348
|
+
await mutators.thread.setSeen(transaction, {
|
|
349
|
+
seen: true,
|
|
350
|
+
threadIds: ['test-thread-id-1', 'test-thread-id-2'],
|
|
351
|
+
});
|
|
352
|
+
expect(threadUpdate).toHaveBeenCalledTimes(2);
|
|
353
|
+
expect(threadUpdate).toHaveBeenCalledWith({
|
|
354
|
+
id: 'test-thread-id-1',
|
|
355
|
+
seen: true,
|
|
356
|
+
});
|
|
357
|
+
expect(threadUpdate).toHaveBeenCalledWith({
|
|
358
|
+
id: 'test-thread-id-2',
|
|
359
|
+
seen: true,
|
|
360
|
+
});
|
|
361
|
+
});
|
|
362
|
+
});
|
|
363
|
+
describe('setSpam', () => {
|
|
364
|
+
it('marks thread as spam', async () => {
|
|
365
|
+
const threadRecord = {
|
|
366
|
+
accountId: 'test-account-id-1',
|
|
367
|
+
id: 'test-thread-id-1',
|
|
368
|
+
};
|
|
369
|
+
const spamLabel = {
|
|
370
|
+
accountId: 'test-account-id-1',
|
|
371
|
+
id: 'test-spam-label-id',
|
|
372
|
+
specialUse: 'SPAM',
|
|
373
|
+
};
|
|
374
|
+
const runThread = mock(async () => threadRecord);
|
|
375
|
+
const oneThread = mock(() => ({ run: runThread }));
|
|
376
|
+
const whereThread = mock(() => ({ one: oneThread }));
|
|
377
|
+
const runSpam = mock(async () => spamLabel);
|
|
378
|
+
const oneLabel = mock(() => ({ run: runSpam }));
|
|
379
|
+
const whereSpecialUse = mock(() => ({ one: oneLabel }));
|
|
380
|
+
const whereLabelAccount = mock(() => ({ where: whereSpecialUse }));
|
|
381
|
+
const runExisting = mock(async () => null);
|
|
382
|
+
const oneExisting = mock(() => ({ run: runExisting }));
|
|
383
|
+
const whereLabel = mock(() => ({ one: oneExisting }));
|
|
384
|
+
const whereThreadLabel = mock(() => ({ where: whereLabel }));
|
|
385
|
+
const threadLabelInsert = mock(async () => { });
|
|
386
|
+
const transaction = {
|
|
387
|
+
mutate: {
|
|
388
|
+
threadLabel: {
|
|
389
|
+
insert: threadLabelInsert,
|
|
390
|
+
},
|
|
391
|
+
},
|
|
392
|
+
query: {
|
|
393
|
+
accountLabel: {
|
|
394
|
+
where: whereLabelAccount,
|
|
395
|
+
},
|
|
396
|
+
thread: {
|
|
397
|
+
where: whereThread,
|
|
398
|
+
},
|
|
399
|
+
threadLabel: {
|
|
400
|
+
where: whereThreadLabel,
|
|
401
|
+
},
|
|
402
|
+
},
|
|
403
|
+
};
|
|
404
|
+
const mutators = createMutators();
|
|
405
|
+
await mutators.thread.setSpam(transaction, {
|
|
406
|
+
threadIds: ['test-thread-id-1'],
|
|
407
|
+
});
|
|
408
|
+
expect(threadLabelInsert).toHaveBeenCalledWith({
|
|
409
|
+
labelId: 'test-spam-label-id',
|
|
410
|
+
threadId: 'test-thread-id-1',
|
|
411
|
+
});
|
|
412
|
+
});
|
|
413
|
+
});
|
|
414
|
+
describe('setTrash', () => {
|
|
415
|
+
it('moves thread to trash', async () => {
|
|
416
|
+
const threadRecord = {
|
|
417
|
+
accountId: 'test-account-id-1',
|
|
418
|
+
id: 'test-thread-id-1',
|
|
419
|
+
};
|
|
420
|
+
const trashLabel = {
|
|
421
|
+
accountId: 'test-account-id-1',
|
|
422
|
+
id: 'test-trash-label-id',
|
|
423
|
+
specialUse: 'TRASH',
|
|
424
|
+
};
|
|
425
|
+
const runThread = mock(async () => threadRecord);
|
|
426
|
+
const oneThread = mock(() => ({ run: runThread }));
|
|
427
|
+
const whereThread = mock(() => ({ one: oneThread }));
|
|
428
|
+
const runTrash = mock(async () => trashLabel);
|
|
429
|
+
const oneLabel = mock(() => ({ run: runTrash }));
|
|
430
|
+
const whereSpecialUse = mock(() => ({ one: oneLabel }));
|
|
431
|
+
const whereLabelAccount = mock(() => ({ where: whereSpecialUse }));
|
|
432
|
+
const runExisting = mock(async () => null);
|
|
433
|
+
const oneExisting = mock(() => ({ run: runExisting }));
|
|
434
|
+
const whereLabel = mock(() => ({ one: oneExisting }));
|
|
435
|
+
const whereThreadLabel = mock(() => ({ where: whereLabel }));
|
|
436
|
+
const threadLabelInsert = mock(async () => { });
|
|
437
|
+
const transaction = {
|
|
438
|
+
mutate: {
|
|
439
|
+
threadLabel: {
|
|
440
|
+
insert: threadLabelInsert,
|
|
441
|
+
},
|
|
442
|
+
},
|
|
443
|
+
query: {
|
|
444
|
+
accountLabel: {
|
|
445
|
+
where: whereLabelAccount,
|
|
446
|
+
},
|
|
447
|
+
thread: {
|
|
448
|
+
where: whereThread,
|
|
449
|
+
},
|
|
450
|
+
threadLabel: {
|
|
451
|
+
where: whereThreadLabel,
|
|
452
|
+
},
|
|
453
|
+
},
|
|
454
|
+
};
|
|
455
|
+
const mutators = createMutators();
|
|
456
|
+
await mutators.thread.setTrash(transaction, {
|
|
457
|
+
threadIds: ['test-thread-id-1'],
|
|
458
|
+
});
|
|
459
|
+
expect(threadLabelInsert).toHaveBeenCalledWith({
|
|
460
|
+
labelId: 'test-trash-label-id',
|
|
461
|
+
threadId: 'test-thread-id-1',
|
|
462
|
+
});
|
|
463
|
+
});
|
|
464
|
+
});
|
|
465
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/zero/mutators/userMutators/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './userMutators';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type * as v from 'valibot';
|
|
2
|
+
import type { AuthData, HandlerMap } from '../../../types';
|
|
3
|
+
import type { userMutatorSchemas } from '../../../zero/mutatorSchemas';
|
|
4
|
+
export type UserMutatorCallbacks = {
|
|
5
|
+
[K in keyof typeof userMutatorSchemas]?: (args: v.InferOutput<(typeof userMutatorSchemas)[K]['delta']>) => Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
export declare const createUserMutators: (_authData: AuthData | undefined, callbacks?: UserMutatorCallbacks) => HandlerMap<typeof userMutatorSchemas>;
|
|
8
|
+
//# sourceMappingURL=userMutators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userMutators.d.ts","sourceRoot":"","sources":["../../../../src/zero/mutators/userMutators/userMutators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,CAAC,MAAM,SAAS,CAAA;AAEjC,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAC/D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAA;AAE3E,MAAM,MAAM,oBAAoB,GAAG;KAChC,CAAC,IAAI,MAAM,OAAO,kBAAkB,CAAC,CAAC,EAAE,CACvC,IAAI,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,OAAO,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,KACzD,OAAO,CAAC,IAAI,CAAC;CACnB,CAAA;AAED,eAAO,MAAM,kBAAkB,cAClB,QAAQ,GAAG,SAAS,cACnB,oBAAoB,KAC/B,UAAU,CAAC,OAAO,kBAAkB,CAuCrC,CAAA"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export const createUserMutators = (_authData, callbacks) => ({
|
|
2
|
+
deleteSettingsPushNotificationToken: async (tx, args) => {
|
|
3
|
+
await tx.mutate.userPushNotificationToken.delete({
|
|
4
|
+
id: args.id,
|
|
5
|
+
});
|
|
6
|
+
await callbacks?.deleteSettingsPushNotificationToken?.(args);
|
|
7
|
+
},
|
|
8
|
+
setSettingsName: async (tx, args) => {
|
|
9
|
+
await tx.mutate.user.update({
|
|
10
|
+
id: args.id,
|
|
11
|
+
name: args.name,
|
|
12
|
+
});
|
|
13
|
+
await callbacks?.setSettingsName?.(args);
|
|
14
|
+
},
|
|
15
|
+
setSettingsPushNotificationToken: async (tx, args) => {
|
|
16
|
+
const existing = await tx.query.userPushNotificationToken
|
|
17
|
+
.where('userId', args.id)
|
|
18
|
+
.where('token', args.pushNotificationToken.token)
|
|
19
|
+
.one()
|
|
20
|
+
.run();
|
|
21
|
+
if (existing) {
|
|
22
|
+
await tx.mutate.userPushNotificationToken.update({
|
|
23
|
+
createdAt: args.pushNotificationToken.createdAt,
|
|
24
|
+
id: existing.id,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
await tx.mutate.userPushNotificationToken.insert({
|
|
29
|
+
createdAt: args.pushNotificationToken.createdAt,
|
|
30
|
+
id: `${args.id}-${args.pushNotificationToken.deviceId}`,
|
|
31
|
+
token: args.pushNotificationToken.token,
|
|
32
|
+
userId: args.id,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
await callbacks?.setSettingsPushNotificationToken?.(args);
|
|
36
|
+
},
|
|
37
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userMutators.test.d.ts","sourceRoot":"","sources":["../../../../src/zero/mutators/userMutators/userMutators.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { describe, expect, it, mock } from 'bun:test';
|
|
2
|
+
import { createMutators } from '../mutators';
|
|
3
|
+
describe('userMutators', () => {
|
|
4
|
+
describe('deleteSettingsPushNotificationToken', () => {
|
|
5
|
+
it('deletes push notification token', async () => {
|
|
6
|
+
const tokenDelete = mock(async () => { });
|
|
7
|
+
const transaction = {
|
|
8
|
+
mutate: {
|
|
9
|
+
userPushNotificationToken: {
|
|
10
|
+
delete: tokenDelete,
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
query: {},
|
|
14
|
+
};
|
|
15
|
+
const mutators = createMutators();
|
|
16
|
+
await mutators.user.deleteSettingsPushNotificationToken(transaction, {
|
|
17
|
+
id: 'test-user-id',
|
|
18
|
+
token: 'test-token',
|
|
19
|
+
});
|
|
20
|
+
expect(tokenDelete).toHaveBeenCalledWith({
|
|
21
|
+
id: 'test-user-id',
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
describe('setSettingsName', () => {
|
|
26
|
+
it('sets user name', async () => {
|
|
27
|
+
const userUpdate = mock(async () => { });
|
|
28
|
+
const transaction = {
|
|
29
|
+
mutate: {
|
|
30
|
+
user: {
|
|
31
|
+
update: userUpdate,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
query: {},
|
|
35
|
+
};
|
|
36
|
+
const mutators = createMutators();
|
|
37
|
+
await mutators.user.setSettingsName(transaction, {
|
|
38
|
+
id: 'test-user-id',
|
|
39
|
+
name: 'John Doe',
|
|
40
|
+
});
|
|
41
|
+
expect(userUpdate).toHaveBeenCalledWith({
|
|
42
|
+
id: 'test-user-id',
|
|
43
|
+
name: 'John Doe',
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
describe('setSettingsPushNotificationToken', () => {
|
|
48
|
+
it('sets push notification token when token does not exist', async () => {
|
|
49
|
+
const run = mock(async () => null);
|
|
50
|
+
const one = mock(() => ({ run }));
|
|
51
|
+
const whereToken = mock(() => ({ one }));
|
|
52
|
+
const whereUserId = mock(() => ({ where: whereToken }));
|
|
53
|
+
const tokenInsert = mock(async () => { });
|
|
54
|
+
const transaction = {
|
|
55
|
+
mutate: {
|
|
56
|
+
userPushNotificationToken: {
|
|
57
|
+
insert: tokenInsert,
|
|
58
|
+
update: mock(async () => { }),
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
query: {
|
|
62
|
+
userPushNotificationToken: {
|
|
63
|
+
where: whereUserId,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
const mutators = createMutators();
|
|
68
|
+
await mutators.user.setSettingsPushNotificationToken(transaction, {
|
|
69
|
+
id: 'test-user-id',
|
|
70
|
+
pushNotificationToken: {
|
|
71
|
+
createdAt: 1_000,
|
|
72
|
+
deviceId: 'test-device-id',
|
|
73
|
+
token: 'test-token',
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
expect(tokenInsert).toHaveBeenCalledWith({
|
|
77
|
+
createdAt: 1_000,
|
|
78
|
+
id: 'test-user-id-test-device-id',
|
|
79
|
+
token: 'test-token',
|
|
80
|
+
userId: 'test-user-id',
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
it('updates push notification token when token exists', async () => {
|
|
84
|
+
const existingToken = {
|
|
85
|
+
createdAt: 500,
|
|
86
|
+
id: 'test-user-id-test-device-id',
|
|
87
|
+
token: 'test-token',
|
|
88
|
+
userId: 'test-user-id',
|
|
89
|
+
};
|
|
90
|
+
const run = mock(async () => existingToken);
|
|
91
|
+
const one = mock(() => ({ run }));
|
|
92
|
+
const whereToken = mock(() => ({ one }));
|
|
93
|
+
const whereUserId = mock(() => ({ where: whereToken }));
|
|
94
|
+
const tokenUpdate = mock(async () => { });
|
|
95
|
+
const transaction = {
|
|
96
|
+
mutate: {
|
|
97
|
+
userPushNotificationToken: {
|
|
98
|
+
insert: mock(async () => { }),
|
|
99
|
+
update: tokenUpdate,
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
query: {
|
|
103
|
+
userPushNotificationToken: {
|
|
104
|
+
where: whereUserId,
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
const mutators = createMutators();
|
|
109
|
+
await mutators.user.setSettingsPushNotificationToken(transaction, {
|
|
110
|
+
id: 'test-user-id',
|
|
111
|
+
pushNotificationToken: {
|
|
112
|
+
createdAt: 2_000,
|
|
113
|
+
deviceId: 'test-device-id',
|
|
114
|
+
token: 'test-token',
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
expect(tokenUpdate).toHaveBeenCalledWith({
|
|
118
|
+
createdAt: 2_000,
|
|
119
|
+
id: 'test-user-id-test-device-id',
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
});
|