Skip to content

Commit

Permalink
Merge pull request #589 from SourcePointUSA/DIA-2956_expire_consent_v…
Browse files Browse the repository at this point in the history
…endorlistId

DIA-2956 expire consent based on vendorListId change
  • Loading branch information
andresilveirah authored Jan 9, 2025
2 parents f5aeb02 + 881ffb4 commit 1997d2c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class SourcepointClientCoordinator: SPClientCoordinator {
static let version = 4

struct GDPRMetaData: Codable, SPSampleable, Equatable {
var vendorListId: String?
var additionsChangeDate = SPDate.now()
var legalBasisChangeDate: SPDate?
var sampleRate = Float(1)
Expand All @@ -104,13 +105,8 @@ class SourcepointClientCoordinator: SPClientCoordinator {
var sampleRate = Float(1)
var wasSampled: Bool?
var wasSampledAt: Float?
var vendorListId: String = ""
var vendorListId: String?
var applicableSections: [Int] = []

enum CodingKeys: String, CodingKey {
case additionsChangeDate, sampleRate, wasSampled, wasSampledAt, applicableSections
case vendorListId = "_id"
}
}

struct AttCampaign: Codable {
Expand Down Expand Up @@ -515,10 +511,14 @@ class SourcepointClientCoordinator: SPClientCoordinator {

func handleMetaDataResponse(_ response: SPMobileCore.MetaDataResponse) {
if let gdprMetaData = response.gdpr {
if state.gdprMetaData?.vendorListId != nil && state.gdprMetaData?.vendorListId != gdprMetaData.vendorListId {
state.gdpr = .empty()
}
state.gdpr?.applies = gdprMetaData.applies
state.gdprMetaData?.additionsChangeDate = SPDate(string: gdprMetaData.additionsChangeDate)
state.gdprMetaData?.legalBasisChangeDate = SPDate(string: gdprMetaData.legalBasisChangeDate)
state.gdprMetaData?.updateSampleFields(gdprMetaData.sampleRate)
state.gdprMetaData?.vendorListId = gdprMetaData.vendorListId
if campaigns.gdpr?.groupPmId != gdprMetaData.childPmId {
storage.gdprChildPmId = gdprMetaData.childPmId
}
Expand All @@ -529,6 +529,9 @@ class SourcepointClientCoordinator: SPClientCoordinator {
}
if let usnatMetaData = response.usnat {
let previousApplicableSections = state.usNatMetaData?.applicableSections ?? []
if state.usNatMetaData?.vendorListId != nil && state.usNatMetaData?.vendorListId != usnatMetaData.vendorListId {
state.usnat = .empty()
}
state.usnat?.applies = usnatMetaData.applies
state.usNatMetaData?.vendorListId = usnatMetaData.vendorListId
state.usNatMetaData?.additionsChangeDate = SPDate(string: usnatMetaData.additionsChangeDate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -892,5 +892,48 @@ class SPClientCoordinatorSpec: QuickSpec {
}
}
}

describe("flushing consent") {
it("when gdpr vendorListId changes") {
waitUntil { done in
coordinator.loadMessages(forAuthId: nil, pubData: nil) { firstLoadMessages in
let (firstMessages, _) = try! firstLoadMessages.get()
expect(firstMessages.filter { $0.type == .gdpr }).notTo(beEmpty())

coordinator.reportAction(SPAction(type: .AcceptAll, campaignType: .gdpr)) { _ in
coordinator.state.gdprMetaData?.vendorListId = "foo"
coordinator.storage.spState = coordinator.state

coordinator.loadMessages(forAuthId: nil, pubData: nil) { secondLoadMessages in
let (secondMessages, _) = try! secondLoadMessages.get()
expect(secondMessages.filter { $0.type == .gdpr }).notTo(beEmpty())
done()
}
}
}
}
}

it("when usnat vendorListId changes") {
waitUntil { done in
coordinator = coordinatorFor(campaigns: SPCampaigns(usnat: SPCampaign()))
coordinator.loadMessages(forAuthId: nil, pubData: nil) { firstLoadMessages in
let (firstMessages, _) = try! firstLoadMessages.get()
expect(firstMessages.filter { $0.type == .usnat }).notTo(beEmpty())

coordinator.reportAction(SPAction(type: .AcceptAll, campaignType: .usnat)) { _ in
coordinator.state.usNatMetaData?.vendorListId = "foo"
coordinator.storage.spState = coordinator.state

coordinator.loadMessages(forAuthId: nil, pubData: nil) { secondLoadMessages in
let (secondMessages, _) = try! secondLoadMessages.get()
expect(secondMessages.filter { $0.type == .usnat }).notTo(beEmpty())
done()
}
}
}
}
}
}
}
}

0 comments on commit 1997d2c

Please sign in to comment.