github.com/prebid/prebid-server/v2@v2.18.0/schain/schain_test.go (about) 1 package schain 2 3 import ( 4 "testing" 5 6 "github.com/prebid/openrtb/v20/openrtb2" 7 "github.com/prebid/prebid-server/v2/openrtb_ext" 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func TestBidderToPrebidChains(t *testing.T) { 12 input := openrtb_ext.ExtRequest{ 13 Prebid: openrtb_ext.ExtRequestPrebid{ 14 SChains: []*openrtb_ext.ExtRequestPrebidSChain{ 15 { 16 Bidders: []string{"Bidder1", "Bidder2"}, 17 SChain: openrtb2.SupplyChain{ 18 Complete: 1, 19 Nodes: []openrtb2.SupplyChainNode{ 20 { 21 ASI: "asi1", 22 SID: "sid1", 23 Name: "name1", 24 RID: "rid1", 25 Domain: "domain1", 26 HP: openrtb2.Int8Ptr(1), 27 }, 28 { 29 ASI: "asi2", 30 SID: "sid2", 31 Name: "name2", 32 RID: "rid2", 33 Domain: "domain2", 34 HP: openrtb2.Int8Ptr(2), 35 }, 36 }, 37 Ver: "version1", 38 }, 39 }, 40 { 41 Bidders: []string{"Bidder3", "Bidder4"}, 42 SChain: openrtb2.SupplyChain{}, 43 }, 44 }, 45 }, 46 } 47 48 output, err := BidderToPrebidSChains(input.Prebid.SChains) 49 50 assert.Nil(t, err) 51 assert.Equal(t, len(output), 4) 52 assert.Same(t, output["Bidder1"], &input.Prebid.SChains[0].SChain) 53 assert.Same(t, output["Bidder2"], &input.Prebid.SChains[0].SChain) 54 assert.Same(t, output["Bidder3"], &input.Prebid.SChains[1].SChain) 55 assert.Same(t, output["Bidder4"], &input.Prebid.SChains[1].SChain) 56 } 57 58 func TestBidderToPrebidChainsDiscardMultipleChainsForBidder(t *testing.T) { 59 input := openrtb_ext.ExtRequest{ 60 Prebid: openrtb_ext.ExtRequestPrebid{ 61 SChains: []*openrtb_ext.ExtRequestPrebidSChain{ 62 { 63 Bidders: []string{"Bidder1"}, 64 SChain: openrtb2.SupplyChain{}, 65 }, 66 { 67 Bidders: []string{"Bidder1", "Bidder2"}, 68 SChain: openrtb2.SupplyChain{}, 69 }, 70 }, 71 }, 72 } 73 74 output, err := BidderToPrebidSChains(input.Prebid.SChains) 75 76 assert.NotNil(t, err) 77 assert.Nil(t, output) 78 } 79 80 func TestBidderToPrebidChainsNilSChains(t *testing.T) { 81 input := openrtb_ext.ExtRequest{ 82 Prebid: openrtb_ext.ExtRequestPrebid{ 83 SChains: nil, 84 }, 85 } 86 87 output, err := BidderToPrebidSChains(input.Prebid.SChains) 88 89 assert.Nil(t, err) 90 assert.Equal(t, len(output), 0) 91 } 92 93 func TestBidderToPrebidChainsZeroLengthSChains(t *testing.T) { 94 input := openrtb_ext.ExtRequest{ 95 Prebid: openrtb_ext.ExtRequestPrebid{ 96 SChains: []*openrtb_ext.ExtRequestPrebidSChain{}, 97 }, 98 } 99 100 output, err := BidderToPrebidSChains(input.Prebid.SChains) 101 102 assert.Nil(t, err) 103 assert.Equal(t, len(output), 0) 104 }