Skip to content

Commit

Permalink
requested changes & added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ah-tappx committed Oct 29, 2019
1 parent c0b3c56 commit 1ca51f1
Show file tree
Hide file tree
Showing 15 changed files with 187 additions and 36 deletions.
4 changes: 2 additions & 2 deletions adapters/tappx/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ func TestInvalidParams(t *testing.T) {
}

var validParams = []string{
`{"tappxkey":"pub-12345-android-9876", "endpoint":"ZZ1INTERNALTEST149147915", "host":"test.tappx.com/"}`,
`{"tappxkey":"pub-12345-android-9876", "endpoint":"ZZ1INTERNALTEST149147915", "host":"test.tappx.com/", "bidfloor":0.5}`,
`{"tappxkey":"pub-12345-android-9876", "endpoint":"ZZ1INTERNALTEST149147915", "host":"test.tappx.com"}`,
`{"tappxkey":"pub-12345-android-9876", "endpoint":"ZZ1INTERNALTEST149147915", "host":"test.tappx.com", "bidfloor":0.5}`,
}

var invalidParams = []string{
Expand Down
37 changes: 24 additions & 13 deletions adapters/tappx/tappx.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import (
"github.com/prebid/prebid-server/macros"
"github.com/prebid/prebid-server/openrtb_ext"
"net/http"
"net/url"
"strconv"
"text/template"
"time"
)

const TAPPX_BIDDER_VERSION = "1.1"
const TYPE_CNN = "prebid"

type TappxAdapter struct {
http *adapters.HTTPAdapter
Expand All @@ -35,13 +37,6 @@ func NewTappxBidder(client *http.Client, endpointTemplate string) *TappxAdapter
}
}

type tappxParams struct {
Host string `json:"host"`
TappxKey string `json:"tappxkey"`
Endpoint string `json:"endpoint"`
BidFloor string `json:"bidfloor"`
}

func (a *TappxAdapter) Name() string {
return "tappx"
}
Expand Down Expand Up @@ -129,9 +124,11 @@ func (a *TappxAdapter) buildEndpointURL(params *openrtb_ext.ExtImpTappx, test in
}
}

if reqKey == "" {
thisURI, err := url.Parse(host)

if err != nil {
return "", &errortypes.BadInput{
Message: "Tappx key undefined",
Message: "Malformed URL: check host parameter",
}
}

Expand All @@ -141,16 +138,30 @@ func (a *TappxAdapter) buildEndpointURL(params *openrtb_ext.ExtImpTappx, test in
}
}

thisURI := host + params.Endpoint + "?tappxkey=" + params.TappxKey
thisURI.Path += params.Endpoint

queryParams := url.Values{}

if reqKey == "" {
return "", &errortypes.BadInput{
Message: "Tappx key undefined",
}
}

queryParams.Add("tappxkey", params.TappxKey)

if test == 0 {
t := time.Now().UnixNano() / (int64(time.Millisecond) / int64(time.Nanosecond))
thisURI = thisURI + "&ts=" + strconv.Itoa(int(t))
queryParams.Add("ts", strconv.Itoa(int(t)))
}

thisURI = thisURI + "&v=" + TAPPX_BIDDER_VERSION + "&type_cnn=prebid"
queryParams.Add("v", TAPPX_BIDDER_VERSION)

queryParams.Add("type_cnn", TYPE_CNN)

thisURI.RawQuery = queryParams.Encode()

return thisURI, nil
return thisURI.String(), nil
}

