@@ -6,19 +6,18 @@ import TestKit
66
77final class PrivacyBannerPresentationUseCaseTests : XCTestCase {
88
9- @MainActor func test_show_banner_is_true_when_WPCOM_user_is_in_EU_and_choices_havent_been_saved ( ) async throws {
9+ @MainActor func test_show_banner_is_true_when_user_is_in_EU_and_choices_havent_been_saved ( ) async throws {
1010 // Given
1111 let defaults = try XCTUnwrap ( UserDefaults ( suiteName: " TestingSuite " ) )
1212 defaults [ . hasSavedPrivacyBannerSettings] = false
1313
1414 // Iterate through all of the country codes
1515 let stores = MockStoresManager ( sessionManager: . makeForTesting( authenticated: true , isWPCom: true ) )
1616 for euCode in Country . GDPRCountryCodes {
17- stores. whenReceivingAction ( ofType: AccountAction . self) { action in
17+ stores. whenReceivingAction ( ofType: UserAction . self) { action in
1818 switch action {
19- case . synchronizeAccount( let onCompletion) :
20- let account = Account ( userID: 123 , displayName: " " , email: " " , username: " " , gravatarUrl: " " , ipCountryCode: euCode)
21- onCompletion ( . success( account) )
19+ case . fetchUserIPCountryCode( let onCompletion) :
20+ onCompletion ( . success( euCode) )
2221 default :
2322 break
2423 }
@@ -33,77 +32,16 @@ final class PrivacyBannerPresentationUseCaseTests: XCTestCase {
3332 }
3433 }
3534
36- @MainActor func test_show_banner_is_false_when_WPCOM_user_is_outside_of_EU_and_choices_have_not_been_saved ( ) async throws {
35+ @MainActor func test_show_banner_is_false_when_user_is_outside_of_EU_and_choices_have_not_been_saved ( ) async throws {
3736 // Given
3837 let defaults = try XCTUnwrap ( UserDefaults ( suiteName: " TestingSuite " ) )
3938 defaults [ . hasSavedPrivacyBannerSettings] = false
4039
4140 let stores = MockStoresManager ( sessionManager: . makeForTesting( authenticated: true , isWPCom: true ) )
42- stores. whenReceivingAction ( ofType: AccountAction . self) { action in
43- switch action {
44- case . synchronizeAccount( let onCompletion) :
45- let account = Account ( userID: 123 , displayName: " " , email: " " , username: " " , gravatarUrl: " " , ipCountryCode: " US " )
46- onCompletion ( . success( account) )
47- default :
48- break
49- }
50- }
51-
52- // When
53- let useCase = PrivacyBannerPresentationUseCase ( defaults: defaults, stores: stores)
54- let shouldShowBanner = await useCase. shouldShowPrivacyBanner ( )
55-
56- // Then
57- XCTAssertFalse ( shouldShowBanner)
58- }
59-
60- @MainActor func test_show_banner_is_false_when_WPCOM_user_is_inside_of_EU_and_choices_have_been_saved( ) async throws {
61- // Given
62- let stores = MockStoresManager ( sessionManager: . makeForTesting( authenticated: true , isWPCom: true ) )
63- let defaults = try XCTUnwrap ( UserDefaults ( suiteName: " TestingSuite " ) )
64- defaults [ . hasSavedPrivacyBannerSettings] = true
65-
66- // When
67- let useCase = PrivacyBannerPresentationUseCase ( defaults: defaults, stores: stores)
68- let shouldShowBanner = await useCase. shouldShowPrivacyBanner ( )
69-
70- // Then
71- XCTAssertFalse ( shouldShowBanner)
72- }
73-
74- @MainActor func test_show_banner_is_true_when_non_WPCOM_is_in_EU_and_choices_have_not_been_saved( ) async throws {
75- // Given
76- let defaults = try XCTUnwrap ( UserDefaults ( suiteName: " TestingSuite " ) )
77- defaults [ . hasSavedPrivacyBannerSettings] = false
78-
79- let stores = MockStoresManager ( sessionManager: . makeForTesting( authenticated: true , isWPCom: false ) )
80- stores. whenReceivingAction ( ofType: UserAction . self) { action in
81- switch action {
82- case . fetchUserIPCountryCode( let onCompletion) :
83- onCompletion ( . success( " GB " ) )
84- default :
85- break
86- }
87- }
88-
89- // When
90- let useCase = PrivacyBannerPresentationUseCase ( defaults: defaults, stores: stores)
91- let shouldShowBanner = await useCase. shouldShowPrivacyBanner ( )
92-
93- // Then
94- XCTAssertTrue ( shouldShowBanner)
95- }
96-
97- @MainActor func test_show_banner_is_false_when_non_WPCOM_is_not_in_EU_and_choices_have_not_been_saved( ) async throws {
98- // Given
99- let defaults = try XCTUnwrap ( UserDefaults ( suiteName: " TestingSuite " ) )
100- defaults [ . hasSavedPrivacyBannerSettings] = false
101-
102- let stores = MockStoresManager ( sessionManager: . makeForTesting( authenticated: true , isWPCom: false ) )
10341 stores. whenReceivingAction ( ofType: UserAction . self) { action in
10442 switch action {
10543 case . fetchUserIPCountryCode( let onCompletion) :
106- onCompletion ( . success( " PE " ) )
44+ onCompletion ( . success( " US " ) )
10745 default :
10846 break
10947 }
@@ -117,69 +55,17 @@ final class PrivacyBannerPresentationUseCaseTests: XCTestCase {
11755 XCTAssertFalse ( shouldShowBanner)
11856 }
11957
120- @MainActor func test_show_banner_is_true_when_non_WPCOM_user_has_EU_locale_and_choices_have_not_been_saved( ) async throws {
121- // Given
122- let defaults = try XCTUnwrap ( UserDefaults ( suiteName: " TestingSuite " ) )
123- defaults [ . hasSavedPrivacyBannerSettings] = false
124-
125- let stores = MockStoresManager ( sessionManager: . makeForTesting( authenticated: true , isWPCom: false ) )
126- stores. whenReceivingAction ( ofType: UserAction . self) { action in
127- switch action {
128- case . fetchUserIPCountryCode( let onCompletion) :
129- onCompletion ( . failure( NSError ( domain: " " , code: 0 ) ) )
130- default :
131- break
132- }
133- }
134-
135- // When
136- let useCase = PrivacyBannerPresentationUseCase ( defaults: defaults, stores: stores, currentLocale: . init( identifier: " en_GB " ) )
137- let shouldShowBanner = await useCase. shouldShowPrivacyBanner ( )
138-
139- // Then
140- XCTAssertTrue ( shouldShowBanner)
141- }
142-
143- @MainActor func test_show_banner_is_false_when_non_WPCOM_user_has_none_EU_locale_and_choices_have_not_been_saved( ) async throws {
144- // Given
145- let defaults = try XCTUnwrap ( UserDefaults ( suiteName: " TestingSuite " ) )
146- defaults [ . hasSavedPrivacyBannerSettings] = false
147-
148- let stores = MockStoresManager ( sessionManager: . makeForTesting( authenticated: true , isWPCom: false ) )
149- stores. whenReceivingAction ( ofType: UserAction . self) { action in
150- switch action {
151- case . fetchUserIPCountryCode( let onCompletion) :
152- onCompletion ( . failure( NSError ( domain: " " , code: 0 ) ) )
153- default :
154- break
155- }
156- }
157-
158- // When
159- let useCase = PrivacyBannerPresentationUseCase ( defaults: defaults, stores: stores, currentLocale: . init( identifier: " en_US " ) )
160- let shouldShowBanner = await useCase. shouldShowPrivacyBanner ( )
161-
162- // Then
163- XCTAssertFalse ( shouldShowBanner)
164- }
165-
166- @MainActor func test_show_banner_is_false_when_non_WPCOM_user_has_EU_locale_and_choices_have_been_saved( ) async throws {
58+ @MainActor func test_show_banner_is_false_when_choices_have_been_saved( ) async throws {
16759 // Given
60+ let stores = MockStoresManager ( sessionManager: . makeForTesting( authenticated: true , isWPCom: true ) )
16861 let defaults = try XCTUnwrap ( UserDefaults ( suiteName: " TestingSuite " ) )
16962 defaults [ . hasSavedPrivacyBannerSettings] = true
17063
171- let stores = MockStoresManager ( sessionManager: . makeForTesting( authenticated: true , isWPCom: false ) )
172-
17364 // When
174- let useCase = PrivacyBannerPresentationUseCase ( defaults: defaults, stores: stores, currentLocale : . init ( identifier : " en_GB " ) )
65+ let useCase = PrivacyBannerPresentationUseCase ( defaults: defaults, stores: stores)
17566 let shouldShowBanner = await useCase. shouldShowPrivacyBanner ( )
17667
17768 // Then
17869 XCTAssertFalse ( shouldShowBanner)
17970 }
180-
181- override class func tearDown( ) {
182- super. tearDown ( )
183- SessionManager . removeTestingDatabase ( )
184- }
18571}
0 commit comments