36 lines
1.3 KiB
TypeScript
36 lines
1.3 KiB
TypeScript
import { describe, expect, it } from "vitest"
|
|
import { reconcileLocalSessionStart } from "@/components/tickets/ticket-timer.utils"
|
|
|
|
describe("reconcileLocalSessionStart", () => {
|
|
it("usa o timestamp remoto quando não há marcador local", () => {
|
|
const result = reconcileLocalSessionStart({ remoteStart: 5000, localStart: 0, origin: "unknown" })
|
|
expect(result).toEqual({ localStart: 5000, origin: "remote" })
|
|
})
|
|
|
|
it("mantém o fallback local quando o remoto é menor e a sessão acabou de começar", () => {
|
|
const result = reconcileLocalSessionStart({
|
|
remoteStart: 1_000,
|
|
localStart: 2_000,
|
|
origin: "fresh-local",
|
|
})
|
|
expect(result).toEqual({ localStart: 2_000, origin: "fresh-local" })
|
|
})
|
|
|
|
it("substitui o fallback local quando já havia sessão em andamento", () => {
|
|
const result = reconcileLocalSessionStart({
|
|
remoteStart: 1_000,
|
|
localStart: 2_000,
|
|
origin: "already-running-fallback",
|
|
})
|
|
expect(result).toEqual({ localStart: 1_000, origin: "remote" })
|
|
})
|
|
|
|
it("sincroniza com o servidor quando o remoto é mais recente", () => {
|
|
const result = reconcileLocalSessionStart({
|
|
remoteStart: 4_000,
|
|
localStart: 2_000,
|
|
origin: "fresh-local",
|
|
})
|
|
expect(result).toEqual({ localStart: 4_000, origin: "remote" })
|
|
})
|
|
})
|