diff --git a/Tests/ConfidenceProviderTests/CacheDataInteractorTests.swift b/Tests/ConfidenceProviderTests/CacheDataInteractorTests.swift index 30ba8ace..e9425a69 100644 --- a/Tests/ConfidenceProviderTests/CacheDataInteractorTests.swift +++ b/Tests/ConfidenceProviderTests/CacheDataInteractorTests.swift @@ -5,7 +5,7 @@ import XCTest @testable import ConfidenceProvider final class CacheDataInteractorTests: XCTestCase { - func testCacheDataInteractor_loadsEventsFromStorage() throws { + func testCacheDataInteractor_loadsEventsFromStorage() async throws { // Given prefilled storage with 10 resolve events (20 apply events in each) let prefilledCache = try CacheDataUtility.prefilledCacheData( resolveEventCount: 10, @@ -16,30 +16,25 @@ final class CacheDataInteractorTests: XCTestCase { let cacheDataInteractor = CacheDataInteractor(cacheData: prefilledCache) // Then cache data is loaded from storage - Task { - // Wrapped it in the Task in order to ensure that async code is completed before assertions - let cache = await cacheDataInteractor.cache - XCTAssertEqual(cache.resolveEvents.count, 10) - XCTAssertEqual(cache.resolveEvents.last?.events.count, 20) - } + let cache = await cacheDataInteractor.cache + XCTAssertEqual(cache.resolveEvents.count, 10) + XCTAssertEqual(cache.resolveEvents.last?.events.count, 20) } func testCacheDataInteractor_addEventToEmptyCache() async throws { // Given cache data interactor with no previously stored data let cacheDataInteractor = CacheDataInteractor(cacheData: .empty()) - Task { - let cache = await cacheDataInteractor.cache - XCTAssertEqual(cache.resolveEvents.count, 0) - } - - Task { - // When cache data add method is called - _ = await cacheDataInteractor.add(resolveToken: "token", flagName: "name", applyTime: Date()) - - // Then event is added with - let cache = await cacheDataInteractor.cache - XCTAssertEqual(cache.resolveEvents.count, 1) - } + + let cache = await cacheDataInteractor.cache + XCTAssertEqual(cache.resolveEvents.count, 0) + + + // When cache data add method is called + _ = await cacheDataInteractor.add(resolveToken: "token", flagName: "name", applyTime: Date()) + + // Then event is added with + let cache2 = await cacheDataInteractor.cache + XCTAssertEqual(cache2.resolveEvents.count, 1) } func testCacheDataInteractor_addEventToPreFilledCache() async throws { @@ -47,13 +42,11 @@ final class CacheDataInteractorTests: XCTestCase { let prefilledCacheData = try CacheDataUtility.prefilledCacheData(applyEventCount: 2) let cacheDataInteractor = CacheDataInteractor(cacheData: prefilledCacheData) - Task { - // When cache data add method is called - _ = await cacheDataInteractor.add(resolveToken: "token", flagName: "name", applyTime: Date()) + // When cache data add method is called + _ = await cacheDataInteractor.add(resolveToken: "token", flagName: "name", applyTime: Date()) - // Then event is added with - let cache = await cacheDataInteractor.cache - XCTAssertEqual(cache.resolveEvents.count, 2) - } + // Then event is added with + let cache = await cacheDataInteractor.cache + XCTAssertEqual(cache.resolveEvents.count, 2) } }