Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(test): add integration test cases of CPK for API lazy loading #2769

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,80 @@ extension GraphQLLazyLoadCompositePKTests {
}
assertList(queriedChild, state: .isLoaded(count: 1))
}

/*
- Given: Api category setup with CompositePKModels
- When:
- Subscribe onCreate events of ChildSansBelongsTo
- Create new CompositePKParent instance with API
- Create new ChildSansBelongsTo instance with API
- Then:
- the newly created instance is successfully created through API. onCreate event is received.
*/
func testSubscribeChildSansBelongsToOnCreate() async throws {
await setup(withModels: CompositePKModels())

let parent = CompositePKParent(customId: UUID().uuidString, content: UUID().uuidString)
let child = initChildSansBelongsTo(with: parent)
let (onCreate, subscription) = try await subscribe(of: ChildSansBelongsTo.self, type: .onCreate) { createdChild in
createdChild.identifier == child.identifier
}

try await mutate(.create(parent))
try await mutate(.create(child))
await waitForExpectations([onCreate], timeout: 10)
subscription.cancel()
}

/*
- Given: Api category setup with CompositePKModels
- When:
- Subscribe onCreate events of ChildSansBelongsTo
- Create new CompositePKParent instance with API
- Create new ChildSansBelongsTo instance with API
- Update newly created ChildSansBelongsTo instance with API
- Then:
- the newly created instance is successfully updated through API. onUpdate event is received.
*/
func testSubscribeChildSansBelongsToOnUpdate() async throws {
await setup(withModels: CompositePKModels())

let parent = CompositePKParent(customId: UUID().uuidString, content: UUID().uuidString)
let child = initChildSansBelongsTo(with: parent)
let (onUpdate, subscription) = try await subscribe(of: ChildSansBelongsTo.self, type: .onUpdate) { updatedChild in
updatedChild.identifier == child.identifier
}

try await mutate(.create(parent))
try await mutate(.create(child))
try await mutate(.update(child))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this call the update mutation event even if there are no changes to child model?

await waitForExpectations([onUpdate], timeout: 10)
subscription.cancel()
}

/*
- Given: Api category setup with CompositePKModels
- When:
- Subscribe onCreate events of ChildSansBelongsTo
- Create new CompositePKParent instance with API
- Create new ChildSansBelongsTo instance with API
- Delete newly created ChildSansBelongsTo with API
- Then:
- the newly created instance is successfully deleted through API. onDelete event is received.
*/
func testSubscribeChildSansBelongsToOnDelete() async throws {
await setup(withModels: CompositePKModels())

let parent = CompositePKParent(customId: UUID().uuidString, content: UUID().uuidString)
let child = initChildSansBelongsTo(with: parent)
let (onDelete, subscription) = try await subscribe(of: ChildSansBelongsTo.self, type: .onDelete) { deletedChild in
deletedChild.identifier == child.identifier
}

try await mutate(.create(parent))
try await mutate(.create(child))
try await mutate(.delete(child))
await waitForExpectations([onDelete], timeout: 10)
subscription.cancel()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,81 @@ extension GraphQLLazyLoadCompositePKTests {
}
assertList(queriedChild, state: .isLoaded(count: 1))
}

/*
- Given: Api category setup with CompositePKModels
- When:
- Subscribe onCreate events of CompositePKChild
- Create new CompositePKChild instance with API
- Then:
- the newly created instance is successfully created through API. onCreate event is received.
*/
func testSubscribeCompositePKChildOnCreate() async throws {
await setup(withModels: CompositePKModels())

let child = CompositePKChild(childId: UUID().uuidString, content: UUID().uuidString)
let (onCreate, subscription) = try await subscribe(of: CompositePKChild.self, type: .onCreate) { createdChild in
createdChild.identifier == child.identifier
}

try await mutate(.create(child))
await waitForExpectations([onCreate], timeout: 10)
subscription.cancel()
}

