[#1041] Implement ClearCacheAction

- ClearCacheAction tests
- CompactBlockRepository mock added
This commit is contained in:
Lukas Korba 2023-05-22 10:39:41 +02:00
parent 23378a5a8d
commit 778a67b605
1 changed files with 36 additions and 0 deletions

View File

@ -0,0 +1,36 @@
//
// ClearCacheActionTests.swift
//
//
// Created by Lukáš Korba on 22.05.2023.
//
import XCTest
@testable import TestUtils
@testable import ZcashLightClientKit
final class ClearCacheActionTests: ZcashTestCase {
func testClearCacheActionTests_NextAction() async throws {
let compactBlockRepositoryMock = CompactBlockRepositoryMock()
compactBlockRepositoryMock.clearClosure = { }
mockContainer.mock(type: CompactBlockRepository.self, isSingleton: true) { _ in compactBlockRepositoryMock }
let clearCacheAction = ClearCacheAction(
container: mockContainer
)
do {
let nextContext = try await clearCacheAction.run(with: .init(state: .clearCache)) { _ in }
XCTAssertTrue(compactBlockRepositoryMock.clearCalled, "storage.clear() is expected to be called.")
let nextState = await nextContext.state
XCTAssertTrue(
nextState == .finished,
"nextContext after .clearCache is expected to be .finished but received \(nextState)"
)
} catch {
XCTFail("testClearCacheActionTests_NextAction is not expected to fail. \(error)")
}
}
}