Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions adapters/smilewanted/smilewanted.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,27 @@ type adapter struct {
}

func (a *adapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
var errs []error

// Extract zoneId from the first impression if available
var zoneId string
if len(request.Imp) > 0 {
// Parse imp.ext
var bidderExt adapters.ExtImpBidder
if err := jsonutil.Unmarshal(request.Imp[0].Ext, &bidderExt); err == nil {
// Parse bidderExt.Bidder to get zoneId
var smilewantedExt openrtb_ext.ExtImpSmilewanted
if err := jsonutil.Unmarshal(bidderExt.Bidder, &smilewantedExt); err == nil {
zoneId = smilewantedExt.ZoneId
}
}
}

// Build the endpoint URL with zoneId
endpoint := a.URI
if zoneId != "" {
endpoint = a.URI + zoneId
}

request.AT = 1 //Defaulting to first price auction for all prebid requests

Expand All @@ -36,11 +57,11 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.E

return []*adapters.RequestData{{
Method: "POST",
Uri: a.URI,
Uri: endpoint,
Body: reqJSON,
Headers: headers,
ImpIDs: openrtb_ext.GetImpIDs(request.Imp),
}}, []error{}
}}, errs
}

func (a *adapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) {
Expand Down
58 changes: 57 additions & 1 deletion adapters/smilewanted/smilewanted_test.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,76 @@
package smilewanted

import (
"encoding/json"
"math"
"net/http"
"testing"

"github.com/prebid/openrtb/v20/openrtb2"
"github.com/prebid/prebid-server/v3/adapters"
"github.com/prebid/prebid-server/v3/adapters/adapterstest"
"github.com/prebid/prebid-server/v3/config"
"github.com/prebid/prebid-server/v3/openrtb_ext"
"github.com/stretchr/testify/assert"
)

func TestJsonSamples(t *testing.T) {
bidder, buildErr := Builder(openrtb_ext.BidderSmileWanted, config.Adapter{
Endpoint: "http://example.com"}, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"})
Endpoint: "http://example.com/go/"}, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"})

if buildErr != nil {
t.Fatalf("Builder returned unexpected error %v", buildErr)
}

adapterstest.RunJSONBidderTest(t, "smilewantedtest", bidder)
}

// TestMakeRequestsJSONMarshalError tests the error handling when JSON marshalling fails
func TestMakeRequestsJSONMarshalError(t *testing.T) {
bidder := &adapter{
URI: "http://example.com/go/",
}

// Create a request with a float value that cannot be marshalled to JSON (NaN)
request := &openrtb2.BidRequest{
ID: "test-request-id",
Imp: []openrtb2.Imp{{
ID: "test-imp-id",
BidFloor: math.NaN(), // NaN cannot be marshalled to JSON
Ext: json.RawMessage(`{"bidder": {"zoneId": "test"}}`),
}},
}

_, errs := bidder.MakeRequests(request, &adapters.ExtraRequestInfo{})
assert.NotNil(t, errs)
assert.Len(t, errs, 1)
assert.Contains(t, errs[0].Error(), "Json not encoded")
}

// TestMakeBidsJSONUnmarshalError tests the error handling when unmarshalling external request fails
func TestMakeBidsJSONUnmarshalError(t *testing.T) {
bidder := &adapter{
URI: "http://example.com/go/",
}

internalRequest := &openrtb2.BidRequest{
ID: "test-request-id",
Imp: []openrtb2.Imp{{
ID: "test-imp-id",
}},
}

// Create external request with invalid JSON that will fail unmarshalling
externalRequest := &adapters.RequestData{
Body: []byte(`{invalid json}`),
}

response := &adapters.ResponseData{
StatusCode: http.StatusOK,
Body: []byte(`{"id":"test-response-id","seatbid":[{"bid":[{"id":"test-bid-id","impid":"test-imp-id","price":1.0}]}]}`),
}

_, errs := bidder.MakeBids(internalRequest, externalRequest, response)
assert.NotNil(t, errs)
assert.Len(t, errs, 1)
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"mockBidRequest": {
"id": "test-request-id",
"at": 1,
"imp": [
{
"id": "test-imp-id",
"at" : 1,
"banner": {
"format": [
{
Expand All @@ -25,10 +25,10 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "http://example.com",
"uri": "http://example.com/go/zone_code_test_display",
"body": {
"id": "test-request-id",
"at" : 1,
"at": 1,
"imp": [
{
"id": "test-imp-id",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"mockBidRequest": {
"id": "test-request-id",
"at": 1,
"imp": [
{
"id": "test-imp-id",
Expand All @@ -22,7 +23,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "http://example.com",
"uri": "http://example.com/go/zone_code_test_video",
"body": {
"id": "test-request-id",
"at": 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"mockBidRequest": {
"id": "test-request-id",
"at": 1,
"imp": [
{
"id": "test-imp-id",
"at" : 1,
"banner": {
"format": [
{
Expand All @@ -24,10 +24,10 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "http://example.com",
"uri": "http://example.com/go/zone_code_test_display",
"body": {
"id": "test-request-id",
"at" : 1,
"at": 1,
"imp": [
{
"id": "test-imp-id",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"banner": {
"w": 300,
"h": 250
},
"ext": {
"bidder": {
"zoneId": "testzone"
}
}
}
]
},
"httpCalls": [
{
"expectedRequest": {
"uri": "http://example.com/go/testzone",
"body": {
"id": "test-request-id",
"at": 1,
"imp": [
{
"id": "test-imp-id",
"banner": {
"w": 300,
"h": 250
},
"ext": {
"bidder": {
"zoneId": "testzone"
}
}
}
]
},
"impIDs": ["test-imp-id"]
},
"mockResponse": {
"status": 200,
"body": "invalid json response body"
}
}
],
"expectedMakeBidsErrors": [
{
"value": "Bad server response: expect { or n, but found \".",
"comparison": "literal"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"mockBidRequest": {
"id": "test-request-id",
"at": 1,
"imp": [
{
"id": "test-imp-id",
"at" : 1,
"banner": {
"format": [
{
Expand All @@ -25,10 +25,10 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "http://example.com",
"uri": "http://example.com/go/zone_code_test_display",
"body": {
"id": "test-request-id",
"at" : 1,
"at": 1,
"imp": [
{
"id": "test-imp-id",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"mockBidRequest": {
"id": "test-request-id",
"at": 1,
"imp": [
{
"id": "test-imp-id",
"at" : 1,
"banner": {
"format": [
{
Expand All @@ -25,10 +25,10 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "http://example.com",
"uri": "http://example.com/go/zone_code_test_display",
"body": {
"id": "test-request-id",
"at" : 1,
"at": 1,
"imp": [
{
"id": "test-imp-id",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"mockBidRequest": {
"id": "test-request-id",
"at": 1,
"imp": [
{
"id": "test-imp-id",
"at" : 1,
"banner": {
"format": [
{
Expand All @@ -25,10 +25,10 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "http://example.com",
"uri": "http://example.com/go/zone_code_test_display",
"body": {
"id": "test-request-id",
"at" : 1,
"at": 1,
"imp": [
{
"id": "test-imp-id",
Expand Down
Loading
Loading