Skip to content

Commit

Permalink
fix(api): support query predicate Temporal.DateTime, fix integ tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lawmicha committed Jun 2, 2020
1 parent ea2cb5b commit 9860fd1
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@ class AnyModelIntegrationTests: XCTestCase {
}

func testCreateAsAnyModel() throws {

let originalPost = Post(title: "Post title",
content: "Original post content as of \(Date())",
createdAt: Date())
let originalPost = AmplifyTestCommon.Post(title: "Post title",
content: "Original post content as of \(Date())",
createdAt: Temporal.DateTime(Date()))
let anyPost = try originalPost.eraseToAnyModel()

let callbackInvoked = expectation(description: "Callback invoked")
Expand Down Expand Up @@ -93,9 +92,9 @@ class AnyModelIntegrationTests: XCTestCase {
}

func testUpdateAsAnyModel() throws {
let originalPost = Post(title: "Post title",
content: "Original post content as of \(Date())",
createdAt: Date())
let originalPost = AmplifyTestCommon.Post(title: "Post title",
content: "Original post content as of \(Date())",
createdAt: Temporal.DateTime(Date()))
let originalAnyPost = try originalPost.eraseToAnyModel()

let createCallbackInvoked = expectation(description: "Create callback invoked")
Expand Down Expand Up @@ -154,9 +153,9 @@ class AnyModelIntegrationTests: XCTestCase {
}

func testDeleteAsAnyModel() throws {
let originalPost = Post(title: "Post title",
content: "Original post content as of \(Date())",
createdAt: Date())
let originalPost = AmplifyTestCommon.Post(title: "Post title",
content: "Original post content as of \(Date())",
createdAt: Temporal.DateTime(Date()))
let originalAnyPost = try originalPost.eraseToAnyModel()

let createCallbackInvoked = expectation(description: "Create callback invoked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ class GraphQLModelBasedTests: XCTestCase {
let uuid = UUID().uuidString
let testMethodName = String("\(#function)".dropLast(2))
let uniqueTitle = testMethodName + uuid + "Title"
let createdPost = Post(id: uuid,
title: uniqueTitle,
content: "content",
createdAt: Date(),
draft: true,
rating: 12.3)
let createdPost = AmplifyTestCommon.Post(id: uuid,
title: uniqueTitle,
content: "content",
createdAt: Temporal.DateTime.now(),
draft: true,
rating: 12.3)
guard createPost(post: createdPost) != nil else {
XCTFail("Failed to ensure at least one Post to be retrieved on the listQuery")
return
Expand Down Expand Up @@ -156,7 +156,7 @@ class GraphQLModelBasedTests: XCTestCase {
func testCreatPostWithModel() {
let completeInvoked = expectation(description: "request completed")

let post = Post(title: "title", content: "content", createdAt: Date())
let post = AmplifyTestCommon.Post(title: "title", content: "content", createdAt: Temporal.DateTime.now())
_ = Amplify.API.mutate(request: .create(post)) { event in
switch event {
case .success(let data):
Expand Down Expand Up @@ -184,7 +184,9 @@ class GraphQLModelBasedTests: XCTestCase {
}

let completeInvoked = expectation(description: "request completed")
let comment = Comment(content: "commentContent", createdAt: Date(), post: createdPost)
let comment = AmplifyTestCommon.Comment(content: "commentContent",
createdAt: Temporal.DateTime.now(),
post: createdPost)
_ = Amplify.API.mutate(request: .create(comment)) { event in
switch event {
case .success(let data):
Expand Down Expand Up @@ -497,12 +499,12 @@ class GraphQLModelBasedTests: XCTestCase {
// MARK: Helpers

func createPost(id: String, title: String) -> AmplifyTestCommon.Post? {
let post = Post(id: id, title: title, content: "content", createdAt: Date())
let post = Post(id: id, title: title, content: "content", createdAt: Temporal.DateTime.now())
return createPost(post: post)
}

func createComment(content: String, post: AmplifyTestCommon.Post) -> AmplifyTestCommon.Comment? {
let comment = Comment(content: content, createdAt: Date(), post: post)
let comment = Comment(content: content, createdAt: Temporal.DateTime.now(), post: post)
return createComment(comment: comment)
}

Expand Down Expand Up @@ -554,7 +556,7 @@ class GraphQLModelBasedTests: XCTestCase {
var result: AmplifyTestCommon.Post?
let completeInvoked = expectation(description: "request completed")

let post = Post(id: id, title: title, content: "content", createdAt: Date())
let post = Post(id: id, title: title, content: "content", createdAt: Temporal.DateTime.now())
_ = Amplify.API.mutate(request: .update(post)) { event in
switch event {
case .success(let data):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ The following steps demonstrate how to set up a GraphQL endpoint with AppSync. T
```
When asked to provide the schema, create the `schema.graphql` file
```
enum PostStatus {
PRIVATE
DRAFT
PUBLISHED
}
type Post @model {
id: ID!
title: String!
Expand All @@ -30,6 +36,7 @@ type Post @model {
updatedAt: AWSDateTime
draft: Boolean
rating: Float
status: PostStatus
comments: [Comment] @connection(name: "PostComment")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ class GraphQLSyncBasedTests: XCTestCase {

let updatedTitle = title + "Updated"

let modifiedPost = Post(id: createdPost.model["id"] as? String ?? "",
title: updatedTitle,
content: createdPost.model["content"] as? String ?? "",
createdAt: Date())
let modifiedPost = AmplifyTestCommon.Post(id: createdPost.model["id"] as? String ?? "",
title: updatedTitle,
content: createdPost.model["content"] as? String ?? "",
createdAt: Temporal.DateTime.now())

let completeInvoked = expectation(description: "request completed")
var responseFromOperation: GraphQLResponse<MutationSync<AnyModel>>?
Expand Down Expand Up @@ -235,10 +235,10 @@ class GraphQLSyncBasedTests: XCTestCase {

let updatedTitle = title + "Updated"

let modifiedPost = Post(id: createdPost.model["id"] as? String ?? "",
let modifiedPost = AmplifyTestCommon.Post(id: createdPost.model["id"] as? String ?? "",
title: updatedTitle,
content: createdPost.model["content"] as? String ?? "",
createdAt: Date())
createdAt: Temporal.DateTime(Date()))

let completeInvoked = expectation(description: "request completed")
var responseFromOperation: GraphQLResponse<MutationSync<AnyModel>>?
Expand Down Expand Up @@ -305,10 +305,10 @@ class GraphQLSyncBasedTests: XCTestCase {
return
}
let updatedTitle = title + "Updated"
let modifiedPost = Post(id: createdPost.model["id"] as? String ?? "",
title: updatedTitle,
content: createdPost.model["content"] as? String ?? "",
createdAt: Date())
let modifiedPost = AmplifyTestCommon.Post(id: createdPost.model["id"] as? String ?? "",
title: updatedTitle,
content: createdPost.model["content"] as? String ?? "",
createdAt: Temporal.DateTime.now())
let firstUpdateSuccess = expectation(description: "first update mutation should be successful")

let request = GraphQLRequest<MutationSyncResult>.updateMutation(of: modifiedPost,
Expand Down Expand Up @@ -523,7 +523,9 @@ class GraphQLSyncBasedTests: XCTestCase {
// MARK: Helpers

func createPost(id: String, title: String) -> MutationSyncResult? {
let post = Post(id: id, title: title, content: "content", createdAt: Date())
let post = AmplifyTestCommon.Post(id: id, title: title,
content: "content",
createdAt: Temporal.DateTime.now())
return createPost(post: post)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ The following steps demonstrate how to set up an GraphQL endpoint with AppSync t
```
When asked to provide the schema, create the `schema.graphql` file
```
enum PostStatus {
PRIVATE
DRAFT
PUBLISHED
}
type Post @model {
id: ID!
title: String!
Expand All @@ -34,6 +40,7 @@ type Post @model {
updatedAt: AWSDateTime
draft: Boolean
rating: Float
status: PostStatus
comments: [Comment] @connection(name: "PostComment")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ extension Persistable {
return value.iso8601String
}

if let value = value as? Temporal.DateTime {
return value.iso8601String
}

if let value = value as? Double {
return Decimal(value)
}
Expand Down

0 comments on commit 9860fd1

Please sign in to comment.