// // CollectionsTests.swift // LeStorageTests // // Created by Laurent Morvillier on 15/10/2024. // import Testing @testable import LeStorage class Car: ModelObject, Storable { var id: String = Store.randomId() static func resourceName() -> String { return "car" } func copy(from other: any LeStorage.Storable) { } static func relationships() -> [LeStorage.Relationship] { return [] } static func storeParent() -> Bool { return false } } class Boat: ModelObject, SyncedStorable { var id: String = Store.randomId() var lastUpdate: Date = Date() var sharing: LeStorage.SharingStatus? override required init() { super.init() } static func tokenExemptedMethods() -> [LeStorage.HTTPMethod] { return [] } static func resourceName() -> String { return "boat" } static var copyServerResponse: Bool = false static func storeParent() -> Bool { return false } var storeId: String? { return nil } func copy(from other: any LeStorage.Storable) { } static func relationships() -> [LeStorage.Relationship] { return [] } } struct CollectionsTests { var cars: StoredCollection var boats: SyncedCollection init() async { cars = await StoreCenter.main.mainStore.asyncLoadingStoredCollection(inMemory: true) boats = await StoreCenter.main.mainStore.asyncLoadingSynchronizedCollection(inMemory: true) } @Test func testLoading() async { #expect(self.cars.hasLoaded) #expect(self.boats.hasLoaded) } @Test func differentiationTest() async throws { // Cars #expect(cars.count == 0) cars.addOrUpdate(instance: Car()) #expect(cars.count == 1) // Boats #expect(boats.count == 0) let oldApiCallCount = await StoreCenter.main.apiCallCount(type: Boat.self) #expect(oldApiCallCount == 0) boats.addOrUpdate(instance: Boat()) #expect(boats.count == 1) // Cars and boats cars.reset() boats.reset() #expect(cars.count == 0) #expect(boats.count == 0) } }