You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
2.8 KiB
90 lines
2.8 KiB
//
|
|
// 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 == 2) // one post and one put
|
|
if let apiCall = await collection.items.first {
|
|
#expect(apiCall.method == .post)
|
|
}
|
|
if let apiCall = await collection.items.last {
|
|
#expect(apiCall.method == .put)
|
|
}
|
|
|
|
let _ = try await collection.sendDeletion(thing)
|
|
await #expect(collection.items.count == 1)
|
|
}
|
|
|
|
@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)
|
|
let _ = try await collection.sendUpdate(thing)
|
|
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)
|
|
}
|
|
|
|
}
|
|
|