getUnreadByConversationAndMarkRead: Take 'now' param for reliable tests
This commit is contained in:
parent
77bf3a8669
commit
a7253be213
4 changed files with 9 additions and 3 deletions
|
@ -1269,6 +1269,7 @@ async function getUnreadByConversationAndMarkRead(options: {
|
|||
conversationId: string;
|
||||
isGroup?: boolean;
|
||||
newestUnreadAt: number;
|
||||
now?: number;
|
||||
readAt?: number;
|
||||
storyId?: UUIDStringType;
|
||||
}): Promise<GetUnreadByConversationAndMarkReadResultType> {
|
||||
|
|
|
@ -465,6 +465,7 @@ export type DataInterface = {
|
|||
conversationId: string;
|
||||
isGroup?: boolean;
|
||||
newestUnreadAt: number;
|
||||
now?: number;
|
||||
readAt?: number;
|
||||
storyId?: UUIDStringType;
|
||||
}) => Promise<GetUnreadByConversationAndMarkReadResultType>;
|
||||
|
|
|
@ -2169,16 +2169,18 @@ async function getUnreadByConversationAndMarkRead({
|
|||
newestUnreadAt,
|
||||
storyId,
|
||||
readAt,
|
||||
now = Date.now(),
|
||||
}: {
|
||||
conversationId: string;
|
||||
isGroup?: boolean;
|
||||
newestUnreadAt: number;
|
||||
storyId?: UUIDStringType;
|
||||
readAt?: number;
|
||||
now?: number;
|
||||
}): Promise<GetUnreadByConversationAndMarkReadResultType> {
|
||||
const db = getInstance();
|
||||
return db.transaction(() => {
|
||||
const expirationStartTimestamp = Math.min(Date.now(), readAt ?? Infinity);
|
||||
const expirationStartTimestamp = Math.min(now, readAt ?? Infinity);
|
||||
db.prepare<Query>(
|
||||
`
|
||||
UPDATE messages
|
||||
|
|
|
@ -304,6 +304,7 @@ describe('sql/markRead', () => {
|
|||
});
|
||||
|
||||
it('properly starts disappearing message timer, even if message is already read', async () => {
|
||||
const now = Date.now();
|
||||
assert.lengthOf(await _getAllMessages(), 0);
|
||||
|
||||
const start = Date.now();
|
||||
|
@ -387,6 +388,7 @@ describe('sql/markRead', () => {
|
|||
conversationId,
|
||||
newestUnreadAt: message4.received_at,
|
||||
readAt,
|
||||
now,
|
||||
});
|
||||
|
||||
assert.lengthOf(markedRead, 1, 'one message marked read');
|
||||
|
@ -412,14 +414,14 @@ describe('sql/markRead', () => {
|
|||
assert.strictEqual(sorted[1].id, message2.id, 'checking message 2');
|
||||
assert.isAtMost(
|
||||
sorted[1].expirationStartTimestamp ?? Infinity,
|
||||
Date.now(),
|
||||
now,
|
||||
'checking message 2 expirationStartTimestamp'
|
||||
);
|
||||
|
||||
assert.strictEqual(sorted[3].id, message4.id, 'checking message 4');
|
||||
assert.isAtMost(
|
||||
sorted[3].expirationStartTimestamp ?? Infinity,
|
||||
Date.now(),
|
||||
now,
|
||||
'checking message 4 expirationStartTimestamp'
|
||||
);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue