-
Notifications
You must be signed in to change notification settings - Fork 7
test: Add unit tests for consent mapping logic #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nickolas-dimitrakas
merged 13 commits into
development
from
test/add-unit-tests-for-consent-mapping-logic
Sep 17, 2025
Merged
Changes from 3 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
78816e9
add test target for swift tests
nickolas-dimitrakas 0b4dedc
extract logic and make functions available in swift
nickolas-dimitrakas 4ba82cb
create tests for updateConsent logic in swift
nickolas-dimitrakas 6d9dd05
Revert "extract logic and make functions available in swift"
nickolas-dimitrakas 4aff81b
add extension to NSString
nickolas-dimitrakas 43ae14c
remove singleton from update consent
nickolas-dimitrakas 6387cb8
add wrapper to didFinishLaunching
nickolas-dimitrakas bb4abf4
corrected not using key parameter
nickolas-dimitrakas 3a00e34
make helper functions available for testing
nickolas-dimitrakas 4db4d8e
create tests for helper functions
nickolas-dimitrakas de9884d
got objc tests working in xcode UI
nickolas-dimitrakas 8acdfb9
remove unused info.plist
nickolas-dimitrakas 386e67a
adjust naming for test targets
nickolas-dimitrakas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
mParticle-Google-Analytics-Firebase-GA4Tests/Swift/MPKitFirebaseGA4SwiftTests.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
// | ||
// MPKitFirebaseGA4SwiftTests.swift | ||
// mParticle-Google-Analytics-Firebase-GA4 | ||
// | ||
// Created by Nick Dimitrakas on 9/12/25. | ||
// | ||
|
||
import XCTest | ||
@testable import mParticle_Google_Analytics_Firebase_GA4 | ||
|
||
final class MPKitFirebaseGA4AnalyticsTests: XCTestCase { | ||
var kit: MPKitFirebaseGA4Analytics! | ||
|
||
override func setUp() { | ||
super.setUp() | ||
kit = MPKitFirebaseGA4Analytics() | ||
kit.configuration = [:] | ||
} | ||
|
||
override func tearDown() { | ||
kit = nil | ||
super.tearDown() | ||
} | ||
|
||
// MARK: - resolvedConsentForPurpose | ||
|
||
func testResolvedConsentForPurpose_whenConsentGranted_returnsYES() { | ||
let consent = MPGDPRConsent() | ||
consent.consented = true | ||
let gdprConsents = ["analytics": consent] | ||
|
||
let result = kit.resolvedConsent(forPurpose: "analytics", gdprConsents: gdprConsents) | ||
|
||
XCTAssertEqual(result, true) | ||
} | ||
|
||
func testResolvedConsentForPurpose_whenConsentDenied_returnsNO() { | ||
let consent = MPGDPRConsent() | ||
consent.consented = false | ||
let gdprConsents = ["ads": consent] | ||
|
||
let result = kit.resolvedConsent(forPurpose: "ads", gdprConsents: gdprConsents) | ||
|
||
XCTAssertEqual(result, false) | ||
} | ||
|
||
func testResolvedConsentForPurpose_whenConsentMissing_returnsNil() { | ||
let gdprConsents: [String: MPGDPRConsent] = [:] | ||
|
||
let result = kit.resolvedConsent(forPurpose: "ads", gdprConsents: gdprConsents) | ||
|
||
XCTAssertNil(result) | ||
} | ||
|
||
// MARK: - resolvedConsentFromDefault | ||
|
||
func testResolvedConsentFromDefault_whenGranted_returnsYES() { | ||
kit.configuration = ["purpose_default": "Granted"] | ||
|
||
let result = kit.resolvedConsent(fromDefault: "purpose_default") | ||
|
||
XCTAssertEqual(result, true) | ||
} | ||
|
||
func testResolvedConsentFromDefault_whenDenied_returnsNO() { | ||
kit.configuration = ["purpose_default": "Denied"] | ||
|
||
let result = kit.resolvedConsent(fromDefault: "purpose_default") | ||
|
||
XCTAssertEqual(result, false) | ||
} | ||
|
||
func testResolvedConsentFromDefault_whenMissing_returnsNil() { | ||
kit.configuration = [:] | ||
|
||
let result = kit.resolvedConsent(fromDefault: "purpose_default") | ||
|
||
XCTAssertNil(result) | ||
} | ||
|
||
// MARK: - resolvedConsentForMappingKey | ||
|
||
func testResolvedConsentForMappingKey_prefersGDPRConsentOverDefault() { | ||
let consent = MPGDPRConsent() | ||
consent.consented = true | ||
let gdprConsents = ["analytics": consent] | ||
|
||
let mapping = ["tracking": "analytics"] | ||
kit.configuration = ["tracking_default": "Denied"] | ||
|
||
let result = kit.resolvedConsent(forMappingKey: "tracking", | ||
defaultKey: "tracking_default", | ||
gdprConsents: gdprConsents, | ||
mapping: mapping) | ||
|
||
// Should return GDPR (true) instead of config (Denied/false) | ||
XCTAssertEqual(result, true) | ||
} | ||
|
||
func testResolvedConsentForMappingKey_fallsBackToDefaultWhenNoGDPR() { | ||
let gdprConsents: [String: MPGDPRConsent] = [:] | ||
let mapping = ["tracking": "ads"] | ||
kit.configuration = ["tracking_default": "Granted"] | ||
|
||
let result = kit.resolvedConsent(forMappingKey: "tracking", | ||
defaultKey: "tracking_default", | ||
gdprConsents: gdprConsents, | ||
mapping: mapping) | ||
|
||
XCTAssertEqual(result, true) | ||
} | ||
|
||
func testResolvedConsentForMappingKey_returnsNilWhenNeitherFound() { | ||
let gdprConsents: [String: MPGDPRConsent] = [:] | ||
let mapping = ["tracking": "ads"] | ||
kit.configuration = [:] | ||
|
||
let result = kit.resolvedConsent(forMappingKey: "tracking", | ||
defaultKey: "tracking_default", | ||
gdprConsents: gdprConsents, | ||
mapping: mapping) | ||
|
||
XCTAssertNil(result) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.