/*
- Given: Api category setup with CompositePKModels
- When:
- Subscribe onCreate events of CompositePKChild
- Create new CompositePKChild instance with API
- Create new CompositePKParent instance with API
- Update newly created CompositePKParent instance with API
- Then:
- the newly created instance is successfully updated through API. onUpdate event is received.
*/
func testSubscribeCompositePKChildOnUpdate() async throws {
await setup(withModels: CompositePKModels())

let child = CompositePKChild(childId: UUID().uuidString, content: UUID().uuidString)
let parent = CompositePKParent(customId: UUID().uuidString, content: UUID().uuidString)
let (onUpdate, subscription) = try await subscribe(of: CompositePKChild.self, type: .onUpdate) { updatedChild in
if let associatedParent = try await updatedChild.parent {
return associatedParent.identifier == parent.identifier
&& updatedChild.identifier == child.identifier
}
return false
}

try await mutate(.create(child))
try await mutate(.create(parent))

var updatingChild = child
updatingChild.setParent(parent)
try await mutate(.update(updatingChild))
await waitForExpectations([onUpdate], timeout: 10)
subscription.cancel()
}

/*
- Given: Api category setup with CompositePKModels
- When:
- Subscribe onCreate events of CompositePKChild
- Create new CompositePKChild instance with API
- Delete newly created CompositePKChild with API
- Then:
- the newly created instance is successfully deleted through API. onDelete event is received.
*/
func testSubscribeCompositePKChildOnDelete() async throws {
await setup(withModels: CompositePKModels())

let child = CompositePKChild(childId: UUID().uuidString, content: UUID().uuidString)
let (onDelete, subscription) = try await subscribe(of: CompositePKChild.self, type: .onDelete) { deletedChild in
deletedChild.identifier == child.identifier
}

try await mutate(.create(child))
try await mutate(.delete(child))
await waitForExpectations([onDelete], timeout: 10)
subscription.cancel()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,85 @@ extension GraphQLLazyLoadCompositePKTests {
}
assertList(queriedChild, state: .isLoaded(count: 1))
}

/*
- Given: Api category setup with CompositePKModels
- When:
- Subscribe onCreate events of ImplicitChild
- Create new CompositePKParent instance with API
- Create new ImplicitChild instance with API
- Then:
- the newly created instance is successfully created through API. onCreate event is received.
*/
func testSubscribeImplicitChildOnCreate() async throws {
await setup(withModels: CompositePKModels())

let parent = CompositePKParent(customId: UUID().uuidString, content: UUID().uuidString)
let child = ImplicitChild(childId: UUID().uuidString, content: UUID().uuidString, parent: parent)
let (onCreate, subscription) = try await subscribe(of: ImplicitChild.self, type: .onCreate) { createdChild in
createdChild.identifier == child.identifier
}

try await mutate(.create(parent))
try await mutate(.create(child))
await waitForExpectations([onCreate], timeout: 10)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be great if we can we use a constant for timeout value

subscription.cancel()
}

/*
- Given: Api category setup with CompositePKModels
- When:
- Subscribe onCreate events of ImplicitChild
- Create new CompositePKParent instance with API
- Create new ImplicitChild instance with API
- Update newly created ImplicitChild instance with API
- Then:
- the newly created instance is successfully updated through API. onUpdate event is received.
*/
func testSubscribeImplicitChildOnUpdate() async throws {
await setup(withModels: CompositePKModels())

let parent = CompositePKParent(customId: UUID().uuidString, content: UUID().uuidString)
let child = ImplicitChild(childId: UUID().uuidString, content: UUID().uuidString, parent: parent)
let (onUpdate, subscription) = try await subscribe(of: ImplicitChild.self, type: .onUpdate, verifyChange: { updatedChild in
let associatedParent = try await updatedChild.parent
return associatedParent.identifier == parent.identifier
&& updatedChild.identifier == child.identifier
})

try await mutate(.create(parent))
try await mutate(.create(child))

var updatingChild = child
updatingChild.setParent(parent)
try await mutate(.update(updatingChild))
await waitForExpectations([onUpdate], timeout: 10)
subscription.cancel()
}

