Skip to content

Commit

Permalink
Add clearCache test
Browse files Browse the repository at this point in the history
  • Loading branch information
larryonoff committed Jan 3, 2019
1 parent 11f2b46 commit d95e200
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions AWSAppSyncTests/AWSAppSyncTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,55 @@ class AWSAppSyncTests: XCTestCase {
wait(for: [successfullistEventExpectation], timeout: 5.0)
}

func testClearCache() {
shouldDeleteDuringTearDown = true
let mutationExpectation = expectation(description: "Mutation done successfully.")

let addEvent = AddEventMutation(
name: EventName,
when: EventTime,
where: EventLocation,
description: EventDescription)

appSyncClient.perform(mutation: addEvent) { (result, error) in
defer { mutationExpectation.fulfill() }

XCTAssertNil(error, "Error expected to be nil, but is not.")
XCTAssertNotNil(result?.data?.createEvent?.id, "Expected service to return a UUID.")
XCTAssertEqual(self.EventName, result?.data?.createEvent?.name, "Event names should match.")
}

wait(for: [mutationExpectation], timeout: 5.0)

let query = ListEventsQuery()

let fetchQueryIgnoringCacheExpectation = expectation(description: "Fetch query ignoring cache")
let emptyCacheExpectation = expectation(description: "Fetch query from empty cache")

appSyncClient.fetch(query: query, cachePolicy: .fetchIgnoringCacheData) { (result, error) in
defer { fetchQueryIgnoringCacheExpectation.fulfill() }

XCTAssertNil(error, "Error expected to be nil, but is not.")
XCTAssertNotNil(result?.data?.listEvents?.items, "Items array should not be empty.")
XCTAssertGreaterThan(result?.data?.listEvents?.items?.count ?? 0, 0, "Expected service to return at least 1 event.")

do {
try self.appSyncClient.store?.clearCache().await()
} catch {
XCTFail()
}

self.appSyncClient.fetch(query: query, cachePolicy: .returnCacheDataDontFetch) { (result, error) in
defer { emptyCacheExpectation.fulfill() }

XCTAssertNil(result, "Expected empty cache")
XCTAssertNil(error, "Expected no error")
}
}

wait(for: [fetchQueryIgnoringCacheExpectation, emptyCacheExpectation], timeout: 5.0)
}

func testMutation() {
shouldDeleteDuringTearDown = true
let successfulMutationEventExpectation = expectation(description: "Mutation done successfully.")
Expand Down

0 comments on commit d95e200

Please sign in to comment.