Skip to content

Commit

Permalink
add additional tests and minor code fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hasan-kanjee committed Nov 5, 2023
1 parent e3ed794 commit f8a96e2
Show file tree
Hide file tree
Showing 6 changed files with 573 additions and 38 deletions.
34 changes: 31 additions & 3 deletions adapters/flipp/flipp.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ const (
inlineDivName = "inline"
flippBidder = "flipp"
defaultCurrency = "USD"
fakeUuid = "30470a14-2949-4110-abce-b62d57304ad5"
)

var uuidGenerator UUIDGenerator

var (
count int64 = 1
adTypes = []int64{4309, 641}
Expand All @@ -33,6 +36,30 @@ type adapter struct {
endpoint string
}

type UUIDGenerator interface {
Generate() (uuid.UUID, error)
}

type RealUUIDGenerator struct{}

func (g *RealUUIDGenerator) Generate() (uuid.UUID, error) {
return uuid.NewV4()
}

type FakeUUIDGenerator struct{}

func (g *FakeUUIDGenerator) Generate() (uuid.UUID, error) {
return uuid.FromStringOrNil(fakeUuid), nil
}

func NewUUIDGenerator(isTest bool) {
if isTest {
uuidGenerator = &FakeUUIDGenerator{}
} else {
uuidGenerator = &RealUUIDGenerator{}
}
}

// Builder builds a new instance of the Flipp adapter for the given bidder with the given config.
func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server config.Server) (adapters.Bidder, error) {
bidder := &adapter{
Expand Down Expand Up @@ -127,7 +154,8 @@ func (a *adapter) processImp(request *openrtb2.BidRequest, imp openrtb2.Imp) (*a
} else if flippExtParams.UserKey != "" && paramsUserKeyPermitted(request) {
userKey = flippExtParams.UserKey
} else {
uid, err := uuid.NewV4()

uid, err := uuidGenerator.Generate()
if err != nil {
return nil, fmt.Errorf("unable to generate user uuid. %v", err)
}
Expand Down Expand Up @@ -247,10 +275,10 @@ func paramsUserKeyPermitted(request *openrtb2.BidRequest) bool {
if request.User != nil && request.User.Consent != "" {
tcModel, err := iabtcfv2.Decode(request.User.Consent)
if err != nil {
fmt.Printf("%v", err)
return true
}
if !tcModel.IsPurposeAllowed(4) {
_, tcf4InScope := tcModel.CoreString.PurposesConsent[4]
if tcf4InScope && !tcModel.IsPurposeAllowed(4) {
return false
}
}
Expand Down
37 changes: 2 additions & 35 deletions adapters/flipp/flipp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ package flipp
import (
"encoding/json"
"testing"
"time"

"github.com/SirDataFR/iabtcfv2"
"github.com/aws/smithy-go/ptr"
"github.com/prebid/openrtb/v19/openrtb2"
"github.com/prebid/prebid-server/v2/adapters/adapterstest"
"github.com/prebid/prebid-server/v2/config"
Expand All @@ -15,6 +12,7 @@ import (
)

func TestJsonSamples(t *testing.T) {
NewUUIDGenerator(true)
bidder, buildErr := Builder(openrtb_ext.BidderFlipp, config.Adapter{
Endpoint: "http://example.com/pserver"},
config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"})
Expand All @@ -41,44 +39,13 @@ func TestParamsUserKeyPermitted(t *testing.T) {
t.Run("The Global Privacy Control is set", func(t *testing.T) {
request := &openrtb2.BidRequest{
Regs: &openrtb2.Regs{
GDPR: ptr.Int8(1),
GDPR: openrtb2.Int8Ptr(1),
},
}
result := paramsUserKeyPermitted(request)
assert.New(t)
assert.False(t, result, "param user key not permitted because Global Privacy Control is set")
})
t.Run("TCF purpose 4 is in scope and doesn't have consent", func(t *testing.T) {
tcData := &iabtcfv2.TCData{
CoreString: &iabtcfv2.CoreString{
PublisherCC: "test",
Version: 2,
Created: time.Now(),
LastUpdated: time.Now(),
CmpId: 92,
CmpVersion: 1,
ConsentScreen: 1,
ConsentLanguage: "EN",
VendorListVersion: 32,
TcfPolicyVersion: 2,
PurposesConsent: map[int]bool{
1: true,
2: true,
3: true,
},
},
}
segmentValue := tcData.CoreString.Encode()
user := &openrtb2.User{
Consent: segmentValue,
}
request := &openrtb2.BidRequest{
User: user,
}
result := paramsUserKeyPermitted(request)
assert.New(t)
assert.False(t, result, "param user key not permitted because TCF purpose 4 is in scope and doesn't have consent")
})
t.Run("The Prebid transmitEids activity is disallowed", func(t *testing.T) {
extData := struct {
TransmitEids bool `json:"transmitEids"`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
{
"mockBidRequest": {
"id": "test-request-id",
"test": 1,
"device": {
"ip": "123.123.123.123"
},
"site": {
"id": "1243066",
"page": "http://www.example.com/test?flipp-content-code=publisher-test"
},
"user": {
},
"ext": {
"transmitEids": false
},
"regs": {
"coppa": 0,
"gdpr": 0
},
"imp": [
{
"id": "test-imp-id",
"tagid": "test",
"banner": {
"format": [
{
"w": 300,
"h": 1800
}
]
},
"ext": {
"bidder": {
"publisherNameIdentifier": "wishabi-test-publisher",
"creativeType": "NativeX",
"siteId": 1243066,
"zoneIds": [285431],
"options": {
"startCompact": true
},
"userKey": "abc123"
}
}
}

]
},
"httpCalls": [
{
"expectedRequest": {
"uri": "http://example.com/pserver",
"body": {
"ip":"123.123.123.123",
"keywords":[
""
],
"placements":[
{
"adTypes":[
4309,
641
],
"count":1,
"divName":"inline",
"prebid":{
"creativeType":"NativeX",
"height":1800,
"publisherNameIdentifier":"wishabi-test-publisher",
"requestId":"test-imp-id",
"width":300
},
"properties":{
"contentCode":"publisher-test"
},
"siteId":1243066,
"zoneIds":[
285431
],
"options": {
"startCompact": true
}
}
],
"url":"http://www.example.com/test?flipp-content-code=publisher-test",
"user":{
"key":"30470a14-2949-4110-abce-b62d57304ad5"
}
}
},
"mockResponse": {
"status": 200,
"body": {
"decisions": {
"inline": [
{
"adId": 183599115,
"advertiserId": 1988027,
"campaignId": 63285392,
"clickUrl": "https://e-11090.adzerk.net/r?e=eyJ2IjoiMS4xMSIsImF2IjoxOTg4MDI3LCJhdCI6NDMwOSwiYnQiOjAsImNtIjo2MzI4NTM5MiwiY2giOjU4MDgxLCJjayI6e30sImNyIjo4MTMyNTY5MCwiZGkiOiJiOTg3MGNkYTA5MTU0NDlmOTkwZGNkZTNmNjYyNGNhMyIsImRqIjowLCJpaSI6IjJmNjYwMjMyODBmYjQ4NTRiYTY0YzFlYzA1ZDU5MTNiIiwiZG0iOjMsImZjIjoxODM1OTkxMTUsImZsIjoxNzU0MjE3OTUsImlwIjoiMTQyLjE4MS41OC41MiIsIm53IjoxMDkyMiwicGMiOjAsIm9wIjowLCJlYyI6MCwiZ20iOjAsImVwIjpudWxsLCJwciI6MjMyNjk5LCJydCI6MywicnMiOjUwMCwic2EiOiIzNCIsInNiIjoiaS0wNDZjMWNlNWRjYmExMTVjNSIsInNwIjozNzIzMDU1LCJzdCI6MTI0MzA2NiwidWsiOiJkOTU1N2Q2NS1kNWI5LTQyOTItYjg2My0xNGEyOTcyNTk3ZjQiLCJ6biI6Mjg1NDMxLCJ0cyI6MTY4MDU1NTc4MzkyMiwicG4iOiJpbmxpbmUiLCJnYyI6dHJ1ZSwiZ0MiOnRydWUsImdzIjoibm9uZSIsInR6IjoiQW1lcmljYS9OZXdfWW9yayIsInVyIjoiaHR0cDovL3d3dy5mbGlwcC5jb20ifQ&s=Mnss8P1kc37Eftik5RJvLJb4S9Y",
"contents": [
{
"data": {
"customData": {
"campaignConfigUrl": "https://campaign-config.flipp.com/dist-campaign-admin/215",
"campaignNameIdentifier": "US Grocery Demo (Kroger)"
},
"height": 1800,
"width": 300
},
"type": "raw"
}
],
"creativeId": 81325690,
"flightId": 175421795,
"height": 1800,
"impressionUrl": "https://e-11090.adzerk.net/i.gif?e=eyJ2IjoiMS4xMSIsImF2IjoxOTg4MDI3LCJhdCI6NDMwOSwiYnQiOjAsImNtIjo2MzI4NTM5MiwiY2giOjU4MDgxLCJjayI6e30sImNyIjo4MTMyNTY5MCwiZGkiOiJiOTg3MGNkYTA5MTU0NDlmOTkwZGNkZTNmNjYyNGNhMyIsImRqIjowLCJpaSI6IjJmNjYwMjMyODBmYjQ4NTRiYTY0YzFlYzA1ZDU5MTNiIiwiZG0iOjMsImZjIjoxODM1OTkxMTUsImZsIjoxNzU0MjE3OTUsImlwIjoiMTQyLjE4MS41OC41MiIsIm53IjoxMDkyMiwicGMiOjAsIm9wIjowLCJlYyI6MCwiZ20iOjAsImVwIjpudWxsLCJwciI6MjMyNjk5LCJydCI6MywicnMiOjUwMCwic2EiOiIzNCIsInNiIjoiaS0wNDZjMWNlNWRjYmExMTVjNSIsInNwIjozNzIzMDU1LCJzdCI6MTI0MzA2NiwidWsiOiJkOTU1N2Q2NS1kNWI5LTQyOTItYjg2My0xNGEyOTcyNTk3ZjQiLCJ6biI6Mjg1NDMxLCJ0cyI6MTY4MDU1NTc4MzkyMywicG4iOiJpbmxpbmUiLCJnYyI6dHJ1ZSwiZ0MiOnRydWUsImdzIjoibm9uZSIsInR6IjoiQW1lcmljYS9OZXdfWW9yayIsImJhIjoxLCJmcSI6MH0&s=Qce4_IohtESeNA_sB71Qjb4TouY",
"prebid": {
"cpm": 12.34,
"creative":"creativeContent",
"creativeType": "NativeX",
"requestId": "test-imp-id"
},
"priorityId": 232699,
"storefront": {
"campaignConfig": {
"fallbackImageUrl": "https://f.wishabi.net/arbitrary_files/115856/1666018811/115856_Featured Local Savings - Flipp Fallback - US (1).png",
"fallbackLinkUrl": "https://flipp.com/flyers/",
"tags": {
"advertiser": {
"engagement": "https://f.wishabi.net/creative/happyfruits/_itemlevelv2/apple.png?cb=[[random]]"
}
}
},
"flyer_id": 5554080,
"flyer_run_id": 873256,
"flyer_type_id": 2826,
"is_fallback": true,
"merchant": "Kroger",
"merchant_id": 2778,
"name": "Weekly Ad",
"storefront_logo_url": "https://images.wishabi.net/merchants/qX1/BGIzc9sFcA==/RackMultipart20210421-1-e3k5rx.jpeg",
"storefront_payload_url": "https://cdn-gateflipp.flippback.com/storefront-payload/v2/873256/5554080/ff14f675705934507c269b5750e124a323bc9bf60e8a6f210f422f4528b233ff?merchant_id=2778",
"valid_from": "2023-03-29 04:00:00 +0000 UTC",
"valid_to": "2023-04-05 03:59:59 +0000 UTC"
},
"width": 300
}
]
},
"location": {
"accuracy_radius": 5,
"city": "Toronto",
"country": "CA",
"ip": "123.123.123.123",
"postal_code": "M4S",
"region": "ON",
"region_name": "Ontario"
}
}
}
}
],
"expectedBidResponses": [
{
"bids": [
{
"bid": {
"id": "183599115",
"impid": "test-imp-id",
"price": 12.34,
"adm": "creativeContent",
"crid": "81325690",
"w": 300
},
"type": "banner"
}
]
}
]
}
Loading

0 comments on commit f8a96e2

Please sign in to comment.