github.com/prebid/prebid-server/v2@v2.18.0/adapters/smaato/richmedia_test.go (about)

     1  package smaato
     2  
     3  import (
     4  	"github.com/stretchr/testify/assert"
     5  	"testing"
     6  )
     7  
     8  func TestExtractAdmRichMedia(t *testing.T) {
     9  	tests := []struct {
    10  		testName         string
    11  		adMarkup         string
    12  		expectedAdMarkup string
    13  		expectedError    string
    14  	}{
    15  		{
    16  			testName: "extract richmedia",
    17  			adMarkup: "{\"richmedia\":{\"mediadata\":{\"content\":\"<div>hello</div>\"," +
    18  				"" + "\"w\":350," +
    19  				"\"h\":50},\"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 onclick="fetch(decodeURIComponent('%2F%2Fprebid-test.smaatolabs.net%2Ftrack%2Fclick%2F1'),` +
    22  				` {cache: 'no-cache'});fetch(decodeURIComponent('%2F%2Fprebid-test.smaatolabs.net%2Ftrack%2Fclick%2F2'),` +
    23  				` {cache: 'no-cache'});"><div>hello</div><img src="//prebid-test.smaatolabs.net/track/imp/1" alt="" width="0" height="0"/>` +
    24  				`<img src="//prebid-test.smaatolabs.net/track/imp/2" alt="" width="0" height="0"/></div>`,
    25  			expectedError: "",
    26  		},
    27  		{
    28  			testName:         "invalid adMarkup",
    29  			adMarkup:         "{",
    30  			expectedAdMarkup: "",
    31  			expectedError:    "Invalid ad markup {.",
    32  		},
    33  	}
    34  
    35  	for _, tt := range tests {
    36  		t.Run(tt.testName, func(t *testing.T) {
    37  			adMarkup, err := extractAdmRichMedia(tt.adMarkup)
    38  
    39  			if tt.expectedError != "" {
    40  				assert.EqualError(t, err, tt.expectedError)
    41  			} else {
    42  				assert.NoError(t, err)
    43  			}
    44  
    45  			assert.Equal(t, tt.expectedAdMarkup, adMarkup)
    46  		})
    47  	}
    48  }