diff --git a/adapters/33across/33acrosstest/exemplary/multi-imp-banner.json b/adapters/33across/33acrosstest/exemplary/multi-imp-banner.json new file mode 100644 index 00000000000..db03a001526 --- /dev/null +++ b/adapters/33across/33acrosstest/exemplary/multi-imp-banner.json @@ -0,0 +1,354 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "imp": [ + { + "id": "test-imp-id1", + "banner": { + "format": [{"w": 728, "h": 90}] + }, + "ext": { + "bidder": { + "siteId": "fake-site-id", + "productId": "inview" + } + } + }, + { + "id": "test-imp-id2", + "banner": { + "format": [{"w": 728, "h": 90}] + }, + "ext": { + "bidder": { + "siteId": "fake-site-id", + "productId": "inview" + } + } + }, + { + "id": "test-imp-id3", + "banner": { + "format": [{"w": 728, "h": 90}] + }, + "ext": { + "bidder": { + "siteId": "fake-site-id1", + "productId": "inview" + } + } + }, + { + "id": "test-imp-id4", + "banner": { + "format": [{"w": 728, "h": 90}] + }, + "ext": { + "bidder": { + "siteId": "fake-site-id", + "productId": "siab" + } + } + } + ], + "site": {} + }, + + "httpCalls": [ + { + "expectedRequest": { + "uri": "http://ssc.33across.com", + "body": { + "ext": { + "ttx": { + "caller": [ + { + "name": "Prebid-Server", + "version": "n/a" + } + ] + } + }, + "id": "test-request-id", + "imp": [ + { + "id":"test-imp-id1", + "banner": { + "format": [{"w": 728, "h": 90}] + }, + "ext": { + "ttx": { + "prod": "inview", + "zoneid": "fake-site-id" + } + } + }, + { + "id":"test-imp-id2", + "banner": { + "format": [{"w": 728, "h": 90}] + }, + "ext": { + "ttx": { + "prod": "inview", + "zoneid": "fake-site-id" + } + } + } + ], + "site": {} + } + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-id", + "seatbid": [ + { + "seat": "ttx", + "bid": [ + { + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id1", + "price": 0.500000, + "adm": "some-test-ad", + "crid": "crid_10", + "h": 90, + "w": 728, + "ext": { + "ttx": { + "mediaType": "banner" + } + } + }, + { + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id2", + "price": 0.600000, + "adm": "some-test-ad", + "crid": "crid_10", + "h": 90, + "w": 728, + "ext": { + "ttx": { + "mediaType": "banner" + } + } + } + ] + } + ], + "cur": "USD" + } + } + }, + { + "expectedRequest": { + "uri": "http://ssc.33across.com", + "body": { + "ext": { + "ttx": { + "caller": [ + { + "name": "Prebid-Server", + "version": "n/a" + } + ] + } + }, + "id": "test-request-id", + "imp": [ + { + "id":"test-imp-id3", + "banner": { + "format": [{"w": 728, "h": 90}] + }, + "ext": { + "ttx": { + "prod": "inview", + "zoneid": "fake-site-id1" + } + } + } + ], + "site": {} + } + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-id", + "seatbid": [ + { + "seat": "ttx", + "bid": [ + { + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id3", + "price": 0.500000, + "adm": "some-test-ad", + "crid": "crid_10", + "h": 90, + "w": 728, + "ext": { + "ttx": { + "mediaType": "banner" + } + } + } + ] + } + ], + "cur": "USD" + } + } + }, + { + "expectedRequest": { + "uri": "http://ssc.33across.com", + "body": { + "ext": { + "ttx": { + "caller": [ + { + "name": "Prebid-Server", + "version": "n/a" + } + ] + } + }, + "id": "test-request-id", + "imp": [ + { + "id":"test-imp-id4", + "banner": { + "format": [{"w": 728, "h": 90}] + }, + "ext": { + "ttx": { + "prod": "siab", + "zoneid": "fake-site-id" + } + } + } + ], + "site": {} + } + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-id", + "seatbid": [ + { + "seat": "ttx", + "bid": [ + { + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id4", + "price": 0.500000, + "adm": "some-test-ad", + "crid": "crid_10", + "h": 90, + "w": 728, + "ext": { + "ttx": { + "mediaType": "banner" + } + } + } + ] + } + ], + "cur": "USD" + } + } + } + ], + + "expectedBidResponses": [ + { + "currency": "USD", + "bids": [ + { + "bid": { + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id1", + "price": 0.5, + "adm": "some-test-ad", + "crid": "crid_10", + "w": 728, + "h": 90, + "ext": { + "ttx": { + "mediaType": "banner" + } + } + }, + "type": "banner" + }, + { + "bid": { + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id2", + "price": 0.6, + "adm": "some-test-ad", + "crid": "crid_10", + "w": 728, + "h": 90, + "ext": { + "ttx": { + "mediaType": "banner" + } + } + }, + "type": "banner" + } + ] + }, + { + "currency": "USD", + "bids": [ + { + "bid": { + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id3", + "price": 0.5, + "adm": "some-test-ad", + "crid": "crid_10", + "w": 728, + "h": 90, + "ext": { + "ttx": { + "mediaType": "banner" + } + } + }, + "type": "banner" + } + ] + }, + { + "currency": "USD", + "bids": [ + { + "bid": { + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id4", + "price": 0.5, + "adm": "some-test-ad", + "crid": "crid_10", + "w": 728, + "h": 90, + "ext": { + "ttx": { + "mediaType": "banner" + } + } + }, + "type": "banner" + } + ] + } + ] +} diff --git a/adapters/adapterstest/test_json.go b/adapters/adapterstest/test_json.go index 453dccf74eb..6d2533df82a 100644 --- a/adapters/adapterstest/test_json.go +++ b/adapters/adapterstest/test_json.go @@ -223,8 +223,15 @@ func assertMakeRequestsOutput(t *testing.T, filename string, actual []*adapters. if len(expected) != len(actual) { t.Fatalf("%s: MakeRequests had wrong request count. Expected %d, got %d", filename, len(expected), len(actual)) } - for i := 0; i < len(actual); i++ { - diffHttpRequests(t, fmt.Sprintf("%s: httpRequest[%d]", filename, i), actual[i], &(expected[i].Request)) + + for i := 0; i < len(expected); i++ { + var err error + for j := 0; j < len(actual); j++ { + if err = diffHttpRequests(fmt.Sprintf("%s: httpRequest[%d]", filename, i), actual[j], &(expected[i].Request)); err == nil { + break + } + } + assert.NoError(t, err, fmt.Sprintf("%s Expected RequestData was not returned by adapters' MakeRequests() implementation: httpRequest[%d]", filename, i)) } } @@ -275,19 +282,30 @@ func assertMakeBidsOutput(t *testing.T, filename string, bidderResponse *adapter // diffHttpRequests compares the actual HTTP request data to the expected one. // It assumes that the request bodies are JSON -func diffHttpRequests(t *testing.T, description string, actual *adapters.RequestData, expected *httpRequest) { +func diffHttpRequests(description string, actual *adapters.RequestData, expected *httpRequest) error { + if actual == nil { - t.Errorf("Bidders cannot return nil HTTP calls. %s was nil.", description) - return + return fmt.Errorf("Bidders cannot return nil HTTP calls. %s was nil.", description) + } + + if expected.Uri != actual.Uri { + return fmt.Errorf(`%s.uri "%s" does not match expected "%s."`, description, actual.Uri, expected.Uri) } - diffStrings(t, fmt.Sprintf("%s.uri", description), actual.Uri, expected.Uri) if expected.Headers != nil { - actualHeader, _ := json.Marshal(actual.Headers) - expectedHeader, _ := json.Marshal(expected.Headers) - diffJson(t, description, actualHeader, expectedHeader) + actualHeader, err := json.Marshal(actual.Headers) + if err != nil { + return fmt.Errorf(`%s actual.Headers could not be marshalled. Error: %s"`, description, err.Error()) + } + expectedHeader, err := json.Marshal(expected.Headers) + if err != nil { + return fmt.Errorf(`%s expected.Headers could not be marshalled. Error: %s"`, description, err.Error()) + } + if err := diffJson(description, actualHeader, expectedHeader); err != nil { + return err + } } - diffJson(t, description, actual.Body, expected.Body) + return diffJson(description, actual.Body, expected.Body) } func diffBids(t *testing.T, description string, actual *adapters.TypedBid, expected *expectedBid) { @@ -296,60 +314,54 @@ func diffBids(t *testing.T, description string, actual *adapters.TypedBid, expec return } - diffStrings(t, fmt.Sprintf("%s.type", description), string(actual.BidType), string(expected.Type)) - diffOrtbBids(t, fmt.Sprintf("%s.bid", description), actual.Bid, expected.Bid) + assert.Equal(t, string(expected.Type), string(actual.BidType), fmt.Sprintf(`%s.type "%s" does not match expected "%s."`, description, string(actual.BidType), string(expected.Type))) + assert.NoError(t, diffOrtbBids(fmt.Sprintf("%s.bid", description), actual.Bid, expected.Bid)) } // diffOrtbBids compares the actual Bid made by the adapter to the expectation from the JSON file. -func diffOrtbBids(t *testing.T, description string, actual *openrtb2.Bid, expected json.RawMessage) { +func diffOrtbBids(description string, actual *openrtb2.Bid, expected json.RawMessage) error { if actual == nil { - t.Errorf("Bidders cannot return nil Bids. %s was nil.", description) - return + return fmt.Errorf("Bidders cannot return nil Bids. %s was nil.", description) } actualJson, err := json.Marshal(actual) if err != nil { - t.Fatalf("%s failed to marshal actual Bid into JSON. %v", description, err) + return fmt.Errorf("%s failed to marshal actual Bid into JSON. %v", description, err) } - diffJson(t, description, actualJson, expected) -} - -func diffStrings(t *testing.T, description string, actual string, expected string) { - if actual != expected { - t.Errorf(`%s "%s" does not match expected "%s."`, description, actual, expected) - } + return diffJson(description, actualJson, expected) } // diffJson compares two JSON byte arrays for structural equality. It will produce an error if either // byte array is not actually JSON. -func diffJson(t *testing.T, description string, actual []byte, expected []byte) { +func diffJson(description string, actual []byte, expected []byte) error { if len(actual) == 0 && len(expected) == 0 { - return + return nil } if len(actual) == 0 || len(expected) == 0 { - t.Fatalf("%s json diff failed. Expected %d bytes in body, but got %d.", description, len(expected), len(actual)) + return fmt.Errorf("%s json diff failed. Expected %d bytes in body, but got %d.", description, len(expected), len(actual)) } diff, err := gojsondiff.New().Compare(actual, expected) if err != nil { - t.Fatalf("%s json diff failed. %v", description, err) + return fmt.Errorf("%s json diff failed. %v", description, err) } if diff.Modified() { var left interface{} if err := json.Unmarshal(actual, &left); err != nil { - t.Fatalf("%s json did not match, but unmarshalling failed. %v", description, err) + return fmt.Errorf("%s json did not match, but unmarshalling failed. %v", description, err) } printer := formatter.NewAsciiFormatter(left, formatter.AsciiFormatterConfig{ ShowArrayIndex: true, }) output, err := printer.Format(diff) if err != nil { - t.Errorf("%s did not match, but diff formatting failed. %v", description, err) + return fmt.Errorf("%s did not match, but diff formatting failed. %v", description, err) } else { - t.Errorf("%s json did not match expected.\n\n%s", description, output) + return fmt.Errorf("%s json did not match expected.\n\n%s", description, output) } } + return nil } // testMakeRequestsImpl asserts the resulting values of the bidder's `MakeRequests()` implementation