@@ -89,6 +89,10 @@ class CCPAConsentViewControllerSpec: QuickSpec, ConsentDelegate {
89
89
consentViewController = self . getCCPAConsentViewController ( )
90
90
}
91
91
92
+ afterEach {
93
+ consentViewController. clearAllConsentData ( )
94
+ }
95
+
92
96
it ( " Load message in webview without authId " ) {
93
97
consentViewController. loadMessage ( )
94
98
expect ( consentViewController. loading) . to ( equal ( . Loading) , description: " loadMessage method works as expected " )
@@ -133,9 +137,23 @@ class CCPAConsentViewControllerSpec: QuickSpec, ConsentDelegate {
133
137
consentViewController = self . getCCPAConsentViewController ( )
134
138
}
135
139
136
- it ( " Test did AuthId Change " ) {
137
- let authIdChangeStatus = consentViewController. didAuthIdChange ( newAuthId: Date ( ) . description)
138
- expect ( authIdChangeStatus) . to ( equal ( true ) , description: " Auth Id changed successfully " )
140
+ context ( " when the new authId is nil " ) {
141
+ it ( " returns false " ) {
142
+ expect ( consentViewController. didAuthIdChange ( newAuthId: nil ) ) . to ( equal ( false ) )
143
+ }
144
+ }
145
+
146
+ context ( " when there's no stored id " ) {
147
+ it ( " returns false " ) {
148
+ expect ( consentViewController. didAuthIdChange ( newAuthId: " different " ) ) . to ( equal ( false ) )
149
+ }
150
+ }
151
+
152
+ context ( " when there is stored id " ) {
153
+ it ( " returns true " ) {
154
+ UserDefaults . standard. set ( " authId " , forKey: CCPAConsentViewController . CCPA_AUTH_ID_KEY)
155
+ expect ( consentViewController. didAuthIdChange ( newAuthId: " different " ) ) . to ( equal ( true ) )
156
+ }
139
157
}
140
158
}
141
159
@@ -166,6 +184,19 @@ class CCPAConsentViewControllerSpec: QuickSpec, ConsentDelegate {
166
184
consentViewController = self . getCCPAConsentViewController ( )
167
185
consentViewController. consentDelegate = mockConsentDelegate
168
186
}
187
+
188
+ describe ( " onAction " ) {
189
+ it ( " should set the consentUUID in the UserDefaults " ) {
190
+ consentViewController. onAction ( . AcceptAll, consents: nil )
191
+ expect ( UserDefaults . standard. string ( forKey: CCPAConsentViewController . CONSENT_UUID_KEY) ) . toEventuallyNot ( beEmpty ( ) )
192
+ }
193
+
194
+ it ( " should set the consentUUID as attribute of CCPAConsentViewController " ) {
195
+ consentViewController. onAction ( . AcceptAll, consents: nil )
196
+ expect ( consentViewController. consentUUID) . toEventuallyNot ( beEmpty ( ) )
197
+ }
198
+ }
199
+
169
200
context ( " Test consentUIWillShow delegate method " ) {
170
201
it ( " Test CCPAConsentViewController calls consentUIWillShow delegate method " ) {
171
202
consentViewController. ccpaConsentUIWillShow ( )
@@ -193,21 +224,10 @@ class CCPAConsentViewControllerSpec: QuickSpec, ConsentDelegate {
193
224
}
194
225
195
226
context ( " onConsentReady delegate method " ) {
196
-
197
227
it ( " calls onConsentReady delegate method " ) {
198
228
consentViewController. onConsentReady ( consentUUID: consentUUID, userConsent: userConsents)
199
229
expect ( mockConsentDelegate. isOnConsentReadyCalled) . to ( equal ( true ) , description: " onConsentReady delegate method calls successfully " )
200
230
}
201
-
202
- it ( " should set the consentUUID in the UserDefaults " ) {
203
- consentViewController. onConsentReady ( consentUUID: " sp_ccpa_consentUUID " , userConsent: userConsents)
204
- expect ( UserDefaults . standard. string ( forKey: CCPAConsentViewController . CONSENT_UUID_KEY) ) . to ( equal ( " sp_ccpa_consentUUID " ) )
205
- }
206
-
207
- it ( " should set the consentUUID as attribute of CCPAConsentViewController " ) {
208
- consentViewController. onConsentReady ( consentUUID: " sp_ccpa_consentUUID " , userConsent: userConsents)
209
- expect ( consentViewController. consentUUID) . to ( equal ( " sp_ccpa_consentUUID " ) )
210
- }
211
231
}
212
232
213
233
context ( " Test messageWillShow delegate method " ) {
0 commit comments