diff --git a/utils/client-schedule.nuxt.test.ts b/utils/client-schedule.nuxt.test.ts index 6b92cde..5559b4b 100644 --- a/utils/client-schedule.nuxt.test.ts +++ b/utils/client-schedule.nuxt.test.ts @@ -6,6 +6,7 @@ import { DateTime, FixedOffsetZone } from "~/shared/utils/luxon"; const locale = "en-GB"; const now = DateTime.now().setLocale(locale); +const later = now.plus({ minutes: 2 }); const zone = now.zone; const nowIso = now.setZone(FixedOffsetZone.utcInstance).toISO(); @@ -172,19 +173,24 @@ describe("class ClientSchedule", () => { ]; for (const pattern of updatePatterns) { test(`apply diff pattern ${pattern}`, () => { - const fixture: Record = { + const fixtureClient: Record = { a: new ClientScheduleLocation(1, now, false, "A", ""), b: new ClientScheduleLocation(1, now, false, "B", ""), x: new ClientScheduleLocation(1, now, true, "X", ""), }; + const fixtureServer: Record = { + a: new ClientScheduleLocation(1, later, false, "A", ""), + b: new ClientScheduleLocation(1, later, false, "B", ""), + x: new ClientScheduleLocation(1, later, true, "X", ""), + }; const schedule = new ClientSchedule(111, now, false, new Map(), new Map(), new Map(), new Map()); - if (fixture[pattern[0]]) - schedule.originalLocations.set(1, fixture[pattern[0]]); - if (fixture[pattern[1]]) - schedule.locations.set(1, fixture[pattern[1]]); - const update = fixture[pattern[3]]; - const expectedOriginalLocation = pattern[5] === "x" ? undefined : fixture[pattern[5]]; - const expectedLocation = fixture[pattern[6]]; + if (fixtureClient[pattern[0]]) + schedule.originalLocations.set(1, fixtureClient[pattern[0]]); + if (fixtureClient[pattern[1]]) + schedule.locations.set(1, fixtureClient[pattern[1]]); + const update = fixtureServer[pattern[3]]; + const expectedOriginalLocation = pattern[5] === "x" ? undefined : fixtureServer[pattern[5]]; + const expectedLocation = pattern[5] === pattern[6] ? fixtureServer[pattern[6]] : fixtureClient[pattern[6]]; schedule.applyUpdate({ id: 111, diff --git a/utils/client-schedule.ts b/utils/client-schedule.ts index 1a14345..a75dfe7 100644 --- a/utils/client-schedule.ts +++ b/utils/client-schedule.ts @@ -62,7 +62,6 @@ export class ClientScheduleLocation extends ClientEntity { equals(other: ClientScheduleLocation) { return ( this.id === other.id - && this.updatedAt.toMillis() === other.updatedAt.toMillis() && this.deleted === other.deleted && this.name === other.name && this.description === other.description @@ -130,7 +129,6 @@ export class ClientScheduleEvent extends ClientEntity { equals(other: ClientScheduleEvent) { return ( this.id === other.id - && this.updatedAt.toMillis() === other.updatedAt.toMillis() && this.deleted === other.deleted && this.name === other.name && this.crew === other.crew @@ -267,7 +265,6 @@ export class ClientScheduleRole extends ClientEntity { equals(other: ClientScheduleRole) { return ( this.id === other.id - && this.updatedAt.toMillis() === other.updatedAt.toMillis() && this.deleted === other.deleted && this.name === other.name && this.description === other.description @@ -329,7 +326,6 @@ export class ClientScheduleShift extends ClientEntity { equals(other: ClientScheduleShift) { return ( this.id === other.id - && this.updatedAt.toMillis() === other.updatedAt.toMillis() && this.deleted === other.deleted && this.role.id === other.role.id && this.name === other.name