Skip to content

Commit

Permalink
Yandex: add adapter (#3419)
Browse files Browse the repository at this point in the history
  • Loading branch information
chernodub authored Jan 25, 2024
1 parent 1ac3fbe commit 106f22d
Show file tree
Hide file tree
Showing 20 changed files with 1,975 additions and 0 deletions.
87 changes: 87 additions & 0 deletions adapters/yandex/params_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package yandex

import (
"encoding/json"
"testing"

"github.com/prebid/prebid-server/v2/openrtb_ext"
"github.com/stretchr/testify/assert"
)

func TestValidParams(t *testing.T) {
validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
if err != nil {
t.Fatalf("Failed to fetch the json schema. %v", err)
}

for _, p := range validParams {
if err := validator.Validate(openrtb_ext.BidderYandex, json.RawMessage(p)); err != nil {
t.Errorf("Schema rejected valid params: %s", p)
}
}
}

func TestInvalidParams(t *testing.T) {
validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
if err != nil {
t.Fatalf("Failed to fetch the json schema. %v", err)
}

for _, p := range invalidParams {
if err := validator.Validate(openrtb_ext.BidderYandex, json.RawMessage(p)); err == nil {
t.Errorf("Schema allowed invalid params: %s", p)
}
}
}

var validParams = []string{
`{"page_id": 123123, "imp_id": 123}`,
`{"placement_id": "A-123123-123"}`,
`{"placement_id": "B-A-123123-123"}`,
`{"placement_id": "123123-123"}`,
}

var invalidParams = []string{
`{"pageId": 123123, "impId": 123}`,
`{"page_id": 0, "imp_id": 0}`,
`{"page_id": "123123", "imp_id": "123"}`,
`{"page_id": "123123", "imp_id": "123", "placement_id": "123123"}`,
`{"page_id": "123123"}`,
`{"imp_id": "123"}`,
`{"placement_id": 123123}`,
`{"placement_id": "123123"}`,
`{"placement_id": "A-123123"}`,
`{"placement_id": "B-A-123123"}`,
`{}`,
}

func TestValidPlacementIdMapper(t *testing.T) {
for ext, expectedPlacementId := range validPlacementIds {
val, err := mapExtToPlacementID(ext)

assert.Equal(t, &expectedPlacementId, val)
assert.NoError(t, err)
}
}

func TestInvalidPlacementIdMapper(t *testing.T) {
for _, ext := range invalidPlacementIds {
_, err := mapExtToPlacementID(ext)

assert.Error(t, err)
}
}

var validPlacementIds = map[openrtb_ext.ExtImpYandex]yandexPlacementID{
{PlacementID: "A-12345-1"}: {PageID: "12345", ImpID: "1"},
{PlacementID: "B-A-123123-123"}: {PageID: "123123", ImpID: "123"},
{PlacementID: "111-222"}: {PageID: "111", ImpID: "222"},
{PageID: 111, ImpID: 222}: {PageID: "111", ImpID: "222"},
}

var invalidPlacementIds = []openrtb_ext.ExtImpYandex{
{PlacementID: "123123"},
{PlacementID: "A-123123"},
{PlacementID: "B-A-123123"},
{PlacementID: "C-B-A-123123"},
}
Loading

0 comments on commit 106f22d

Please sign in to comment.