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.
 
 
LeStorage/LeStorageTests/CollectionsTests.swift

60 lines
1.5 KiB

//
// CollectionsTests.swift
// LeStorageTests
//
// Created by Laurent Morvillier on 15/10/2024.
//
import Testing
import LeStorage
class Car: ModelObject, Storable {
var id: String = Store.randomId()
static func resourceName() -> String { return "car" }
static var relationshipNames: [String] = []
}
class Boat: ModelObject, SyncedStorable {
var id: String = Store.randomId()
var lastUpdate: Date = Date()
static func tokenExemptedMethods() -> [LeStorage.HTTPMethod] { return [] }
static func resourceName() -> String { return "boat" }
static var relationshipNames: [String] = []
var storeId: String? { return nil }
}
struct CollectionsTests {
@Test func differentiationTest() async throws {
let cars: StoredCollection<Car> = Store.main.registerCollection(inMemory: true)
let boats: StoredCollection<Boat> = Store.main.registerSynchronizedCollection(inMemory: true)
#expect(cars.count == 0)
cars.addOrUpdate(instance: Car())
#expect(cars.count == 1)
#expect(boats.count == 0)
let oldApiCallCount = await StoreCenter.main.apiCallCount(type: Boat.self)
boats.addOrUpdate(instance: Boat())
#expect(boats.count == 1)
let newApiCallCount = await StoreCenter.main.apiCallCount(type: Boat.self)
#expect(oldApiCallCount == newApiCallCount - 1)
cars.reset()
boats.reset()
#expect(cars.count == 0)
#expect(boats.count == 0)
}
}