diff --git a/Tests/CohesionKitTests/EntityStoreTests.swift b/Tests/CohesionKitTests/EntityStoreTests.swift index 381908b..fffbe58 100644 --- a/Tests/CohesionKitTests/EntityStoreTests.swift +++ b/Tests/CohesionKitTests/EntityStoreTests.swift @@ -411,6 +411,22 @@ extension EntityStoreTests { XCTAssertTrue(registry.hasPendingChange(for: AliasContainer.self)) } + // make sure that when we have A -> B -> C and update C, we enqueue parents B AND A. + func test_update_entityIsNested_itEnqueuesAllParents() { + let a = AFixture(b: BFixture(c: SingleNodeFixture(id: 1))) + let registry = ObserverRegistryStub() + let entityStore = EntityStore(registry: registry) + + withExtendedLifetime(entityStore.store(entity: a)) { + registry.clearPendingChangesStub() + + _ = entityStore.nodeStore(entity: SingleNodeFixture(id: 1, primitive: "updated"), modifiedAt: nil) + } + + XCTAssertTrue(registry.hasPendingChange(for: BFixture.self)) + XCTAssertTrue(registry.hasPendingChange(for: AFixture.self)) + } + func test_update_entityIsInsideAggregagte_aggreateIsAliased_itEnqueuesAliasInRegistry() { let aggregate = RootFixture(id: 1, primitive: "", singleNode: SingleNodeFixture(id: 1), listNodes: []) let registry = ObserverRegistryStub() diff --git a/Tests/CohesionKitTests/RootFixture.swift b/Tests/CohesionKitTests/RootFixture.swift index 7f353aa..e81a614 100644 --- a/Tests/CohesionKitTests/RootFixture.swift +++ b/Tests/CohesionKitTests/RootFixture.swift @@ -1,6 +1,24 @@ import Foundation import CohesionKit +struct AFixture: Aggregate { + var id: BFixture.ID { b.id } + var b: BFixture + + var nestedEntitiesKeyPaths: [PartialIdentifiableKeyPath] { + [.init(\.b)] + } +} + +struct BFixture: Aggregate { + var id: SingleNodeFixture.ID { c.id } + var c: SingleNodeFixture + + var nestedEntitiesKeyPaths: [PartialIdentifiableKeyPath] { + [.init(\.c)] + } +} + struct RootFixture: Aggregate, Equatable { let id: Int let primitive: String @@ -56,4 +74,4 @@ struct ListNodeFixture: Identifiable, Equatable { PartialIdentifiableKeyPath(parent.appending(path: \.singleNode)) ] } -} \ No newline at end of file +}