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