Skip to content

Commit

Permalink
Merge pull request #564 from SourcePointUSA/add_tests_for_legacy_usps…
Browse files Browse the repository at this point in the history
…tring

Add tests for legacy uspstring
  • Loading branch information
andresilveirah committed Apr 16, 2024
2 parents 6d5bd01 + cfd58fb commit fd02078
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ extension SPUSNatConsent {

public extension SPUSNatConsent {
struct Statuses: CustomStringConvertible, Equatable {
let rejectedAny, consentedToAll, consentedToAny,
public let rejectedAny, consentedToAll, consentedToAny,
hasConsentData, sellStatus, shareStatus,
sensitiveDataStatus, gpcStatus: Bool?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import WebKit
/// * you should append query param `_sp_pass_consent=true` to your page (so the our web script knows it should wait for consent data)
/// * you need to call `preloadConsent` only _after_ the url been loaded into the webview (ie. after `.load(URLRequest)`)
func preloadConsent(from consents: SPUserData) {
guard
guard
let consentsData = try? JSONEncoder().encode(
PreloadConsentsPayload(consent: consents.webConsents)
),
Expand Down
2 changes: 2 additions & 0 deletions Example/AuthExample/HomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ class HomeViewController: UIViewController {
var accountId, propertyId, propertyName: String!

override func viewDidLoad() {
#if compiler(>=5.8) && DEBUG
if #available(iOS 16.4, *) {
webview.isInspectable = true
}
#endif
webview.cleanCache()
webview.navigationDelegate = self
webview.load(URLRequest(url: webviewUrl))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,18 +498,65 @@ class SPClientCoordinatorSpec: QuickSpec {
coordinator = coordinatorFor(campaigns: SPCampaigns(usnat: SPCampaign()))
}

it("can support legacy uspstring") {
coordinator = coordinatorFor(
campaigns: SPCampaigns(
usnat: SPCampaign(supportLegacyUSPString: true)
describe("with the supportLegacyUSPString flag") {
it("receives the IABUSPrivacy_String on GPPData") {
coordinator = coordinatorFor(
campaigns: SPCampaigns(
usnat: SPCampaign(supportLegacyUSPString: true)
)
)
)
waitUntil { done in
coordinator.loadMessages(forAuthId: nil, pubData: nil) { _ in
expect(
coordinator.userData.usnat?.consents?.GPPData?["IABUSPrivacy_String"]?.stringValue
).notTo(beEmpty())
done()
waitUntil { done in
coordinator.loadMessages(forAuthId: nil, pubData: nil) { _ in
let optedOutUspString = "1YYN"
let optedInUspString = "1YNN"
let newUserUspString = coordinator.userData.usnat?.consents?.GPPData?["IABUSPrivacy_String"]?.stringValue
expect(newUserUspString).to(equal(optedOutUspString))

let saveAndExitAcceptAction = SPAction(
type: .SaveAndExit,
campaignType: .usnat,
pmPayload: try! SPJson([
"shownCategories": [
"65a6a785cc78fac48ab34e65",
"65a6a785cc78fac48ab34e6a",
"65a6a785cc78fac48ab34e6f",
"65a6a785cc78fac48ab34e74",
"65a6a785cc78fac48ab34e79",
"65a6a785cc78fac48ab34e7e",
"65a6a785cc78fac48ab34e83",
"65a6a785cc78fac48ab34e88",
"65a6a785cc78fac48ab34e8d",
"65a6a785cc78fac48ab34e92",
"65a6a785cc78fac48ab34e97",
"65a6a785cc78fac48ab34e9c"
],
"privacyManagerId": "995256",
"lan": "EN",
"vendors": [],
"categories": [
"65a6a785cc78fac48ab34e65",
"65a6a785cc78fac48ab34e6a",
"65a6a785cc78fac48ab34e6f",
"65a6a785cc78fac48ab34e74",
"65a6a785cc78fac48ab34e79",
"65a6a785cc78fac48ab34e7e",
"65a6a785cc78fac48ab34e83",
"65a6a785cc78fac48ab34e88",
"65a6a785cc78fac48ab34e8d",
"65a6a785cc78fac48ab34e92",
"65a6a785cc78fac48ab34e97",
"65a6a785cc78fac48ab34e9c",
"648c9c48e17a3c7a82360c54"
]
])
)
coordinator.reportAction(saveAndExitAcceptAction) { result in
let actionUserData = try? result.get()
let actionUspString = actionUserData?.usnat?.consents?.GPPData?["IABUSPrivacy_String"]?.stringValue
expect(actionUspString).to(equal(optedInUspString))
done()
}
}
}
}
}
Expand Down

0 comments on commit fd02078

Please sign in to comment.