Skip to content

Commit

Permalink
fix broken unit test cases of AWSAPIPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
5d committed Apr 25, 2024
1 parent 3079ec7 commit fa72566
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ extension AppSyncListProviderTests {
let nextPage = List(elements: [Comment4(content: "content"),
Comment4(content: "content"),
Comment4(content: "content")])
let event: GraphQLOperation<List<Comment4>>.OperationResult = .success(.success(nextPage))
return event
return .success(nextPage)
}
let elements = [Comment4(content: "content")]
let provider = AppSyncListProvider(elements: elements, nextToken: "nextToken")
Expand Down Expand Up @@ -84,10 +83,8 @@ extension AppSyncListProviderTests {
}

func testLoadedStateGetNextPageFailure_APIError() async {
mockAPIPlugin.responders[.queryRequestResponse] =
QueryRequestResponder<List<Comment4>> { _ in
let event: GraphQLOperation<List<Comment4>>.OperationResult = .failure(APIError.unknown("", "", nil))
return event
mockAPIPlugin.responders[.queryRequestResponse] = QueryRequestResponder<List<Comment4>> { _ in
throw APIError.unknown("", "", nil)
}
let elements = [Comment4(content: "content")]
let provider = AppSyncListProvider(elements: elements, nextToken: "nextToken")
Expand All @@ -108,12 +105,10 @@ extension AppSyncListProviderTests {
}

func testLoadedStateGetNextPageFailure_GraphQLErrorResponse() async {
mockAPIPlugin.responders[.queryRequestResponse] =
QueryRequestResponder<List<Comment4>> { _ in
let event: GraphQLOperation<List<Comment4>>.OperationResult = .success(
.failure(GraphQLResponseError.error([GraphQLError]())))
return event
mockAPIPlugin.responders[.queryRequestResponse] = QueryRequestResponder<List<Comment4>> { _ in
return .failure(GraphQLResponseError.error([GraphQLError]()))
}

let elements = [Comment4(content: "content")]
let provider = AppSyncListProvider(elements: elements, nextToken: "nextToken")
guard case .loaded = provider.loadedState else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ class AppSyncListProviderTests: XCTestCase {
],
"nextToken": "nextToken"
]
let event: GraphQLOperation<JSONValue>.OperationResult = .success(.success(json))
return event
return .success(json)
}
let modelMetadata = AppSyncListDecoder.Metadata(appSyncAssociatedIdentifiers: ["postId"],
appSyncAssociatedFields: ["post"],
Expand Down Expand Up @@ -168,10 +167,8 @@ class AppSyncListProviderTests: XCTestCase {
}

func testNotLoadedStateSynchronousLoadFailure() async {
mockAPIPlugin.responders[.queryRequestResponse] =
QueryRequestResponder<JSONValue> { _ in
let event: GraphQLOperation<JSONValue>.OperationResult = .failure(APIError.unknown("", "", nil))
return event
mockAPIPlugin.responders[.queryRequestResponse] = QueryRequestResponder<JSONValue> { _ in
throw APIError.unknown("", "", nil)
}
let modelMetadata = AppSyncListDecoder.Metadata(appSyncAssociatedIdentifiers: ["postId"],
appSyncAssociatedFields: ["post"],
Expand Down Expand Up @@ -217,8 +214,7 @@ class AppSyncListProviderTests: XCTestCase {
],
"nextToken": "nextToken"
]
let event: GraphQLOperation<JSONValue>.OperationResult = .success(.success(json))
return event
return .success(json)
}
let modelMetadata = AppSyncListDecoder.Metadata(appSyncAssociatedIdentifiers: ["postId"],
appSyncAssociatedFields: ["post"],
Expand Down Expand Up @@ -252,10 +248,8 @@ class AppSyncListProviderTests: XCTestCase {
}

func testNotLoadedStateLoadWithCompletionFailure_APIError() async {
mockAPIPlugin.responders[.queryRequestResponse] =
QueryRequestResponder<JSONValue> { _ in
let event: GraphQLOperation<JSONValue>.OperationResult = .failure(APIError.unknown("", "", nil))
return event
mockAPIPlugin.responders[.queryRequestResponse] = QueryRequestResponder<JSONValue> { _ in
throw APIError.unknown("", "", nil)
}
let modelMetadata = AppSyncListDecoder.Metadata(appSyncAssociatedIdentifiers: ["postId"],
appSyncAssociatedFields: ["post"],
Expand Down Expand Up @@ -287,11 +281,8 @@ class AppSyncListProviderTests: XCTestCase {
}

func testNotLoadedStateLoadWithCompletionFailure_GraphQLErrorResponse() async {
mockAPIPlugin.responders[.queryRequestResponse] =
QueryRequestResponder<JSONValue> { _ in
let event: GraphQLOperation<JSONValue>.OperationResult = .success(
.failure(GraphQLResponseError.error([GraphQLError]())))
return event
mockAPIPlugin.responders[.queryRequestResponse] = QueryRequestResponder<JSONValue> { _ in
return .failure(GraphQLResponseError.error([GraphQLError]()))
}
let modelMetadata = AppSyncListDecoder.Metadata(appSyncAssociatedIdentifiers: ["postId"],
appSyncAssociatedFields: ["post"],
Expand Down Expand Up @@ -339,8 +330,7 @@ class AppSyncListProviderTests: XCTestCase {
],
"nextToken": "nextToken"
]
let event: GraphQLOperation<JSONValue>.OperationResult = .success(.success(json))
return event
return .success(json)
}
let modelMetadata = AppSyncListDecoder.Metadata(appSyncAssociatedIdentifiers: ["postId"],
appSyncAssociatedFields: ["post"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AWSRESTOperationTests: OperationTestBase {
}

// TODO: Fix this test
func testGetReturnsOperation() throws {
func testGetReturnsOperation() async throws {
try setUpPlugin(endpointType: .rest)

// Use this as a semaphore to ensure the task is cleaned up before proceeding to the next test
Expand All @@ -49,8 +49,7 @@ class AWSRESTOperationTests: OperationTestBase {
}

XCTAssertNotNil(operation.request)

waitForExpectations(timeout: 1.00)
await fulfillment(of: [listenerWasInvoked], timeout: 1)
}

func testGetFailsWithBadAPIName() throws {
Expand Down

0 comments on commit fa72566

Please sign in to comment.