mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-04-17 15:23:36 +01:00
Enable tsconfig noUncheckedIndexedAccess
Co-authored-by: Jamie <113370520+jamiebuilds-signal@users.noreply.github.com>
This commit is contained in:
@@ -134,12 +134,12 @@ describe('SQL/updateToSchemaVersion1000', () => {
|
||||
|
||||
assert.strictEqual(messages.length, 2);
|
||||
|
||||
assert.strictEqual(messages[0].message.readStatus, ReadStatus.Read);
|
||||
assert.strictEqual(messages[0]?.message.readStatus, ReadStatus.Read);
|
||||
assert.strictEqual(messages[0].message.seenStatus, SeenStatus.Unseen);
|
||||
assert.strictEqual(messages[0].readStatus, ReadStatus.Read);
|
||||
assert.strictEqual(messages[0].seenStatus, SeenStatus.Unseen);
|
||||
|
||||
assert.strictEqual(messages[1].message.readStatus, ReadStatus.Read);
|
||||
assert.strictEqual(messages[1]?.message.readStatus, ReadStatus.Read);
|
||||
assert.strictEqual(messages[1].message.seenStatus, SeenStatus.Unseen);
|
||||
assert.strictEqual(messages[1].readStatus, ReadStatus.Read);
|
||||
assert.strictEqual(messages[1].seenStatus, SeenStatus.Unseen);
|
||||
@@ -174,12 +174,12 @@ describe('SQL/updateToSchemaVersion1000', () => {
|
||||
|
||||
assert.strictEqual(messages.length, 2);
|
||||
|
||||
assert.strictEqual(messages[0].message.readStatus, ReadStatus.Read);
|
||||
assert.strictEqual(messages[0]?.message.readStatus, ReadStatus.Read);
|
||||
assert.strictEqual(messages[0].message.seenStatus, SeenStatus.Seen);
|
||||
assert.strictEqual(messages[0].readStatus, ReadStatus.Read);
|
||||
assert.strictEqual(messages[0].seenStatus, SeenStatus.Seen);
|
||||
|
||||
assert.strictEqual(messages[1].message.readStatus, ReadStatus.Read);
|
||||
assert.strictEqual(messages[1]?.message.readStatus, ReadStatus.Read);
|
||||
assert.strictEqual(messages[1].message.seenStatus, SeenStatus.Seen);
|
||||
assert.strictEqual(messages[1].readStatus, ReadStatus.Read);
|
||||
assert.strictEqual(messages[1].seenStatus, SeenStatus.Seen);
|
||||
|
||||
@@ -201,7 +201,7 @@ describe('SQL/updateToSchemaVersion1040', () => {
|
||||
|
||||
const attachments = getAttachmentDownloadJobs(db);
|
||||
assert.strictEqual(attachments.length, 1);
|
||||
assert.strictEqual(attachments[0].attempts, 0);
|
||||
assert.strictEqual(attachments[0]?.attempts, 0);
|
||||
});
|
||||
|
||||
it('uses indices searching for next job', () => {
|
||||
|
||||
@@ -204,7 +204,7 @@ describe('SQL/updateToSchemaVersion1060', () => {
|
||||
describe('Sync Tasks', () => {
|
||||
it('creates tasks in bulk, and fetches all', () => {
|
||||
const now = Date.now();
|
||||
const expected: Array<SyncTaskType> = [
|
||||
const expected = [
|
||||
{
|
||||
id: generateGuid(),
|
||||
attempts: 1,
|
||||
@@ -241,7 +241,7 @@ describe('SQL/updateToSchemaVersion1060', () => {
|
||||
sentAt: 3,
|
||||
type: 'delete-conversation',
|
||||
},
|
||||
];
|
||||
] as const satisfies Array<SyncTaskType>;
|
||||
|
||||
saveSyncTasks(db, expected);
|
||||
|
||||
|
||||
@@ -172,7 +172,7 @@ describe('SQL/updateToSchemaVersion1200', () => {
|
||||
const [query, params] = template;
|
||||
const result = db.prepare(query).all(params);
|
||||
assert.strictEqual(result.length, 1);
|
||||
assert.deepStrictEqual(result[0].messageId, 'message12');
|
||||
assert.deepStrictEqual(result[0]?.messageId, 'message12');
|
||||
const details = explain(db, template);
|
||||
assert.equal(
|
||||
details,
|
||||
|
||||
@@ -194,8 +194,8 @@ describe('SQL/updateToSchemaVersion89', () => {
|
||||
const callHistory = getAllCallHistory();
|
||||
|
||||
assert.strictEqual(callHistory.length, 2);
|
||||
assert.strictEqual(callHistory[0].callId, callId1);
|
||||
assert.strictEqual(callHistory[1].callId, getCallIdFromEra(eraId2));
|
||||
assert.strictEqual(callHistory[0]?.callId, callId1);
|
||||
assert.strictEqual(callHistory[1]?.callId, getCallIdFromEra(eraId2));
|
||||
});
|
||||
|
||||
it('migrates older messages without a callId', () => {
|
||||
@@ -215,7 +215,7 @@ describe('SQL/updateToSchemaVersion89', () => {
|
||||
const callHistory = getAllCallHistory();
|
||||
|
||||
assert.strictEqual(callHistory.length, 1);
|
||||
assert.isTrue(isValidUuid(callHistory[0].callId));
|
||||
assert.isTrue(isValidUuid(callHistory[0]?.callId));
|
||||
});
|
||||
|
||||
it('migrates older messages without a callMode', () => {
|
||||
@@ -245,8 +245,8 @@ describe('SQL/updateToSchemaVersion89', () => {
|
||||
const callHistory = getAllCallHistory();
|
||||
|
||||
assert.strictEqual(callHistory.length, 2);
|
||||
assert.strictEqual(callHistory[0].mode, CallMode.Direct);
|
||||
assert.strictEqual(callHistory[1].mode, CallMode.Group);
|
||||
assert.strictEqual(callHistory[0]?.mode, CallMode.Direct);
|
||||
assert.strictEqual(callHistory[1]?.mode, CallMode.Group);
|
||||
});
|
||||
|
||||
it('handles unique constraint violations', () => {
|
||||
@@ -298,8 +298,8 @@ describe('SQL/updateToSchemaVersion89', () => {
|
||||
|
||||
const callHistory = getAllCallHistory();
|
||||
assert.strictEqual(callHistory.length, 2);
|
||||
assert.strictEqual(callHistory[0].peerId, conversation1.serviceId);
|
||||
assert.strictEqual(callHistory[1].peerId, conversation2.groupId);
|
||||
assert.strictEqual(callHistory[0]?.peerId, conversation1.serviceId);
|
||||
assert.strictEqual(callHistory[1]?.peerId, conversation2.groupId);
|
||||
});
|
||||
|
||||
it('migrates older unregistered conversations with no serviceId', () => {
|
||||
@@ -318,7 +318,7 @@ describe('SQL/updateToSchemaVersion89', () => {
|
||||
|
||||
const callHistory = getAllCallHistory();
|
||||
assert.strictEqual(callHistory.length, 1);
|
||||
assert.strictEqual(callHistory[0].peerId, conversation.id);
|
||||
assert.strictEqual(callHistory[0]?.peerId, conversation.id);
|
||||
});
|
||||
|
||||
it('migrates call-history messages with no timestamp', () => {
|
||||
@@ -374,14 +374,14 @@ describe('SQL/updateToSchemaVersion89', () => {
|
||||
|
||||
const callHistory = getAllCallHistory();
|
||||
assert.strictEqual(callHistory.length, 8);
|
||||
assert.strictEqual(callHistory[0].timestamp, 0);
|
||||
assert.strictEqual(callHistory[1].timestamp, 0);
|
||||
assert.strictEqual(callHistory[2].timestamp, 1);
|
||||
assert.strictEqual(callHistory[3].timestamp, 1);
|
||||
assert.strictEqual(callHistory[4].timestamp, 2);
|
||||
assert.strictEqual(callHistory[5].timestamp, 2);
|
||||
assert.strictEqual(callHistory[6].timestamp, 3);
|
||||
assert.strictEqual(callHistory[7].timestamp, 3);
|
||||
assert.strictEqual(callHistory[0]?.timestamp, 0);
|
||||
assert.strictEqual(callHistory[1]?.timestamp, 0);
|
||||
assert.strictEqual(callHistory[2]?.timestamp, 1);
|
||||
assert.strictEqual(callHistory[3]?.timestamp, 1);
|
||||
assert.strictEqual(callHistory[4]?.timestamp, 2);
|
||||
assert.strictEqual(callHistory[5]?.timestamp, 2);
|
||||
assert.strictEqual(callHistory[6]?.timestamp, 3);
|
||||
assert.strictEqual(callHistory[7]?.timestamp, 3);
|
||||
});
|
||||
|
||||
describe('clients with schema version 87', () => {
|
||||
@@ -482,8 +482,8 @@ describe('SQL/updateToSchemaVersion89', () => {
|
||||
|
||||
const callHistory = getAllCallHistory();
|
||||
assert.strictEqual(callHistory.length, 2);
|
||||
assert.strictEqual(callHistory[0].peerId, conversation1.serviceId);
|
||||
assert.strictEqual(callHistory[1].peerId, conversation2.groupId);
|
||||
assert.strictEqual(callHistory[0]?.peerId, conversation1.serviceId);
|
||||
assert.strictEqual(callHistory[1]?.peerId, conversation2.groupId);
|
||||
});
|
||||
|
||||
it('migrates duplicate call history where the first was already migrated', () => {
|
||||
@@ -522,12 +522,12 @@ describe('SQL/updateToSchemaVersion89', () => {
|
||||
const callHistory = getAllCallHistory();
|
||||
|
||||
assert.strictEqual(callHistory.length, 1);
|
||||
assert.strictEqual(callHistory[0].status, DirectCallStatus.Declined);
|
||||
assert.strictEqual(callHistory[0]?.status, DirectCallStatus.Declined);
|
||||
|
||||
const messages = getMessages();
|
||||
assert.strictEqual(messages.length, 1);
|
||||
assert.strictEqual(messages[0].type, 'call-history');
|
||||
assert.strictEqual(messages[0].callId, '123');
|
||||
assert.strictEqual(messages[0]?.type, 'call-history');
|
||||
assert.strictEqual(messages[0]?.callId, '123');
|
||||
assert.notProperty(messages[0], 'callHistoryDetails');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3371,35 +3371,22 @@ describe('SQL migrations test', () => {
|
||||
return json;
|
||||
}
|
||||
|
||||
function addMessages(
|
||||
messages: Array<{
|
||||
mentions?: Array<AciString>;
|
||||
boldRanges?: Array<Array<number>>;
|
||||
}>
|
||||
) {
|
||||
const formattedMessages = messages.map(composeMessage);
|
||||
function addMessage(message: {
|
||||
mentions?: Array<AciString>;
|
||||
boldRanges?: Array<Array<number>>;
|
||||
}) {
|
||||
const formattedMessage = composeMessage(message);
|
||||
|
||||
db.exec(
|
||||
`
|
||||
INSERT INTO messages
|
||||
(id, json)
|
||||
VALUES
|
||||
${formattedMessages
|
||||
.map(message => `('${message.id}', '${objectToJSON(message)}')`)
|
||||
.join(', ')};
|
||||
('${formattedMessage.id}', '${objectToJSON(formattedMessage)}')
|
||||
`
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
db
|
||||
.prepare('SELECT COUNT(*) FROM messages;', {
|
||||
pluck: true,
|
||||
})
|
||||
.get(),
|
||||
messages.length
|
||||
);
|
||||
|
||||
return { formattedMessages };
|
||||
return formattedMessage;
|
||||
}
|
||||
|
||||
function getMentions() {
|
||||
@@ -3408,17 +3395,24 @@ describe('SQL migrations test', () => {
|
||||
.all();
|
||||
}
|
||||
|
||||
const userIds = [
|
||||
generateAci(),
|
||||
generateAci(),
|
||||
generateAci(),
|
||||
generateAci(),
|
||||
generateAci(),
|
||||
] as const;
|
||||
|
||||
it('Creates and populates the mentions table with existing mentions', () => {
|
||||
updateToVersion(db, schemaVersion - 1);
|
||||
|
||||
const userIds = new Array(5).fill(undefined).map(() => generateAci());
|
||||
const { formattedMessages } = addMessages([
|
||||
{ mentions: [userIds[0]] },
|
||||
{ mentions: [userIds[1]], boldRanges: [[1, 1]] },
|
||||
{ mentions: [userIds[1], userIds[2]] },
|
||||
{},
|
||||
{ boldRanges: [[1, 4]] },
|
||||
]);
|
||||
const formattedMessages = [
|
||||
addMessage({ mentions: [userIds[0]] }),
|
||||
addMessage({ mentions: [userIds[1]], boldRanges: [[1, 1]] }),
|
||||
addMessage({ mentions: [userIds[1], userIds[2]] }),
|
||||
addMessage({}),
|
||||
addMessage({ boldRanges: [[1, 4]] }),
|
||||
] as const;
|
||||
|
||||
// now create mentions table
|
||||
updateToVersion(db, schemaVersion);
|
||||
@@ -3467,14 +3461,13 @@ describe('SQL migrations test', () => {
|
||||
0
|
||||
);
|
||||
|
||||
const userIds = new Array(5).fill(undefined).map(() => generateAci());
|
||||
const { formattedMessages } = addMessages([
|
||||
{ mentions: [userIds[0]] },
|
||||
{ mentions: [userIds[1]], boldRanges: [[1, 1]] },
|
||||
{ mentions: [userIds[1], userIds[2]] },
|
||||
{},
|
||||
{ boldRanges: [[1, 4]] },
|
||||
]);
|
||||
const formattedMessages = [
|
||||
addMessage({ mentions: [userIds[0]] }),
|
||||
addMessage({ mentions: [userIds[1]], boldRanges: [[1, 1]] }),
|
||||
addMessage({ mentions: [userIds[1], userIds[2]] }),
|
||||
addMessage({}),
|
||||
addMessage({ boldRanges: [[1, 4]] }),
|
||||
] as const;
|
||||
|
||||
// the 4 mentions should be included, with multiple rows for multiple mentions in a
|
||||
// message
|
||||
@@ -3519,11 +3512,13 @@ describe('SQL migrations test', () => {
|
||||
0
|
||||
);
|
||||
|
||||
const userIds = new Array(5).fill(undefined).map(() => generateAci());
|
||||
const { formattedMessages } = addMessages([
|
||||
{ mentions: [userIds[0]] },
|
||||
{ mentions: [userIds[1], userIds[2]], boldRanges: [[1, 1]] },
|
||||
]);
|
||||
const formattedMessages = [
|
||||
addMessage({ mentions: [userIds[0]] }),
|
||||
addMessage({
|
||||
mentions: [userIds[1], userIds[2]],
|
||||
boldRanges: [[1, 1]],
|
||||
}),
|
||||
] as const;
|
||||
|
||||
assert.equal(getMentions().length, 3);
|
||||
|
||||
@@ -3553,8 +3548,9 @@ describe('SQL migrations test', () => {
|
||||
0
|
||||
);
|
||||
|
||||
const userIds = new Array(5).fill(undefined).map(() => generateAci());
|
||||
const { formattedMessages } = addMessages([{ mentions: [userIds[0]] }]);
|
||||
const formattedMessages = [
|
||||
addMessage({ mentions: [userIds[0]] }),
|
||||
] as const;
|
||||
|
||||
assert.equal(getMentions().length, 1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user