From 536f1183cc355a9683d5dfb1576512441b3f79c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D0=BE=D0=B3=D0=B0=D1=82=D0=BE=D0=B2=20=D0=93=D0=B5?= =?UTF-8?q?=D1=80=D0=BC=D0=B0=D0=BD?= Date: Thu, 22 Aug 2024 15:10:49 +0300 Subject: [PATCH] zentotem: fix after review fix after review --- adapters/zentotem/zentotem.go | 62 ++++--------------- adapters/zentotem/zentotem_test.go | 27 ++++---- .../exemplary/banner-200-212.json | 32 ++++++---- .../exemplary/banner-201-202-203.json | 32 ++++++---- .../zentotemtest/exemplary/banner-207.json | 36 ++++++----- .../zentotemtest/exemplary/native.json | 36 ++++++----- .../zentotemtest/exemplary/video-300.json | 34 ++++++---- .../zentotemtest/exemplary/video-301.json | 36 ++++++----- .../supplemental/empty-imp-400.json | 2 +- .../supplemental/empty-imp-native-400.json | 2 +- .../empty-imp-ver-native-400.json | 2 +- 11 files changed, 150 insertions(+), 151 deletions(-) diff --git a/adapters/zentotem/zentotem.go b/adapters/zentotem/zentotem.go index 5ad3634a9a4..b016acc2e74 100644 --- a/adapters/zentotem/zentotem.go +++ b/adapters/zentotem/zentotem.go @@ -6,9 +6,7 @@ import ( "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/openrtb_ext" - "net/http" ) type adapter struct { @@ -24,13 +22,6 @@ func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server co } func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { - if request == nil { - return nil, []error{&errortypes.BadInput{Message: "empty request"}} - } - if len(request.Imp) == 0 { - return nil, []error{&errortypes.BadInput{Message: "empty request.Imp"}} - } - requests := make([]*adapters.RequestData, 0, len(request.Imp)) var errors []error @@ -55,48 +46,27 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapte return requests, errors } -func getMediaTypeForBid(imp openrtb2.Imp) (openrtb_ext.BidType, error) { - if imp.Native != nil { - return openrtb_ext.BidTypeNative, nil - } - - if imp.Banner != nil { +func getMediaTypeForBid(bid openrtb2.Bid) (openrtb_ext.BidType, error) { + switch bid.MType { + case openrtb2.MarkupBanner: return openrtb_ext.BidTypeBanner, nil - } - - if imp.Video != nil { + case openrtb2.MarkupVideo: return openrtb_ext.BidTypeVideo, nil + case openrtb2.MarkupNative: + return openrtb_ext.BidTypeNative, nil } - return "", &errortypes.BadInput{ - Message: fmt.Sprintf("Processing an invalid impression; cannot resolve impression type for imp #%s", imp.ID), - } + return "", fmt.Errorf("could not define media type for impression: %s", bid.ImpID) } func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.RequestData, responseData *adapters.ResponseData) (*adapters.BidderResponse, []error) { - if responseData.StatusCode == http.StatusNoContent { + if adapters.IsResponseStatusCodeNoContent(responseData) { return nil, nil } - if responseData.StatusCode == http.StatusBadRequest { - err := &errortypes.BadInput{ - Message: "Unexpected status code: 400. Bad request from publisher. Run with request.debug = 1 for more info.", - } - return nil, []error{err} - } - - if responseData.StatusCode != http.StatusOK { - err := &errortypes.BadServerResponse{ - Message: fmt.Sprintf("Unexpected status code: %d. Run with request.debug = 1 for more info.", responseData.StatusCode), - } + if err := adapters.CheckResponseStatusCodeForErrors(responseData); err != nil { return nil, []error{err} } - - impMap := map[string]openrtb2.Imp{} - for _, imp := range request.Imp { - impMap[imp.ID] = imp - } - var response openrtb2.BidResponse if err := json.Unmarshal(responseData.Body, &response); err != nil { return nil, []error{err} @@ -106,23 +76,15 @@ func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.R bidResponse.Currency = response.Cur var errors []error for _, seatBid := range response.SeatBid { - for i, bid := range seatBid.Bid { - imp, ok := impMap[bid.ImpID] - if !ok { - errors = append(errors, &errortypes.BadInput{ - Message: fmt.Sprintf("Invalid bid imp ID #%s does not match any imp IDs from the original bid request", bid.ImpID), - }) - continue - } - - bidType, err := getMediaTypeForBid(imp) + for _, bid := range seatBid.Bid { + bidType, err := getMediaTypeForBid(bid) if err != nil { errors = append(errors, err) continue } bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{ - Bid: &seatBid.Bid[i], + Bid: &bid, BidType: bidType, }) } diff --git a/adapters/zentotem/zentotem_test.go b/adapters/zentotem/zentotem_test.go index 6d1d434ebd8..d485fc9fda4 100644 --- a/adapters/zentotem/zentotem_test.go +++ b/adapters/zentotem/zentotem_test.go @@ -23,45 +23,44 @@ func TestJsonSamples(t *testing.T) { func TestGetMediaTypeForBid(t *testing.T) { tests := []struct { name string - imp openrtb2.Imp + bid openrtb2.Bid wantType openrtb_ext.BidType wantErr bool }{ { name: "get bid native type", - imp: openrtb2.Imp{ - Native: &openrtb2.Native{ - Request: "test", - }, + bid: openrtb2.Bid{ + MType: 4, }, wantType: openrtb_ext.BidTypeNative, wantErr: false, }, { name: "get bid banner type", - imp: openrtb2.Imp{ - Banner: &openrtb2.Banner{ - ID: "test", - }, + bid: openrtb2.Bid{ + MType: 1, }, wantType: openrtb_ext.BidTypeBanner, wantErr: false, }, { name: "get bid video type", - imp: openrtb2.Imp{ - Video: &openrtb2.Video{ - PodID: "test", - }, + bid: openrtb2.Bid{ + MType: 2, }, wantType: openrtb_ext.BidTypeVideo, wantErr: false, }, + { + name: "fail", + wantType: "", + wantErr: true, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - bType, err := getMediaTypeForBid(tt.imp) + bType, err := getMediaTypeForBid(tt.bid) if (err != nil) != tt.wantErr { t.Errorf("getMediaTypeForBid error = %v, wantErr %v", err, tt.wantErr) } diff --git a/adapters/zentotem/zentotemtest/exemplary/banner-200-212.json b/adapters/zentotem/zentotemtest/exemplary/banner-200-212.json index c0ca977b293..3083850c083 100644 --- a/adapters/zentotem/zentotemtest/exemplary/banner-200-212.json +++ b/adapters/zentotem/zentotemtest/exemplary/banner-200-212.json @@ -159,7 +159,8 @@ "adomain": [ "app.apple.com" ], - "crid": "36" + "crid": "36", + "mtype": 1 } ], "seat": "boldwin" @@ -172,19 +173,24 @@ ], "expectedBidResponses": [ { - "bid": [ + "currency": "USD", + "bids": [ { - "id": "36", - "impid": "1", - "price": 150, - "nurl": "some-test-nurl", - "burl": "some-test-burl", - "adm": "some-test-adm", - "adid": "36", - "adomain": [ - "app.apple.com" - ], - "crid": "36" + "bid": { + "id": "36", + "impid": "1", + "price": 150, + "nurl": "some-test-nurl", + "burl": "some-test-burl", + "adm": "some-test-adm", + "adid": "36", + "adomain": [ + "app.apple.com" + ], + "crid": "36", + "mtype": 1 + }, + "type": "banner" } ] } diff --git a/adapters/zentotem/zentotemtest/exemplary/banner-201-202-203.json b/adapters/zentotem/zentotemtest/exemplary/banner-201-202-203.json index a1aa4ad0f41..b985d8b1412 100644 --- a/adapters/zentotem/zentotemtest/exemplary/banner-201-202-203.json +++ b/adapters/zentotem/zentotemtest/exemplary/banner-201-202-203.json @@ -157,7 +157,8 @@ "adomain": [ "app.apple.com" ], - "crid": "38" + "crid": "38", + "mtype": 1 } ], "seat": "boldwin" @@ -170,19 +171,24 @@ ], "expectedBidResponses": [ { - "bid": [ + "currency": "USD", + "bids": [ { - "id": "38", - "impid": "1", - "price": 150, - "nurl": "some-test-nurl", - "burl": "some-test-burl", - "adm": "some-test-adm", - "adid": "38", - "adomain": [ - "app.apple.com" - ], - "crid": "38" + "bid": { + "id": "38", + "impid": "1", + "price": 150, + "nurl": "some-test-nurl", + "burl": "some-test-burl", + "adm": "some-test-adm", + "adid": "38", + "adomain": [ + "app.apple.com" + ], + "crid": "38", + "mtype": 1 + }, + "type": "banner" } ] } diff --git a/adapters/zentotem/zentotemtest/exemplary/banner-207.json b/adapters/zentotem/zentotemtest/exemplary/banner-207.json index 0bf704bad8f..f516cbb2d36 100644 --- a/adapters/zentotem/zentotemtest/exemplary/banner-207.json +++ b/adapters/zentotem/zentotemtest/exemplary/banner-207.json @@ -163,7 +163,8 @@ ], "crid": "40", "w": 320, - "h": 50 + "h": 50, + "mtype": 1 } ], "seat": "boldwin" @@ -176,21 +177,26 @@ ], "expectedBidResponses": [ { - "bid": [ + "currency": "USD", + "bids": [ { - "id": "40", - "impid": "1", - "price": 150, - "nurl": "some-test-nurl", - "burl": "some-test-burl", - "adm": "some-test-adm", - "adid": "40", - "adomain": [ - "app.apple.com" - ], - "crid": "40", - "w": 320, - "h": 50 + "bid": { + "id": "40", + "impid": "1", + "price": 150, + "nurl": "some-test-nurl", + "burl": "some-test-burl", + "adm": "some-test-adm", + "adid": "40", + "adomain": [ + "app.apple.com" + ], + "crid": "40", + "w": 320, + "h": 50, + "mtype": 1 + }, + "type": "banner" } ] } diff --git a/adapters/zentotem/zentotemtest/exemplary/native.json b/adapters/zentotem/zentotemtest/exemplary/native.json index cc319d42343..916e3badefc 100644 --- a/adapters/zentotem/zentotemtest/exemplary/native.json +++ b/adapters/zentotem/zentotemtest/exemplary/native.json @@ -125,7 +125,8 @@ ], "crid": "40", "w": 320, - "h": 50 + "h": 50, + "mtype": 4 } ], "seat": "boldwin" @@ -138,21 +139,26 @@ ], "expectedBidResponses": [ { - "bid": [ + "currency": "USD", + "bids": [ { - "id": "40", - "impid": "1", - "price": 150, - "nurl": "some-test-nurl", - "burl": "some-test-burl", - "adm": "some-test-adm", - "adid": "40", - "adomain": [ - "app.apple.com" - ], - "crid": "40", - "w": 320, - "h": 50 + "bid": { + "id": "40", + "impid": "1", + "price": 150, + "nurl": "some-test-nurl", + "burl": "some-test-burl", + "adm": "some-test-adm", + "adid": "40", + "adomain": [ + "app.apple.com" + ], + "crid": "40", + "w": 320, + "h": 50, + "mtype": 4 + }, + "type": "native" } ] } diff --git a/adapters/zentotem/zentotemtest/exemplary/video-300.json b/adapters/zentotem/zentotemtest/exemplary/video-300.json index ac4554e0ad1..09c74fdb82c 100644 --- a/adapters/zentotem/zentotemtest/exemplary/video-300.json +++ b/adapters/zentotem/zentotemtest/exemplary/video-300.json @@ -161,7 +161,8 @@ ], "crid": "43", "w": 1280, - "h": 720 + "h": 720, + "mtype": 2 } ], "seat": "boldwin" @@ -174,19 +175,26 @@ ], "expectedBidResponses": [ { - "bid": [ + "currency": "USD", + "bids": [ { - "id": "36", - "impid": "1", - "price": 150, - "nurl": "some-test-nurl", - "burl": "some-test-burl", - "adm": "some-test-adm", - "adid": "36", - "adomain": [ - "app.apple.com" - ], - "crid": "36" + "bid": { + "id": "43", + "impid": "8f3ac58c-1e03-4264-8619-f79ddb137110", + "price": 150, + "nurl": "some-test-nurl", + "burl": "some-test-burl", + "adm": "some-test-adm", + "adid": "43", + "adomain": [ + "app.apple.com" + ], + "crid": "43", + "w": 1280, + "h": 720, + "mtype": 2 + }, + "type": "video" } ] } diff --git a/adapters/zentotem/zentotemtest/exemplary/video-301.json b/adapters/zentotem/zentotemtest/exemplary/video-301.json index b025068c00f..aca6d4bd172 100644 --- a/adapters/zentotem/zentotemtest/exemplary/video-301.json +++ b/adapters/zentotem/zentotemtest/exemplary/video-301.json @@ -161,7 +161,8 @@ ], "crid": "44", "w": 1280, - "h": 720 + "h": 720, + "mtype": 2 } ], "seat": "boldwin" @@ -174,21 +175,26 @@ ], "expectedBidResponses": [ { - "bid": [ + "currency": "USD", + "bids": [ { - "id": "44", - "impid": "8f3ac58c-1e03-4264-8619-f79ddb137110", - "price": 150, - "nurl": "some-test-nurl", - "burl": "some-test-burl", - "adm": "some-test-adm", - "adid": "44", - "adomain": [ - "app.apple.com" - ], - "crid": "44", - "w": 1280, - "h": 720 + "bid": { + "id": "44", + "impid": "8f3ac58c-1e03-4264-8619-f79ddb137110", + "price": 150, + "nurl": "some-test-nurl", + "burl": "some-test-burl", + "adm": "some-test-adm", + "adid": "44", + "adomain": [ + "app.apple.com" + ], + "crid": "44", + "w": 1280, + "h": 720, + "mtype": 2 + }, + "type": "video" } ] } diff --git a/adapters/zentotem/zentotemtest/supplemental/empty-imp-400.json b/adapters/zentotem/zentotemtest/supplemental/empty-imp-400.json index c46b2e3a6fd..26fbf6236c7 100644 --- a/adapters/zentotem/zentotemtest/supplemental/empty-imp-400.json +++ b/adapters/zentotem/zentotemtest/supplemental/empty-imp-400.json @@ -111,7 +111,7 @@ "expectedBidResponses": [], "expectedMakeBidsErrors": [ { - "value": "Unexpected status code: 400. Bad request from publisher. Run with request.debug = 1 for more info.", + "value": "Unexpected status code: 400. Run with request.debug = 1 for more info", "comparison": "literal" } ] diff --git a/adapters/zentotem/zentotemtest/supplemental/empty-imp-native-400.json b/adapters/zentotem/zentotemtest/supplemental/empty-imp-native-400.json index dd3e4a40b84..a6a42c5833e 100644 --- a/adapters/zentotem/zentotemtest/supplemental/empty-imp-native-400.json +++ b/adapters/zentotem/zentotemtest/supplemental/empty-imp-native-400.json @@ -105,7 +105,7 @@ "expectedBidResponses": [], "expectedMakeBidsErrors": [ { - "value": "Unexpected status code: 400. Bad request from publisher. Run with request.debug = 1 for more info.", + "value": "Unexpected status code: 400. Run with request.debug = 1 for more info", "comparison": "literal" } ] diff --git a/adapters/zentotem/zentotemtest/supplemental/empty-imp-ver-native-400.json b/adapters/zentotem/zentotemtest/supplemental/empty-imp-ver-native-400.json index b81d6257ead..68dcdbb0e61 100644 --- a/adapters/zentotem/zentotemtest/supplemental/empty-imp-ver-native-400.json +++ b/adapters/zentotem/zentotemtest/supplemental/empty-imp-ver-native-400.json @@ -111,7 +111,7 @@ "expectedBidResponses": [], "expectedMakeBidsErrors": [ { - "value": "Unexpected status code: 400. Bad request from publisher. Run with request.debug = 1 for more info.", + "value": "Unexpected status code: 400. Run with request.debug = 1 for more info", "comparison": "literal" } ]