Skip to content

Commit

Permalink
tests cleanup
Browse files Browse the repository at this point in the history
use of request copy for makeRequests
  • Loading branch information
xdevel committed Jul 3, 2024
1 parent 58a4f96 commit cab0d02
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 602 deletions.
31 changes: 15 additions & 16 deletions adapters/displayio/displayio.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import (
"encoding/json"
"errors"
"fmt"
"net/http"
"text/template"

"github.com/prebid/openrtb/v20/openrtb2"
"github.com/prebid/prebid-server/v2/adapters"
"github.com/prebid/prebid-server/v2/config"
"github.com/prebid/prebid-server/v2/errortypes"
"github.com/prebid/prebid-server/v2/macros"
"github.com/prebid/prebid-server/v2/openrtb_ext"
"net/http"
"text/template"
)

type adapter struct {
Expand All @@ -30,14 +31,12 @@ func (adapter *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *
headers.Add("Accept", "application/json")
headers.Add("x-openrtb-version", "2.5")

var requestExt map[string]interface{}
var dioExt reqDioExt
result := make([]*adapters.RequestData, 0, len(request.Imp))
errs := make([]error, 0, len(request.Imp))

impressions := request.Imp
result := make([]*adapters.RequestData, 0, len(impressions))
errs := make([]error, 0, len(impressions))
for _, impression := range request.Imp {
var requestExt map[string]interface{}

for _, impression := range impressions {
if impression.BidFloor == 0 {
errs = append(errs, &errortypes.BadInput{
Message: "BidFloor should be defined",
Expand Down Expand Up @@ -81,23 +80,25 @@ func (adapter *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *
continue
}

dioExt = reqDioExt{PlacementId: impressionExt.PlacementId, InventoryId: impressionExt.InventoryId}
dioExt := reqDioExt{PlacementId: impressionExt.PlacementId, InventoryId: impressionExt.InventoryId}

requestCopy := *request

err = json.Unmarshal(request.Ext, &requestExt)
err = json.Unmarshal(requestCopy.Ext, &requestExt)
if err != nil {
requestExt = make(map[string]interface{})
}

requestExt["displayio"] = dioExt

request.Ext, err = json.Marshal(requestExt)
requestCopy.Ext, err = json.Marshal(requestExt)
if err != nil {
errs = append(errs, err)
continue
}

request.Imp = []openrtb2.Imp{impression}
body, err := json.Marshal(request)
requestCopy.Imp = []openrtb2.Imp{impression}
body, err := json.Marshal(requestCopy)
if err != nil {
errs = append(errs, err)
continue
Expand All @@ -113,12 +114,10 @@ func (adapter *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *
Uri: url,
Body: body,
Headers: headers,
ImpIDs: openrtb_ext.GetImpIDs(request.Imp),
ImpIDs: openrtb_ext.GetImpIDs(requestCopy.Imp),
})
}

request.Imp = impressions

if len(result) == 0 {
return nil, errs
}
Expand Down
7 changes: 3 additions & 4 deletions adapters/displayio/displayio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ package displayio
import (
"testing"

"github.com/prebid/prebid-server/v2/adapters/adapterstest"
"github.com/prebid/prebid-server/v2/config"
"github.com/prebid/prebid-server/v2/openrtb_ext"

"github.com/prebid/prebid-server/v2/adapters/adapterstest"
)

func TestJsonSamples(t *testing.T) {
bidder, buildErr := Builder(openrtb_ext.BidderDisplayio,
config.Adapter{Endpoint: "https://prebid.display.io/?publisher={{.PublisherID}}"},
config.Server{ExternalUrl: "https://prebid.display.io/?publisher=101"},
config.Adapter{Endpoint: "https://adapter.endpoint/?macro={{.PublisherID}}"},
config.Server{ExternalUrl: "https://server.endpoint/"},
)

if buildErr != nil {
Expand Down
153 changes: 10 additions & 143 deletions adapters/displayio/displayiotest/exemplary/multi-format.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,12 @@
"mockBidRequest": {
"id": "requestId10111011101110111011",
"app": {
"bundle": "displayio101",
"cat": [
"IAB1"
],
"id": "1011",
"name": "Display.io 101",
"pagecat": [
"IAB1"
],
"publisher": {
"id": "1101"
},
"storeurl": "https://apps.apple.com/app/id1000000000"
"id": "1011"
},
"at": 2,
"cur": [
"USD"
],
"imp": [
{
"id": "impId10111011101110111011",
"tagid": "1011",
"secure": 1,
"ext": {
"bidder": {
"placementId": "1011",
Expand All @@ -37,10 +20,6 @@
{
"w": 300,
"h": 250
},
{
"w": 320,
"h": 50
}
]
},
Expand All @@ -58,54 +37,21 @@
"bidfloor": 0.5,
"bidfloorcur": "USD"
}
],
"regs": {
"ext": {
"gdpr": 0
}
},
"source": {},
"tmax": 1000,
"user": {
"id": "user10111011101110111011"
},
"ext": {
"displayio": {
"placementId": "1011",
"inventoryId": "1011"
}
}
]
},
"httpCalls": [
{
"expectedRequest": {
"uri": "https://prebid.display.io/?publisher=101",
"uri": "https://adapter.endpoint/?macro=101",
"body": {
"id": "requestId10111011101110111011",
"app": {
"bundle": "displayio101",
"cat": [
"IAB1"
],
"id": "1011",
"name": "Display.io 101",
"pagecat": [
"IAB1"
],
"publisher": {
"id": "1101"
},
"storeurl": "https://apps.apple.com/app/id1000000000"
"id": "1011"
},
"at": 2,
"cur": [
"USD"
],
"imp": [
{
"id": "impId10111011101110111011",
"tagid": "1011",
"secure": 1,
"ext": {
"bidder": {
"placementId": "1011",
Expand All @@ -118,10 +64,6 @@
{
"w": 300,
"h": 250
},
{
"w": 320,
"h": 50
}
]
},
Expand All @@ -140,16 +82,6 @@
"bidfloorcur": "USD"
}
],
"regs": {
"ext": {
"gdpr": 0
}
},
"source": {},
"tmax": 1000,
"user": {
"id": "user10111011101110111011"
},
"ext": {
"displayio": {
"placementId": "1011",
Expand All @@ -168,57 +100,24 @@
"bidid": "5778926625248726496",
"seatbid": [
{
"seat": "906295",
"seat": "seat1",
"bid": [
{
"id": "12345",
"impid": "impId10111011101110111011",
"price": 0.01,
"nurl": "http://appsrv.displayio.loc/imp?msessId=requestId10111011101110111011&p=1011&app=1011&metric=nurl&amw=${AUCTION_MIN_TO_WIN}",
"lurl": "http://appsrv.displayio.loc/imp?msessId=requestId10111011101110111011&p=1011&app=1011&metric=lurl&amw=${AUCTION_MIN_TO_WIN}&lr=${AUCTION_LOSS}",
"adm": "<html><body style=\"margin: 0;background-color: black; height:100%;\">\r\n\t\t\t\t\t<script src=\"mraid.js\"></script>\r\n\t\t\t\t\t<img id=\"img1\" style=\"position: absolute;\r\n\t\t\t\t\t\twidth: 100%; top: 50%;\r\n\t\t\t\t\t\t-webkit-transform: translateY(-50%);\r\n\t\t\t\t\t\ttransform: translateY(-50%);\"\r\n\t\t\t\t\t\tsrc=\"https://ctv.displayio.loc/ctvbins/asset/static/320_480.jpeg\" width=\"100%\"/>\r\n\t\t\t\t\t<script>\r\n\t\t\t\t\t\tdocument.getElementById(\"img1\").addEventListener(\"touchend\", function() {\r\n\t\t\t\t\t\t var img = new Image();\r\n\t\t\t\t\t\t\timg.style = \"display:none;\";\r\n\t\t\t\t\t\t\timg.src = \"\";\r\n\t\t\t\t\t\t document.body.appendChild(img);\r\n\t\t\t\t\t\t mraid.open(\"https://www.display.io\");\r\n\t\t\t\t\t\t})\r\n\t\t\t\t\t</script>\r\n\t\t\t\t\t</body>\r\n\t\t\t\t\t</html>",
"adid": "12235",
"adm": "<html/>",
"adomain": [
"domain.test"
],
"bundle": "io.display",
"cid": "12346",
"crid": "123456",
"tactic": "test",
"cattax": 1,
"cat": [
"IAB4-1"
],
"attr": [
2
],
"api": 7,
"protocol": 3,
"qagmediarating": 1,
"language": "en",
"langb": "en",
"dealid": "test",
"w": 300,
"h": 250,
"wratio": 1,
"hratio": 1,
"dur": 10,
"mtype": 1,
"ext": {
"dio": {
"impMethod": 2,
"key": "NujhVn9bRUSS5P5WwDS/zfvIGIjHSo89KiOazjRPxD4=",
"advertiserName": "",
"impTrackingInView": 90,
"auctionId": "6632f9cbcbe3e"
}
}
"mtype": 1
}
]
}
],
"cur": "USD",
"ext": {}
"cur": "USD"
}
}
}
Expand All @@ -232,45 +131,13 @@
"id": "12345",
"impid": "impId10111011101110111011",
"price": 0.01,
"nurl": "http://appsrv.displayio.loc/imp?msessId=requestId10111011101110111011&p=1011&app=1011&metric=nurl&amw=${AUCTION_MIN_TO_WIN}",
"lurl": "http://appsrv.displayio.loc/imp?msessId=requestId10111011101110111011&p=1011&app=1011&metric=lurl&amw=${AUCTION_MIN_TO_WIN}&lr=${AUCTION_LOSS}",
"adm": "<html><body style=\"margin: 0;background-color: black; height:100%;\">\r\n\t\t\t\t\t<script src=\"mraid.js\"></script>\r\n\t\t\t\t\t<img id=\"img1\" style=\"position: absolute;\r\n\t\t\t\t\t\twidth: 100%; top: 50%;\r\n\t\t\t\t\t\t-webkit-transform: translateY(-50%);\r\n\t\t\t\t\t\ttransform: translateY(-50%);\"\r\n\t\t\t\t\t\tsrc=\"https://ctv.displayio.loc/ctvbins/asset/static/320_480.jpeg\" width=\"100%\"/>\r\n\t\t\t\t\t<script>\r\n\t\t\t\t\t\tdocument.getElementById(\"img1\").addEventListener(\"touchend\", function() {\r\n\t\t\t\t\t\t var img = new Image();\r\n\t\t\t\t\t\t\timg.style = \"display:none;\";\r\n\t\t\t\t\t\t\timg.src = \"\";\r\n\t\t\t\t\t\t document.body.appendChild(img);\r\n\t\t\t\t\t\t mraid.open(\"https://www.display.io\");\r\n\t\t\t\t\t\t})\r\n\t\t\t\t\t</script>\r\n\t\t\t\t\t</body>\r\n\t\t\t\t\t</html>",
"adid": "12235",
"adm": "<html/>",
"adomain": [
"domain.test"
],
"bundle": "io.display",
"cid": "12346",
"crid": "123456",
"tactic": "test",
"cattax": 1,
"cat": [
"IAB4-1"
],
"attr": [
2
],
"api": 7,
"protocol": 3,
"qagmediarating": 1,
"language": "en",
"langb": "en",
"dealid": "test",
"w": 300,
"h": 250,
"wratio": 1,
"hratio": 1,
"dur": 10,
"mtype": 1,
"ext": {
"dio": {
"impMethod": 2,
"key": "NujhVn9bRUSS5P5WwDS/zfvIGIjHSo89KiOazjRPxD4=",
"advertiserName": "",
"impTrackingInView": 90,
"auctionId": "6632f9cbcbe3e"
}
}
"mtype": 1
},
"type": "banner"
}
Expand Down
Loading

0 comments on commit cab0d02

Please sign in to comment.