-
Notifications
You must be signed in to change notification settings - Fork 99
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
Update TargetingInfo Behavior #1088
Changes from 10 commits
2da2426
61cacf7
ac8fcb7
531e162
25067ec
da3528b
611d197
8150037
9e3820c
2f63f0c
67b6145
dcd244b
8b5981f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,10 @@ class AdUnitTests: XCTestCase { | |
|
||
override func tearDown() { | ||
Targeting.shared.clearUserKeywords() | ||
Targeting.shared.forceSdkToChooseWinner = true | ||
|
||
Prebid.shared.useExternalClickthroughBrowser = false | ||
Prebid.shared.useCacheForReportingWithRenderingAPI = false | ||
} | ||
|
||
func testFetchDemand() { | ||
|
@@ -114,6 +117,98 @@ class AdUnitTests: XCTestCase { | |
XCTAssertEqual(realBidInfo?.nativeAdCacheId, expectedCacheId) | ||
} | ||
|
||
//forceSdkToChooseWinner + Winner = Contains Targeting Info | ||
func testForcedWinnerAndWinningBid() { | ||
//given | ||
Targeting.shared.forceSdkToChooseWinner = true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please reset all global values to their default settings after the test completes (e.g. in tearDown) to prevent any unexpected behaviour. |
||
|
||
let expected = ResultCode.prebidDemandFetchSuccess | ||
|
||
let adUnit = AdUnit(configId: "138c4d03-0efb-4498-9dc6-cb5a9acb2ea4", size: CGSize(width: 300, height: 250), adFormats: [.banner]) | ||
//This needs to after AdUnit init as the AdUnit enables this value. | ||
//We need to disabled to not look for cache id for winning bid | ||
Prebid.shared.useCacheForReportingWithRenderingAPI = false | ||
let adObject = NSMutableDictionary() | ||
let rawWinningBid = PBMBidResponseTransformer.makeValidResponse(bidPrice: 0.75) | ||
let jsonDict = rawWinningBid.jsonDict as? NSDictionary | ||
let bidResponse = BidResponse(jsonDictionary: jsonDict ?? [:]) | ||
|
||
//when | ||
let resultCode = adUnit.setUp(adObject, with: bidResponse) | ||
|
||
//then | ||
XCTAssertTrue((adObject.allKeys as? [String])?.contains("hb_bidder") ?? false) | ||
XCTAssertEqual(resultCode, expected) | ||
} | ||
|
||
//forceSdkToChooseWinner + No Winner = Doesn't contain Targeting Info | ||
func testForcedWinnerAndLoosingBid() { | ||
//given | ||
Targeting.shared.forceSdkToChooseWinner = true | ||
let expected = ResultCode.prebidDemandNoBids | ||
let adUnit = AdUnit(configId: "138c4d03-0efb-4498-9dc6-cb5a9acb2ea4", size: CGSize(width: 300, height: 250), adFormats: [.banner]) | ||
//This needs to after AdUnit init as the AdUnit enables this value. | ||
//We need to disabled to not look for cache id for winning bid | ||
Prebid.shared.useCacheForReportingWithRenderingAPI = false | ||
let adObject = NSMutableDictionary() | ||
let rawWinningBid = PBMBidResponseTransformer.makeValidResponseWithNonWinningTargetingInfo() | ||
let jsonDict = rawWinningBid.jsonDict as? NSDictionary | ||
let bidResponse = BidResponse(jsonDictionary: jsonDict ?? [:]) | ||
|
||
//when | ||
let resultCode = adUnit.setUp(adObject, with: bidResponse) | ||
|
||
//then | ||
XCTAssertFalse((adObject.allKeys as? [String])?.contains("hb_bidder") ?? false) | ||
XCTAssertEqual(resultCode, expected) | ||
} | ||
|
||
//Don't forceSdkToChooseWinner + Winner = Contains Targeting Info | ||
func testNonForcedWinnerAndWinningBid() { | ||
//given | ||
Targeting.shared.forceSdkToChooseWinner = false | ||
let expected = ResultCode.prebidDemandFetchSuccess | ||
let adUnit = AdUnit(configId: "138c4d03-0efb-4498-9dc6-cb5a9acb2ea4", size: CGSize(width: 300, height: 250), adFormats: [.banner]) | ||
//This needs to after AdUnit init as the AdUnit enables this value. | ||
//We need to disabled to not look for cache id for winning bid | ||
Prebid.shared.useCacheForReportingWithRenderingAPI = false | ||
let adObject = NSMutableDictionary() | ||
let rawWinningBid = PBMBidResponseTransformer.makeValidResponse(bidPrice: 0.75) | ||
let jsonDict = rawWinningBid.jsonDict as? NSDictionary | ||
let bidResponse = BidResponse(jsonDictionary: jsonDict ?? [:]) | ||
|
||
//when | ||
let resultCode = adUnit.setUp(adObject, with: bidResponse) | ||
|
||
//then | ||
XCTAssertTrue((adObject.allKeys as? [String])?.contains("hb_bidder") ?? false) | ||
XCTAssertEqual(resultCode, expected) | ||
} | ||
|
||
//Don't forceSdkToChooseWinner + No Winner = Contains Targeting Info | ||
func testNonForcedWinnerAndNonWinningBid() { | ||
//given | ||
Targeting.shared.forceSdkToChooseWinner = false | ||
|
||
let expected = ResultCode.prebidDemandFetchSuccess | ||
let adUnit = AdUnit(configId: "138c4d03-0efb-4498-9dc6-cb5a9acb2ea4", size: CGSize(width: 300, height: 250), adFormats: [.banner]) | ||
//This needs to after AdUnit init as the AdUnit enables this value. | ||
//We need to disabled to not look for cache id for winning bid | ||
Prebid.shared.useCacheForReportingWithRenderingAPI = false | ||
let adObject = NSMutableDictionary() | ||
let rawWinningBid = PBMBidResponseTransformer.makeValidResponseWithNonWinningTargetingInfo() | ||
let jsonDict = rawWinningBid.jsonDict as? NSDictionary | ||
let bidResponse = BidResponse(jsonDictionary: jsonDict ?? [:]) | ||
|
||
//when | ||
let resultCode = adUnit.setUp(adObject, with: bidResponse) | ||
|
||
//then | ||
XCTAssertTrue((adObject.allKeys as? [String])?.contains("hb_bidder") ?? false) | ||
XCTAssertEqual(adObject["hb_bidder"] as? String, "Test-Bidder-1") | ||
XCTAssertEqual(resultCode, expected) | ||
} | ||
|
||
func testBidInfoCompletion() { | ||
Prebid.shared.prebidServerAccountId = "test-account-id" | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,7 @@ class TargetingTests: XCTestCase { | |
|
||
override func tearDown() { | ||
UtilitiesForTesting.resetTargeting(.shared) | ||
Targeting.shared.forceSdkToChooseWinner = true | ||
} | ||
|
||
func testDomain() { | ||
|
@@ -122,6 +123,17 @@ class TargetingTests: XCTestCase { | |
XCTAssertEqual(locationPrecision, Targeting.shared.locationPrecision) | ||
} | ||
|
||
func testforceSdkToChooseWinner() { | ||
//given | ||
let forceSdkToChooseWinner = true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated |
||
|
||
//when | ||
Targeting.shared.forceSdkToChooseWinner = forceSdkToChooseWinner | ||
|
||
//then | ||
XCTAssertEqual(forceSdkToChooseWinner, Targeting.shared.forceSdkToChooseWinner) | ||
} | ||
|
||
// MARK: - Year Of Birth | ||
func testYearOfBirth() { | ||
//given | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are missing the addition of
hb_cache_id_local
(cacheId
) to theadObject
, which is crucial for certain types of ads (e.g., native in-app).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It currently uses winning bid, this is the case when there are no winning bids.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, the
winningBid
is the bid intended for display. The SDK should cache such a bid and attach thecacheID
to theadObject
ashb_cache_id_local
. Otherwise, it will break the existing functionality. The SDK should maintain the default behaivior.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates! I’d also suggest adding some unit tests to ensure this functionality doesn’t break in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added 2 tests that target
Do you mean more tests for
hb_cache_id_local
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 2 other tests target the old behavior
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I mean more tests for
hb_cache_id_local
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added 2 cases for native format, please can you verify those. I'm not that versed in the native format from Prebid yet