From ac2f35ca437758af13207e4f10457d92884338e7 Mon Sep 17 00:00:00 2001 From: Avinash Kapre Date: Tue, 19 Nov 2024 16:52:05 +0530 Subject: [PATCH] test6 --- adapters/pubmatic/pubmatic.go | 38 --- adapters/pubmatic/pubmatic_ow.go | 39 +++ adapters/pubmatic/pubmatic_ow_test.go | 414 +++++++++++++++++++++++ adapters/pubmatic/pubmatic_test.go | 413 ---------------------- modules/pubmatic/openwrap/defaultbids.go | 6 +- 5 files changed, 458 insertions(+), 452 deletions(-) diff --git a/adapters/pubmatic/pubmatic.go b/adapters/pubmatic/pubmatic.go index cc9c846442..30fe14c758 100644 --- a/adapters/pubmatic/pubmatic.go +++ b/adapters/pubmatic/pubmatic.go @@ -259,44 +259,6 @@ func (a *PubmaticAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *ad return requestData, errs } -// buildMultiFloorRequests builds multiple requests for each floor value -func (a *PubmaticAdapter) buildMultiFloorRequests(request *openrtb2.BidRequest, impFloorsMap map[string][]float64, cookies []string) ([]*adapters.RequestData, []error) { - requestData := []*adapters.RequestData{} - errs := make([]error, 0, MAX_MULTIFLOORS_PUBMATIC*len(request.Imp)) - - for i := 0; i < MAX_MULTIFLOORS_PUBMATIC; i++ { - isFloorsUpdated := false - newImps := make([]openrtb2.Imp, len(request.Imp)) - copy(newImps, request.Imp) - //TODO-AK: Remove the imp from the request if the floor is not present except for the first floor - for j := range newImps { - floors, ok := impFloorsMap[request.Imp[j].ID] - if !ok || len(floors) <= i { - continue - } - isFloorsUpdated = true - newImps[j].BidFloor = floors[i] - newImps[j].ID = fmt.Sprintf("%s"+multiFloors+"%d", newImps[j].ID, i+1) - } - - if !isFloorsUpdated { - continue - } - - newRequest := *request - newRequest.Imp = newImps - - newRequestData, errData := a.buildAdapterRequest(&newRequest, cookies) - if errData != nil { - errs = append(errs, errData) - } - if len(newRequestData) > 0 { - requestData = append(requestData, newRequestData...) - } - } - return requestData, errs -} - // buildAdapterRequest builds the request for Pubmatic func (a *PubmaticAdapter) buildAdapterRequest(request *openrtb2.BidRequest, cookies []string) ([]*adapters.RequestData, error) { reqJSON, err := json.Marshal(request) diff --git a/adapters/pubmatic/pubmatic_ow.go b/adapters/pubmatic/pubmatic_ow.go index 55285bf8a8..8d44449a46 100644 --- a/adapters/pubmatic/pubmatic_ow.go +++ b/adapters/pubmatic/pubmatic_ow.go @@ -9,6 +9,7 @@ import ( "github.com/buger/jsonparser" "github.com/prebid/openrtb/v20/openrtb2" + "github.com/prebid/prebid-server/v2/adapters" "github.com/prebid/prebid-server/v2/openrtb_ext" ) @@ -109,6 +110,44 @@ func renameTransparencyParamsKey(bidExt []byte) []byte { return bidExt } +// buildMultiFloorRequests builds multiple requests for each floor value +func (a *PubmaticAdapter) buildMultiFloorRequests(request *openrtb2.BidRequest, impFloorsMap map[string][]float64, cookies []string) ([]*adapters.RequestData, []error) { + requestData := []*adapters.RequestData{} + errs := make([]error, 0, MAX_MULTIFLOORS_PUBMATIC*len(request.Imp)) + + for i := 0; i < MAX_MULTIFLOORS_PUBMATIC; i++ { + isFloorsUpdated := false + newImps := make([]openrtb2.Imp, len(request.Imp)) + copy(newImps, request.Imp) + //TODO-AK: Remove the imp from the request if the floor is not present except for the first floor + for j := range newImps { + floors, ok := impFloorsMap[request.Imp[j].ID] + if !ok || len(floors) <= i { + continue + } + isFloorsUpdated = true + newImps[j].BidFloor = floors[i] + newImps[j].ID = fmt.Sprintf("%s"+multiFloors+"%d", newImps[j].ID, i+1) + } + + if !isFloorsUpdated { + continue + } + + newRequest := *request + newRequest.Imp = newImps + + newRequestData, errData := a.buildAdapterRequest(&newRequest, cookies) + if errData != nil { + errs = append(errs, errData) + } + if len(newRequestData) > 0 { + requestData = append(requestData, newRequestData...) + } + } + return requestData, errs +} + func trimSuffixWithPattern(input string) string { return re.ReplaceAllString(input, "") } diff --git a/adapters/pubmatic/pubmatic_ow_test.go b/adapters/pubmatic/pubmatic_ow_test.go index d431973154..9517aa209c 100644 --- a/adapters/pubmatic/pubmatic_ow_test.go +++ b/adapters/pubmatic/pubmatic_ow_test.go @@ -9,6 +9,7 @@ import ( "github.com/prebid/openrtb/v20/openrtb2" "github.com/prebid/prebid-server/v2/adapters" "github.com/prebid/prebid-server/v2/openrtb_ext" + "github.com/prebid/prebid-server/v2/util/ptrutil" "github.com/stretchr/testify/assert" ) @@ -487,6 +488,419 @@ func TestPubmaticMakeBids(t *testing.T) { } } +func TestPubmaticAdapter_buildMultiFloorRequests(t *testing.T) { + type fields struct { + URI string + bidderName string + } + type args struct { + request *openrtb2.BidRequest + impFloorsMap map[string][]float64 + cookies []string + } + tests := []struct { + name string + fields fields + args args + wantRequestData []*adapters.RequestData + wantError []error + }{ + { + name: "request with single imp and single floor", + fields: fields{ + URI: "https://hbopenbid.pubmatic.com/translator?source=prebid-server", + bidderName: "pubmatic", + }, + args: args{ + request: &openrtb2.BidRequest{ + ID: "test-request-id", + App: &openrtb2.App{ + Name: "AutoScout24", + Bundle: "com.autoscout24", + StoreURL: "https://play.google.com/store/apps/details?id=com.autoscout24&hl=fr", + }, + Imp: []openrtb2.Imp{ + { + ID: "test-imp-id", + BidFloor: 0.12, + Banner: &openrtb2.Banner{ + W: ptrutil.ToPtr[int64](300), + H: ptrutil.ToPtr[int64](250), + }, + Ext: json.RawMessage(`{}`), + }, + }, + }, + impFloorsMap: map[string][]float64{ + "test-imp-id": {1.2}, + }, + cookies: []string{"test-cookie"}, + }, + wantRequestData: []*adapters.RequestData{ + { + Method: "POST", + Uri: "https://hbopenbid.pubmatic.com/translator?source=prebid-server", + Body: []byte(`{"id":"test-request-id","imp":[{"id":"test-imp-id_mf1","banner":{"w":300,"h":250},"bidfloor":1.2,"ext":{}}],"app":{"name":"AutoScout24","bundle":"com.autoscout24","storeurl":"https://play.google.com/store/apps/details?id=com.autoscout24\u0026hl=fr"}}`), + Headers: http.Header{ + "Content-Type": []string{"application/json;charset=utf-8"}, + "Accept": []string{"application/json"}, + "Cookie": []string{"test-cookie"}, + }, + ImpIDs: []string{"test-imp-id_mf1"}, + }, + }, + wantError: []error{}, + }, + { + name: "request with single imp and two floors", + fields: fields{ + URI: "https://hbopenbid.pubmatic.com/translator?source=prebid-server", + bidderName: "pubmatic", + }, + args: args{ + request: &openrtb2.BidRequest{ + ID: "test-request-id", + App: &openrtb2.App{ + Name: "AutoScout24", + Bundle: "com.autoscout24", + StoreURL: "https://play.google.com/store/apps/details?id=com.autoscout24&hl=fr", + }, + Imp: []openrtb2.Imp{ + { + ID: "test-imp-id", + BidFloor: 0.12, + Banner: &openrtb2.Banner{ + W: ptrutil.ToPtr[int64](300), + H: ptrutil.ToPtr[int64](250), + }, + Ext: json.RawMessage(`{}`), + }, + }, + }, + impFloorsMap: map[string][]float64{ + "test-imp-id": {1.2, 1.3}, + }, + cookies: []string{"test-cookie"}, + }, + wantRequestData: []*adapters.RequestData{ + { + Method: "POST", + Uri: "https://hbopenbid.pubmatic.com/translator?source=prebid-server", + Body: []byte(`{"id":"test-request-id","imp":[{"id":"test-imp-id_mf1","banner":{"w":300,"h":250},"bidfloor":1.2,"ext":{}}],"app":{"name":"AutoScout24","bundle":"com.autoscout24","storeurl":"https://play.google.com/store/apps/details?id=com.autoscout24\u0026hl=fr"}}`), + Headers: http.Header{ + "Content-Type": []string{"application/json;charset=utf-8"}, + "Accept": []string{"application/json"}, + "Cookie": []string{"test-cookie"}, + }, + ImpIDs: []string{"test-imp-id_mf1"}, + }, + { + Method: "POST", + Uri: "https://hbopenbid.pubmatic.com/translator?source=prebid-server", + Body: []byte(`{"id":"test-request-id","imp":[{"id":"test-imp-id_mf2","banner":{"w":300,"h":250},"bidfloor":1.3,"ext":{}}],"app":{"name":"AutoScout24","bundle":"com.autoscout24","storeurl":"https://play.google.com/store/apps/details?id=com.autoscout24\u0026hl=fr"}}`), + Headers: http.Header{ + "Content-Type": []string{"application/json;charset=utf-8"}, + "Accept": []string{"application/json"}, + "Cookie": []string{"test-cookie"}, + }, + ImpIDs: []string{"test-imp-id_mf2"}, + }, + }, + wantError: []error{}, + }, + { + name: "request with single imp and max multi floors(3)", + fields: fields{ + URI: "https://hbopenbid.pubmatic.com/translator?source=prebid-server", + bidderName: "pubmatic", + }, + args: args{ + request: &openrtb2.BidRequest{ + ID: "test-request-id", + App: &openrtb2.App{ + Name: "AutoScout24", + Bundle: "com.autoscout24", + StoreURL: "https://play.google.com/store/apps/details?id=com.autoscout24&hl=fr", + }, + Imp: []openrtb2.Imp{ + { + ID: "test-imp-id", + BidFloor: 0.12, + Banner: &openrtb2.Banner{ + W: ptrutil.ToPtr[int64](300), + H: ptrutil.ToPtr[int64](250), + }, + Ext: json.RawMessage(`{}`), + }, + }, + }, + impFloorsMap: map[string][]float64{ + "test-imp-id": {1.2, 1.3, 1.4}, + }, + cookies: []string{"test-cookie"}, + }, + wantRequestData: []*adapters.RequestData{ + { + Method: "POST", + Uri: "https://hbopenbid.pubmatic.com/translator?source=prebid-server", + Body: []byte(`{"id":"test-request-id","imp":[{"id":"test-imp-id_mf1","banner":{"w":300,"h":250},"bidfloor":1.2,"ext":{}}],"app":{"name":"AutoScout24","bundle":"com.autoscout24","storeurl":"https://play.google.com/store/apps/details?id=com.autoscout24\u0026hl=fr"}}`), + Headers: http.Header{ + "Content-Type": []string{"application/json;charset=utf-8"}, + "Accept": []string{"application/json"}, + "Cookie": []string{"test-cookie"}, + }, + ImpIDs: []string{"test-imp-id_mf1"}, + }, + { + Method: "POST", + Uri: "https://hbopenbid.pubmatic.com/translator?source=prebid-server", + Body: []byte(`{"id":"test-request-id","imp":[{"id":"test-imp-id_mf2","banner":{"w":300,"h":250},"bidfloor":1.3,"ext":{}}],"app":{"name":"AutoScout24","bundle":"com.autoscout24","storeurl":"https://play.google.com/store/apps/details?id=com.autoscout24\u0026hl=fr"}}`), + Headers: http.Header{ + "Content-Type": []string{"application/json;charset=utf-8"}, + "Accept": []string{"application/json"}, + "Cookie": []string{"test-cookie"}, + }, + ImpIDs: []string{"test-imp-id_mf2"}, + }, + { + Method: "POST", + Uri: "https://hbopenbid.pubmatic.com/translator?source=prebid-server", + Body: []byte(`{"id":"test-request-id","imp":[{"id":"test-imp-id_mf3","banner":{"w":300,"h":250},"bidfloor":1.4,"ext":{}}],"app":{"name":"AutoScout24","bundle":"com.autoscout24","storeurl":"https://play.google.com/store/apps/details?id=com.autoscout24\u0026hl=fr"}}`), + Headers: http.Header{ + "Content-Type": []string{"application/json;charset=utf-8"}, + "Accept": []string{"application/json"}, + "Cookie": []string{"test-cookie"}, + }, + ImpIDs: []string{"test-imp-id_mf3"}, + }, + }, + wantError: []error{}, + }, + { + name: "request with multiple imp and single floor", + fields: fields{ + URI: "https://hbopenbid.pubmatic.com/translator?source=prebid-server", + bidderName: "pubmatic", + }, + args: args{ + request: &openrtb2.BidRequest{ + ID: "test-request-id", + App: &openrtb2.App{ + Name: "AutoScout24", + Bundle: "com.autoscout24", + StoreURL: "https://play.google.com/store/apps/details?id=com.autoscout24&hl=fr", + }, + Imp: []openrtb2.Imp{ + { + ID: "test-imp-id", + BidFloor: 0.12, + Banner: &openrtb2.Banner{ + W: ptrutil.ToPtr[int64](300), + H: ptrutil.ToPtr[int64](250), + }, + Ext: json.RawMessage(`{}`), + }, + { + ID: "test-imp-id2", + BidFloor: 0.13, + Banner: &openrtb2.Banner{ + W: ptrutil.ToPtr[int64](300), + H: ptrutil.ToPtr[int64](250), + }, + Ext: json.RawMessage(`{}`), + }, + }, + }, + impFloorsMap: map[string][]float64{ + "test-imp-id": {1.2}, + "test-imp-id2": {1.3}, + }, + cookies: []string{"test-cookie"}, + }, + wantRequestData: []*adapters.RequestData{ + { + Method: "POST", + Uri: "https://hbopenbid.pubmatic.com/translator?source=prebid-server", + Body: []byte(`{"id":"test-request-id","imp":[{"id":"test-imp-id_mf1","banner":{"w":300,"h":250},"bidfloor":1.2,"ext":{}},{"id":"test-imp-id2_mf1","banner":{"w":300,"h":250},"bidfloor":1.3,"ext":{}}],"app":{"name":"AutoScout24","bundle":"com.autoscout24","storeurl":"https://play.google.com/store/apps/details?id=com.autoscout24\u0026hl=fr"}}`), + Headers: http.Header{ + "Content-Type": []string{"application/json;charset=utf-8"}, + "Accept": []string{"application/json"}, + "Cookie": []string{"test-cookie"}, + }, + ImpIDs: []string{"test-imp-id_mf1", "test-imp-id2_mf1"}, + }, + }, + wantError: []error{}, + }, + { + name: "request with multiple imp and 3 floors (max) for only one imp", + fields: fields{ + URI: "https://hbopenbid.pubmatic.com/translator?source=prebid-server", + bidderName: "pubmatic", + }, + args: args{ + request: &openrtb2.BidRequest{ + ID: "test-request-id", + App: &openrtb2.App{ + Name: "AutoScout24", + Bundle: "com.autoscout24", + StoreURL: "https://play.google.com/store/apps/details?id=com.autoscout24&hl=fr", + }, + Imp: []openrtb2.Imp{ + { + ID: "test-imp-id", + BidFloor: 0.12, + Banner: &openrtb2.Banner{ + W: ptrutil.ToPtr[int64](300), + H: ptrutil.ToPtr[int64](250), + }, + Ext: json.RawMessage(`{}`), + }, + { + ID: "test-imp-id2", + BidFloor: 0.34, + Banner: &openrtb2.Banner{ + W: ptrutil.ToPtr[int64](300), + H: ptrutil.ToPtr[int64](250), + }, + Ext: json.RawMessage(`{}`), + }, + }, + }, + impFloorsMap: map[string][]float64{ + "test-imp-id": {1.2, 1.3, 1.4}, + }, + cookies: []string{"test-cookie"}, + }, + wantRequestData: []*adapters.RequestData{ + { + Method: "POST", + Uri: "https://hbopenbid.pubmatic.com/translator?source=prebid-server", + Body: []byte(`{"id":"test-request-id","imp":[{"id":"test-imp-id_mf1","banner":{"w":300,"h":250},"bidfloor":1.2,"ext":{}},{"id":"test-imp-id2","banner":{"w":300,"h":250},"bidfloor":0.34,"ext":{}}],"app":{"name":"AutoScout24","bundle":"com.autoscout24","storeurl":"https://play.google.com/store/apps/details?id=com.autoscout24\u0026hl=fr"}}`), + Headers: http.Header{ + "Content-Type": []string{"application/json;charset=utf-8"}, + "Accept": []string{"application/json"}, + "Cookie": []string{"test-cookie"}, + }, + ImpIDs: []string{"test-imp-id_mf1", "test-imp-id2"}, + }, + { + Method: "POST", + Uri: "https://hbopenbid.pubmatic.com/translator?source=prebid-server", + Body: []byte(`{"id":"test-request-id","imp":[{"id":"test-imp-id_mf2","banner":{"w":300,"h":250},"bidfloor":1.3,"ext":{}},{"id":"test-imp-id2","banner":{"w":300,"h":250},"bidfloor":0.34,"ext":{}}],"app":{"name":"AutoScout24","bundle":"com.autoscout24","storeurl":"https://play.google.com/store/apps/details?id=com.autoscout24\u0026hl=fr"}}`), + Headers: http.Header{ + "Content-Type": []string{"application/json;charset=utf-8"}, + "Accept": []string{"application/json"}, + "Cookie": []string{"test-cookie"}, + }, + ImpIDs: []string{"test-imp-id_mf2", "test-imp-id2"}, + }, + { + Method: "POST", + Uri: "https://hbopenbid.pubmatic.com/translator?source=prebid-server", + Body: []byte(`{"id":"test-request-id","imp":[{"id":"test-imp-id_mf3","banner":{"w":300,"h":250},"bidfloor":1.4,"ext":{}},{"id":"test-imp-id2","banner":{"w":300,"h":250},"bidfloor":0.34,"ext":{}}],"app":{"name":"AutoScout24","bundle":"com.autoscout24","storeurl":"https://play.google.com/store/apps/details?id=com.autoscout24\u0026hl=fr"}}`), + Headers: http.Header{ + "Content-Type": []string{"application/json;charset=utf-8"}, + "Accept": []string{"application/json"}, + "Cookie": []string{"test-cookie"}, + }, + ImpIDs: []string{"test-imp-id_mf3", "test-imp-id2"}, + }, + }, + wantError: []error{}, + }, + { + name: "request with multiple imp with 3 floors for one imp and 2 floors for another imp", + fields: fields{ + URI: "https://hbopenbid.pubmatic.com/translator?source=prebid-server", + bidderName: "pubmatic", + }, + args: args{ + request: &openrtb2.BidRequest{ + ID: "test-request-id", + App: &openrtb2.App{ + Name: "AutoScout24", + Bundle: "com.autoscout24", + StoreURL: "https://play.google.com/store/apps/details?id=com.autoscout24&hl=fr", + }, + Imp: []openrtb2.Imp{ + { + ID: "test-imp-id", + BidFloor: 0.12, + Banner: &openrtb2.Banner{ + W: ptrutil.ToPtr[int64](300), + H: ptrutil.ToPtr[int64](250), + }, + Ext: json.RawMessage(`{}`), + }, + { + ID: "test-imp-id2", + BidFloor: 0.34, + Banner: &openrtb2.Banner{ + W: ptrutil.ToPtr[int64](300), + H: ptrutil.ToPtr[int64](250), + }, + Ext: json.RawMessage(`{}`), + }, + }, + }, + impFloorsMap: map[string][]float64{ + "test-imp-id": {1.2, 1.3, 1.4}, + "test-imp-id2": {1.2, 1.3}, + }, + cookies: []string{"test-cookie"}, + }, + wantRequestData: []*adapters.RequestData{ + { + Method: "POST", + Uri: "https://hbopenbid.pubmatic.com/translator?source=prebid-server", + Body: []byte(`{"id":"test-request-id","imp":[{"id":"test-imp-id_mf1","banner":{"w":300,"h":250},"bidfloor":1.2,"ext":{}},{"id":"test-imp-id2_mf1","banner":{"w":300,"h":250},"bidfloor":1.2,"ext":{}}],"app":{"name":"AutoScout24","bundle":"com.autoscout24","storeurl":"https://play.google.com/store/apps/details?id=com.autoscout24\u0026hl=fr"}}`), + Headers: http.Header{ + "Content-Type": []string{"application/json;charset=utf-8"}, + "Accept": []string{"application/json"}, + "Cookie": []string{"test-cookie"}, + }, + ImpIDs: []string{"test-imp-id_mf1", "test-imp-id2_mf1"}, + }, + { + Method: "POST", + Uri: "https://hbopenbid.pubmatic.com/translator?source=prebid-server", + Body: []byte(`{"id":"test-request-id","imp":[{"id":"test-imp-id_mf2","banner":{"w":300,"h":250},"bidfloor":1.3,"ext":{}},{"id":"test-imp-id2_mf2","banner":{"w":300,"h":250},"bidfloor":1.3,"ext":{}}],"app":{"name":"AutoScout24","bundle":"com.autoscout24","storeurl":"https://play.google.com/store/apps/details?id=com.autoscout24\u0026hl=fr"}}`), + Headers: http.Header{ + "Content-Type": []string{"application/json;charset=utf-8"}, + "Accept": []string{"application/json"}, + "Cookie": []string{"test-cookie"}, + }, + ImpIDs: []string{"test-imp-id_mf2", "test-imp-id2_mf2"}, + }, + { + Method: "POST", + Uri: "https://hbopenbid.pubmatic.com/translator?source=prebid-server", + Body: []byte(`{"id":"test-request-id","imp":[{"id":"test-imp-id_mf3","banner":{"w":300,"h":250},"bidfloor":1.4,"ext":{}},{"id":"test-imp-id2","banner":{"w":300,"h":250},"bidfloor":0.34,"ext":{}}],"app":{"name":"AutoScout24","bundle":"com.autoscout24","storeurl":"https://play.google.com/store/apps/details?id=com.autoscout24\u0026hl=fr"}}`), + Headers: http.Header{ + "Content-Type": []string{"application/json;charset=utf-8"}, + "Accept": []string{"application/json"}, + "Cookie": []string{"test-cookie"}, + }, + ImpIDs: []string{"test-imp-id_mf3", "test-imp-id2"}, + }, + }, + wantError: []error{}, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + a := &PubmaticAdapter{ + URI: tt.fields.URI, + bidderName: tt.fields.bidderName, + } + gotRequestData, gotError := a.buildMultiFloorRequests(tt.args.request, tt.args.impFloorsMap, tt.args.cookies) + assert.Equal(t, tt.wantRequestData, gotRequestData) + assert.Equal(t, tt.wantError, gotError) + }) + } +} + func TestTrimSuffixWithPattern(t *testing.T) { type args struct { input string diff --git a/adapters/pubmatic/pubmatic_test.go b/adapters/pubmatic/pubmatic_test.go index b1d6fe3137..565adc8774 100644 --- a/adapters/pubmatic/pubmatic_test.go +++ b/adapters/pubmatic/pubmatic_test.go @@ -996,419 +996,6 @@ func TestGetMapFromJSON(t *testing.T) { } } -func TestPubmaticAdapter_buildMultiFloorRequests(t *testing.T) { - type fields struct { - URI string - bidderName string - } - type args struct { - request *openrtb2.BidRequest - impFloorsMap map[string][]float64 - cookies []string - } - tests := []struct { - name string - fields fields - args args - wantRequestData []*adapters.RequestData - wantError []error - }{ - { - name: "request with single imp and single floor", - fields: fields{ - URI: "https://hbopenbid.pubmatic.com/translator?source=prebid-server", - bidderName: "pubmatic", - }, - args: args{ - request: &openrtb2.BidRequest{ - ID: "test-request-id", - App: &openrtb2.App{ - Name: "AutoScout24", - Bundle: "com.autoscout24", - StoreURL: "https://play.google.com/store/apps/details?id=com.autoscout24&hl=fr", - }, - Imp: []openrtb2.Imp{ - { - ID: "test-imp-id", - BidFloor: 0.12, - Banner: &openrtb2.Banner{ - W: ptrutil.ToPtr[int64](300), - H: ptrutil.ToPtr[int64](250), - }, - Ext: json.RawMessage(`{}`), - }, - }, - }, - impFloorsMap: map[string][]float64{ - "test-imp-id": {1.2}, - }, - cookies: []string{"test-cookie"}, - }, - wantRequestData: []*adapters.RequestData{ - { - Method: "POST", - Uri: "https://hbopenbid.pubmatic.com/translator?source=prebid-server", - Body: []byte(`{"id":"test-request-id","imp":[{"id":"test-imp-id_mf1","banner":{"w":300,"h":250},"bidfloor":1.2,"ext":{}}],"app":{"name":"AutoScout24","bundle":"com.autoscout24","storeurl":"https://play.google.com/store/apps/details?id=com.autoscout24\u0026hl=fr"}}`), - Headers: http.Header{ - "Content-Type": []string{"application/json;charset=utf-8"}, - "Accept": []string{"application/json"}, - "Cookie": []string{"test-cookie"}, - }, - ImpIDs: []string{"test-imp-id_mf1"}, - }, - }, - wantError: []error{}, - }, - { - name: "request with single imp and two floors", - fields: fields{ - URI: "https://hbopenbid.pubmatic.com/translator?source=prebid-server", - bidderName: "pubmatic", - }, - args: args{ - request: &openrtb2.BidRequest{ - ID: "test-request-id", - App: &openrtb2.App{ - Name: "AutoScout24", - Bundle: "com.autoscout24", - StoreURL: "https://play.google.com/store/apps/details?id=com.autoscout24&hl=fr", - }, - Imp: []openrtb2.Imp{ - { - ID: "test-imp-id", - BidFloor: 0.12, - Banner: &openrtb2.Banner{ - W: ptrutil.ToPtr[int64](300), - H: ptrutil.ToPtr[int64](250), - }, - Ext: json.RawMessage(`{}`), - }, - }, - }, - impFloorsMap: map[string][]float64{ - "test-imp-id": {1.2, 1.3}, - }, - cookies: []string{"test-cookie"}, - }, - wantRequestData: []*adapters.RequestData{ - { - Method: "POST", - Uri: "https://hbopenbid.pubmatic.com/translator?source=prebid-server", - Body: []byte(`{"id":"test-request-id","imp":[{"id":"test-imp-id_mf1","banner":{"w":300,"h":250},"bidfloor":1.2,"ext":{}}],"app":{"name":"AutoScout24","bundle":"com.autoscout24","storeurl":"https://play.google.com/store/apps/details?id=com.autoscout24\u0026hl=fr"}}`), - Headers: http.Header{ - "Content-Type": []string{"application/json;charset=utf-8"}, - "Accept": []string{"application/json"}, - "Cookie": []string{"test-cookie"}, - }, - ImpIDs: []string{"test-imp-id_mf1"}, - }, - { - Method: "POST", - Uri: "https://hbopenbid.pubmatic.com/translator?source=prebid-server", - Body: []byte(`{"id":"test-request-id","imp":[{"id":"test-imp-id_mf2","banner":{"w":300,"h":250},"bidfloor":1.3,"ext":{}}],"app":{"name":"AutoScout24","bundle":"com.autoscout24","storeurl":"https://play.google.com/store/apps/details?id=com.autoscout24\u0026hl=fr"}}`), - Headers: http.Header{ - "Content-Type": []string{"application/json;charset=utf-8"}, - "Accept": []string{"application/json"}, - "Cookie": []string{"test-cookie"}, - }, - ImpIDs: []string{"test-imp-id_mf2"}, - }, - }, - wantError: []error{}, - }, - { - name: "request with single imp and max multi floors(3)", - fields: fields{ - URI: "https://hbopenbid.pubmatic.com/translator?source=prebid-server", - bidderName: "pubmatic", - }, - args: args{ - request: &openrtb2.BidRequest{ - ID: "test-request-id", - App: &openrtb2.App{ - Name: "AutoScout24", - Bundle: "com.autoscout24", - StoreURL: "https://play.google.com/store/apps/details?id=com.autoscout24&hl=fr", - }, - Imp: []openrtb2.Imp{ - { - ID: "test-imp-id", - BidFloor: 0.12, - Banner: &openrtb2.Banner{ - W: ptrutil.ToPtr[int64](300), - H: ptrutil.ToPtr[int64](250), - }, - Ext: json.RawMessage(`{}`), - }, - }, - }, - impFloorsMap: map[string][]float64{ - "test-imp-id": {1.2, 1.3, 1.4}, - }, - cookies: []string{"test-cookie"}, - }, - wantRequestData: []*adapters.RequestData{ - { - Method: "POST", - Uri: "https://hbopenbid.pubmatic.com/translator?source=prebid-server", - Body: []byte(`{"id":"test-request-id","imp":[{"id":"test-imp-id_mf1","banner":{"w":300,"h":250},"bidfloor":1.2,"ext":{}}],"app":{"name":"AutoScout24","bundle":"com.autoscout24","storeurl":"https://play.google.com/store/apps/details?id=com.autoscout24\u0026hl=fr"}}`), - Headers: http.Header{ - "Content-Type": []string{"application/json;charset=utf-8"}, - "Accept": []string{"application/json"}, - "Cookie": []string{"test-cookie"}, - }, - ImpIDs: []string{"test-imp-id_mf1"}, - }, - { - Method: "POST", - Uri: "https://hbopenbid.pubmatic.com/translator?source=prebid-server", - Body: []byte(`{"id":"test-request-id","imp":[{"id":"test-imp-id_mf2","banner":{"w":300,"h":250},"bidfloor":1.3,"ext":{}}],"app":{"name":"AutoScout24","bundle":"com.autoscout24","storeurl":"https://play.google.com/store/apps/details?id=com.autoscout24\u0026hl=fr"}}`), - Headers: http.Header{ - "Content-Type": []string{"application/json;charset=utf-8"}, - "Accept": []string{"application/json"}, - "Cookie": []string{"test-cookie"}, - }, - ImpIDs: []string{"test-imp-id_mf2"}, - }, - { - Method: "POST", - Uri: "https://hbopenbid.pubmatic.com/translator?source=prebid-server", - Body: []byte(`{"id":"test-request-id","imp":[{"id":"test-imp-id_mf3","banner":{"w":300,"h":250},"bidfloor":1.4,"ext":{}}],"app":{"name":"AutoScout24","bundle":"com.autoscout24","storeurl":"https://play.google.com/store/apps/details?id=com.autoscout24\u0026hl=fr"}}`), - Headers: http.Header{ - "Content-Type": []string{"application/json;charset=utf-8"}, - "Accept": []string{"application/json"}, - "Cookie": []string{"test-cookie"}, - }, - ImpIDs: []string{"test-imp-id_mf3"}, - }, - }, - wantError: []error{}, - }, - { - name: "request with multiple imp and single floor", - fields: fields{ - URI: "https://hbopenbid.pubmatic.com/translator?source=prebid-server", - bidderName: "pubmatic", - }, - args: args{ - request: &openrtb2.BidRequest{ - ID: "test-request-id", - App: &openrtb2.App{ - Name: "AutoScout24", - Bundle: "com.autoscout24", - StoreURL: "https://play.google.com/store/apps/details?id=com.autoscout24&hl=fr", - }, - Imp: []openrtb2.Imp{ - { - ID: "test-imp-id", - BidFloor: 0.12, - Banner: &openrtb2.Banner{ - W: ptrutil.ToPtr[int64](300), - H: ptrutil.ToPtr[int64](250), - }, - Ext: json.RawMessage(`{}`), - }, - { - ID: "test-imp-id2", - BidFloor: 0.13, - Banner: &openrtb2.Banner{ - W: ptrutil.ToPtr[int64](300), - H: ptrutil.ToPtr[int64](250), - }, - Ext: json.RawMessage(`{}`), - }, - }, - }, - impFloorsMap: map[string][]float64{ - "test-imp-id": {1.2}, - "test-imp-id2": {1.3}, - }, - cookies: []string{"test-cookie"}, - }, - wantRequestData: []*adapters.RequestData{ - { - Method: "POST", - Uri: "https://hbopenbid.pubmatic.com/translator?source=prebid-server", - Body: []byte(`{"id":"test-request-id","imp":[{"id":"test-imp-id_mf1","banner":{"w":300,"h":250},"bidfloor":1.2,"ext":{}},{"id":"test-imp-id2_mf1","banner":{"w":300,"h":250},"bidfloor":1.3,"ext":{}}],"app":{"name":"AutoScout24","bundle":"com.autoscout24","storeurl":"https://play.google.com/store/apps/details?id=com.autoscout24\u0026hl=fr"}}`), - Headers: http.Header{ - "Content-Type": []string{"application/json;charset=utf-8"}, - "Accept": []string{"application/json"}, - "Cookie": []string{"test-cookie"}, - }, - ImpIDs: []string{"test-imp-id_mf1", "test-imp-id2_mf1"}, - }, - }, - wantError: []error{}, - }, - { - name: "request with multiple imp and 3 floors (max) for only one imp", - fields: fields{ - URI: "https://hbopenbid.pubmatic.com/translator?source=prebid-server", - bidderName: "pubmatic", - }, - args: args{ - request: &openrtb2.BidRequest{ - ID: "test-request-id", - App: &openrtb2.App{ - Name: "AutoScout24", - Bundle: "com.autoscout24", - StoreURL: "https://play.google.com/store/apps/details?id=com.autoscout24&hl=fr", - }, - Imp: []openrtb2.Imp{ - { - ID: "test-imp-id", - BidFloor: 0.12, - Banner: &openrtb2.Banner{ - W: ptrutil.ToPtr[int64](300), - H: ptrutil.ToPtr[int64](250), - }, - Ext: json.RawMessage(`{}`), - }, - { - ID: "test-imp-id2", - BidFloor: 0.34, - Banner: &openrtb2.Banner{ - W: ptrutil.ToPtr[int64](300), - H: ptrutil.ToPtr[int64](250), - }, - Ext: json.RawMessage(`{}`), - }, - }, - }, - impFloorsMap: map[string][]float64{ - "test-imp-id": {1.2, 1.3, 1.4}, - }, - cookies: []string{"test-cookie"}, - }, - wantRequestData: []*adapters.RequestData{ - { - Method: "POST", - Uri: "https://hbopenbid.pubmatic.com/translator?source=prebid-server", - Body: []byte(`{"id":"test-request-id","imp":[{"id":"test-imp-id_mf1","banner":{"w":300,"h":250},"bidfloor":1.2,"ext":{}},{"id":"test-imp-id2","banner":{"w":300,"h":250},"bidfloor":0.34,"ext":{}}],"app":{"name":"AutoScout24","bundle":"com.autoscout24","storeurl":"https://play.google.com/store/apps/details?id=com.autoscout24\u0026hl=fr"}}`), - Headers: http.Header{ - "Content-Type": []string{"application/json;charset=utf-8"}, - "Accept": []string{"application/json"}, - "Cookie": []string{"test-cookie"}, - }, - ImpIDs: []string{"test-imp-id_mf1", "test-imp-id2"}, - }, - { - Method: "POST", - Uri: "https://hbopenbid.pubmatic.com/translator?source=prebid-server", - Body: []byte(`{"id":"test-request-id","imp":[{"id":"test-imp-id_mf2","banner":{"w":300,"h":250},"bidfloor":1.3,"ext":{}},{"id":"test-imp-id2","banner":{"w":300,"h":250},"bidfloor":0.34,"ext":{}}],"app":{"name":"AutoScout24","bundle":"com.autoscout24","storeurl":"https://play.google.com/store/apps/details?id=com.autoscout24\u0026hl=fr"}}`), - Headers: http.Header{ - "Content-Type": []string{"application/json;charset=utf-8"}, - "Accept": []string{"application/json"}, - "Cookie": []string{"test-cookie"}, - }, - ImpIDs: []string{"test-imp-id_mf2", "test-imp-id2"}, - }, - { - Method: "POST", - Uri: "https://hbopenbid.pubmatic.com/translator?source=prebid-server", - Body: []byte(`{"id":"test-request-id","imp":[{"id":"test-imp-id_mf3","banner":{"w":300,"h":250},"bidfloor":1.4,"ext":{}},{"id":"test-imp-id2","banner":{"w":300,"h":250},"bidfloor":0.34,"ext":{}}],"app":{"name":"AutoScout24","bundle":"com.autoscout24","storeurl":"https://play.google.com/store/apps/details?id=com.autoscout24\u0026hl=fr"}}`), - Headers: http.Header{ - "Content-Type": []string{"application/json;charset=utf-8"}, - "Accept": []string{"application/json"}, - "Cookie": []string{"test-cookie"}, - }, - ImpIDs: []string{"test-imp-id_mf3", "test-imp-id2"}, - }, - }, - wantError: []error{}, - }, - { - name: "request with multiple imp with 3 floors for one imp and 2 floors for another imp", - fields: fields{ - URI: "https://hbopenbid.pubmatic.com/translator?source=prebid-server", - bidderName: "pubmatic", - }, - args: args{ - request: &openrtb2.BidRequest{ - ID: "test-request-id", - App: &openrtb2.App{ - Name: "AutoScout24", - Bundle: "com.autoscout24", - StoreURL: "https://play.google.com/store/apps/details?id=com.autoscout24&hl=fr", - }, - Imp: []openrtb2.Imp{ - { - ID: "test-imp-id", - BidFloor: 0.12, - Banner: &openrtb2.Banner{ - W: ptrutil.ToPtr[int64](300), - H: ptrutil.ToPtr[int64](250), - }, - Ext: json.RawMessage(`{}`), - }, - { - ID: "test-imp-id2", - BidFloor: 0.34, - Banner: &openrtb2.Banner{ - W: ptrutil.ToPtr[int64](300), - H: ptrutil.ToPtr[int64](250), - }, - Ext: json.RawMessage(`{}`), - }, - }, - }, - impFloorsMap: map[string][]float64{ - "test-imp-id": {1.2, 1.3, 1.4}, - "test-imp-id2": {1.2, 1.3}, - }, - cookies: []string{"test-cookie"}, - }, - wantRequestData: []*adapters.RequestData{ - { - Method: "POST", - Uri: "https://hbopenbid.pubmatic.com/translator?source=prebid-server", - Body: []byte(`{"id":"test-request-id","imp":[{"id":"test-imp-id_mf1","banner":{"w":300,"h":250},"bidfloor":1.2,"ext":{}},{"id":"test-imp-id2_mf1","banner":{"w":300,"h":250},"bidfloor":1.2,"ext":{}}],"app":{"name":"AutoScout24","bundle":"com.autoscout24","storeurl":"https://play.google.com/store/apps/details?id=com.autoscout24\u0026hl=fr"}}`), - Headers: http.Header{ - "Content-Type": []string{"application/json;charset=utf-8"}, - "Accept": []string{"application/json"}, - "Cookie": []string{"test-cookie"}, - }, - ImpIDs: []string{"test-imp-id_mf1", "test-imp-id2_mf1"}, - }, - { - Method: "POST", - Uri: "https://hbopenbid.pubmatic.com/translator?source=prebid-server", - Body: []byte(`{"id":"test-request-id","imp":[{"id":"test-imp-id_mf2","banner":{"w":300,"h":250},"bidfloor":1.3,"ext":{}},{"id":"test-imp-id2_mf2","banner":{"w":300,"h":250},"bidfloor":1.3,"ext":{}}],"app":{"name":"AutoScout24","bundle":"com.autoscout24","storeurl":"https://play.google.com/store/apps/details?id=com.autoscout24\u0026hl=fr"}}`), - Headers: http.Header{ - "Content-Type": []string{"application/json;charset=utf-8"}, - "Accept": []string{"application/json"}, - "Cookie": []string{"test-cookie"}, - }, - ImpIDs: []string{"test-imp-id_mf2", "test-imp-id2_mf2"}, - }, - { - Method: "POST", - Uri: "https://hbopenbid.pubmatic.com/translator?source=prebid-server", - Body: []byte(`{"id":"test-request-id","imp":[{"id":"test-imp-id_mf3","banner":{"w":300,"h":250},"bidfloor":1.4,"ext":{}},{"id":"test-imp-id2","banner":{"w":300,"h":250},"bidfloor":0.34,"ext":{}}],"app":{"name":"AutoScout24","bundle":"com.autoscout24","storeurl":"https://play.google.com/store/apps/details?id=com.autoscout24\u0026hl=fr"}}`), - Headers: http.Header{ - "Content-Type": []string{"application/json;charset=utf-8"}, - "Accept": []string{"application/json"}, - "Cookie": []string{"test-cookie"}, - }, - ImpIDs: []string{"test-imp-id_mf3", "test-imp-id2"}, - }, - }, - wantError: []error{}, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - a := &PubmaticAdapter{ - URI: tt.fields.URI, - bidderName: tt.fields.bidderName, - } - gotRequestData, gotError := a.buildMultiFloorRequests(tt.args.request, tt.args.impFloorsMap, tt.args.cookies) - assert.Equal(t, tt.wantRequestData, gotRequestData) - assert.Equal(t, tt.wantError, gotError) - }) - } -} - func TestPubmaticAdapter_buildAdapterRequest(t *testing.T) { type fields struct { URI string diff --git a/modules/pubmatic/openwrap/defaultbids.go b/modules/pubmatic/openwrap/defaultbids.go index b3a086ade6..b5683cafac 100644 --- a/modules/pubmatic/openwrap/defaultbids.go +++ b/modules/pubmatic/openwrap/defaultbids.go @@ -199,8 +199,12 @@ func (m *OpenWrap) addDefaultBidsForMultiFloorsConfig(rctx *models.RequestCtx, b for impID, impCtx := range rctx.ImpBidCtx { defaultBidsCount := len(rctx.AppLovinMax.MultiFloorsConfig.Config[impCtx.TagID]) - seatBidsMultiFloor[impID] + if defaultBids[impID] == nil { + defaultBids[impID] = make(map[string][]openrtb2.Bid) + } + //if defaultbid is already present for pubmatic, then reset it, as we are adding new defaultbids with MultiBidMultiFloor - if _, ok := defaultBids[impID][models.BidderPubMatic]; ok { + if _, ok := defaultBids[impID][models.BidderPubMatic]; ok && defaultBidsCount > 0 { defaultBids[impID][models.BidderPubMatic] = make([]openrtb2.Bid, 0, defaultBidsCount) }