Skip to content

Commit

Permalink
Using JSON framework for unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
sachin-pubmatic committed Feb 11, 2021
1 parent ce8d2e2 commit facb87b
Show file tree
Hide file tree
Showing 2 changed files with 159 additions and 35 deletions.
35 changes: 0 additions & 35 deletions adapters/pubmatic/pubmatic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
"github.com/prebid/prebid-server/openrtb_ext"
"github.com/prebid/prebid-server/pbs"
"github.com/prebid/prebid-server/usersync"

"github.com/stretchr/testify/assert"
)

func TestJsonSamples(t *testing.T) {
Expand Down Expand Up @@ -730,36 +728,3 @@ func TestGetBidTypeForUnsupportedCode(t *testing.T) {
t.Errorf("Expected Bid Type value was: %v, actual value is: %v", openrtb_ext.BidTypeBanner, actualBidTypeValue)
}
}

func TestMakeRequestsTrimsPubID(t *testing.T) {
var a PubmaticAdapter
a.URI = "http://test.com/openrtb2"

var bidderExt adapters.ExtImpBidder
extImpPubMatic := openrtb_ext.ExtImpPubmatic{}
extImpPubMatic.PublisherId = " 5890 "
bidderExt.Bidder, _ = json.Marshal(extImpPubMatic)
extRaw, _ := json.Marshal(bidderExt)

var w, h uint64
w = 300
h = 250
var impression = openrtb.Imp{
Banner: &openrtb.Banner{
W: &w,
H: &h,
},
Ext: extRaw,
}
request := &openrtb.BidRequest{
Imp: []openrtb.Imp{impression},
Site: &openrtb.Site{
Publisher: &openrtb.Publisher{},
},
}
a.MakeRequests(request, nil)

updatedPubID := request.Site.Publisher.ID

assert.Equal(t, "5890", updatedPubID, "Publisher.ID field should be trimmed")
}
159 changes: 159 additions & 0 deletions adapters/pubmatic/pubmatictest/supplemental/trimPublisherID.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
}
]
},
"ext": {
"bidder": {
"adSlot": "AdTag_Div1@300x250",
"publisherId": " 999 ",
"keywords": [
{
"key": "pmZoneID",
"value": [
"Zone1",
"Zone2"
]
},
{
"key": "preference",
"value": [
"sports",
"movies"
]
}
],
"wrapper": {
"version": 1,
"profile": 5123
}
}
}
}
],
"device": {
"ua": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"
},
"site": {
"id": "siteID",
"publisher": {
"id": "1234"
}
}
},
"httpCalls": [
{
"expectedRequest": {
"uri": "https://hbopenbid.pubmatic.com/translator?source=prebid-server",
"body": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"tagid": "AdTag_Div1",
"banner": {
"format": [
{
"w": 300,
"h": 250
}
],
"h": 250,
"w": 300
},
"ext": {
"pmZoneID": "Zone1,Zone2",
"preference": "sports,movies"
}
}
],
"device": {
"ua": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"
},
"site": {
"id": "siteID",
"publisher": {
"id": "999"
}
},
"ext": {
"wrapper": {
"profile": 5123,
"version": 1
}
}
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"seatbid": [
{
"seat": "958",
"bid": [
{
"id": "7706636740145184841",
"impid": "test-imp-id",
"price": 0.500000,
"adid": "29681110",
"adm": "some-test-ad",
"adomain": [
"pubmatic.com"
],
"crid": "29681110",
"h": 250,
"w": 300,
"dealid": "test deal",
"ext": {
"dspid": 6,
"deal_channel": 1
}
}
]
}
],
"bidid": "5778926625248726496",
"cur": "USD"
}
}
}
],
"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "7706636740145184841",
"impid": "test-imp-id",
"price": 0.5,
"adid": "29681110",
"adm": "some-test-ad",
"adomain": [
"pubmatic.com"
],
"crid": "29681110",
"w": 300,
"h": 250,
"dealid": "test deal",
"ext": {
"dspid": 6,
"deal_channel": 1
}
},
"type": "banner"
}
]
}
]
}

0 comments on commit facb87b

Please sign in to comment.