Skip to content
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

ORTB 2.6: Add auction endpoint test and capture validated request #4013

Merged
merged 1 commit into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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