/*
- Given: Api category setup with CompositePKModels
- When:
- Subscribe onCreate events of CompositePKChild
- Create new CompositePKParent instance with API
- Create new CompositePKChild instance with API
- Delete newly created CompositePKChild with API
- Then:
- the newly created instance is successfully deleted through API. onDelete event is received.
*/
func testSubscribeImplicitChildOnDelete() async throws {
await setup(withModels: CompositePKModels())

let parent = CompositePKParent(customId: UUID().uuidString, content: UUID().uuidString)
let child = ImplicitChild(childId: UUID().uuidString, content: UUID().uuidString, parent: parent)
let (onDelete, subscription) = try await subscribe(of: ImplicitChild.self, type: .onDelete) { deletedChild in
deletedChild.identifier == child.identifier
}

try await mutate(.create(parent))
try await mutate(.create(child))
try await mutate(.delete(child))
await waitForExpectations([onDelete], timeout: 10)
subscription.cancel()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,85 @@ extension GraphQLLazyLoadCompositePKTests {
}
assertList(queriedChild, state: .isLoaded(count: 1))
}

/*
- Given: Api category setup with CompositePKModels
- When:
- Subscribe onCreate events of StrangeExplicitChild
- Create new CompositePKParent instance with API
- Create new StrangeExplicitChild instance with API
- Then:
- the newly created instance is successfully created through API. onCreate event is received.
*/
func testSubscribeStrangeExplicitChildOnCreate() async throws {
await setup(withModels: CompositePKModels())

let parent = CompositePKParent(customId: UUID().uuidString, content: UUID().uuidString)
let child = StrangeExplicitChild(strangeId: UUID().uuidString, content: UUID().uuidString, parent: parent)
let (onCreate, subscription) = try await subscribe(of: StrangeExplicitChild.self, type: .onCreate) { createdChild in
createdChild.identifier == child.identifier
}

try await mutate(.create(parent))
try await mutate(.create(child))
await waitForExpectations([onCreate], timeout: 10)
subscription.cancel()
}

/*
- Given: Api category setup with CompositePKModels
- When:
- Subscribe onCreate events of StrangeExplicitChild
- Create new CompositePKParent instance with API
- Create new StrangeExplicitChild instance with API
- Update newly created StrangeExplicitChild instance with API
- Then:
- the newly created instance is successfully updated through API. onUpdate event is received.
*/
func testSubscribeStrangeExplicitChildOnUpdate() async throws {
await setup(withModels: CompositePKModels())

let parent = CompositePKParent(customId: UUID().uuidString, content: UUID().uuidString)
let child = StrangeExplicitChild(strangeId: UUID().uuidString, content: UUID().uuidString, parent: parent)
let (onUpdate, subscription) = try await subscribe(of: StrangeExplicitChild.self, type: .onUpdate, verifyChange: { updatedChild in
let associatedParent = try await updatedChild.parent
return associatedParent.identifier == parent.identifier
&& updatedChild.identifier == child.identifier
})

try await mutate(.create(parent))
try await mutate(.create(child))

var updatingChild = child
updatingChild.setParent(parent)
try await mutate(.update(updatingChild))
await waitForExpectations([onUpdate], timeout: 10)
subscription.cancel()
}

/*
- Given: Api category setup with CompositePKModels
- When:
- Subscribe onCreate events of StrangeExplicitChild
- Create new CompositePKParent instance with API
- Create new StrangeExplicitChild instance with API
- Delete newly created StrangeExplicitChild with API
- Then:
- the newly created instance is successfully deleted through API. onDelete event is received.
*/
func testSubscribeStrangeExplicitChildOnDelete() async throws {
await setup(withModels: CompositePKModels())

let parent = CompositePKParent(customId: UUID().uuidString, content: UUID().uuidString)
let child = StrangeExplicitChild(strangeId: UUID().uuidString, content: UUID().uuidString, parent: parent)
let (onDelete, subscription) = try await subscribe(of: StrangeExplicitChild.self, type: .onDelete) { deletedChild in
deletedChild.identifier == child.identifier
}

try await mutate(.create(parent))
try await mutate(.create(child))
try await mutate(.delete(child))
await waitForExpectations([onDelete], timeout: 10)
subscription.cancel()
}
}
Loading