Skip to content

Commit

Permalink
Tests: BidResponse validations (#3114)
Browse files Browse the repository at this point in the history
  • Loading branch information
marki1an authored May 29, 2024
1 parent edd4dd1 commit 0b89797
Show file tree
Hide file tree
Showing 9 changed files with 909 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ class Asset {
}
}

static Asset getImgAsset() {
static Asset getImgAsset(String url = PBSUtils.randomString) {
new Asset().tap {
id = 2
required = 1
img = new AssetImage(type: 3, w: PBSUtils.randomNumber, h: PBSUtils.randomNumber)
img = new AssetImage(type: 3, w: PBSUtils.randomNumber, h: PBSUtils.randomNumber, url: url)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package org.prebid.server.functional.model.request.auction

import com.fasterxml.jackson.annotation.JsonProperty
import groovy.transform.ToString

@ToString(includeNames = true, ignoreNulls = true)
class Banner {

List<Format> format
Integer w
Integer h
@JsonProperty("w")
Integer weight
@JsonProperty("h")
Integer height
List<Integer> btype
List<Integer> battr
Integer pos
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
package org.prebid.server.functional.model.request.auction

import com.fasterxml.jackson.annotation.JsonProperty
import groovy.transform.ToString

@ToString(includeNames = true, ignoreNulls = true)
class Format {

Integer w
Integer h
Integer wratio
Integer hratio
Integer wmin
@JsonProperty("w")
Integer weight
@JsonProperty("h")
Integer height
@JsonProperty("wratio")
Integer weightRatio
@JsonProperty("hratio")
Integer heightRatio
@JsonProperty("wmin")
Integer weightMin

static Format getDefaultFormat() {
new Format().tap {
w = 300
h = 250
weight = 300
height = 250
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.prebid.server.functional.model.request.auction

import com.fasterxml.jackson.annotation.JsonProperty
import groovy.transform.EqualsAndHashCode
import groovy.transform.ToString

Expand All @@ -14,8 +15,10 @@ class Video {
Integer maxseq
Integer poddur
List<Integer> protocols
Integer w
Integer h
@JsonProperty("w")
Integer weight
@JsonProperty("h")
Integer height
Integer podid
Integer podseq
List<Integer> rqddurs
Expand All @@ -42,6 +45,6 @@ class Video {
List<Integer> companiontype

static Video getDefaultVideo() {
new Video(mimes: ["video/mp4"], w: 300, h: 200)
new Video(mimes: ["video/mp4"], weight: 300, height: 200)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.prebid.server.functional.model.response.auction

import com.fasterxml.jackson.annotation.JsonProperty
import groovy.transform.EqualsAndHashCode
import groovy.transform.ToString
import org.prebid.server.functional.model.request.auction.Asset
Expand Down Expand Up @@ -31,14 +32,19 @@ class Bid implements ObjectMapperWrapper {
List<Integer> apis
Integer api
Integer protocol
Integer qagmediarating
@JsonProperty("qagmediarating")
Integer qagMediaRating
String language
String langb
String dealid
Integer w
Integer h
Integer wratio
Integer hratio
@JsonProperty("w")
Integer weight
@JsonProperty("h")
Integer height
@JsonProperty("wratio")
Integer weightRatio
@JsonProperty("hratio")
Integer heightRatio
Integer exp
Integer dur
Integer mtype
Expand All @@ -55,8 +61,8 @@ class Bid implements ObjectMapperWrapper {
impid = imp.id
price = PBSUtils.getRandomPrice()
crid = 1
h = imp.banner && imp.banner.format ? imp.banner.format.first().h : null
w = imp.banner && imp.banner.format ? imp.banner.format.first().w : null
height = imp.banner && imp.banner.format ? imp.banner.format.first().height : null
weight = imp.banner && imp.banner.format ? imp.banner.format.first().weight : null
if (imp.nativeObj || imp.video) {
adm = new Adm(assets: [Asset.defaultAsset])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Bidder extends NetworkScaffolding {
def formatNode = it.get("banner") != null ? it.get("banner").get("format") : null
new Imp(id: it.get("id").asText(),
banner: formatNode != null
? new Banner(format: [new Format(w: formatNode.first().get("w").asInt(), h: formatNode.first().get("h").asInt())])
? new Banner(format: [new Format(weight: formatNode.first().get("w").asInt(), height: formatNode.first().get("h").asInt())])
: null)}
def bidRequest = new BidRequest(id: id, imp: imps)
def response = BidResponse.getDefaultBidResponse(bidRequest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class AmpSpec extends BaseSpec {
then: "Response should contain information from stored response"
def price = storedAuctionResponse.bid[0].price
assert response.targeting["hb_pb"] == getRoundedTargetingValueWithDefaultPrecision(price)
assert response.targeting["hb_size"] == "${storedAuctionResponse.bid[0].w}x${storedAuctionResponse.bid[0].h}"
assert response.targeting["hb_size"] == "${storedAuctionResponse.bid[0].weight}x${storedAuctionResponse.bid[0].height}"

and: "PBS not send request to bidder"
assert bidder.getRequestCount(ampStoredRequest.id) == 0
Expand Down Expand Up @@ -122,8 +122,8 @@ class AmpSpec extends BaseSpec {
assert bidderRequest.site?.page == ampRequest.curl
assert bidderRequest.site?.publisher?.id == ampRequest.account.toString()
assert bidderRequest.imp[0]?.tagId == ampRequest.slot
assert bidderRequest.imp[0]?.banner?.format*.h == [ampRequest.h, msH]
assert bidderRequest.imp[0]?.banner?.format*.w == [ampRequest.w, msW]
assert bidderRequest.imp[0]?.banner?.format*.height == [ampRequest.h, msH]
assert bidderRequest.imp[0]?.banner?.format*.weight == [ampRequest.w, msW]
assert bidderRequest.regs?.gdpr == (ampRequest.gdprApplies ? 1 : 0)
}

Expand All @@ -150,8 +150,8 @@ class AmpSpec extends BaseSpec {
then: "Bidder request should contain parameters from request"
def bidderRequest = bidder.getBidderRequest(ampStoredRequest.id)

assert bidderRequest.imp[0]?.banner?.format*.h == [ampRequest.oh]
assert bidderRequest.imp[0]?.banner?.format*.w == [ampRequest.ow]
assert bidderRequest.imp[0]?.banner?.format*.height == [ampRequest.oh]
assert bidderRequest.imp[0]?.banner?.format*.weight == [ampRequest.ow]
}

def "PBS should take parameters from the stored request when it's not specified in the request"() {
Expand All @@ -176,8 +176,8 @@ class AmpSpec extends BaseSpec {
assert bidderRequest.site?.page == ampStoredRequest.site.page
assert bidderRequest.site?.publisher?.id == ampStoredRequest.site.publisher.id
assert !bidderRequest.imp[0]?.tagId
assert bidderRequest.imp[0]?.banner?.format[0]?.h == ampStoredRequest.imp[0].banner.format[0].h
assert bidderRequest.imp[0]?.banner?.format[0]?.w == ampStoredRequest.imp[0].banner.format[0].w
assert bidderRequest.imp[0]?.banner?.format[0]?.height == ampStoredRequest.imp[0].banner.format[0].height
assert bidderRequest.imp[0]?.banner?.format[0]?.weight == ampStoredRequest.imp[0].banner.format[0].weight
assert bidderRequest.regs?.gdpr == ampStoredRequest.regs.ext.gdpr
}
}
Loading

0 comments on commit 0b89797

Please sign in to comment.