diff --git a/adapters/adapterstest/test_json.go b/adapters/adapterstest/test_json.go index 1c10513919b..78f08421b3d 100644 --- a/adapters/adapterstest/test_json.go +++ b/adapters/adapterstest/test_json.go @@ -226,9 +226,10 @@ type expectedBidResponse struct { } type expectedBid struct { - Bid json.RawMessage `json:"bid"` - Type string `json:"type"` - Seat string `json:"seat"` + Bid json.RawMessage `json:"bid"` + Type string `json:"type"` + Seat string `json:"seat"` + Video json.RawMessage `json:"video,omitempty"` } // --------------------------------------- @@ -342,6 +343,9 @@ func diffBids(t *testing.T, description string, actual *adapters.TypedBid, expec assert.Equal(t, string(expected.Seat), string(actual.Seat), fmt.Sprintf(`%s.seat "%s" does not match expected "%s."`, description, string(actual.Seat), string(expected.Seat))) 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)) + if expected.Video != nil { + assert.NoError(t, diffBidVideo(fmt.Sprintf("%s.video", description), actual.BidVideo, expected.Video)) + } } // diffOrtbBids compares the actual Bid made by the adapter to the expectation from the JSON file. @@ -358,6 +362,15 @@ func diffOrtbBids(description string, actual *openrtb2.Bid, expected json.RawMes return diffJson(description, actualJson, expected) } +func diffBidVideo(description string, actual *openrtb_ext.ExtBidPrebidVideo, expected json.RawMessage) error { + actualJson, err := json.Marshal(actual) + if err != nil { + return fmt.Errorf("%s failed to marshal actual Bid Video into JSON. %v", description, err) + } + + return diffJson(description, actualJson, []byte(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(description string, actual []byte, expected []byte) error { diff --git a/openrtb_ext/bid.go b/openrtb_ext/bid.go index 7d3dcbd70bf..c02e0d23c23 100644 --- a/openrtb_ext/bid.go +++ b/openrtb_ext/bid.go @@ -74,8 +74,8 @@ type ExtBidPrebidMeta struct { // ExtBidPrebidVideo defines the contract for bidresponse.seatbid.bid[i].ext.prebid.video type ExtBidPrebidVideo struct { - Duration int `json:"duration"` - PrimaryCategory string `json:"primary_category"` + Duration int `json:"duration,omitempty"` + PrimaryCategory string `json:"primary_category,omitempty"` } // ExtBidPrebidEvents defines the contract for bidresponse.seatbid.bid[i].ext.prebid.events