Skip to content

Commit

Permalink
ORTB 2.6: Add auction endpoint test and allow capturing validated req…
Browse files Browse the repository at this point in the history
…uest (#4013)
  • Loading branch information
bsardo authored Oct 26, 2024
1 parent 88630ff commit 9364cb8
Show file tree
Hide file tree
Showing 3 changed files with 202 additions and 1 deletion.
10 changes: 9 additions & 1 deletion endpoints/openrtb2/auction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,19 @@ func runJsonBasedTest(t *testing.T, filename, desc string) {
cfg.MarshalAccountDefaults()
test.endpointType = OPENRTB_ENDPOINT

auctionEndpointHandler, _, mockBidServers, mockCurrencyRatesServer, err := buildTestEndpoint(test, cfg)
auctionEndpointHandler, ex, mockBidServers, mockCurrencyRatesServer, err := buildTestEndpoint(test, cfg)
if assert.NoError(t, err) {
assert.NotPanics(t, func() { runEndToEndTest(t, auctionEndpointHandler, test, fileData, filename) }, filename)
}

if test.ExpectedValidatedBidReq != nil {
// compare as json to ignore whitespace and ext field ordering
actualJson, err := jsonutil.Marshal(ex.actualValidatedBidReq)
if assert.NoError(t, err, "Error converting actual bid request to json. Test file: %s", filename) {
assert.JSONEq(t, string(test.ExpectedValidatedBidReq), string(actualJson), "Not the expected validated request. Test file: %s", filename)
}
}

// Close servers regardless if the test case was run or not
for _, mockBidServer := range mockBidServers {
mockBidServer.Close()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
{
"description": "Request with all 2.5 ext fields that were moved into 2.6 ortb fields",
"config": {
"mockBidders": [
{
"bidderName": "appnexus",
"currency": "USD",
"price": 15
}
]
},
"mockBidRequest": {
"id": "some-request-id",
"site": {
"page": "prebid.org"
},
"imp": [
{
"id": "some-impression-id",
"banner": {
"format": [
{
"w": 300,
"h": 600
}
]
},
"ext": {
"prebid": {
"bidder": {
"appnexus": {
"placementId": 12883451
}
},
"is_rewarded_inventory": 1
}
}
}
],
"regs": {
"ext": {
"gdpr": 1,
"us_privacy": "1YYY"
}
},
"user": {
"ext": {
"consent": "some-consent-string",
"eids": [
{
"source": "source",
"uids": [
{
"id": "1",
"atype": 1,
"ext": {}
},
{
"id": "1",
"atype": 1,
"ext": {}
}
],
"ext": {}
}
]
}
},
"source": {
"ext": {
"schain": {
"complete": 1,
"nodes": [
{
"asi": "whatever.com",
"sid": "1234",
"rid": "123-456-7890",
"hp": 1
}
],
"ver": "2.0"
}
}
},
"ext": {}
},
"expectedValidatedBidRequest": {
"id": "some-request-id",
"site": {
"page": "prebid.org",
"ext": {
"amp": 0
}
},
"at": 1,
"device": {
"ip": "192.0.2.1"
},
"imp": [
{
"id": "some-impression-id",
"banner": {
"format": [
{
"w": 300,
"h": 600
}
]
},
"ext": {
"prebid": {
"bidder": {
"appnexus": {
"placementId": 12883451
}
}
}
},
"secure": 1,
"rwdd": 1
}
],
"regs": {
"gdpr": 1,
"us_privacy": "1YYY"
},
"user": {
"consent": "some-consent-string",
"eids": [
{
"source": "source",
"uids": [
{
"id": "1",
"atype": 1,
"ext": {}
},
{
"id": "1",
"atype": 1,
"ext": {}
}
],
"ext": {}
}
]
},
"source": {
"schain": {
"complete": 1,
"nodes": [
{
"asi": "whatever.com",
"sid": "1234",
"rid": "123-456-7890",
"hp": 1
}
],
"ver": "2.0"
}
}
},
"expectedBidResponse": {
"id": "some-request-id",
"seatbid": [
{
"bid": [
{
"id": "appnexus-bid",
"impid": "some-impression-id",
"price": 15,
"ext": {
"origbidcpm": 15,
"origbidcur": "USD",
"prebid": {
"meta": {
"adaptercode": "appnexus"
},
"type": "banner"
}
}
}
],
"seat": "appnexus"
}
],
"bidid": "test-bid-id",
"cur": "USD",
"nbr": 0
},
"expectedReturnCode": 200
}
1 change: 1 addition & 0 deletions endpoints/openrtb2/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,7 @@ func parseTestData(fileData []byte, testFile string) (testCase, error) {
}

// Get both bid response and error message, if any
parsedTestData.ExpectedValidatedBidReq, _, _, err = jsonparser.Get(fileData, "expectedValidatedBidRequest")
parsedTestData.ExpectedBidResponse, _, _, err = jsonparser.Get(fileData, "expectedBidResponse")
parsedTestData.ExpectedErrorMessage, errEm = jsonparser.GetString(fileData, "expectedErrorMessage")

Expand Down

0 comments on commit 9364cb8

Please sign in to comment.