github.com/prebid/prebid-server/v2@v2.18.0/adapters/huaweiads/huaweiads_test.go (about) 1 package huaweiads 2 3 import ( 4 "testing" 5 6 "github.com/prebid/prebid-server/v2/adapters/adapterstest" 7 "github.com/prebid/prebid-server/v2/config" 8 "github.com/prebid/prebid-server/v2/openrtb_ext" 9 "github.com/stretchr/testify/assert" 10 ) 11 12 func TestJsonSamples(t *testing.T) { 13 bidder, buildErr := Builder(openrtb_ext.BidderHuaweiAds, config.Adapter{ 14 Endpoint: "https://huaweiads.com/adxtest/", 15 ExtraAdapterInfo: "{\"pkgNameConvert\":[{\"convertedPkgName\":\"com.example.pkgname1\"," + 16 "\"unconvertedPkgNames\":[\"com.example.p1\",\"com.example.p2\"]," + 17 "\"unconvertedPkgNameKeyWords\":[\"p3\",\"p4\"]," + 18 "\"unconvertedPkgNamePrefixs\":[\"com.example1\",\"com.example2\"]," + 19 "\"exceptionPkgNames\":[\"com.example.p7\",\"com.example.p8\"]}," + 20 "{\"convertedPkgName\":\"com.example.pkgname2\"," + 21 "\"unconvertedPkgNames\":[\"com.example.p9\",\"com.example.p10\"]," + 22 "\"unconvertedPkgNameKeyWords\":[\"p11\",\"p12\"]," + 23 "\"unconvertedPkgNamePrefixs\":[\"com.example3\",\"com.example4\"]," + 24 "\"exceptionPkgNames\":[\"com.example.p15\",\"com.example3.unchanged\"]}]}", 25 }, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"}) 26 27 if buildErr != nil { 28 t.Fatalf("Builder returned unexpected error %v", buildErr) 29 } 30 adapterstest.RunJSONBidderTest(t, "huaweiadstest", bidder) 31 } 32 33 func TestExtraInfoDefaultWhenEmpty(t *testing.T) { 34 bidder, buildErr := Builder(openrtb_ext.BidderHuaweiAds, config.Adapter{ 35 Endpoint: `https://huaweiads.com/adxtest/`, 36 ExtraAdapterInfo: ``, 37 }, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"}) 38 39 if buildErr != nil { 40 t.Fatalf("Builder returned unexpected error %v", buildErr) 41 } 42 43 bidderHuaweiAds, _ := bidder.(*adapter) 44 45 assert.Equal(t, bidderHuaweiAds.extraInfo.PkgNameConvert, []pkgNameConvert(nil)) 46 } 47 48 func TestExtraInfo1(t *testing.T) { 49 bidder, buildErr := Builder(openrtb_ext.BidderHuaweiAds, config.Adapter{ 50 Endpoint: `https://huaweiads.com/adxtest/`, 51 ExtraAdapterInfo: "{\"pkgNameConvert\":[{\"convertedPkgName\":\"com.example.pkgname\"," + 52 "\"unconvertedPkgNames\":[\"com.example.p1\",\"com.example.p2\"]," + 53 "\"unconvertedPkgNameKeyWords\":[\"com.example.p3\",\"com.example.p4\"]," + 54 "\"unconvertedPkgNamePrefixs\":[\"com.example.p5\",\"com.example.p6\"]," + 55 "\"exceptionPkgNames\":[\"com.example.p7\",\"com.example.p8\"]}]}", 56 }, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"}) 57 58 if buildErr != nil { 59 t.Fatalf("Builder returned unexpected error %v", buildErr) 60 } 61 62 bidderHuaweiAds, _ := bidder.(*adapter) 63 64 assert.Equal(t, bidderHuaweiAds.extraInfo.PkgNameConvert[0].ConvertedPkgName, "com.example.pkgname") 65 assert.Equal(t, bidderHuaweiAds.extraInfo.PkgNameConvert[0].UnconvertedPkgNameKeyWords, []string{"com.example.p3", "com.example.p4"}) 66 assert.Equal(t, bidderHuaweiAds.extraInfo.PkgNameConvert[0].UnconvertedPkgNamePrefixs, []string{"com.example.p5", "com.example.p6"}) 67 assert.Equal(t, bidderHuaweiAds.extraInfo.PkgNameConvert[0].UnconvertedPkgNames, []string{"com.example.p1", "com.example.p2"}) 68 assert.Equal(t, bidderHuaweiAds.extraInfo.PkgNameConvert[0].ExceptionPkgNames, []string{"com.example.p7", "com.example.p8"}) 69 } 70 71 func TestExtraInfo2(t *testing.T) { 72 bidder, buildErr := Builder(openrtb_ext.BidderHuaweiAds, config.Adapter{ 73 Endpoint: `https://huaweiads.com/adxtest/`, 74 ExtraAdapterInfo: "{\"pkgNameConvert\":[{\"convertedPkgName\":\"com.example.pkgname1\"," + 75 "\"unconvertedPkgNames\":[\"com.example.p1\",\"com.example.p2\"]," + 76 "\"unconvertedPkgNameKeyWords\":[\"com.example.p3\",\"com.example.p4\"]," + 77 "\"unconvertedPkgNamePrefixs\":[\"com.example.p5\",\"com.example.p6\"]," + 78 "\"exceptionPkgNames\":[\"com.example.p7\",\"com.example.p8\"]}," + 79 "{\"convertedPkgName\":\"com.example.pkgname2\"," + 80 "\"unconvertedPkgNames\":[\"com.example.p9\",\"com.example.p10\"]," + 81 "\"unconvertedPkgNameKeyWords\":[\"com.example.p11\",\"com.example.p12\"]," + 82 "\"unconvertedPkgNamePrefixs\":[\"com.example.p13\",\"com.example.p14\"]," + 83 "\"exceptionPkgNames\":[\"com.example.p15\",\"com.example.p16\"]}]}", 84 }, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"}) 85 86 if buildErr != nil { 87 t.Fatalf("Builder returned unexpected error %v", buildErr) 88 } 89 90 bidderHuaweiAds, _ := bidder.(*adapter) 91 92 assert.Equal(t, bidderHuaweiAds.extraInfo.PkgNameConvert[1].ConvertedPkgName, "com.example.pkgname2") 93 assert.Equal(t, bidderHuaweiAds.extraInfo.PkgNameConvert[0].UnconvertedPkgNameKeyWords, []string{"com.example.p3", "com.example.p4"}) 94 assert.Equal(t, bidderHuaweiAds.extraInfo.PkgNameConvert[1].UnconvertedPkgNamePrefixs, []string{"com.example.p13", "com.example.p14"}) 95 assert.Equal(t, bidderHuaweiAds.extraInfo.PkgNameConvert[0].UnconvertedPkgNames, []string{"com.example.p1", "com.example.p2"}) 96 assert.Equal(t, bidderHuaweiAds.extraInfo.PkgNameConvert[1].ExceptionPkgNames, []string{"com.example.p15", "com.example.p16"}) 97 } 98 99 func TestExtraInfo3(t *testing.T) { 100 _, buildErr := Builder(openrtb_ext.BidderHuaweiAds, config.Adapter{ 101 Endpoint: `https://huaweiads.com/adxtest/`, 102 ExtraAdapterInfo: "{\"pkgNameConvert\":[{\"convertedPkgName\":\"\"," + 103 "\"unconvertedPkgNames\":[\"com.example.p1\",\"com.example.p2\"]," + 104 "\"unconvertedPkgNameKeyWords\":[\"com.example.p3\",\"com.example.p4\"]," + 105 "\"unconvertedPkgNamePrefixs\":[\"com.example.p5\",\"com.example.p6\"]," + 106 "\"exceptionPkgNames\":[\"com.example.p7\",\"com.example.p8\"]}]," + 107 "\"closeSiteSelectionByCountry\":\"1\"}", 108 }, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"}) 109 assert.Equal(t, buildErr.Error(), "invalid extra info: ConvertedPkgName is empty, pls check") 110 } 111 112 func TestExtraInfo4(t *testing.T) { 113 _, buildErr := Builder(openrtb_ext.BidderHuaweiAds, config.Adapter{ 114 Endpoint: `https://huaweiads.com/adxtest/`, 115 ExtraAdapterInfo: "{\"pkgNameConvert\":[{\"convertedPkgName\":\"com.example.pkgname1\"," + 116 "\"unconvertedPkgNames\":[\"com.example.p1\",\"com.example.p2\"]," + 117 "\"unconvertedPkgNameKeyWords\":[\"\",\"com.example.p4\"]," + 118 "\"unconvertedPkgNamePrefixs\":[\"com.example.p5\",\"\"]," + 119 "\"exceptionPkgNames\":[\"com.example.p7\",\"com.example.p8\"]}]," + 120 "\"closeSiteSelectionByCountry\":\"1\"}", 121 }, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"}) 122 assert.Equal(t, buildErr.Error(), "invalid extra info: UnconvertedPkgNameKeyWords has a empty keyword, pls check") 123 } 124 125 func TestExtraInfo5(t *testing.T) { 126 _, buildErr := Builder(openrtb_ext.BidderHuaweiAds, config.Adapter{ 127 Endpoint: `https://huaweiads.com/adxtest/`, 128 ExtraAdapterInfo: "{\"pkgNameConvert\":[{\"convertedPkgName\":\"com.example.pkgname1\"," + 129 "\"unconvertedPkgNames\":[\"com.example.p1\",\"com.example.p2\"]," + 130 "\"unconvertedPkgNameKeyWords\":[\"com.example.p3\",\"com.example.p4\"]," + 131 "\"unconvertedPkgNamePrefixs\":[\"com.example.p5\",\"\"]," + 132 "\"exceptionPkgNames\":[\"com.example.p7\",\"com.example.p8\"]}]," + 133 "\"closeSiteSelectionByCountry\":\"1\"}", 134 }, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"}) 135 assert.Equal(t, buildErr.Error(), "invalid extra info: UnconvertedPkgNamePrefixs has a empty value, pls check") 136 } 137 138 func TestExtraInfo6(t *testing.T) { 139 bidder, buildErr := Builder(openrtb_ext.BidderHuaweiAds, config.Adapter{ 140 Endpoint: `https://huaweiads.com/adxtest/`, 141 ExtraAdapterInfo: "{\"pkgNameConvert\":[{\"convertedPkgName\":\"com.example.pkgname1\"," + 142 "\"unconvertedPkgNames\":[\"com.example.p1\",\"com.example.p2\"]," + 143 "\"unconvertedPkgNameKeyWords\":[\"com.example.p3\",\"com.example.p4\"]," + 144 "\"unconvertedPkgNamePrefixs\":[\"com.example.p5\",\"com.example.p6\"]," + 145 "\"exceptionPkgNames\":[\"com.example.p7\",\"com.example.p8\"]}," + 146 "{\"convertedPkgName\":\"com.example.pkgname2\"," + 147 "\"unconvertedPkgNames\":[\"com.example.p9\",\"com.example.p10\"]," + 148 "\"unconvertedPkgNameKeyWords\":[\"com.example.p11\",\"com.example.p12\"]," + 149 "\"unconvertedPkgNamePrefixs\":[\"com.example.p13\",\"com.example.p14\"]," + 150 "\"exceptionPkgNames\":[\"com.example.p15\",\"com.example.p16\"]}],\"closeSiteSelectionByCountry\":\"1\"}", 151 }, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"}) 152 153 if buildErr != nil { 154 t.Fatalf("Builder returned unexpected error %v", buildErr) 155 } 156 157 bidderHuaweiAds, _ := bidder.(*adapter) 158 159 assert.Equal(t, bidderHuaweiAds.extraInfo.CloseSiteSelectionByCountry, "1") 160 }