Skip to content
This repository was archived by the owner on Apr 16, 2024. It is now read-only.

Commit 12c808f

Browse files
fix specs
1 parent 0e57859 commit 12c808f

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

Example/CCPAConsentViewController_ExampleTests/CCPAConsentViewControllerSpec.swift

+34-14
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ class CCPAConsentViewControllerSpec: QuickSpec, ConsentDelegate {
8989
consentViewController = self.getCCPAConsentViewController()
9090
}
9191

92+
afterEach {
93+
consentViewController.clearAllConsentData()
94+
}
95+
9296
it("Load message in webview without authId") {
9397
consentViewController.loadMessage()
9498
expect(consentViewController.loading).to(equal(.Loading), description: "loadMessage method works as expected")
@@ -133,9 +137,23 @@ class CCPAConsentViewControllerSpec: QuickSpec, ConsentDelegate {
133137
consentViewController = self.getCCPAConsentViewController()
134138
}
135139

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+
}
139157
}
140158
}
141159

@@ -166,6 +184,19 @@ class CCPAConsentViewControllerSpec: QuickSpec, ConsentDelegate {
166184
consentViewController = self.getCCPAConsentViewController()
167185
consentViewController.consentDelegate = mockConsentDelegate
168186
}
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+
169200
context("Test consentUIWillShow delegate method") {
170201
it("Test CCPAConsentViewController calls consentUIWillShow delegate method") {
171202
consentViewController.ccpaConsentUIWillShow()
@@ -193,21 +224,10 @@ class CCPAConsentViewControllerSpec: QuickSpec, ConsentDelegate {
193224
}
194225

195226
context("onConsentReady delegate method") {
196-
197227
it("calls onConsentReady delegate method") {
198228
consentViewController.onConsentReady(consentUUID: consentUUID, userConsent: userConsents)
199229
expect(mockConsentDelegate.isOnConsentReadyCalled).to(equal(true), description: "onConsentReady delegate method calls successfully")
200230
}
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-
}
211231
}
212232

213233
context("Test messageWillShow delegate method") {

0 commit comments

Comments
 (0)