Skip to content

Commit

Permalink
Fix json test framework to include BidVideo
Browse files Browse the repository at this point in the history
There are a few tests that do not specify `primary_category` and would have failed; we can update the tests or update the structure. Here I update the structure assuming that the tests show the intention.
  • Loading branch information
laurb9 committed Jul 30, 2024
1 parent ed3e4a1 commit 588862b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
19 changes: 16 additions & 3 deletions adapters/adapterstest/test_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

// ---------------------------------------
Expand Down Expand Up @@ -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.
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions openrtb_ext/bid.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 588862b

Please sign in to comment.