github.com/prebid/prebid-server/v2@v2.18.0/adapters/smaato/image_test.go (about) 1 package smaato 2 3 import ( 4 "github.com/stretchr/testify/assert" 5 "testing" 6 ) 7 8 func TestExtractAdmImage(t *testing.T) { 9 tests := []struct { 10 testName string 11 adMarkup string 12 expectedAdMarkup string 13 expectedError string 14 }{ 15 { 16 testName: "extract image", 17 adMarkup: "{\"image\":{\"img\":{\"url\":\"//prebid-test.smaatolabs.net/img/320x50.jpg\"," + 18 "\"w\":350,\"h\":50,\"ctaurl\":\"//prebid-test.smaatolabs.net/track/ctaurl/1\"}," + 19 "\"impressiontrackers\":[\"//prebid-test.smaatolabs.net/track/imp/1\",\"//prebid-test.smaatolabs.net/track/imp/2\"]," + 20 "\"clicktrackers\":[\"//prebid-test.smaatolabs.net/track/click/1\",\"//prebid-test.smaatolabs.net/track/click/2\"]}}", 21 expectedAdMarkup: `<div style="cursor:pointer"` + 22 ` onclick="fetch(decodeURIComponent('%2F%2Fprebid-test.smaatolabs.net%2Ftrack%2Fclick%2F1'.replace(/\+/g, ' ')),` + 23 ` {cache: 'no-cache'});fetch(decodeURIComponent('%2F%2Fprebid-test.smaatolabs.net%2Ftrack%2Fclick%2F2'.replace(/\+/g, ' ')),` + 24 ` {cache: 'no-cache'});;window.open(decodeURIComponent('%2F%2Fprebid-test.smaatolabs.net%2Ftrack%2Fctaurl%2F1'.replace(/\+/g, ' ')));">` + 25 `<img src="//prebid-test.smaatolabs.net/img/320x50.jpg" width="350" height="50"/>` + 26 `<img src="//prebid-test.smaatolabs.net/track/imp/1" alt="" width="0" height="0"/>` + 27 `<img src="//prebid-test.smaatolabs.net/track/imp/2" alt="" width="0" height="0"/></div>`, 28 expectedError: "", 29 }, 30 { 31 testName: "invalid adMarkup", 32 adMarkup: "{", 33 expectedAdMarkup: "", 34 expectedError: "Invalid ad markup {.", 35 }, 36 } 37 38 for _, tt := range tests { 39 t.Run(tt.testName, func(t *testing.T) { 40 adMarkup, err := extractAdmImage(tt.adMarkup) 41 42 if tt.expectedError != "" { 43 assert.EqualError(t, err, tt.expectedError) 44 } else { 45 assert.NoError(t, err) 46 } 47 48 assert.Equal(t, tt.expectedAdMarkup, adMarkup) 49 }) 50 } 51 }