import XCTest @testable import MultiSimAdmin final class UpstreamRouteTests: XCTestCase { func testKnownRoutesUseExactPathsMethodsAndPayloads() throws { XCTAssertEqual(UpstreamRoute.health.method, "GET") XCTAssertEqual(UpstreamRoute.health.path, "/api/health") XCTAssertEqual(UpstreamRoute.device.path, "/api/device") XCTAssertEqual(UpstreamRoute.sim.path, "/api/sim") XCTAssertEqual(UpstreamRoute.network.path, "/api/network") XCTAssertEqual(UpstreamRoute.signalStrength.path, "/api/network/signal-strength") XCTAssertEqual(UpstreamRoute.smsList(limit: 100, offset: 0, direction: nil).path, "/api/sms/list?limit=100&offset=0") XCTAssertEqual(UpstreamRoute.smsList(limit: 20, offset: 2, direction: "outgoing").path, "/api/sms/list?limit=20&offset=2&direction=outgoing") let login = UpstreamRoute.authLogin(password: "secret") XCTAssertEqual(login.method, "POST") XCTAssertEqual(login.path, "/api/auth/login") let loginObject = try XCTUnwrap(JSONSerialization.jsonObject(with: XCTUnwrap(login.body)) as? [String: String]) XCTAssertEqual(loginObject, ["password": "secret"]) let delete = UpstreamRoute.smsBatchDelete(ids: [2, 1]) XCTAssertEqual(delete.method, "POST") XCTAssertEqual(delete.path, "/api/sms/batch-delete") let deleteObject = try XCTUnwrap( JSONSerialization.jsonObject(with: XCTUnwrap(delete.body)) as? [String: [Int]] ) XCTAssertEqual(deleteObject, ["ids": [2, 1]]) } func testSessionStoreIsIsolatedByInstanceAndOrigin() async { let store = InstanceSessionStore() let origin = URL(string: "http://192.168.1.10:3000")! await store.set(UUID(uuidString: "00000000-0000-0000-0000-000000000001")!, origin: origin, cookie: "a") await store.set(UUID(uuidString: "00000000-0000-0000-0000-000000000002")!, origin: origin, cookie: "b") let sameID = URL(string: "https://other.example")! await store.set(UUID(uuidString: "00000000-0000-0000-0000-000000000001")!, origin: sameID, cookie: "c") await store.clear(UUID(uuidString: "00000000-0000-0000-0000-000000000001")!) let first = await store.cookie( for: UUID(uuidString: "00000000-0000-0000-0000-000000000001")!, origin: origin ) let second = await store.cookie( for: UUID(uuidString: "00000000-0000-0000-0000-000000000002")!, origin: origin ) XCTAssertEqual(first, nil) XCTAssertEqual(second, "b") } }