|
|
|
|
@ -20,34 +20,17 @@ struct StoredCollectionTests { |
|
|
|
|
|
|
|
|
|
var collection: StoredCollection<MockStorable> |
|
|
|
|
|
|
|
|
|
init() { |
|
|
|
|
collection = StoreCenter.main.mainStore.registerCollection() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func ensureCollectionLoaded() async throws { |
|
|
|
|
// Wait for the collection to finish loading |
|
|
|
|
// Adjust the timeout as needed |
|
|
|
|
let timeout = 5.0 // seconds |
|
|
|
|
let startTime = Date() |
|
|
|
|
|
|
|
|
|
while !collection.hasLoaded { |
|
|
|
|
// Check for timeout |
|
|
|
|
if Date().timeIntervalSince(startTime) > timeout { |
|
|
|
|
throw Error("Collection loading timed out") |
|
|
|
|
} |
|
|
|
|
// Wait a bit before checking again |
|
|
|
|
try await Task.sleep(for: .milliseconds(100)) |
|
|
|
|
} |
|
|
|
|
init() async { |
|
|
|
|
collection = await StoreCenter.main.mainStore.asyncLoadingStoredCollection(inMemory: true) |
|
|
|
|
collection.reset() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test func testInitialization() async throws { |
|
|
|
|
try await ensureCollectionLoaded() |
|
|
|
|
#expect(self.collection.hasLoaded) |
|
|
|
|
#expect(collection.items.count == 0) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test func testAddOrUpdate() async throws { |
|
|
|
|
try await ensureCollectionLoaded() |
|
|
|
|
let item = MockStorable(id: "1", name: "Test") |
|
|
|
|
collection.addOrUpdate(instance: item) |
|
|
|
|
|
|
|
|
|
@ -61,7 +44,6 @@ struct StoredCollectionTests { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test func testDelete() async throws { |
|
|
|
|
try await ensureCollectionLoaded() |
|
|
|
|
let item = MockStorable(id: "1", name: "Test") |
|
|
|
|
collection.addOrUpdate(instance: item) |
|
|
|
|
#expect(collection.items.count == 1) |
|
|
|
|
@ -71,7 +53,6 @@ struct StoredCollectionTests { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test func testFindById() async throws { |
|
|
|
|
try await ensureCollectionLoaded() |
|
|
|
|
let item = MockStorable(id: "1", name: "Test") |
|
|
|
|
collection.addOrUpdate(instance: item) |
|
|
|
|
|
|
|
|
|
@ -83,7 +64,6 @@ struct StoredCollectionTests { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test func testDeleteById() async throws { |
|
|
|
|
try await ensureCollectionLoaded() |
|
|
|
|
let item = MockStorable(id: "1", name: "Test") |
|
|
|
|
collection.addOrUpdate(instance: item) |
|
|
|
|
|
|
|
|
|
@ -93,7 +73,6 @@ struct StoredCollectionTests { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test func testAddOrUpdateMultiple() async throws { |
|
|
|
|
try await ensureCollectionLoaded() |
|
|
|
|
let items = [ |
|
|
|
|
MockStorable(id: "1", name: "Test1"), |
|
|
|
|
MockStorable(id: "2", name: "Test2"), |
|
|
|
|
@ -104,7 +83,6 @@ struct StoredCollectionTests { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test func testDeleteAll() async throws { |
|
|
|
|
try await ensureCollectionLoaded() |
|
|
|
|
let items = [ |
|
|
|
|
MockStorable(id: "1", name: "Test1"), |
|
|
|
|
MockStorable(id: "2", name: "Test2"), |
|
|
|
|
@ -118,7 +96,6 @@ struct StoredCollectionTests { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test func testRandomAccessCollection() async throws { |
|
|
|
|
try await ensureCollectionLoaded() |
|
|
|
|
let items = [ |
|
|
|
|
MockStorable(id: "1", name: "Test1"), |
|
|
|
|
MockStorable(id: "2", name: "Test2"), |
|
|
|
|
|