|
| 1 | +// |
| 2 | +// Copyright 2018-2020 Amazon.com, |
| 3 | +// Inc. or its affiliates. All Rights Reserved. |
| 4 | +// |
| 5 | +// SPDX-License-Identifier: Apache-2.0 |
| 6 | +// |
| 7 | + |
| 8 | +import Foundation |
| 9 | +import XCTest |
| 10 | + |
| 11 | +@testable import Amplify |
| 12 | +@testable import AmplifyTestCommon |
| 13 | +@testable import AWSPluginsCore |
| 14 | +@testable import AWSDataStoreCategoryPlugin |
| 15 | + |
| 16 | +class MutationEventClearStateTests: XCTestCase { |
| 17 | + var mockStorageAdapter: MockSQLiteStorageEngineAdapter! |
| 18 | + var mutationEventClearState: MutationEventClearState! |
| 19 | + |
| 20 | + override func setUp() { |
| 21 | + mockStorageAdapter = MockSQLiteStorageEngineAdapter() |
| 22 | + mutationEventClearState = MutationEventClearState(storageAdapter: mockStorageAdapter) |
| 23 | + } |
| 24 | + |
| 25 | + func testInProcessIsSetFromTrueToFalse() { |
| 26 | + let queryExpectation = expectation(description: "query is called") |
| 27 | + let saveExpectation = expectation(description: "save is Called") |
| 28 | + let completionExpectation = expectation(description: "completion handler is called") |
| 29 | + |
| 30 | + let queryResponder = QueryModelTypePredicateAdditionalStatementsResponder<MutationEvent> { _, _, _ in |
| 31 | + queryExpectation.fulfill() |
| 32 | + var mutationEvent = MutationEvent(modelId: "1111-22", |
| 33 | + modelName: "Post", |
| 34 | + json: "{}", |
| 35 | + mutationType: .create) |
| 36 | + mutationEvent.inProcess = true |
| 37 | + return .success([mutationEvent]) |
| 38 | + } |
| 39 | + mockStorageAdapter.responders[.queryModelTypePredicateAdditionalStatements] = queryResponder |
| 40 | + |
| 41 | + let saveResponder = SaveModelCompletionResponder<MutationEvent> { model, completion in |
| 42 | + XCTAssertEqual("1111-22", model.modelId) |
| 43 | + XCTAssertFalse(model.inProcess) |
| 44 | + saveExpectation.fulfill() |
| 45 | + completion(.success(model)) |
| 46 | + } |
| 47 | + mockStorageAdapter.responders[.saveModelCompletion] = saveResponder |
| 48 | + |
| 49 | + mutationEventClearState.clearStateOutgoingMutations { |
| 50 | + completionExpectation.fulfill() |
| 51 | + } |
| 52 | + wait(for: [queryExpectation, |
| 53 | + saveExpectation, |
| 54 | + completionExpectation], timeout: 1.0) |
| 55 | + } |
| 56 | +} |
0 commit comments