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.
85 lines
2.0 KiB
85 lines
2.0 KiB
//
|
|
// 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 [] }
|
|
|
|
}
|
|
|
|
class Boat: ModelObject, SyncedStorable {
|
|
|
|
var id: String = Store.randomId()
|
|
var lastUpdate: Date = Date()
|
|
var shared: Bool? = false
|
|
|
|
override required init() {
|
|
super.init()
|
|
}
|
|
|
|
static func tokenExemptedMethods() -> [LeStorage.HTTPMethod] { return [] }
|
|
static func resourceName() -> String { return "boat" }
|
|
static var copyServerResponse: Bool = false
|
|
|
|
var storeId: String? { return nil }
|
|
func copy(from other: any LeStorage.Storable) {
|
|
|
|
}
|
|
static func relationships() -> [LeStorage.Relationship] { return [] }
|
|
|
|
}
|
|
|
|
struct CollectionsTests {
|
|
|
|
var cars: StoredCollection<Car>
|
|
var boats: SyncedCollection<Boat>
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|