github.com/prebid/prebid-server/v2@v2.18.0/adapters/audienceNetwork/facebook_test.go (about) 1 package audienceNetwork 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/prebid/prebid-server/v2/adapters" 8 "github.com/prebid/prebid-server/v2/adapters/adapterstest" 9 "github.com/prebid/prebid-server/v2/config" 10 "github.com/prebid/prebid-server/v2/openrtb_ext" 11 "github.com/stretchr/testify/assert" 12 ) 13 14 type tagInfo struct { 15 code string 16 placementID string 17 bid float64 18 content string 19 delay time.Duration 20 W uint64 21 H uint64 22 Instl int8 23 } 24 25 type bidInfo struct { 26 partnerID int 27 appID string 28 appSecret string 29 domain string 30 page string 31 publisherID string 32 tags []tagInfo 33 deviceIP string 34 deviceUA string 35 buyerUID string 36 } 37 38 var fbdata bidInfo 39 40 type FacebookExt struct { 41 PlatformID int `json:"platformid"` 42 } 43 44 func TestJsonSamples(t *testing.T) { 45 bidder, buildErr := Builder(openrtb_ext.BidderAudienceNetwork, config.Adapter{ 46 Endpoint: "https://an.facebook.com/placementbid.ortb", 47 PlatformID: "test-platform-id", 48 AppSecret: "test-app-secret", 49 }, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"}) 50 51 if buildErr != nil { 52 t.Fatalf("Builder returned unexpected error %v", buildErr) 53 } 54 55 adapterstest.RunJSONBidderTest(t, "audienceNetworktest", bidder) 56 } 57 58 func TestMakeTimeoutNoticeApp(t *testing.T) { 59 req := adapters.RequestData{ 60 Body: []byte(`{"id":"1234","imp":[{"id":"1234"}],"app":{"publisher":{"id":"5678"}}}`), 61 } 62 bidder, buildErr := Builder(openrtb_ext.BidderAudienceNetwork, config.Adapter{ 63 Endpoint: "https://an.facebook.com/placementbid.ortb", 64 PlatformID: "test-platform-id", 65 AppSecret: "test-app-secret", 66 }, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"}) 67 68 if buildErr != nil { 69 t.Fatalf("Builder returned unexpected error %v", buildErr) 70 } 71 72 tb, ok := bidder.(adapters.TimeoutBidder) 73 if !ok { 74 t.Error("Facebook adapter is not a TimeoutAdapter") 75 } 76 77 toReq, err := tb.MakeTimeoutNotification(&req) 78 assert.Nil(t, err, "Facebook MakeTimeoutNotification() return an error %v", err) 79 expectedUri := "https://www.facebook.com/audiencenetwork/nurl/?partner=test-platform-id&app=5678&auction=1234&ortb_loss_code=2" 80 assert.Equal(t, expectedUri, toReq.Uri, "Facebook timeout notification not returning the expected URI.") 81 } 82 83 func TestMakeTimeoutNoticeBadRequest(t *testing.T) { 84 req := adapters.RequestData{ 85 Body: []byte(`{"imp":[{{"id":"1234"}}`), 86 } 87 bidder, buildErr := Builder(openrtb_ext.BidderAudienceNetwork, config.Adapter{ 88 Endpoint: "https://an.facebook.com/placementbid.ortb", 89 PlatformID: "test-platform-id", 90 AppSecret: "test-app-secret", 91 }, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"}) 92 93 if buildErr != nil { 94 t.Fatalf("Builder returned unexpected error %v", buildErr) 95 } 96 97 tb, ok := bidder.(adapters.TimeoutBidder) 98 if !ok { 99 t.Error("Facebook adapter is not a TimeoutAdapter") 100 } 101 102 toReq, err := tb.MakeTimeoutNotification(&req) 103 assert.Empty(t, toReq.Uri, "Facebook MakeTimeoutNotification() did not return nil", err) 104 assert.NotNil(t, err, "Facebook MakeTimeoutNotification() did not return an error") 105 106 } 107 108 func TestNewFacebookBidderMissingPlatformID(t *testing.T) { 109 bidder, err := Builder(openrtb_ext.BidderAudienceNetwork, config.Adapter{ 110 Endpoint: "https://an.facebook.com/placementbid.ortb", 111 AppSecret: "test-app-secret", 112 }, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"}) 113 114 assert.Empty(t, bidder) 115 assert.EqualError(t, err, "PartnerID is not configured. Did you set adapters.facebook.platform_id in the app config?") 116 } 117 118 func TestNewFacebookBidderMissingAppSecret(t *testing.T) { 119 bidder, err := Builder(openrtb_ext.BidderAudienceNetwork, config.Adapter{ 120 Endpoint: "https://an.facebook.com/placementbid.ortb", 121 PlatformID: "test-platform-id", 122 }, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"}) 123 124 assert.Empty(t, bidder) 125 assert.EqualError(t, err, "AppSecret is not configured. Did you set adapters.facebook.app_secret in the app config?") 126 }