Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nevazhnovu committed Nov 22, 2024
1 parent c600a9d commit 645b8aa
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,19 @@ class SourcePointClientMock: SourcePointProtocol {
func ccpaPrivacyManagerView(propertyId: Int, consentLanguage: SPMessageLanguage, handler: @escaping CCPAPrivacyManagerViewHandler) {
}

func postCCPAAction(actionType: SPActionType, body: CCPAChoiceBody, handler: @escaping CCPAConsentHandler) {
func postCCPAAction(actionType: ConsentViewController.SPActionType, request: CCPAChoiceRequest, handler: @escaping ConsentViewController.CCPAConsentHandler) {
postCCPAActionCalled = true
postCCPAActionCalledWith = [
"actionType": actionType,
"body": body,
"request": request,
"handler": handler
]
if let error = error {
handler(.failure(error))
} else {
handler(.success(CCPAChoiceResponse(
handler(.success(SPMobileCore.CCPAChoiceResponse(
uuid: "",
dateCreated: .now(),
dateCreated: SPDate.format.string(from: SPDate.now().date),
consentedAll: nil,
rejectedAll: nil,
status: nil,
Expand All @@ -143,26 +143,26 @@ class SourcePointClientMock: SourcePointProtocol {
rejectedVendors: nil,
rejectedCategories: nil,
webConsentPayload: nil,
GPPData: SPJson()
gppData: [:] as [String : Kotlinx_serialization_jsonJsonPrimitive]
)))
}
}

func postGDPRAction(actionType: SPActionType, body: GDPRChoiceBody, handler: @escaping GDPRConsentHandler) {
func postGDPRAction(actionType: ConsentViewController.SPActionType, request: GDPRChoiceRequest, handler: @escaping ConsentViewController.GDPRConsentHandler) {
postGDPRActionCalled = true
postGDPRActionCalledWith = [
"actionType": actionType,
"body": body,
"request": request,
"handler": handler
]
if let error = error {
handler(.failure(error))
} else {
handler(.success(GDPRChoiceResponse(
handler(.success(SPMobileCore.GDPRChoiceResponse(
uuid: "",
dateCreated: .now(),
expirationDate: .distantFuture(),
TCData: nil,
dateCreated: SPDate.format.string(from: SPDate.now().date),
expirationDate: SPDate.format.string(from: SPDate.distantFuture().date),
tcData: nil,
euconsent: nil,
consentStatus: nil,
grants: nil,
Expand All @@ -178,19 +178,30 @@ class SourcePointClientMock: SourcePointProtocol {
}

func postUSNatAction(
actionType: SPActionType,
body: USNatChoiceBody,
handler: @escaping USNatConsentHandler
actionType: ConsentViewController.SPActionType,
request: USNatChoiceRequest,
handler: @escaping ConsentViewController.USNatConsentHandler
) {
postUSNatActionCalledWith = [
"actionType": actionType,
"body": body,
"request": request,
"handler": handler
]
if let error = error {
handler(.failure(error))
} else {
handler(.success(SPUSNatConsent.empty()))
handler(.success(SPMobileCore.USNatChoiceResponse(
uuid: nil,
categories: [],
consentStatus: SPMobileCore.ConsentStatus(rejectedAny: nil, rejectedLI: nil, rejectedAll: nil, consentedAll: nil, consentedToAll: nil, consentedToAny: nil, hasConsentData: nil, vendorListAdditions: nil, legalBasisChanges: nil, granularStatus: nil, rejectedVendors: nil, rejectedCategories: nil),
consentStrings: [],
dateCreated: SPDate.format.string(from: SPDate.now().date),
expirationDate: SPDate.format.string(from: SPDate.distantFuture().date),
gpcEnabled: nil,
webConsentPayload: nil,
gppData: [:] as [String : Kotlinx_serialization_jsonJsonPrimitive],
userConsents: USNatConsent.USNatUserConsents(vendors: [], categories: [])
)))
}
}

Expand Down Expand Up @@ -267,14 +278,13 @@ class SourcePointClientMock: SourcePointProtocol {
}

func choiceAll(
actionType: SPActionType,
actionType: SPMobileCore.SPActionType,
accountId: Int,
propertyId: Int,
idfaStatus: SPIDFAStatus,
metadata: ChoiceAllMetaDataParam,
includeData: IncludeData,
handler: @escaping ChoiceHandler
) {
idfaStatus: SPMobileCore.SPIDFAStatus,
metadata: ChoiceAllMetaDataRequest,
includeData: SPMobileCore.IncludeData,
handler: @escaping ConsentViewController.ChoiceHandler) {
handler(.success(ChoiceAllResponse(gdpr: nil, ccpa: nil, usnat: nil)))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ class SPClientCoordinatorSpec: QuickSpec {
messageId: "1234"
)
gdprAction.encodablePubData = ["foo": .init("gdpr")]
let publisherData = JsonKt.encodeToJsonObject(gdprAction.encodablePubData.toCore())

waitUntil { done in
coordinator.reportAction(gdprAction) { response in
Expand All @@ -194,9 +195,9 @@ class SPClientCoordinatorSpec: QuickSpec {

case .success:
expect(spClientMock.postGDPRActionCalled).to(beTrue())
let body = spClientMock.postGDPRActionCalledWith?["body"] as? GDPRChoiceBody
expect(body?.pubData).to(equal(gdprAction.encodablePubData))
expect(body?.messageId).to(equal("1234"))
let request = spClientMock.postGDPRActionCalledWith?["request"] as? GDPRChoiceRequest
expect(request?.pubData).to(equal(publisherData))
expect(request?.messageId).to(equal("1234"))
}
done()
}
Expand All @@ -210,6 +211,7 @@ class SPClientCoordinatorSpec: QuickSpec {
messageId: "321"
)
ccpaAction.encodablePubData = ["foo": .init("ccpa")]
let publisherData = JsonKt.encodeToJsonObject(ccpaAction.encodablePubData.toCore())

waitUntil { done in
coordinator.reportAction(ccpaAction) { response in
Expand All @@ -218,9 +220,9 @@ class SPClientCoordinatorSpec: QuickSpec {

case .success:
expect(spClientMock.postCCPAActionCalled).to(beTrue())
let body = spClientMock.postCCPAActionCalledWith?["body"] as? CCPAChoiceBody
expect(body?.pubData).to(equal(ccpaAction.encodablePubData))
expect(body?.messageId).to(equal("321"))
let request = spClientMock.postCCPAActionCalledWith?["request"] as? CCPAChoiceRequest
expect(request?.pubData).to(equal(publisherData))
expect(request?.messageId).to(equal("321"))
}
done()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class UnmockedSourcepointClientSpec: QuickSpec {
it("should call the endpoint and parse the response into ChoiceAllResponse") {
waitUntil { done in
client.choiceAll(
actionType: .RejectAll,
actionType: .rejectall,
accountId: accountId,
propertyId: propertyId,
idfaStatus: .accepted,
Expand All @@ -238,7 +238,7 @@ class UnmockedSourcepointClientSpec: QuickSpec {
ccpa: .init(applies: true),
usnat: .init(applies: true)
),
includeData: .standard
includeData: IncludeData.standard.toCore()
) { result in
switch result {
case .success(let response):
Expand All @@ -261,7 +261,7 @@ class UnmockedSourcepointClientSpec: QuickSpec {
it("should call the endpoint and parse the response into ChoiceAllResponse") {
waitUntil { done in
client.choiceAll(
actionType: .AcceptAll,
actionType: .acceptall,
accountId: accountId,
propertyId: propertyId,
idfaStatus: .accepted,
Expand All @@ -270,7 +270,7 @@ class UnmockedSourcepointClientSpec: QuickSpec {
ccpa: .init(applies: true),
usnat: .init(applies: true)
),
includeData: .standard
includeData: IncludeData.standard.toCore()
) { result in
switch result {
case .success(let response):
Expand Down

0 comments on commit 645b8aa

Please sign in to comment.