Skip to content

Commit 5bcd5f0

Browse files
authored
chore: kickoff release
2 parents 8534d75 + d6583e6 commit 5bcd5f0

File tree

74 files changed

+4634
-7
lines changed

Some content is hidden

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

74 files changed

+4634
-7
lines changed

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

Lines changed: 438 additions & 2 deletions
Large diffs are not rendered by default.

AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/AWSAPIPluginGen2GraphQLBaseTest.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ import XCTest
1010
@_spi(InternalAmplifyConfiguration) @testable import Amplify
1111
@testable import APIHostApp
1212
@testable import AWSPluginsCore
13+
import AWSCognitoAuthPlugin
1314

1415
class AWSAPIPluginGen2GraphQLBaseTest: XCTestCase {
1516

17+
var defaultTestEmail = "test-\(UUID().uuidString)@amazon.com"
18+
1619
var amplifyConfig: AmplifyOutputsData!
1720

1821
override func setUp() {
@@ -39,11 +42,15 @@ class AWSAPIPluginGen2GraphQLBaseTest: XCTestCase {
3942
/// Setup API with given models
4043
/// - Parameter models: DataStore models
4144
func setup(withModels models: AmplifyModelRegistration,
42-
logLevel: LogLevel = .verbose) async {
45+
logLevel: LogLevel = .verbose,
46+
withAuthPlugin: Bool = false) async {
4347
do {
4448
setupConfig()
4549
Amplify.Logging.logLevel = logLevel
4650
try Amplify.add(plugin: AWSAPIPlugin(modelRegistration: models))
51+
if withAuthPlugin {
52+
try Amplify.add(plugin: AWSCognitoAuthPlugin())
53+
}
4754
try Amplify.configure(amplifyConfig)
4855

4956
} catch {
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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 Amplify
9+
import XCTest
10+
11+
enum AuthSignInHelper {
12+
13+
static func signOut() async {
14+
let session = try? await Amplify.Auth.fetchAuthSession()
15+
if session?.isSignedIn ?? false {
16+
_ = await Amplify.Auth.signOut()
17+
}
18+
}
19+
20+
static func signUpUser(
21+
username: String,
22+
password: String,
23+
email: String,
24+
phoneNumber: String? = nil) async throws -> Bool {
25+
26+
var userAttributes = [
27+
AuthUserAttribute(.email, value: email)
28+
]
29+
30+
if let phoneNumber = phoneNumber {
31+
userAttributes.append(AuthUserAttribute(.phoneNumber, value: phoneNumber))
32+
}
33+
34+
let options = AuthSignUpRequest.Options(
35+
userAttributes: userAttributes)
36+
let result = try await Amplify.Auth.signUp(username: username, password: password, options: options)
37+
return result.isSignUpComplete
38+
}
39+
40+
static func signInUser(username: String, password: String) async throws -> AuthSignInResult {
41+
return try await Amplify.Auth.signIn(username: username, password: password, options: nil)
42+
}
43+
44+
static func registerAndSignInUser(
45+
username: String,
46+
password: String,
47+
email: String,
48+
phoneNumber: String? = nil) async throws -> Bool {
49+
await signOut()
50+
let signedUp = try await AuthSignInHelper.signUpUser(
51+
username: username,
52+
password: password,
53+
email: email,
54+
phoneNumber: phoneNumber)
55+
guard signedUp else {
56+
throw AuthError.invalidState("Auth sign up failed", "", nil)
57+
}
58+
let result = try await AuthSignInHelper.signInUser(username: username, password: password)
59+
return result.isSignedIn
60+
}
61+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 Foundation
9+
import XCTest
10+
@testable import Amplify
11+
12+
final class GraphQLLocationPostUser1Tests: AWSAPIPluginGen2GraphQLBaseTest {
13+
14+
// Code Snippet for
15+
// https://docs.amplify.aws/swift/build-a-backend/data/data-modeling/add-fields/#specify-an-enum-field-type
16+
func testCodeSnippet() async throws {
17+
await setup(withModels: PostUserLocation1Models())
18+
19+
let post = Post(
20+
location: .init(
21+
lat: 48.837006,
22+
long: 8.28245))
23+
let createdPost = try await Amplify.API.mutate(request: .create(post)).get()
24+
print("\(createdPost)")
25+
26+
XCTAssertEqual(createdPost.location?.lat, 48.837006)
27+
XCTAssertEqual(createdPost.location?.long, 8.28245)
28+
}
29+
}
30+
31+
extension GraphQLLocationPostUser1Tests: DefaultLogger { }
32+
33+
extension GraphQLLocationPostUser1Tests {
34+
typealias Post = Post1
35+
typealias User = User1
36+
typealias Location = Location1
37+
38+
struct PostUserLocation1Models: AmplifyModelRegistration {
39+
public let version: String = "version"
40+
func registerModels(registry: ModelRegistry.Type) {
41+
ModelRegistry.register(modelType: Post1.self)
42+
ModelRegistry.register(modelType: User1.self)
43+
}
44+
}
45+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// swiftlint:disable all
2+
import Amplify
3+
import Foundation
4+
5+
extension Location1 {
6+
// MARK: - CodingKeys
7+
public enum CodingKeys: String, ModelKey {
8+
case lat
9+
case long
10+
}
11+
12+
public static let keys = CodingKeys.self
13+
// MARK: - ModelSchema
14+
15+
public static let schema = defineSchema { model in
16+
let location1 = Location1.keys
17+
18+
model.listPluralName = "Location1s"
19+
model.syncPluralName = "Location1s"
20+
21+
model.fields(
22+
.field(location1.lat, is: .optional, ofType: .double),
23+
.field(location1.long, is: .optional, ofType: .double)
24+
)
25+
}
26+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// swiftlint:disable all
2+
import Amplify
3+
import Foundation
4+
5+
public struct Location1: Embeddable {
6+
var lat: Double?
7+
var long: Double?
8+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// swiftlint:disable all
2+
import Amplify
3+
import Foundation
4+
5+
extension Post1 {
6+
// MARK: - CodingKeys
7+
public enum CodingKeys: String, ModelKey {
8+
case id
9+
case location
10+
case content
11+
case createdAt
12+
case updatedAt
13+
}
14+
15+
public static let keys = CodingKeys.self
16+
// MARK: - ModelSchema
17+
18+
public static let schema = defineSchema { model in
19+
let post1 = Post1.keys
20+
21+
model.authRules = [
22+
rule(allow: .public, provider: .apiKey, operations: [.create, .update, .delete, .read])
23+
]
24+
25+
model.listPluralName = "Post1s"
26+
model.syncPluralName = "Post1s"
27+
28+
model.attributes(
29+
.primaryKey(fields: [post1.id])
30+
)
31+
32+
model.fields(
33+
.field(post1.id, is: .required, ofType: .string),
34+
.field(post1.location, is: .optional, ofType: .embedded(type: Location1.self)),
35+
.field(post1.content, is: .optional, ofType: .string),
36+
.field(post1.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime),
37+
.field(post1.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime)
38+
)
39+
}
40+
public class Path: ModelPath<Post1> { }
41+
42+
public static var rootPath: PropertyContainerPath? { Path() }
43+
}
44+
45+
extension Post1: ModelIdentifiable {
46+
public typealias IdentifierFormat = ModelIdentifierFormat.Default
47+
public typealias IdentifierProtocol = DefaultModelIdentifier<Self>
48+
}
49+
extension ModelPath where ModelType == Post1 {
50+
public var id: FieldPath<String> {
51+
string("id")
52+
}
53+
public var content: FieldPath<String> {
54+
string("content")
55+
}
56+
public var createdAt: FieldPath<Temporal.DateTime> {
57+
datetime("createdAt")
58+
}
59+
public var updatedAt: FieldPath<Temporal.DateTime> {
60+
datetime("updatedAt")
61+
}
62+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// swiftlint:disable all
2+
import Amplify
3+
import Foundation
4+
5+
public struct Post1: Model {
6+
public let id: String
7+
public var location: Location1?
8+
public var content: String?
9+
public var createdAt: Temporal.DateTime?
10+
public var updatedAt: Temporal.DateTime?
11+
12+
public init(id: String = UUID().uuidString,
13+
location: Location1? = nil,
14+
content: String? = nil) {
15+
self.init(id: id,
16+
location: location,
17+
content: content,
18+
createdAt: nil,
19+
updatedAt: nil)
20+
}
21+
internal init(id: String = UUID().uuidString,
22+
location: Location1? = nil,
23+
content: String? = nil,
24+
createdAt: Temporal.DateTime? = nil,
25+
updatedAt: Temporal.DateTime? = nil) {
26+
self.id = id
27+
self.location = location
28+
self.content = content
29+
self.createdAt = createdAt
30+
self.updatedAt = updatedAt
31+
}
32+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// swiftlint:disable all
2+
import Amplify
3+
import Foundation
4+
5+
extension User1 {
6+
// MARK: - CodingKeys
7+
public enum CodingKeys: String, ModelKey {
8+
case id
9+
case lastKnownLocation
10+
case createdAt
11+
case updatedAt
12+
}
13+
14+
public static let keys = CodingKeys.self
15+
// MARK: - ModelSchema
16+
17+
public static let schema = defineSchema { model in
18+
let user1 = User1.keys
19+
20+
model.authRules = [
21+
rule(allow: .public, provider: .apiKey, operations: [.create, .update, .delete, .read])
22+
]
23+
24+
model.listPluralName = "User1s"
25+
model.syncPluralName = "User1s"
26+
27+
model.attributes(
28+
.primaryKey(fields: [user1.id])
29+
)
30+
31+
model.fields(
32+
.field(user1.id, is: .required, ofType: .string),
33+
.field(user1.lastKnownLocation, is: .optional, ofType: .embedded(type: Location1.self)),
34+
.field(user1.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime),
35+
.field(user1.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime)
36+
)
37+
}
38+
public class Path: ModelPath<User1> { }
39+
40+
public static var rootPath: PropertyContainerPath? { Path() }
41+
}
42+
43+
extension User1: ModelIdentifiable {
44+
public typealias IdentifierFormat = ModelIdentifierFormat.Default
45+
public typealias IdentifierProtocol = DefaultModelIdentifier<Self>
46+
}
47+
extension ModelPath where ModelType == User1 {
48+
public var id: FieldPath<String> {
49+
string("id")
50+
}
51+
public var createdAt: FieldPath<Temporal.DateTime> {
52+
datetime("createdAt")
53+
}
54+
public var updatedAt: FieldPath<Temporal.DateTime> {
55+
datetime("updatedAt")
56+
}
57+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// swiftlint:disable all
2+
import Amplify
3+
import Foundation
4+
5+
public struct User1: Model {
6+
public let id: String
7+
public var lastKnownLocation: Location1?
8+
public var createdAt: Temporal.DateTime?
9+
public var updatedAt: Temporal.DateTime?
10+
11+
public init(id: String = UUID().uuidString,
12+
lastKnownLocation: Location1? = nil) {
13+
self.init(id: id,
14+
lastKnownLocation: lastKnownLocation,
15+
createdAt: nil,
16+
updatedAt: nil)
17+
}
18+
internal init(id: String = UUID().uuidString,
19+
lastKnownLocation: Location1? = nil,
20+
createdAt: Temporal.DateTime? = nil,
21+
updatedAt: Temporal.DateTime? = nil) {
22+
self.id = id
23+
self.lastKnownLocation = lastKnownLocation
24+
self.createdAt = createdAt
25+
self.updatedAt = updatedAt
26+
}
27+
}

0 commit comments

Comments
 (0)