Skip to content

Commit 4475dd0

Browse files
committed
test(api): Lazy loading integration tests
1 parent 2b86fe2 commit 4475dd0

File tree

57 files changed

+2776
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+2776
-0
lines changed

AmplifyPlugins/API/Tests/APIHostApp/APIHostApp.xcodeproj/project.pbxproj

Lines changed: 352 additions & 0 deletions
Large diffs are not rendered by default.

AmplifyPlugins/API/Tests/APIHostApp/APIHostApp.xcodeproj/xcshareddata/xcschemes/APIHostApp.xcscheme

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
2929
shouldUseLaunchSchemeArgsEnv = "YES">
3030
<Testables>
31+
<TestableReference
32+
skipped = "NO">
33+
<BuildableReference
34+
BuildableIdentifier = "primary"
35+
BlueprintIdentifier = "21EA887228F9BC600000BA75"
36+
BuildableName = "AWSAPIPluginLazyLoadTests.xctest"
37+
BlueprintName = "AWSAPIPluginLazyLoadTests"
38+
ReferencedContainer = "container:APIHostApp.xcodeproj">
39+
</BuildableReference>
40+
</TestableReference>
3141
</Testables>
3242
</TestAction>
3343
<LaunchAction
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1340"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "NO"
13+
buildForArchiving = "NO"
14+
buildForAnalyzing = "NO">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "21EA887228F9BC600000BA75"
18+
BuildableName = "AWSAPIPluginLazyLoadTests.xctest"
19+
BlueprintName = "AWSAPIPluginLazyLoadTests"
20+
ReferencedContainer = "container:APIHostApp.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES">
30+
<Testables>
31+
<TestableReference
32+
skipped = "NO">
33+
<BuildableReference
34+
BuildableIdentifier = "primary"
35+
BlueprintIdentifier = "21EA887228F9BC600000BA75"
36+
BuildableName = "AWSAPIPluginLazyLoadTests.xctest"
37+
BlueprintName = "AWSAPIPluginLazyLoadTests"
38+
ReferencedContainer = "container:APIHostApp.xcodeproj">
39+
</BuildableReference>
40+
</TestableReference>
41+
</Testables>
42+
</TestAction>
43+
<LaunchAction
44+
buildConfiguration = "Debug"
45+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
46+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
47+
launchStyle = "0"
48+
useCustomWorkingDirectory = "NO"
49+
ignoresPersistentStateOnLaunch = "NO"
50+
debugDocumentVersioning = "YES"
51+
debugServiceExtension = "internal"
52+
allowLocationSimulation = "YES">
53+
</LaunchAction>
54+
<ProfileAction
55+
buildConfiguration = "Release"
56+
shouldUseLaunchSchemeArgsEnv = "YES"
57+
savedToolIdentifier = ""
58+
useCustomWorkingDirectory = "NO"
59+
debugDocumentVersioning = "YES">
60+
</ProfileAction>
61+
<AnalyzeAction
62+
buildConfiguration = "Debug">
63+
</AnalyzeAction>
64+
<ArchiveAction
65+
buildConfiguration = "Release"
66+
revealArchiveInOrganizer = "YES">
67+
</ArchiveAction>
68+
</Scheme>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//
2+
// Copyright Amazon.com Inc. or its affiliates.
3+
// All Rights Reserved.
4+
//
5+
// SPDX-License-Identifier: Apache-2.0
6+
//
7+
8+
import XCTest
9+
@testable import AWSAPIPlugin
10+
@testable import Amplify
11+
@testable import APIHostApp
12+
@testable import AWSPluginsCore
13+
14+
class GraphQLLazyLoadBaseTest: XCTestCase {
15+
static let amplifyConfiguration = "testconfiguration/GraphQLLazyLoadTests-amplifyconfiguration"
16+
17+
override func setUp() async throws {
18+
await Amplify.reset()
19+
Amplify.Logging.logLevel = .verbose
20+
let plugin = AWSAPIPlugin(modelRegistration: AmplifyModels())
21+
22+
do {
23+
try Amplify.add(plugin: plugin)
24+
25+
let amplifyConfig = try TestConfigHelper.retrieveAmplifyConfiguration(
26+
forResource: GraphQLLazyLoadBaseTest.amplifyConfiguration)
27+
try Amplify.configure(amplifyConfig)
28+
29+
} catch {
30+
XCTFail("Error during setup: \(error)")
31+
}
32+
}
33+
34+
func testExample() async throws {
35+
let post = Post4V2(title: "title")
36+
let comment = Comment4V2(content: "content", post: post)
37+
38+
// LazyModel will perform a query for post by the identifier metadata post.id
39+
let response = try await Amplify.API.query(request: .get(Post4V2.self, byId: post.id))
40+
41+
switch response {
42+
case .success(let post):
43+
print("\(post)")
44+
case .failure(let error):
45+
XCTFail("Failed with error \(error)")
46+
}
47+
}
48+
49+
func testGetPostWithCompositeKey() async throws {
50+
let post = PostWithCompositeKey(id: UUID().uuidString,
51+
title: UUID().uuidString)
52+
let comment = CommentWithCompositeKey(content: "content", post: post)
53+
54+
// Save the post
55+
// save the comment with the post
56+
// query for the post with lazy load enabled, and lazy load the comment.
57+
58+
// LazyModel will perform a query for post by the identifier metadata post.id and post.title
59+
// let response = try await Amplify.API.query(
60+
// request: GraphQLLazyLoadBaseTest.get(PostWithCompositeKey.self,
61+
// byIdentifiers: ["id": post.id,
62+
// "title": post.title]))
63+
// switch response {
64+
// case .success(let post):
65+
// print("\(post)")
66+
// case .failure(let error):
67+
// XCTFail("Failed with error \(error)")
68+
// }
69+
}
70+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// swiftlint:disable all
2+
import Amplify
3+
import Foundation
4+
5+
// Contains the set of classes that conforms to the `Model` protocol.
6+
7+
final public class AmplifyModels: AmplifyModelRegistration {
8+
public let version: String = "55f92d13a6658c6c92c10f097e770aa8"
9+
10+
public func registerModels(registry: ModelRegistry.Type) {
11+
ModelRegistry.register(modelType: Post4V2.self)
12+
ModelRegistry.register(modelType: Comment4V2.self)
13+
ModelRegistry.register(modelType: Blog8V2.self)
14+
ModelRegistry.register(modelType: Post8V2.self)
15+
ModelRegistry.register(modelType: Comment8V2.self)
16+
ModelRegistry.register(modelType: PostWithCompositeKey.self)
17+
ModelRegistry.register(modelType: CommentWithCompositeKey.self)
18+
ModelRegistry.register(modelType: PostWithTagsCompositeKey.self)
19+
ModelRegistry.register(modelType: TagWithCompositeKey.self)
20+
ModelRegistry.register(modelType: PostWithCompositeKeyAndIndex.self)
21+
ModelRegistry.register(modelType: CommentWithCompositeKeyAndIndex.self)
22+
ModelRegistry.register(modelType: Project2.self)
23+
ModelRegistry.register(modelType: Team2.self)
24+
ModelRegistry.register(modelType: Post4.self)
25+
ModelRegistry.register(modelType: Comment4.self)
26+
ModelRegistry.register(modelType: Project6.self)
27+
ModelRegistry.register(modelType: Team6.self)
28+
ModelRegistry.register(modelType: Post7.self)
29+
ModelRegistry.register(modelType: Comment7.self)
30+
ModelRegistry.register(modelType: Post8.self)
31+
ModelRegistry.register(modelType: Comment8.self)
32+
ModelRegistry.register(modelType: PostTagsWithCompositeKey.self)
33+
}
34+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// swiftlint:disable all
2+
import Amplify
3+
import Foundation
4+
5+
extension Blog8V2 {
6+
// MARK: - CodingKeys
7+
public enum CodingKeys: String, ModelKey {
8+
case id
9+
case name
10+
case customs
11+
case notes
12+
case posts
13+
case createdAt
14+
case updatedAt
15+
}
16+
17+
public static let keys = CodingKeys.self
18+
// MARK: - ModelSchema
19+
20+
public static let schema = defineSchema { model in
21+
let blog8V2 = Blog8V2.keys
22+
23+
model.pluralName = "Blog8V2s"
24+
25+
model.attributes(
26+
.primaryKey(fields: [blog8V2.id])
27+
)
28+
29+
model.fields(
30+
.field(blog8V2.id, is: .required, ofType: .string),
31+
.field(blog8V2.name, is: .required, ofType: .string),
32+
.field(blog8V2.customs, is: .optional, ofType: .embeddedCollection(of: MyCustomModel8.self)),
33+
.field(blog8V2.notes, is: .optional, ofType: .embeddedCollection(of: String.self)),
34+
.hasMany(blog8V2.posts, is: .optional, ofType: Post8V2.self, associatedWith: Post8V2.keys.blog),
35+
.field(blog8V2.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime),
36+
.field(blog8V2.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime)
37+
)
38+
}
39+
}
40+
41+
extension Blog8V2: ModelIdentifiable {
42+
public typealias IdentifierFormat = ModelIdentifierFormat.Default
43+
public typealias IdentifierProtocol = DefaultModelIdentifier<Self>
44+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// swiftlint:disable all
2+
import Amplify
3+
import Foundation
4+
5+
public struct Blog8V2: Model {
6+
public let id: String
7+
public var name: String
8+
public var customs: [MyCustomModel8?]?
9+
public var notes: [String?]?
10+
public var posts: List<Post8V2>?
11+
public var createdAt: Temporal.DateTime?
12+
public var updatedAt: Temporal.DateTime?
13+
14+
public init(id: String = UUID().uuidString,
15+
name: String,
16+
customs: [MyCustomModel8?]? = nil,
17+
notes: [String?]? = nil,
18+
posts: List<Post8V2>? = []) {
19+
self.init(id: id,
20+
name: name,
21+
customs: customs,
22+
notes: notes,
23+
posts: posts,
24+
createdAt: nil,
25+
updatedAt: nil)
26+
}
27+
internal init(id: String = UUID().uuidString,
28+
name: String,
29+
customs: [MyCustomModel8?]? = nil,
30+
notes: [String?]? = nil,
31+
posts: List<Post8V2>? = [],
32+
createdAt: Temporal.DateTime? = nil,
33+
updatedAt: Temporal.DateTime? = nil) {
34+
self.id = id
35+
self.name = name
36+
self.customs = customs
37+
self.notes = notes
38+
self.posts = posts
39+
self.createdAt = createdAt
40+
self.updatedAt = updatedAt
41+
}
42+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// swiftlint:disable all
2+
import Amplify
3+
import Foundation
4+
5+
extension Comment4 {
6+
// MARK: - CodingKeys
7+
public enum CodingKeys: String, ModelKey {
8+
case commentId
9+
case content
10+
case createdAt
11+
case updatedAt
12+
case post4CommentsPostId
13+
case post4CommentsTitle
14+
}
15+
16+
public static let keys = CodingKeys.self
17+
// MARK: - ModelSchema
18+
19+
public static let schema = defineSchema { model in
20+
let comment4 = Comment4.keys
21+
22+
model.pluralName = "Comment4s"
23+
24+
model.attributes(
25+
.index(fields: ["commentId", "content"], name: nil),
26+
.primaryKey(fields: [comment4.commentId, comment4.content])
27+
)
28+
29+
model.fields(
30+
.field(comment4.commentId, is: .required, ofType: .string),
31+
.field(comment4.content, is: .required, ofType: .string),
32+
.field(comment4.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime),
33+
.field(comment4.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime),
34+
.field(comment4.post4CommentsPostId, is: .optional, ofType: .string),
35+
.field(comment4.post4CommentsTitle, is: .optional, ofType: .string)
36+
)
37+
}
38+
}
39+
40+
extension Comment4: ModelIdentifiable {
41+
public typealias IdentifierFormat = ModelIdentifierFormat.Custom
42+
public typealias IdentifierProtocol = ModelIdentifier<Self, ModelIdentifierFormat.Custom>
43+
}
44+
45+
extension Comment4.IdentifierProtocol {
46+
public static func identifier(commentId: String,
47+
content: String) -> Self {
48+
.make(fields:[(name: "commentId", value: commentId), (name: "content", value: content)])
49+
}
50+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// swiftlint:disable all
2+
import Amplify
3+
import Foundation
4+
5+
public struct Comment4: Model {
6+
public let commentId: String
7+
public let content: String
8+
public var createdAt: Temporal.DateTime?
9+
public var updatedAt: Temporal.DateTime?
10+
public var post4CommentsPostId: String?
11+
public var post4CommentsTitle: String?
12+
13+
public init(commentId: String,
14+
content: String,
15+
post4CommentsPostId: String? = nil,
16+
post4CommentsTitle: String? = nil) {
17+
self.init(commentId: commentId,
18+
content: content,
19+
createdAt: nil,
20+
updatedAt: nil,
21+
post4CommentsPostId: post4CommentsPostId,
22+
post4CommentsTitle: post4CommentsTitle)
23+
}
24+
internal init(commentId: String,
25+
content: String,
26+
createdAt: Temporal.DateTime? = nil,
27+
updatedAt: Temporal.DateTime? = nil,
28+
post4CommentsPostId: String? = nil,
29+
post4CommentsTitle: String? = nil) {
30+
self.commentId = commentId
31+
self.content = content
32+
self.createdAt = createdAt
33+
self.updatedAt = updatedAt
34+
self.post4CommentsPostId = post4CommentsPostId
35+
self.post4CommentsTitle = post4CommentsTitle
36+
}
37+
}

0 commit comments

Comments
 (0)