package com.peachpasswords.sync import org.junit.Assert.assertEquals import org.junit.Assert.assertNull import org.junit.Test class PairedDeviceRevocationTest { private val browser = PairedDevice( deviceId = "browser-1", deviceName = "Chrome", deviceType = "extension", longTermPublicKeyHex = "ab".repeat(32), pairedAt = 1L, ) @Test fun `new revocation records the key and removes the paired row`() { val mutation = planDeviceRevocation( devices = listOf(browser), revocations = emptyList(), deviceId = browser.deviceId, revokedByDeviceId = "phone-1", nowMs = 42L, ) assertEquals(emptyList(), mutation.devices) assertEquals(1, mutation.revocations.size) assertEquals(browser.longTermPublicKeyHex, mutation.added?.longTermPublicKeyHex) assertEquals(42L, mutation.added?.revokedAt) } @Test fun `existing revocation still removes a stale overlapping paired row`() { val existing = DeviceRevocation( deviceId = browser.deviceId, longTermPublicKeyHex = browser.longTermPublicKeyHex!!, revokedAt = 1L, revokedByDeviceId = "phone-1", ) val mutation = planDeviceRevocation( devices = listOf(browser), revocations = listOf(existing), deviceId = browser.deviceId, revokedByDeviceId = "phone-1", nowMs = 99L, ) assertEquals(emptyList(), mutation.devices) assertEquals(listOf(existing), mutation.revocations) assertNull(mutation.added) } }