Skip to content

Commit

Permalink
CR changes: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nickjacob committed Nov 3, 2020
1 parent deb909d commit cade54f
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 66 deletions.
65 changes: 5 additions & 60 deletions adapters/amx/amx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ func TestMakeRequestsApp(t *testing.T) {
assert.Equal(t, "site_publisher_id", body.Site.Publisher.ID)
}

func getRequestBody(requests []*adapters.RequestData) *openrtb.BidRequest {
func getRequestBody(t *testing.T, requests []*adapters.RequestData) *openrtb.BidRequest {
assert.GreaterOrEqual(t, 1, len(requests))

var body openrtb.BidRequest
if err := json.Unmarshal(requests[0].Body, &body); err == nil {
return &body
Expand Down Expand Up @@ -186,10 +188,10 @@ func TestMakeBidVideo(t *testing.T) {
actualAdapterRequests, _ := adapter.MakeRequests(&inputRequest, &adapters.ExtraRequestInfo{})
assert.Len(t, actualAdapterRequests, 1, "expecting 1 request")

body := getRequestBody(actualAdapterRequests)
body := getRequestBody(t, actualAdapterRequests)
assert.NotNil(t, body, "body should be valid JSON")

assert.Len(t, body.Imp, 1, "expecting 1 bid")
assert.Len(t, body.Imp, 1, "expecting 1 Imp")

resps, errs := adapter.MakeBids(body, &adapters.RequestData{}, &adapters.ResponseData{
StatusCode: 200,
Expand Down Expand Up @@ -225,63 +227,6 @@ func TestMakeBidVideo(t *testing.T) {
assert.Equal(t, openrtb_ext.BidTypeVideo, resps.Bids[0].BidType, "the bid should be video type")
}

func TestUserEidsOnly(t *testing.T) {
var w, h int = 300, 250

var width, height uint64 = uint64(w), uint64(h)

adapter := NewAMXBidder(amxTestEndpoint)
imp1 := openrtb.Imp{
ID: "imp1",
Ext: json.RawMessage(defaultImpExt),
Banner: &openrtb.Banner{
W: &width,
H: &height,
Format: []openrtb.Format{
{W: 300, H: 250},
},
}}

inputRequest := openrtb.BidRequest{
Imp: []openrtb.Imp{imp1, imp1, imp1},
Site: &openrtb.Site{
Publisher: &openrtb.Publisher{
ID: "10007",
},
},
User: &openrtb.User{Ext: json.RawMessage(
`{
"eids": [{
"source": "adserver.org",
"uids": [{
"id": "111111111111",
"ext": {
"rtiPartner": "TDID"
}
}]
},{
"source": "example.buid",
"uids": [{
"id": "123456"
}]
}]
}`)},
ID: "1234",
}

actualAdapterRequests, _ := adapter.MakeRequests(&inputRequest, &adapters.ExtraRequestInfo{})
assert.Len(t, actualAdapterRequests, 1, "there should be 1 request")

body := getRequestBody(actualAdapterRequests)
assert.NotNil(t, body, "the generated OpenRTB request is not valid JSON")

userExt := getUserExt(body.User)
assert.NotNil(t, userExt, "the generated user.ext is invalid")

assert.Len(t, userExt.Eids, 2)
assert.Equal(t, "adserver.org", userExt.Eids[0].Source, "the eid source does is incorrect")
}

func TestVideoImpInsertion(t *testing.T) {
var bidResp openrtb.BidResponse
var bid openrtb.Bid
Expand Down
22 changes: 22 additions & 0 deletions adapters/amx/amxtest/exemplary/web-simple.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@
"id": "88de601e-3d98-48e7-81d7-00000000"
}
]
},
{
"source": "adserver.org",
"uids": [
{
"id": "1234567",
"ext": {
"rtiPartner": "TDID"
}
}
]
}
],
"gdpr": 0,
Expand Down Expand Up @@ -164,6 +175,17 @@
"id": "88de601e-3d98-48e7-81d7-00000000"
}
]
},
{
"source": "adserver.org",
"uids": [
{
"id": "1234567",
"ext": {
"rtiPartner": "TDID"
}
}
]
}
],
"gdpr": 0,
Expand Down
2 changes: 1 addition & 1 deletion adapters/amx/amxtest/params/race/display.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"publisher_id":"sample345"}
{"tagId":"sample345"}
2 changes: 1 addition & 1 deletion adapters/amx/amxtest/params/race/video.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"publisher_id": "sample123"}
{"tagId": "sample123"}
4 changes: 2 additions & 2 deletions adapters/amx/usersync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
)

func TestAMXSyncer(t *testing.T) {
syncURL := "http://pbs.amxrtb.com/cchain/0?gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&cb=localhost%2Fsetuid%3Fbidder%3Damx%26uid=%3D"
syncURL := "http://pbs.amxrtb.com/cchain/0?gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&cb=localhost%2Fsetuid%3Fbidder%3Damx%26uid%3D"
syncURLTemplate := template.Must(template.New("sync-template").Parse(syncURL))

syncer := NewAMXSyncer(syncURLTemplate)
syncInfo, err := syncer.GetUsersyncInfo(privacy.Policies{})

assert.NoError(t, err)
assert.Equal(t, "http://pbs.amxrtb.com/cchain/0?gdpr=&gdpr_consent=&cb=localhost%2Fsetuid%3Fbidder%3Damx%26uid=%3D", syncInfo.URL)
assert.Equal(t, "http://pbs.amxrtb.com/cchain/0?gdpr=&gdpr_consent=&cb=localhost%2Fsetuid%3Fbidder%3Damx%26uid%3D", syncInfo.URL)
assert.Equal(t, "redirect", syncInfo.Type)
assert.EqualValues(t, 737, syncer.GDPRVendorID())
assert.Equal(t, false, syncInfo.SupportCORS)
Expand Down
4 changes: 2 additions & 2 deletions static/bidder-params/amx.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"description": "A schema to validate params accepted by the AMX adapter",
"type": "object",
"properties": {
"publisher_id" : {
"tagId" : {
"type": "string",
"description": "Override the site.publisher.id value"
"description": "Set a tagId (overrides site.publisher.id)"
}
}
}

0 comments on commit cade54f

Please sign in to comment.