-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(data): Gen2 data customize data model doc example testing (#3699)
- Loading branch information
Showing
48 changed files
with
3,051 additions
and
6 deletions.
There are no files selected for viewing
276 changes: 274 additions & 2 deletions
276
AmplifyPlugins/API/Tests/APIHostApp/APIHostApp.xcodeproj/project.pbxproj
Large diffs are not rendered by default.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
.../Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_1/GraphQLLocationPostUser1Tests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import Foundation | ||
import XCTest | ||
@testable import Amplify | ||
|
||
final class GraphQLLocationPostUser1Tests: AWSAPIPluginGen2GraphQLBaseTest { | ||
|
||
// Code Snippet for | ||
// https://docs.amplify.aws/swift/build-a-backend/data/data-modeling/add-fields/#specify-an-enum-field-type | ||
func testCodeSnippet() async throws { | ||
await setup(withModels: PostUserLocation1Models()) | ||
|
||
let post = Post( | ||
location: .init( | ||
lat: 48.837006, | ||
long: 8.28245)) | ||
let createdPost = try await Amplify.API.mutate(request: .create(post)).get() | ||
print("\(createdPost)") | ||
|
||
XCTAssertEqual(createdPost.location?.lat, 48.837006) | ||
XCTAssertEqual(createdPost.location?.long, 8.28245) | ||
} | ||
} | ||
|
||
extension GraphQLLocationPostUser1Tests: DefaultLogger { } | ||
|
||
extension GraphQLLocationPostUser1Tests { | ||
typealias Post = Post1 | ||
typealias User = User1 | ||
typealias Location = Location1 | ||
|
||
struct PostUserLocation1Models: AmplifyModelRegistration { | ||
public let version: String = "version" | ||
func registerModels(registry: ModelRegistry.Type) { | ||
ModelRegistry.register(modelType: Post1.self) | ||
ModelRegistry.register(modelType: User1.self) | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...fyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_1/Location1+Schema.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// swiftlint:disable all | ||
import Amplify | ||
import Foundation | ||
|
||
extension Location1 { | ||
// MARK: - CodingKeys | ||
public enum CodingKeys: String, ModelKey { | ||
case lat | ||
case long | ||
} | ||
|
||
public static let keys = CodingKeys.self | ||
// MARK: - ModelSchema | ||
|
||
public static let schema = defineSchema { model in | ||
let location1 = Location1.keys | ||
|
||
model.listPluralName = "Location1s" | ||
model.syncPluralName = "Location1s" | ||
|
||
model.fields( | ||
.field(location1.lat, is: .optional, ofType: .double), | ||
.field(location1.long, is: .optional, ofType: .double) | ||
) | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_1/Location1.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// swiftlint:disable all | ||
import Amplify | ||
import Foundation | ||
|
||
public struct Location1: Embeddable { | ||
var lat: Double? | ||
var long: Double? | ||
} |
62 changes: 62 additions & 0 deletions
62
AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_1/Post1+Schema.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// swiftlint:disable all | ||
import Amplify | ||
import Foundation | ||
|
||
extension Post1 { | ||
// MARK: - CodingKeys | ||
public enum CodingKeys: String, ModelKey { | ||
case id | ||
case location | ||
case content | ||
case createdAt | ||
case updatedAt | ||
} | ||
|
||
public static let keys = CodingKeys.self | ||
// MARK: - ModelSchema | ||
|
||
public static let schema = defineSchema { model in | ||
let post1 = Post1.keys | ||
|
||
model.authRules = [ | ||
rule(allow: .public, provider: .apiKey, operations: [.create, .update, .delete, .read]) | ||
] | ||
|
||
model.listPluralName = "Post1s" | ||
model.syncPluralName = "Post1s" | ||
|
||
model.attributes( | ||
.primaryKey(fields: [post1.id]) | ||
) | ||
|
||
model.fields( | ||
.field(post1.id, is: .required, ofType: .string), | ||
.field(post1.location, is: .optional, ofType: .embedded(type: Location1.self)), | ||
.field(post1.content, is: .optional, ofType: .string), | ||
.field(post1.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), | ||
.field(post1.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) | ||
) | ||
} | ||
public class Path: ModelPath<Post1> { } | ||
|
||
public static var rootPath: PropertyContainerPath? { Path() } | ||
} | ||
|
||
extension Post1: ModelIdentifiable { | ||
public typealias IdentifierFormat = ModelIdentifierFormat.Default | ||
public typealias IdentifierProtocol = DefaultModelIdentifier<Self> | ||
} | ||
extension ModelPath where ModelType == Post1 { | ||
public var id: FieldPath<String> { | ||
string("id") | ||
} | ||
public var content: FieldPath<String> { | ||
string("content") | ||
} | ||
public var createdAt: FieldPath<Temporal.DateTime> { | ||
datetime("createdAt") | ||
} | ||
public var updatedAt: FieldPath<Temporal.DateTime> { | ||
datetime("updatedAt") | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_1/Post1.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// swiftlint:disable all | ||
import Amplify | ||
import Foundation | ||
|
||
public struct Post1: Model { | ||
public let id: String | ||
public var location: Location1? | ||
public var content: String? | ||
public var createdAt: Temporal.DateTime? | ||
public var updatedAt: Temporal.DateTime? | ||
|
||
public init(id: String = UUID().uuidString, | ||
location: Location1? = nil, | ||
content: String? = nil) { | ||
self.init(id: id, | ||
location: location, | ||
content: content, | ||
createdAt: nil, | ||
updatedAt: nil) | ||
} | ||
internal init(id: String = UUID().uuidString, | ||
location: Location1? = nil, | ||
content: String? = nil, | ||
createdAt: Temporal.DateTime? = nil, | ||
updatedAt: Temporal.DateTime? = nil) { | ||
self.id = id | ||
self.location = location | ||
self.content = content | ||
self.createdAt = createdAt | ||
self.updatedAt = updatedAt | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_1/User1+Schema.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// swiftlint:disable all | ||
import Amplify | ||
import Foundation | ||
|
||
extension User1 { | ||
// MARK: - CodingKeys | ||
public enum CodingKeys: String, ModelKey { | ||
case id | ||
case lastKnownLocation | ||
case createdAt | ||
case updatedAt | ||
} | ||
|
||
public static let keys = CodingKeys.self | ||
// MARK: - ModelSchema | ||
|
||
public static let schema = defineSchema { model in | ||
let user1 = User1.keys | ||
|
||
model.authRules = [ | ||
rule(allow: .public, provider: .apiKey, operations: [.create, .update, .delete, .read]) | ||
] | ||
|
||
model.listPluralName = "User1s" | ||
model.syncPluralName = "User1s" | ||
|
||
model.attributes( | ||
.primaryKey(fields: [user1.id]) | ||
) | ||
|
||
model.fields( | ||
.field(user1.id, is: .required, ofType: .string), | ||
.field(user1.lastKnownLocation, is: .optional, ofType: .embedded(type: Location1.self)), | ||
.field(user1.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), | ||
.field(user1.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) | ||
) | ||
} | ||
public class Path: ModelPath<User1> { } | ||
|
||
public static var rootPath: PropertyContainerPath? { Path() } | ||
} | ||
|
||
extension User1: ModelIdentifiable { | ||
public typealias IdentifierFormat = ModelIdentifierFormat.Default | ||
public typealias IdentifierProtocol = DefaultModelIdentifier<Self> | ||
} | ||
extension ModelPath where ModelType == User1 { | ||
public var id: FieldPath<String> { | ||
string("id") | ||
} | ||
public var createdAt: FieldPath<Temporal.DateTime> { | ||
datetime("createdAt") | ||
} | ||
public var updatedAt: FieldPath<Temporal.DateTime> { | ||
datetime("updatedAt") | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_1/User1.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// swiftlint:disable all | ||
import Amplify | ||
import Foundation | ||
|
||
public struct User1: Model { | ||
public let id: String | ||
public var lastKnownLocation: Location1? | ||
public var createdAt: Temporal.DateTime? | ||
public var updatedAt: Temporal.DateTime? | ||
|
||
public init(id: String = UUID().uuidString, | ||
lastKnownLocation: Location1? = nil) { | ||
self.init(id: id, | ||
lastKnownLocation: lastKnownLocation, | ||
createdAt: nil, | ||
updatedAt: nil) | ||
} | ||
internal init(id: String = UUID().uuidString, | ||
lastKnownLocation: Location1? = nil, | ||
createdAt: Temporal.DateTime? = nil, | ||
updatedAt: Temporal.DateTime? = nil) { | ||
self.id = id | ||
self.lastKnownLocation = lastKnownLocation | ||
self.createdAt = createdAt | ||
self.updatedAt = updatedAt | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
...Plugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_10/Customer10+Schema.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// swiftlint:disable all | ||
import Amplify | ||
import Foundation | ||
|
||
extension Customer10 { | ||
// MARK: - CodingKeys | ||
public enum CodingKeys: String, ModelKey { | ||
case id | ||
case name | ||
case phoneNumber | ||
case accountRepresentativeId | ||
case createdAt | ||
case updatedAt | ||
} | ||
|
||
public static let keys = CodingKeys.self | ||
// MARK: - ModelSchema | ||
|
||
public static let schema = defineSchema { model in | ||
let customer10 = Customer10.keys | ||
|
||
model.authRules = [ | ||
rule(allow: .public, provider: .apiKey, operations: [.create, .update, .delete, .read]) | ||
] | ||
|
||
model.listPluralName = "Customer10s" | ||
model.syncPluralName = "Customer10s" | ||
|
||
model.attributes( | ||
.index(fields: ["accountRepresentativeId"], name: "customer10sByAccountRepresentativeId"), | ||
.primaryKey(fields: [customer10.id]) | ||
) | ||
|
||
model.fields( | ||
.field(customer10.id, is: .required, ofType: .string), | ||
.field(customer10.name, is: .optional, ofType: .string), | ||
.field(customer10.phoneNumber, is: .optional, ofType: .string), | ||
.field(customer10.accountRepresentativeId, is: .required, ofType: .string), | ||
.field(customer10.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), | ||
.field(customer10.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) | ||
) | ||
} | ||
public class Path: ModelPath<Customer10> { } | ||
|
||
public static var rootPath: PropertyContainerPath? { Path() } | ||
} | ||
|
||
extension Customer10: ModelIdentifiable { | ||
public typealias IdentifierFormat = ModelIdentifierFormat.Default | ||
public typealias IdentifierProtocol = DefaultModelIdentifier<Self> | ||
} | ||
extension ModelPath where ModelType == Customer10 { | ||
public var id: FieldPath<String> { | ||
string("id") | ||
} | ||
public var name: FieldPath<String> { | ||
string("name") | ||
} | ||
public var phoneNumber: FieldPath<String> { | ||
string("phoneNumber") | ||
} | ||
public var accountRepresentativeId: FieldPath<String> { | ||
string("accountRepresentativeId") | ||
} | ||
public var createdAt: FieldPath<Temporal.DateTime> { | ||
datetime("createdAt") | ||
} | ||
public var updatedAt: FieldPath<Temporal.DateTime> { | ||
datetime("updatedAt") | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_10/Customer10.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// swiftlint:disable all | ||
import Amplify | ||
import Foundation | ||
|
||
public struct Customer10: Model { | ||
public let id: String | ||
public var name: String? | ||
public var phoneNumber: String? | ||
public var accountRepresentativeId: String | ||
public var createdAt: Temporal.DateTime? | ||
public var updatedAt: Temporal.DateTime? | ||
|
||
public init(id: String = UUID().uuidString, | ||
name: String? = nil, | ||
phoneNumber: String? = nil, | ||
accountRepresentativeId: String) { | ||
self.init(id: id, | ||
name: name, | ||
phoneNumber: phoneNumber, | ||
accountRepresentativeId: accountRepresentativeId, | ||
createdAt: nil, | ||
updatedAt: nil) | ||
} | ||
internal init(id: String = UUID().uuidString, | ||
name: String? = nil, | ||
phoneNumber: String? = nil, | ||
accountRepresentativeId: String, | ||
createdAt: Temporal.DateTime? = nil, | ||
updatedAt: Temporal.DateTime? = nil) { | ||
self.id = id | ||
self.name = name | ||
self.phoneNumber = phoneNumber | ||
self.accountRepresentativeId = accountRepresentativeId | ||
self.createdAt = createdAt | ||
self.updatedAt = updatedAt | ||
} | ||
} |
Oops, something went wrong.