fix(syncing-server): case insensitive integrity check

This commit is contained in:
Karol Sójko 2023-09-13 06:33:31 +02:00
parent b1d88b15be
commit d5536f5430
No known key found for this signature in database
GPG key ID: C2F813669419D05F
2 changed files with 11 additions and 9 deletions

View file

@ -22,7 +22,7 @@ describe('CheckIntegrity', () => {
content_type: ContentType.TYPES.Note,
},
{
uuid: '2-3-4',
uuid: '2-3-4-a',
updated_at_timestamp: 2,
content_type: ContentType.TYPES.Note,
},
@ -56,7 +56,7 @@ describe('CheckIntegrity', () => {
updated_at_timestamp: 1,
},
{
uuid: '2-3-4',
uuid: '2-3-4-A',
updated_at_timestamp: 2,
},
{
@ -82,7 +82,7 @@ describe('CheckIntegrity', () => {
updated_at_timestamp: 1,
},
{
uuid: '2-3-4',
uuid: '2-3-4-A',
updated_at_timestamp: 1,
},
{
@ -98,7 +98,7 @@ describe('CheckIntegrity', () => {
})
expect(result.getValue()).toEqual([
{
uuid: '2-3-4',
uuid: '2-3-4-A',
updated_at_timestamp: 2,
},
])
@ -113,7 +113,7 @@ describe('CheckIntegrity', () => {
updated_at_timestamp: 1,
},
{
uuid: '2-3-4',
uuid: '2-3-4-A',
updated_at_timestamp: 2,
},
{
@ -140,7 +140,7 @@ describe('CheckIntegrity', () => {
updated_at_timestamp: 1,
},
{
uuid: '2-3-4',
uuid: '2-3-4-A',
updated_at_timestamp: 2,
},
{

View file

@ -20,15 +20,17 @@ export class CheckIntegrity implements UseCaseInterface<IntegrityPayload[]> {
const serverItemIntegrityPayloadsMap = new Map<string, ExtendedIntegrityPayload>()
for (const serverItemIntegrityPayload of serverItemIntegrityPayloads) {
serverItemIntegrityPayloadsMap.set(serverItemIntegrityPayload.uuid, serverItemIntegrityPayload)
serverItemIntegrityPayloadsMap.set(serverItemIntegrityPayload.uuid.toLowerCase(), serverItemIntegrityPayload)
}
const clientItemIntegrityPayloadsMap = new Map<string, number>()
const caseInsensitiveUuidsMap = new Map<string, string>()
for (const clientItemIntegrityPayload of dto.integrityPayloads) {
clientItemIntegrityPayloadsMap.set(
clientItemIntegrityPayload.uuid,
clientItemIntegrityPayload.uuid.toLowerCase(),
clientItemIntegrityPayload.updated_at_timestamp,
)
caseInsensitiveUuidsMap.set(clientItemIntegrityPayload.uuid.toLowerCase(), clientItemIntegrityPayload.uuid)
}
const mismatches: IntegrityPayload[] = []
@ -58,7 +60,7 @@ export class CheckIntegrity implements UseCaseInterface<IntegrityPayload[]> {
serverItemIntegrityPayload.content_type !== ContentType.TYPES.ItemsKey
) {
mismatches.unshift({
uuid: serverItemIntegrityPayloadUuid,
uuid: caseInsensitiveUuidsMap.get(serverItemIntegrityPayloadUuid) as string,
updated_at_timestamp: serverItemIntegrityPayloadUpdatedAtTimestamp,
})
}