diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL12/CompositePK/GraphQLLazyLoadCompositePKChildSansTests.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL12/CompositePK/GraphQLLazyLoadCompositePKChildSansTests.swift index a98c432fa5..f38a37e189 100644 --- a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL12/CompositePK/GraphQLLazyLoadCompositePKChildSansTests.swift +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL12/CompositePK/GraphQLLazyLoadCompositePKChildSansTests.swift @@ -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)) + 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() + } } diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL12/CompositePK/GraphQLLazyLoadCompositePKChildTests.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL12/CompositePK/GraphQLLazyLoadCompositePKChildTests.swift index d9bc6411d1..44e4efb113 100644 --- a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL12/CompositePK/GraphQLLazyLoadCompositePKChildTests.swift +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL12/CompositePK/GraphQLLazyLoadCompositePKChildTests.swift @@ -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() + } } diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL12/CompositePK/GraphQLLazyLoadCompositePKImplicitTests.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL12/CompositePK/GraphQLLazyLoadCompositePKImplicitTests.swift index 694b7904f7..cbcf7f3800 100644 --- a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL12/CompositePK/GraphQLLazyLoadCompositePKImplicitTests.swift +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL12/CompositePK/GraphQLLazyLoadCompositePKImplicitTests.swift @@ -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) + 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() + } } diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL12/CompositePK/GraphQLLazyLoadCompositePKStrangeExplicitTests.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL12/CompositePK/GraphQLLazyLoadCompositePKStrangeExplicitTests.swift index 1b74ee70c6..de59cd095b 100644 --- a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL12/CompositePK/GraphQLLazyLoadCompositePKStrangeExplicitTests.swift +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL12/CompositePK/GraphQLLazyLoadCompositePKStrangeExplicitTests.swift @@ -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() + } } diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL12/CompositePK/GraphQLLazyLoadCompositePKTests.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL12/CompositePK/GraphQLLazyLoadCompositePKTests.swift index 9f7e8bbf74..b4d7126531 100644 --- a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL12/CompositePK/GraphQLLazyLoadCompositePKTests.swift +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL12/CompositePK/GraphQLLazyLoadCompositePKTests.swift @@ -107,6 +107,95 @@ final class GraphQLLazyLoadCompositePKTests: GraphQLLazyLoadBaseTest { let queriedParent = try await query(request)! XCTAssertNotNil(queriedParent) } + + /* + - 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 testSubscribeCompositePKParentOnCreate() async throws { + await setup(withModels: CompositePKModels()) + let parent = CompositePKParent(customId: UUID().uuidString, content: UUID().uuidString) + let child = CompositePKChild(childId: UUID().uuidString, content: UUID().uuidString, parent: parent) + let (onCreate, subscription) = try await subscribe(of: CompositePKParent.self, type: .onCreate) { createdParent in + try await createdParent.children?.fetch() + if case .some(.loaded(let associatedChildren)) = createdParent.children?.loadedState { + return createdParent.identifier == parent.identifier + && associatedChildren.map(\.identifier).contains(child.identifier) + } + return false + } + + try await mutate(.create(child)) + try await mutate(.create(parent)) + 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 the newly created CompositePKParent instance + - Then: + - the newly created instance is successfully updated through API. onUpdate event is received. + */ + func testSubscribeCompositePKParentOnUpdate() async throws { + await setup(withModels: CompositePKModels()) + let parent = CompositePKParent(customId: UUID().uuidString, content: UUID().uuidString) + let child = CompositePKChild(childId: UUID().uuidString, content: UUID().uuidString, parent: parent) + + let (onUpdate, subscription) = try await subscribe(of: CompositePKParent.self, type: .onCreate) { updatedParent in + try await updatedParent.children?.fetch() + if case .some(.loaded(let associatedChildren)) = updatedParent.children?.loadedState { + return updatedParent.identifier == parent.identifier + && associatedChildren.map(\.identifier).contains(child.identifier) + } + return false + } + + try await mutate(.create(child)) + try await mutate(.create(parent)) + try await mutate(.update(parent)) + await waitForExpectations([onUpdate], timeout: 10) + subscription.cancel() + } + + /* + - Given: Api category setup with CompositePKModels + - When: + - Subscribe onDelete events of CompositePKParent + - Create new CompositePKChild instance with API + - Create new CompositePKParent instance with API + - Then: + - the newly created instance is successfully deleted through API. onDelete event is received. + */ + func testSubscribeCompositePKParentOnDelete() async throws { + await setup(withModels: CompositePKModels()) + + let parent = CompositePKParent(customId: UUID().uuidString, content: UUID().uuidString) + let child = CompositePKChild(childId: UUID().uuidString, content: UUID().uuidString, parent: parent) + + let (onDelete, subscription) = try await subscribe(of: CompositePKParent.self, type: .onDelete) { deletedParent in + try await deletedParent.children?.fetch() + if case .some(.loaded(let associatedChildren)) = deletedParent.children?.loadedState { + return deletedParent.identifier == parent.identifier + && associatedChildren.map(\.identifier).contains(child.identifier) + } + return false + } + + try await mutate(.create(child)) + try await mutate(.create(parent)) + try await mutate(.delete(parent)) + await waitForExpectations([onDelete], timeout: 10) + subscription.cancel() + } } extension GraphQLLazyLoadCompositePKTests: DefaultLogger { } diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL12/DefaultPK/GraphQLLazyLoadDefaultPKTests.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL12/DefaultPK/GraphQLLazyLoadDefaultPKTests.swift index 017e546030..1683db6f11 100644 --- a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL12/DefaultPK/GraphQLLazyLoadDefaultPKTests.swift +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL12/DefaultPK/GraphQLLazyLoadDefaultPKTests.swift @@ -17,67 +17,67 @@ final class GraphQLLazyLoadDefaultPKTests: GraphQLLazyLoadBaseTest { func testConfigure() async throws { await setup(withModels: DefaultPKModels()) } - + func testDefaultPKParentChild() async throws { await setup(withModels: DefaultPKModels()) let defaultPKParent = DefaultPKParent() let savedParent = try await mutate(.create(defaultPKParent)) let defaultPKChild = DefaultPKChild(parent: savedParent) let savedChild = try await mutate(.create(defaultPKChild)) - + assertLazyReference(savedChild._parent, state: .notLoaded(identifiers: [.init(name: "id", value: savedParent.id)])) let loadedParent = try await savedChild.parent assertLazyReference(savedChild._parent, state: .loaded(model: loadedParent)) } - + func testDefaultParentChildUpdate() async throws { await setup(withModels: DefaultPKModels()) let defaultPKParent = DefaultPKParent() let savedParent = try await mutate(.create(defaultPKParent)) let defaultPKChild = DefaultPKChild(parent: savedParent) var savedChild = try await mutate(.create(defaultPKChild)) - + let newParent = DefaultPKParent() let savedNewParent = try await mutate(.create(newParent)) savedChild.setParent(savedNewParent) var updatedChild = try await mutate(.update(savedChild)) - + assertLazyReference(updatedChild._parent, state: .notLoaded(identifiers: [.init(name: "id", value: newParent.id)])) let loadedParent = try await updatedChild.parent assertLazyReference(updatedChild._parent, state: .loaded(model: loadedParent)) } - + func testDefaultParentChildDelete() async throws { await setup(withModels: DefaultPKModels()) let defaultPKParent = DefaultPKParent() let savedParent = try await mutate(.create(defaultPKParent)) let defaultPKChild = DefaultPKChild(parent: savedParent) let savedChild = try await mutate(.create(defaultPKChild)) - + try await mutate(.delete(savedParent)) try await assertModelDoesNotExist(savedParent) try await assertModelExists(savedChild) try await mutate(.delete(savedChild)) try await assertModelDoesNotExist(savedChild) } - + func testDefaultPKParentChildGet() async throws { await setup(withModels: DefaultPKModels()) let defaultPKParent = DefaultPKParent() let savedParent = try await mutate(.create(defaultPKParent)) let defaultPKChild = DefaultPKChild(parent: savedParent) let savedChild = try await mutate(.create(defaultPKChild)) - + let queriedParent = try await query(.get(DefaultPKParent.self, byId: savedParent.id))! assertList(queriedParent.children!, state: .isNotLoaded(associatedIdentifiers: [queriedParent.id], associatedFields: ["parent"])) try await queriedParent.children?.fetch() assertList(queriedParent.children!, state: .isLoaded(count: 1)) - + let queriedChild = try await query(.get(DefaultPKChild.self, byId: savedChild.id))! assertLazyReference(queriedChild._parent, state: .notLoaded(identifiers: [.init(name: "id", value: savedParent.id)])) @@ -85,18 +85,18 @@ final class GraphQLLazyLoadDefaultPKTests: GraphQLLazyLoadBaseTest { assertLazyReference(queriedChild._parent, state: .loaded(model: loadedParent)) } - + func testDefaultPKParentChildList() async throws { await setup(withModels: DefaultPKModels()) let defaultPKParent = DefaultPKParent() let savedParent = try await mutate(.create(defaultPKParent)) let defaultPKChild = DefaultPKChild(parent: savedParent) let savedChild = try await mutate(.create(defaultPKChild)) - + let queriedParents = try await listQuery(.list(DefaultPKParent.self, where: DefaultPKParent.keys.id == defaultPKParent.id)) assertList(queriedParents, state: .isLoaded(count: 1)) - + let queriedChildren = try await listQuery(.list(DefaultPKChild.self, where: DefaultPKChild.keys.id == defaultPKChild.id)) assertList(queriedChildren, state: .isLoaded(count: 1)) @@ -269,7 +269,7 @@ final class GraphQLLazyLoadDefaultPKTests: GraphQLLazyLoadBaseTest { extension GraphQLLazyLoadDefaultPKTests: DefaultLogger { } extension GraphQLLazyLoadDefaultPKTests { - + struct DefaultPKModels: AmplifyModelRegistration { public let version: String = "version" func registerModels(registry: ModelRegistry.Type) { diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL12/HasOneParentChild/GraphQLLazyLoadHasOneTests.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL12/HasOneParentChild/GraphQLLazyLoadHasOneTests.swift index 86311ce52c..dfd31382d1 100644 --- a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL12/HasOneParentChild/GraphQLLazyLoadHasOneTests.swift +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL12/HasOneParentChild/GraphQLLazyLoadHasOneTests.swift @@ -17,82 +17,82 @@ final class GraphQLLazyLoadHasOneTests: GraphQLLazyLoadBaseTest { func testConfigure() async throws { await setup(withModels: HasOneParentChildModels()) } - + func testHasOneParentChild() async throws { await setup(withModels: HasOneParentChildModels()) let hasOneChild = HasOneChild() let savedChild = try await mutate(.create(hasOneChild)) let hasOneParent = HasOneParent(child: hasOneChild) let savedParent = try await mutate(.create(hasOneParent)) - + assertLazyReference(savedParent._child, state: .notLoaded(identifiers: [.init(name: "id", value: savedChild.id)])) let loadedChild = try await savedParent.child assertLazyReference(savedParent._child, state: .loaded(model: loadedChild)) } - + func testHasOneParentChildUpdate() async throws { await setup(withModels: HasOneParentChildModels()) let hasOneChild = HasOneChild() let savedChild = try await mutate(.create(hasOneChild)) let hasOneParent = HasOneParent(child: hasOneChild) var savedParent = try await mutate(.create(hasOneParent)) - + let newChild = HasOneChild() let savedNewChild = try await mutate(.create(newChild)) savedParent.setChild(newChild) var updatedParent = try await mutate(.update(savedParent)) - + assertLazyReference(updatedParent._child, state: .notLoaded(identifiers: [.init(name: "id", value: newChild.id)])) let loadedChild = try await updatedParent.child assertLazyReference(updatedParent._child, state: .loaded(model: loadedChild)) } - + func testHasOneParentChildDelete() async throws { await setup(withModels: HasOneParentChildModels()) let hasOneChild = HasOneChild() let savedChild = try await mutate(.create(hasOneChild)) let hasOneParent = HasOneParent(child: hasOneChild) var savedParent = try await mutate(.create(hasOneParent)) - + try await mutate(.delete(savedParent)) try await assertModelDoesNotExist(savedParent) try await assertModelExists(savedChild) try await mutate(.delete(savedChild)) try await assertModelDoesNotExist(savedChild) } - + func testHasOneParentChildGet() async throws { await setup(withModels: HasOneParentChildModels()) let hasOneChild = HasOneChild() let savedChild = try await mutate(.create(hasOneChild)) let hasOneParent = HasOneParent(child: hasOneChild) let savedParent = try await mutate(.create(hasOneParent)) - + let queriedParent = try await query(.get(HasOneParent.self, byId: savedParent.id))! assertLazyReference(queriedParent._child, state: .notLoaded(identifiers: [.init(name: "id", value: savedChild.id)])) let loadedChild = try await queriedParent.child assertLazyReference(queriedParent._child, state: .loaded(model: loadedChild)) - + let queriedChild = try await query(.get(HasOneChild.self, byId: savedChild.id))! } - + func testHasOneParentChildList() async throws { await setup(withModels: HasOneParentChildModels()) let hasOneChild = HasOneChild() let savedChild = try await mutate(.create(hasOneChild)) let hasOneParent = HasOneParent(child: hasOneChild) let savedParent = try await mutate(.create(hasOneParent)) - + let queriedParents = try await listQuery(.list(HasOneParent.self, where: HasOneParent.keys.id == hasOneParent.id)) assertList(queriedParents, state: .isLoaded(count: 1)) - + let queriedChildren = try await listQuery(.list(HasOneChild.self, where: HasOneChild.keys.id == hasOneChild.id)) assertList(queriedChildren, state: .isLoaded(count: 1)) @@ -256,7 +256,7 @@ final class GraphQLLazyLoadHasOneTests: GraphQLLazyLoadBaseTest { extension GraphQLLazyLoadHasOneTests: DefaultLogger { } extension GraphQLLazyLoadHasOneTests { - + struct HasOneParentChildModels: AmplifyModelRegistration { public let version: String = "version" func registerModels(registry: ModelRegistry.Type) {