Skip to content

Commit

Permalink
Remove hb_size from winning bid markers (#776)
Browse files Browse the repository at this point in the history
* feat: change winning bid determination logic

* feat: add tests
  • Loading branch information
OlenaPostindustria authored Jan 27, 2023
1 parent 58b6824 commit b65953b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,25 @@
import Foundation

public class RawWinningBidFabricator {
static func makeRawWinningBid(price: Double, bidder: String?, cacheID: String?) -> PBMORTBBid<PBMORTBBidExt> {
static func makeRawWinningBid(price: Double?, bidder: String?, cacheID: String?) -> PBMORTBBid<PBMORTBBidExt> {
let rawBid = PBMORTBBid<PBMORTBBidExt>()
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)
Expand Down
41 changes: 35 additions & 6 deletions PrebidMobileTests/RenderingTests/Tests/Prebid/BidTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit b65953b

Please sign in to comment.