Skip to content

Commit

Permalink
remove unnecessary tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pro-nsk committed Nov 16, 2023
1 parent 46a764d commit c3fe4cc
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 215 deletions.
215 changes: 0 additions & 215 deletions adapters/alkimi/alkimi_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package alkimi

import (
"encoding/json"
"testing"

"github.com/prebid/openrtb/v19/openrtb2"
"github.com/prebid/prebid-server/v2/adapters"
"github.com/prebid/prebid-server/v2/adapters/adapterstest"
"github.com/prebid/prebid-server/v2/config"
Expand Down Expand Up @@ -50,219 +48,6 @@ func TestBuilder(t *testing.T) {
assert.NotNil(t, bidder)
}

func TestMakeRequests(t *testing.T) {
// given
bidder, _ := buildBidder()
extImpAlkimi, _ := json.Marshal(extObj{AlkimiBidderExt: openrtb_ext.ExtImpAlkimi{BidFloor: 5, Instl: 1, Exp: 2}})
bidRequest := openrtb2.BidRequest{
Imp: []openrtb2.Imp{
{
BidFloor: 6,
BidFloorCur: "",
Ext: extImpAlkimi,
},
{
BidFloor: -1,
BidFloorCur: "USD",
Ext: extImpAlkimi,
},
{
BidFloor: 10,
BidFloorCur: "USD",
Ext: extImpAlkimi,
},
},
}
// when
requestData, _ := bidder.MakeRequests(&bidRequest, nil)
request := requestData[0]
var updatedRequest openrtb2.BidRequest
errUnmarshal := json.Unmarshal(request.Body, &updatedRequest)
updatedImps := updatedRequest.Imp
// then
assert.Len(t, requestData, 1)
if errUnmarshal != nil {
t.Fatal("Corrupted updated request")
}
assert.Len(t, updatedImps, 3)

assert.Equal(t, 5.0, updatedImps[0].BidFloor)
assert.Equal(t, int8(1), updatedImps[0].Instl)
assert.Equal(t, int64(2), updatedImps[0].Exp)

assert.Equal(t, 5.0, updatedImps[1].BidFloor)
assert.Equal(t, int8(1), updatedImps[1].Instl)
assert.Equal(t, int64(2), updatedImps[1].Exp)

assert.Equal(t, 10.0, updatedImps[2].BidFloor)
assert.Equal(t, int8(1), updatedImps[2].Instl)
assert.Equal(t, int64(2), updatedImps[2].Exp)
}

func TestMakeBidsShouldReturnErrorIfResponseBodyCouldNotBeParsed(t *testing.T) {
// given
bidder, _ := buildBidder()
bid := openrtb2.Bid{
ImpID: "impId-1",
AdM: "adm:${AUCTION_PRICE}",
NURL: "nurl:${AUCTION_PRICE}",
Price: 1,
}
sb := openrtb2.SeatBid{Bid: []openrtb2.Bid{bid}}
resp := openrtb2.BidResponse{SeatBid: []openrtb2.SeatBid{sb}}
respJson, jsonErr := json.Marshal(resp)
request := openrtb2.BidRequest{
Imp: append(make([]openrtb2.Imp, 1), openrtb2.Imp{ID: "impId-1", Banner: &openrtb2.Banner{}}),
}
// when
bids, errs := bidder.MakeBids(&request, nil, &adapters.ResponseData{
StatusCode: 200,
Body: respJson,
})
// then
if jsonErr != nil {
t.Fatalf("Failed to serialize test bid %v: %v", bid, jsonErr)
}
if len(errs) > 0 {
t.Fatalf("Failed to make bids: %v", errs)
}
assert.Len(t, bids.Bids, 1)
assert.Equal(t, "nurl:1", bids.Bids[0].Bid.NURL)
assert.Equal(t, "adm:1", bids.Bids[0].Bid.AdM)
}

func TestMakeBidsShouldReturnErrorIfResponseBodyContainsIncorrectImp(t *testing.T) {
// given
bidder, _ := buildBidder()
bid := openrtb2.Bid{
ImpID: "impId-1-incorrect",
AdM: "adm:${AUCTION_PRICE}",
NURL: "nurl:${AUCTION_PRICE}",
Price: 1,
}
sb := openrtb2.SeatBid{Bid: []openrtb2.Bid{bid}}
resp := openrtb2.BidResponse{SeatBid: []openrtb2.SeatBid{sb}}
respJson, jsonErr := json.Marshal(resp)
request := openrtb2.BidRequest{
Imp: append(make([]openrtb2.Imp, 1), openrtb2.Imp{ID: "impId-1", Banner: &openrtb2.Banner{}}),
}
// when
bids, errs := bidder.MakeBids(&request, nil, &adapters.ResponseData{
StatusCode: 200,
Body: respJson,
})
// then
if jsonErr != nil {
t.Fatalf("Failed to serialize test bid %v: %v", bid, jsonErr)
}
assert.Len(t, bids.Bids, 0)
assert.Len(t, errs, 1)
}

func TestMakeBidsShouldReturnEmptyListIfBidResponseIsNull(t *testing.T) {
// given
bidder, _ := buildBidder()
// when
bids, errs := bidder.MakeBids(&openrtb2.BidRequest{}, nil, &adapters.ResponseData{
StatusCode: 204,
})
// then
if len(errs) > 0 {
t.Fatalf("Failed to make bids: %v", errs)
}
assert.Nil(t, bids)
}

func TestMakeBidsShouldReturnEmptyListIfBidResponseIsError(t *testing.T) {
// given
bidder, _ := buildBidder()
// when
bids, errs := bidder.MakeBids(&openrtb2.BidRequest{}, nil, &adapters.ResponseData{
StatusCode: 500,
})
// then
assert.Len(t, errs, 1)
assert.Nil(t, bids)
}

func TestMakeBidsShouldReturnBidWithResolvedMacros(t *testing.T) {
// given
bidder, _ := buildBidder()
bid := openrtb2.Bid{
ImpID: "impId-1",
AdM: "adm:${AUCTION_PRICE}",
NURL: "nurl:${AUCTION_PRICE}",
Price: 1,
}
seatBid := openrtb2.SeatBid{Bid: []openrtb2.Bid{bid}}
resp := openrtb2.BidResponse{SeatBid: []openrtb2.SeatBid{seatBid}}
respJson, jsonErr := json.Marshal(resp)

request := openrtb2.BidRequest{
Imp: append(make([]openrtb2.Imp, 1), openrtb2.Imp{ID: "impId-1", Banner: &openrtb2.Banner{}}),
}
// when
bids, errs := bidder.MakeBids(&request, nil, &adapters.ResponseData{
StatusCode: 200,
Body: respJson,
})
// then
if jsonErr != nil {
t.Fatalf("Failed to serialize test bid %v: %v", bid, jsonErr)
}
if len(errs) > 0 {
t.Fatalf("Failed to make bids: %v", errs)
}
assert.Len(t, bids.Bids, 1)
assert.Equal(t, "nurl:1", bids.Bids[0].Bid.NURL)
assert.Equal(t, "adm:1", bids.Bids[0].Bid.AdM)
}

func TestMakeBidsShouldReturnBidForAllTypes(t *testing.T) {
// given
bidder, _ := buildBidder()
bid := openrtb2.Bid{
ImpID: "impId-1",
AdM: "adm:${AUCTION_PRICE}",
NURL: "nurl:${AUCTION_PRICE}",
Price: 1,
}
seatBid := openrtb2.SeatBid{Bid: []openrtb2.Bid{bid}}
resp := openrtb2.BidResponse{SeatBid: []openrtb2.SeatBid{seatBid}}
respJson, jsonErr := json.Marshal(resp)

request := openrtb2.BidRequest{
Imp: append(make([]openrtb2.Imp, 1), openrtb2.Imp{ID: "impId-1", Video: &openrtb2.Video{}}),
}
// when
bids, errs := bidder.MakeBids(&request, nil, &adapters.ResponseData{
StatusCode: 200,
Body: respJson,
})
// then
if jsonErr != nil {
t.Fatalf("Failed to serialize test bid %v: %v", bid, jsonErr)
}
if len(errs) > 0 {
t.Fatalf("Failed to make bids: %v", errs)
}
assert.Len(t, bids.Bids, 1)

request = openrtb2.BidRequest{
Imp: append(make([]openrtb2.Imp, 1), openrtb2.Imp{ID: "impId-1", Audio: &openrtb2.Audio{}}),
}
// when
bids, errs = bidder.MakeBids(&request, nil, &adapters.ResponseData{
StatusCode: 200,
Body: respJson,
})
// then
if len(errs) > 0 {
t.Fatalf("Failed to make bids: %v", errs)
}
assert.Len(t, bids.Bids, 1)
}

func buildBidder() (adapters.Bidder, error) {
return Builder(
openrtb_ext.BidderAlkimi,
Expand Down
2 changes: 2 additions & 0 deletions adapters/alkimi/alkimitest/exemplary/simple-banner.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
"adm": "<div id=\"qsum\"><a href='https:\/\/alkimi.org' target='_blank'><img src='https:\/\/cloudfront.net\/jpeg\/2_Banner_02_300x250px.jpg'><\/a><\/div><script async src=\"https:\/\/exchange.alkimi-onboarding.com\/dsp-impression?id=H4sIAAAAAAAA_2NkUElJMkszSjIz17VITDPVNTFONdRNSks10zU3TkpNskhJMjU3TmNkYGDsvuy5eQqQAQZMAFKoSf85AAAA&price=${AUCTION_PRICE}\"><\/script>",
"cid": "test_cid",
"crid": "test_crid",
"nurl": "https://exchange.alkimi-onboarding.com/dsp-win?id=H4sIAAAAAAAA_2NkUElJMkszSjIz17VITDPVNTFONdRNSks10zU3TkpNskhJMjU3TmNkYGDsvuy5eQqQAQZMAFKoSf85AAAA&price=${AUCTION_PRICE}",
"w": 300,
"h": 250,
"ext": {
Expand Down Expand Up @@ -132,6 +133,7 @@
"adm": "<div id=\"qsum\"><a href='https:\/\/alkimi.org' target='_blank'><img src='https:\/\/cloudfront.net\/jpeg\/2_Banner_02_300x250px.jpg'><\/a><\/div><script async src=\"https:\/\/exchange.alkimi-onboarding.com\/dsp-impression?id=H4sIAAAAAAAA_2NkUElJMkszSjIz17VITDPVNTFONdRNSks10zU3TkpNskhJMjU3TmNkYGDsvuy5eQqQAQZMAFKoSf85AAAA&price=0.9\"><\/script>",
"cid": "test_cid",
"crid": "test_crid",
"nurl": "https://exchange.alkimi-onboarding.com/dsp-win?id=H4sIAAAAAAAA_2NkUElJMkszSjIz17VITDPVNTFONdRNSks10zU3TkpNskhJMjU3TmNkYGDsvuy5eQqQAQZMAFKoSf85AAAA&price=0.9",
"w": 300,
"h": 250,
"ext": {
Expand Down

0 comments on commit c3fe4cc

Please sign in to comment.