@remit/drizzle-service 0.0.8 → 0.0.9
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/package.json
CHANGED
|
@@ -164,6 +164,113 @@ describe("DrizzleThreadMessageRepository (sqlite)", () => {
|
|
|
164
164
|
assert.ok(n >= 1);
|
|
165
165
|
});
|
|
166
166
|
|
|
167
|
+
test("listByThread returns inbox and sent messages interleaved in order", async () => {
|
|
168
|
+
const acct = "acct-conversation";
|
|
169
|
+
const threadId = "t-conversation";
|
|
170
|
+
const inbox = "mbx-inbox";
|
|
171
|
+
const sent = "mbx-sent";
|
|
172
|
+
const base = Date.now();
|
|
173
|
+
const turns = [
|
|
174
|
+
{ mailboxId: inbox, subject: "Databricks pricing", at: base },
|
|
175
|
+
{ mailboxId: sent, subject: "Re: Databricks pricing", at: base + 1000 },
|
|
176
|
+
{ mailboxId: inbox, subject: "Re: Databricks pricing", at: base + 2000 },
|
|
177
|
+
{ mailboxId: sent, subject: "Re: Databricks pricing", at: base + 3000 },
|
|
178
|
+
];
|
|
179
|
+
for (const [index, turn] of turns.entries()) {
|
|
180
|
+
await repo.create(
|
|
181
|
+
makeInput({
|
|
182
|
+
accountConfigId: acct,
|
|
183
|
+
threadId,
|
|
184
|
+
messageId: `m-conversation-${index}`,
|
|
185
|
+
mailboxId: turn.mailboxId,
|
|
186
|
+
subject: turn.subject,
|
|
187
|
+
referenceOrder: index,
|
|
188
|
+
internalDate: turn.at,
|
|
189
|
+
sentDate: turn.at,
|
|
190
|
+
}),
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const ascending = await repo.listByThread(threadId, acct, {
|
|
195
|
+
order: "asc",
|
|
196
|
+
excludeDeleted: true,
|
|
197
|
+
});
|
|
198
|
+
assert.deepEqual(
|
|
199
|
+
ascending.items.map((item) => item.mailboxId),
|
|
200
|
+
[inbox, sent, inbox, sent],
|
|
201
|
+
"the conversation carries both received and sent messages, oldest first",
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
const descending = await repo.listByThread(threadId, acct, {
|
|
205
|
+
order: "desc",
|
|
206
|
+
excludeDeleted: true,
|
|
207
|
+
});
|
|
208
|
+
assert.deepEqual(
|
|
209
|
+
descending.items.map((item) => item.mailboxId),
|
|
210
|
+
[sent, inbox, sent, inbox],
|
|
211
|
+
"reversing the order reverses the conversation",
|
|
212
|
+
);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
test("listByThread excludes soft-deleted messages but keeps the rest of the conversation", async () => {
|
|
216
|
+
const acct = "acct-conversation-deleted";
|
|
217
|
+
const threadId = "t-conversation-deleted";
|
|
218
|
+
const base = Date.now();
|
|
219
|
+
const kept = await repo.create(
|
|
220
|
+
makeInput({
|
|
221
|
+
accountConfigId: acct,
|
|
222
|
+
threadId,
|
|
223
|
+
messageId: "m-kept",
|
|
224
|
+
mailboxId: "mbx-sent",
|
|
225
|
+
internalDate: base,
|
|
226
|
+
sentDate: base,
|
|
227
|
+
}),
|
|
228
|
+
);
|
|
229
|
+
await repo.create(
|
|
230
|
+
makeInput({
|
|
231
|
+
accountConfigId: acct,
|
|
232
|
+
threadId,
|
|
233
|
+
messageId: "m-trashed",
|
|
234
|
+
mailboxId: "mbx-trash",
|
|
235
|
+
isDeleted: true,
|
|
236
|
+
internalDate: base + 1000,
|
|
237
|
+
sentDate: base + 1000,
|
|
238
|
+
}),
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
const result = await repo.listByThread(threadId, acct, {
|
|
242
|
+
excludeDeleted: true,
|
|
243
|
+
});
|
|
244
|
+
assert.deepEqual(
|
|
245
|
+
result.items.map((item) => item.threadMessageId),
|
|
246
|
+
[kept.threadMessageId],
|
|
247
|
+
);
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
test("listByThread scopes to the account config", async () => {
|
|
251
|
+
const threadId = "t-shared-id";
|
|
252
|
+
await repo.create(
|
|
253
|
+
makeInput({
|
|
254
|
+
accountConfigId: "acct-mine",
|
|
255
|
+
threadId,
|
|
256
|
+
messageId: "m-mine",
|
|
257
|
+
}),
|
|
258
|
+
);
|
|
259
|
+
await repo.create(
|
|
260
|
+
makeInput({
|
|
261
|
+
accountConfigId: "acct-theirs",
|
|
262
|
+
threadId,
|
|
263
|
+
messageId: "m-theirs",
|
|
264
|
+
}),
|
|
265
|
+
);
|
|
266
|
+
|
|
267
|
+
const mine = await repo.listByThread(threadId, "acct-mine");
|
|
268
|
+
assert.deepEqual(
|
|
269
|
+
mine.items.map((item) => item.messageId),
|
|
270
|
+
["m-mine"],
|
|
271
|
+
);
|
|
272
|
+
});
|
|
273
|
+
|
|
167
274
|
test("listByDate paginates with a stable keyset cursor", async () => {
|
|
168
275
|
const acct = "acct-page";
|
|
169
276
|
const base = Date.now();
|
|
@@ -558,7 +558,6 @@ export class DrizzleThreadMessageRepository
|
|
|
558
558
|
order?: "asc" | "desc";
|
|
559
559
|
limit?: number;
|
|
560
560
|
continuationToken?: string;
|
|
561
|
-
mailboxId?: string;
|
|
562
561
|
excludeDeleted?: boolean;
|
|
563
562
|
},
|
|
564
563
|
): Promise<ResultList<ThreadMessageItem>> {
|
|
@@ -592,9 +591,6 @@ export class DrizzleThreadMessageRepository
|
|
|
592
591
|
and(
|
|
593
592
|
eq(threadMessageTable.threadId, threadId),
|
|
594
593
|
eq(threadMessageTable.accountConfigId, accountConfigId),
|
|
595
|
-
options?.mailboxId
|
|
596
|
-
? eq(threadMessageTable.mailboxId, options.mailboxId)
|
|
597
|
-
: undefined,
|
|
598
594
|
options?.excludeDeleted
|
|
599
595
|
? eq(threadMessageTable.isDeleted, false)
|
|
600
596
|
: undefined,
|