parent
be67b229e0
commit
2b26950d67
@ -0,0 +1,85 @@ |
||||
// |
||||
// ApiCallTests.swift |
||||
// LeStorageTests |
||||
// |
||||
// Created by Laurent Morvillier on 15/02/2025. |
||||
// |
||||
|
||||
import Testing |
||||
@testable import LeStorage |
||||
|
||||
class Thing: ModelObject, Storable { |
||||
static func resourceName() -> String { return "thing" } |
||||
static func tokenExemptedMethods() -> [LeStorage.HTTPMethod] { return [] } |
||||
static func filterByStoreIdentifier() -> Bool { return false } |
||||
|
||||
var id: String = Store.randomId() |
||||
var name: String |
||||
|
||||
init(name: String) { |
||||
self.name = name |
||||
} |
||||
} |
||||
|
||||
struct ApiCallTests { |
||||
|
||||
@Test func testApiCallProvisioning1() async throws { |
||||
let collection = ApiCallCollection<Thing>() |
||||
|
||||
let thing = Thing(name: "yeah") |
||||
|
||||
let _ = try await collection.sendInsertion(thing) |
||||
|
||||
await #expect(collection.items.count == 1) |
||||
if let apiCall = await collection.items.first { |
||||
#expect(apiCall.method == .post) |
||||
} |
||||
|
||||
thing.name = "woo" |
||||
let _ = try await collection.sendUpdate(thing) |
||||
await #expect(collection.items.count == 1) |
||||
if let apiCall = await collection.items.first { |
||||
#expect(apiCall.method == .post) |
||||
} |
||||
|
||||
let _ = try await collection.sendDeletion(thing) |
||||
await #expect(collection.items.count == 0) |
||||
} |
||||
|
||||
@Test func testApiCallProvisioning2() async throws { |
||||
let collection = ApiCallCollection<Thing>() |
||||
|
||||
let thing = Thing(name: "yeah") |
||||
|
||||
let _ = try await collection.sendUpdate(thing) |
||||
|
||||
await #expect(collection.items.count == 1) |
||||
if let apiCall = await collection.items.first { |
||||
#expect(apiCall.method == .put) |
||||
} |
||||
|
||||
thing.name = "woo" |
||||
let _ = try await collection.sendUpdate(thing) |
||||
await #expect(collection.items.count == 1) |
||||
if let apiCall = await collection.items.first { |
||||
#expect(apiCall.method == .put) |
||||
} |
||||
|
||||
let _ = try await collection.sendDeletion(thing) |
||||
await #expect(collection.items.count == 1) |
||||
} |
||||
|
||||
@Test func testApiCallProvisioning3() async throws { |
||||
let collection = ApiCallCollection<Thing>() |
||||
|
||||
let thing = Thing(name: "yeah") |
||||
|
||||
let _ = try await collection.sendDeletion(thing) |
||||
await #expect(collection.items.count == 1) |
||||
let _ = try await collection.sendDeletion(thing) |
||||
await #expect(collection.items.count == 1) |
||||
let _ = try await collection.sendDeletion(thing) |
||||
await #expect(collection.items.count == 1) |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue