Skip to content

Commit

Permalink
Test to check expected BidResponse fields are present (#2680)
Browse files Browse the repository at this point in the history
  • Loading branch information
VeronikaSolovei9 authored Apr 6, 2023
1 parent f035f72 commit 8282d94
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions adservertargeting/respdataprocessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"github.com/prebid/openrtb/v17/openrtb3"
"github.com/prebid/prebid-server/openrtb_ext"
"github.com/stretchr/testify/assert"
"reflect"
"strings"
"testing"
)

Expand Down Expand Up @@ -559,3 +561,30 @@ func TestGetRespData(t *testing.T) {
}

}

func TestResponseObjectStructure(t *testing.T) {
// in case BidResponse format will change in next versions this test will show the error
// current implementation is up to date with OpenRTB 2.5 and OpenRTB 2.6 formats
fieldsToCheck := map[string]reflect.Kind{
"id": reflect.String,
"bidid": reflect.String,
"cur": reflect.String,
"customdata": reflect.String,
"nbr": reflect.Pointer,
}

tt := reflect.TypeOf(openrtb2.BidResponse{})
fields := reflect.VisibleFields(tt)

for fieldName, fieldType := range fieldsToCheck {
fieldFound := false
for _, field := range fields {
if fieldName == strings.ToLower(field.Name) {
fieldFound = true
assert.Equal(t, fieldType, field.Type.Kind(), "incorrect type for field: %s", fieldName)
break
}
}
assert.True(t, fieldFound, "field %s is not found in bidResponse object", fieldName)
}
}

0 comments on commit 8282d94

Please sign in to comment.