diff --git a/PrebidMobile/PrebidMobileRendering/Prebid/PBMCore/Bid.swift b/PrebidMobile/PrebidMobileRendering/Prebid/PBMCore/Bid.swift index 6b30ef9ab..8bcabb4f6 100644 --- a/PrebidMobile/PrebidMobileRendering/Prebid/PBMCore/Bid.swift +++ b/PrebidMobile/PrebidMobileRendering/Prebid/PBMCore/Bid.swift @@ -82,7 +82,7 @@ public class Bid: NSObject { return false } - var winningBidMarkers = ["hb_pb", "hb_bidder", "hb_size"] + var winningBidMarkers = ["hb_pb", "hb_bidder"] if Prebid.shared.useCacheForReportingWithRenderingAPI { winningBidMarkers.append("hb_cache_id") diff --git a/PrebidMobileTests/RenderingTests/Tests/FakeDataFabricationHelpers/RawWinningBidFabricator.swift b/PrebidMobileTests/RenderingTests/Tests/FakeDataFabricationHelpers/RawWinningBidFabricator.swift index ee05ba0a4..2a07c8e37 100644 --- a/PrebidMobileTests/RenderingTests/Tests/FakeDataFabricationHelpers/RawWinningBidFabricator.swift +++ b/PrebidMobileTests/RenderingTests/Tests/FakeDataFabricationHelpers/RawWinningBidFabricator.swift @@ -16,22 +16,25 @@ import Foundation public class RawWinningBidFabricator { - static func makeRawWinningBid(price: Double, bidder: String?, cacheID: String?) -> PBMORTBBid { + static func makeRawWinningBid(price: Double?, bidder: String?, cacheID: String?) -> PBMORTBBid { let rawBid = PBMORTBBid() - rawBid.price = NSNumber(value: price) rawBid.ext = .init() rawBid.ext.prebid = .init() - rawBid.ext.prebid?.targeting = [ - "hb_pb": "\(NSString(format: "%4.2f", price))", - "hb_size": "300x250" - ] + + if let price = price { + rawBid.price = NSNumber(value: price) + + rawBid.ext.prebid?.targeting = [ + "hb_pb": "\(NSString(format: "%4.2f", price))" + ] + } - rawBid.ext.prebid?.targeting!["hb_bidder"] = bidder - rawBid.ext.prebid?.targeting!["hb_cache_id"] = cacheID + rawBid.ext.prebid?.targeting?["hb_bidder"] = bidder + rawBid.ext.prebid?.targeting?["hb_cache_id"] = cacheID return rawBid } - static func makeWinningBid(price: Double, bidder: String?, cacheID: String?) -> Bid { + static func makeWinningBid(price: Double?, bidder: String?, cacheID: String?) -> Bid { let rawBid = makeRawWinningBid(price: price, bidder: bidder, cacheID: cacheID) return Bid(bid: rawBid) diff --git a/PrebidMobileTests/RenderingTests/Tests/Prebid/BidTest.swift b/PrebidMobileTests/RenderingTests/Tests/Prebid/BidTest.swift index b2b48c4ad..c8d1dbc75 100644 --- a/PrebidMobileTests/RenderingTests/Tests/Prebid/BidTest.swift +++ b/PrebidMobileTests/RenderingTests/Tests/Prebid/BidTest.swift @@ -24,20 +24,49 @@ class BidTest: XCTestCase { Prebid.reset() } + + func testWinningBidMarkers_hb_pb_noWinningBid() { + let bid = RawWinningBidFabricator.makeWinningBid(price: nil, bidder: "some bidder", cacheID: nil) + XCTAssertFalse(bid.isWinning) + } + + func testWinningBidMarkers_hb_bidder_noWinningBid() { + let bid = RawWinningBidFabricator.makeWinningBid(price: 0.75, bidder: nil, cacheID: nil) + XCTAssertFalse(bid.isWinning) + } // Rendering API doesn't require cache id by default. // But publisher can set useCacheForReportingWithRenderingAPI to true // in order to add hb_cache_id to winning bid markers. - func testWinningBidRendering() { - let rawBid = RawWinningBidFabricator.makeRawWinningBid(price: 0.75, bidder: "some bidder", cacheID: nil) - let bid = Bid(bid: rawBid) + func testWinningBid_without_hb_cache_id() { + let bid = RawWinningBidFabricator.makeWinningBid(price: 0.75, bidder: "some bidder", cacheID: nil) XCTAssertTrue(bid.isWinning) } - func testNoWinningBidRendering() { + func testNoWinningBid_hb_cache_id() { + Prebid.shared.useCacheForReportingWithRenderingAPI = true + let bid = RawWinningBidFabricator.makeWinningBid(price: 0.75, bidder: "some bidder", cacheID: nil) + XCTAssertFalse(bid.isWinning) + } + + func testWinningBid_with_hb_cache_id() { Prebid.shared.useCacheForReportingWithRenderingAPI = true - let rawBid = RawWinningBidFabricator.makeRawWinningBid(price: 0.75, bidder: "some bidder", cacheID: nil) - let bid = Bid(bid: rawBid) + let bid = RawWinningBidFabricator.makeWinningBid(price: 0.75, bidder: "some bidder", cacheID: "cache/id") + XCTAssertTrue(bid.isWinning) + } + + // No hb_cache_id = no winning bid in Original API + func testWinningBidMarkers_NoWinningBid_OriginalApi() { + let _ = AdUnit(configId: "configID", size: CGSize(width: 300, height: 250)) + + let bid = RawWinningBidFabricator.makeWinningBid(price: 0.75, bidder: "some bidder", cacheID: nil) XCTAssertFalse(bid.isWinning) } + + func testWinningBidMarkers_WinningBid_OriginalApi() { + let _ = AdUnit(configId: "configID", size: CGSize(width: 300, height: 250)) + + let bid = RawWinningBidFabricator.makeWinningBid(price: 0.75, bidder: "some bidder", cacheID: "cache/id") + XCTAssertTrue(bid.isWinning) + } }