func (a *TappxAdapter) MakeBids(internalRequest *openrtb.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) {
Expand Down
21 changes: 21 additions & 0 deletions adapters/tappx/tappx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,31 @@ package tappx

import (
"github.com/prebid/prebid-server/adapters/adapterstest"
"github.com/prebid/prebid-server/openrtb_ext"
"github.com/stretchr/testify/assert"
"net/http"
"regexp"
"testing"
)

func TestJsonSamples(t *testing.T) {
adapterstest.RunJSONBidderTest(t, "tappxtest", NewTappxBidder(new(http.Client), "https://{{.Host}}"))
}

func TestTsValue(t *testing.T) {
adapter := NewTappxBidder(new(http.Client), "https://{{.Host}}")
var test int
test = 0
var tappxExt openrtb_ext.ExtImpTappx
tappxExt.Host = "example.host.tappx.com"
tappxExt.Endpoint = "DUMMYENDPOINT"
tappxExt.TappxKey = "dummy-tappx-key"

url, err := adapter.buildEndpointURL(&tappxExt, test)

match, err := regexp.MatchString(`&ts=[0-9]{13}`, url)
if err != nil {
//something happened during regex validation
}
assert.True(t, match)
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"bidder": {
"tappxkey": "pub-12345-android-9876",
"endpoint": "PREBIDTEMPLATE",
"host": "test.tappx.com/"
"host": "test.tappx.com"
}
}
}
Expand All @@ -33,7 +33,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "https://test.tappx.com/PREBIDTEMPLATE?tappxkey=pub-12345-android-9876&v=1.1&type_cnn=prebid",
"uri": "https://test.tappx.com/PREBIDTEMPLATE?tappxkey=pub-12345-android-9876&type_cnn=prebid&v=1.1",
"body": {
"id": "0000000000001",
"test": 1,
Expand All @@ -48,7 +48,7 @@
"bidder": {
"tappxkey": "pub-12345-android-9876",
"endpoint": "PREBIDTEMPLATE",
"host": "test.tappx.com/"
"host": "test.tappx.com"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"bidder": {
"tappxkey": "pub-12345-android-9876",
"endpoint": "PREBIDTEMPLATE",
"host": "test.tappx.com/"
"host": "test.tappx.com"
}
}
}
Expand All @@ -35,7 +35,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "https://test.tappx.com/PREBIDTEMPLATE?tappxkey=pub-12345-android-9876&v=1.1&type_cnn=prebid",
"uri": "https://test.tappx.com/PREBIDTEMPLATE?tappxkey=pub-12345-android-9876&type_cnn=prebid&v=1.1",
"body": {
"id": "0000000000001",
"test": 1,
Expand All @@ -52,7 +52,7 @@
"ext": {
"bidder": {
"endpoint": "PREBIDTEMPLATE",
"host": "test.tappx.com/",
"host": "test.tappx.com",
"tappxkey": "pub-12345-android-9876"
}
}
Expand Down
2 changes: 1 addition & 1 deletion adapters/tappx/tappxtest/params/race/banner.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"tappxkey": "pub-12345-android-9876",
"endpoint": "PREBIDTEMPLATE",
"host": "test.tappx.com/"
"host": "test.tappx.com"
}
2 changes: 1 addition & 1 deletion adapters/tappx/tappxtest/params/race/video.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"tappxkey": "pub-12345-android-9876",
"endpoint": "PREBIDTEMPLATE",
"host": "test.tappx.com/"
"host": "test.tappx.com"
}
6 changes: 3 additions & 3 deletions adapters/tappx/tappxtest/supplemental/204status.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"bidder": {
"tappxkey": "pub-12345-android-9876",
"endpoint": "PREBIDTEMPLATE",
"host": "test.tappx.com/"
"host": "test.tappx.com"
}
}
}
Expand All @@ -30,7 +30,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "https://test.tappx.com/PREBIDTEMPLATE?tappxkey=pub-12345-android-9876&v=1.1&type_cnn=prebid",
"uri": "https://test.tappx.com/PREBIDTEMPLATE?tappxkey=pub-12345-android-9876&type_cnn=prebid&v=1.1",
"body": {
"id": "0000000000001",
"test": 1,
Expand All @@ -45,7 +45,7 @@
"bidder": {
"tappxkey": "pub-12345-android-9876",
"endpoint": "PREBIDTEMPLATE",
"host": "test.tappx.com/"
"host": "test.tappx.com"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"ext": {
"bidder": {
"tappxkey": "pub-12345-android-9876",
"host": "test.tappx.com/"
"host": "test.tappx.com"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"ext": {
"bidder": {
"endpoint": "PREBIDTEMPLATE",
"host": "test.tappx.com/"
"host": "test.tappx.com"
}
}
}
Expand Down
119 changes: 119 additions & 0 deletions adapters/tappx/tappxtest/supplemental/bidfloor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
{
"mockBidRequest": {
"id": "0000000000001",
"test": 1,
"imp": [
{
"id": "adunit-1",
"banner": {
"w": 300,
"h": 250
},
"ext": {
"bidder": {
"tappxkey": "pub-12345-android-9876",
"endpoint": "PREBIDTEMPLATE",
"host": "test.tappx.com",
"bidfloor": 1.5
}
}
}
],
"app": {
"id": "app_001",
"bundle": "com.rovio.angrybirds",
"publisher": {
"id": "2"
}
},
"user": {
"buyeruid": "A-38327932832"
}
},

"httpCalls": [
{
"expectedRequest": {
"uri": "https://test.tappx.com/PREBIDTEMPLATE?tappxkey=pub-12345-android-9876&type_cnn=prebid&v=1.1",
"body": {
"id": "0000000000001",
"test": 1,
"imp": [
{
"id": "adunit-1",
"banner": {
"w": 300,
"h": 250
},
"bidfloor": 1.5,
"ext": {
"bidder": {
"tappxkey": "pub-12345-android-9876",
"endpoint": "PREBIDTEMPLATE",
"host": "test.tappx.com",
"bidfloor": 1.5
}
}
}
],
"app": {
"bundle": "com.rovio.angrybirds",
"id": "app_001",
"publisher": {
"id": "2"
}
},
"user": {
"buyeruid": "A-38327932832"
}
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "75472df2-1cb3-4f8e-9a28-10cb95fe05a4",
"seatbid": [{
"bid": [{
"id": "wehM-93KGr0_0_0",
"impid": "adunit-1",
"price": 0.5,
"cid": "3706",
"crid": "19005",
"adid": "19005",
"adm": "<!-- admarkup -->",
"cat": ["IAB2"],
"adomain": ["test.com"],
"h": 250,
"w": 300
}]
}],
"bidid": "wehM-93KGr0"
}
}
}
],

"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "wehM-93KGr0_0_0",
"impid": "adunit-1",
"price": 0.5,
"adm": "<!-- admarkup -->",
"adid": "19005",
"adomain": ["test.com"],
"cid": "3706",
"crid": "19005",
"w": 300,
"h": 250,
"cat": ["IAB2"]
},
"type": "banner"
}
]
}
]
}
6 changes: 3 additions & 3 deletions adapters/tappx/tappxtest/supplemental/http-err-status.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"bidder": {
"tappxkey": "pub-12345-android-9876",
"endpoint": "PREBIDTEMPLATE",
"host": "test.tappx.com/"
"host": "test.tappx.com"
}
}
}
Expand All @@ -30,7 +30,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "https://test.tappx.com/PREBIDTEMPLATE?tappxkey=pub-12345-android-9876&v=1.1&type_cnn=prebid",
"uri": "https://test.tappx.com/PREBIDTEMPLATE?tappxkey=pub-12345-android-9876&type_cnn=prebid&v=1.1",
"body": {
"id": "0000000000001",
"test": 1,
Expand All @@ -45,7 +45,7 @@
"bidder": {
"tappxkey": "pub-12345-android-9876",
"endpoint": "PREBIDTEMPLATE",
"host": "test.tappx.com/"
"host": "test.tappx.com"
}
}
}
Expand Down
Loading

0 comments on commit 1ca51f1

Please sign in to comment.