Skip to content

Commit

Permalink
add test about updating parents
Browse files Browse the repository at this point in the history
  • Loading branch information
pjechris committed Aug 29, 2024
1 parent 57f533b commit 43fcc40
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
16 changes: 16 additions & 0 deletions Tests/CohesionKitTests/EntityStoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,22 @@ extension EntityStoreTests {
XCTAssertTrue(registry.hasPendingChange(for: AliasContainer<RootFixture>.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()
Expand Down
20 changes: 19 additions & 1 deletion Tests/CohesionKitTests/RootFixture.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
import Foundation
import CohesionKit

struct AFixture: Aggregate {
var id: BFixture.ID { b.id }
var b: BFixture

var nestedEntitiesKeyPaths: [PartialIdentifiableKeyPath<Self>] {
[.init(\.b)]
}
}

struct BFixture: Aggregate {
var id: SingleNodeFixture.ID { c.id }
var c: SingleNodeFixture

var nestedEntitiesKeyPaths: [PartialIdentifiableKeyPath<Self>] {
[.init(\.c)]
}
}

struct RootFixture: Aggregate, Equatable {
let id: Int
let primitive: String
Expand Down Expand Up @@ -56,4 +74,4 @@ struct ListNodeFixture: Identifiable, Equatable {
PartialIdentifiableKeyPath(parent.appending(path: \.singleNode))
]
}
}
}

0 comments on commit 43fcc40

Please sign in to comment.