Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
miasma13 committed Oct 31, 2024
1 parent 37de1b6 commit 9506581
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public final class SubscriptionCookieManagerMock: SubscriptionCookieManaging {

}

public func enableSettingSubscriptionCookie() { }
public func disableSettingSubscriptionCookie() async { }
public func refreshSubscriptionCookie() async { }
public func resetLastRefreshDate() { }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ final class SubscriptionCookieManagerTests: XCTestCase {
accountManager.accessToken = Constants.accessToken

// When
subscriptionCookieManager.enableSettingSubscriptionCookie()
NotificationCenter.default.post(name: .accountDidSignIn, object: self, userInfo: nil)
try await Task.sleep(seconds: 0.1)

Expand All @@ -88,11 +89,12 @@ final class SubscriptionCookieManagerTests: XCTestCase {
await ensureSubscriptionCookieIsInTheCookieStore()

// When
subscriptionCookieManager.enableSettingSubscriptionCookie()
NotificationCenter.default.post(name: .accountDidSignOut, object: self, userInfo: nil)
try await Task.sleep(seconds: 0.1)

// Then
await checkSubscriptionCookieIsNotPresent()
await checkSubscriptionCookieIsHasEmptyValue()
}

func testRefreshWhenSignedInButCookieIsMissing() async throws {
Expand All @@ -101,6 +103,7 @@ final class SubscriptionCookieManagerTests: XCTestCase {
await ensureNoSubscriptionCookieInTheCookieStore()

// When
subscriptionCookieManager.enableSettingSubscriptionCookie()
await subscriptionCookieManager.refreshSubscriptionCookie()
try await Task.sleep(seconds: 0.1)

Expand All @@ -114,11 +117,12 @@ final class SubscriptionCookieManagerTests: XCTestCase {
await ensureSubscriptionCookieIsInTheCookieStore()

// When
subscriptionCookieManager.enableSettingSubscriptionCookie()
await subscriptionCookieManager.refreshSubscriptionCookie()
try await Task.sleep(seconds: 0.1)

// Then
await checkSubscriptionCookieIsNotPresent()
await checkSubscriptionCookieIsHasEmptyValue()
}

func testRefreshNotTriggeredTwiceWithinSetRefreshInterval() async throws {
Expand All @@ -127,6 +131,7 @@ final class SubscriptionCookieManagerTests: XCTestCase {
let secondRefreshDate: Date?

// When
subscriptionCookieManager.enableSettingSubscriptionCookie()
await subscriptionCookieManager.refreshSubscriptionCookie()
firstRefreshDate = subscriptionCookieManager.lastRefreshDate

Expand All @@ -145,6 +150,7 @@ final class SubscriptionCookieManagerTests: XCTestCase {
let secondRefreshDate: Date?

// When
subscriptionCookieManager.enableSettingSubscriptionCookie()
await subscriptionCookieManager.refreshSubscriptionCookie()
firstRefreshDate = subscriptionCookieManager.lastRefreshDate

Expand Down Expand Up @@ -186,9 +192,12 @@ final class SubscriptionCookieManagerTests: XCTestCase {
XCTAssertEqual(subscriptionCookie.value, Constants.accessToken)
}

private func checkSubscriptionCookieIsNotPresent() async {
let cookie = await cookieStore.fetchSubscriptionCookie()
XCTAssertNil(cookie)
private func checkSubscriptionCookieIsHasEmptyValue() async {
guard let subscriptionCookie = await cookieStore.fetchSubscriptionCookie() else {
XCTFail("No subscription cookie in the store")
return
}
XCTAssertEqual(subscriptionCookie.value, "")
}

}
Expand All @@ -213,6 +222,7 @@ class MockHTTPCookieStore: HTTPCookieStore {
}

func setCookie(_ cookie: HTTPCookie) async {
cookies.removeAll { $0.domain == cookie.domain }
cookies.append(cookie)
}

Expand Down

0 comments on commit 9506581

Please sign in to comment.