forked from prebid/prebid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Smaato: Rework multi imp support and add adpod support (prebid#1902)
- Loading branch information
Showing
46 changed files
with
3,926 additions
and
424 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,51 @@ | ||
package smaato | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestRenderAdMarkup(t *testing.T) { | ||
type args struct { | ||
adType adMarkupType | ||
adapterResponseAdm string | ||
} | ||
expectedResult := `<div style="cursor:pointer"` + | ||
` onclick="fetch(decodeURIComponent('%2F%2Fprebid-test.smaatolabs.net%2Ftrack%2Fclick%2F1'.replace(/\+/g, ' ')),` + | ||
` {cache: 'no-cache'});fetch(decodeURIComponent('%2F%2Fprebid-test.smaatolabs.net%2Ftrack%2Fclick%2F2'.replace(/\+/g, ' ')),` + | ||
` {cache: 'no-cache'});;window.open(decodeURIComponent('%2F%2Fprebid-test.smaatolabs.net%2Ftrack%2Fctaurl%2F1'.replace(/\+/g, ' ')));">` + | ||
`<img src="//prebid-test.smaatolabs.net/img/320x50.jpg" width="350" height="50"/>` + | ||
`<img src="//prebid-test.smaatolabs.net/track/imp/1" alt="" width="0" height="0"/>` + | ||
`<img src="//prebid-test.smaatolabs.net/track/imp/2" alt="" width="0" height="0"/></div>` | ||
|
||
func TestExtractAdmImage(t *testing.T) { | ||
tests := []struct { | ||
testName string | ||
args args | ||
result string | ||
testName string | ||
adMarkup string | ||
expectedAdMarkup string | ||
expectedError string | ||
}{ | ||
{"imageTest", args{"Img", | ||
"{\"image\":{\"img\":{\"url\":\"//prebid-test.smaatolabs.net/img/320x50.jpg\"," + | ||
{ | ||
testName: "extract image", | ||
adMarkup: "{\"image\":{\"img\":{\"url\":\"//prebid-test.smaatolabs.net/img/320x50.jpg\"," + | ||
"\"w\":350,\"h\":50,\"ctaurl\":\"//prebid-test.smaatolabs.net/track/ctaurl/1\"}," + | ||
"\"impressiontrackers\":[\"//prebid-test.smaatolabs.net/track/imp/1\",\"//prebid-test.smaatolabs.net/track/imp/2\"]," + | ||
"\"clicktrackers\":[\"//prebid-test.smaatolabs.net/track/click/1\",\"//prebid-test.smaatolabs.net/track/click/2\"]}}"}, | ||
expectedResult, | ||
"\"clicktrackers\":[\"//prebid-test.smaatolabs.net/track/click/1\",\"//prebid-test.smaatolabs.net/track/click/2\"]}}", | ||
expectedAdMarkup: `<div style="cursor:pointer"` + | ||
` onclick="fetch(decodeURIComponent('%2F%2Fprebid-test.smaatolabs.net%2Ftrack%2Fclick%2F1'.replace(/\+/g, ' ')),` + | ||
` {cache: 'no-cache'});fetch(decodeURIComponent('%2F%2Fprebid-test.smaatolabs.net%2Ftrack%2Fclick%2F2'.replace(/\+/g, ' ')),` + | ||
` {cache: 'no-cache'});;window.open(decodeURIComponent('%2F%2Fprebid-test.smaatolabs.net%2Ftrack%2Fctaurl%2F1'.replace(/\+/g, ' ')));">` + | ||
`<img src="//prebid-test.smaatolabs.net/img/320x50.jpg" width="350" height="50"/>` + | ||
`<img src="//prebid-test.smaatolabs.net/track/imp/1" alt="" width="0" height="0"/>` + | ||
`<img src="//prebid-test.smaatolabs.net/track/imp/2" alt="" width="0" height="0"/></div>`, | ||
expectedError: "", | ||
}, | ||
{ | ||
testName: "invalid adMarkup", | ||
adMarkup: "{", | ||
expectedAdMarkup: "", | ||
expectedError: "Invalid ad markup {.", | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.testName, func(t *testing.T) { | ||
got, err := renderAdMarkup(tt.args.adType, tt.args.adapterResponseAdm) | ||
if err != nil { | ||
t.Errorf("error rendering ad markup: %v", err) | ||
} | ||
if got != tt.result { | ||
t.Errorf("renderAdMarkup() got = %v, result %v", got, tt.result) | ||
adMarkup, err := extractAdmImage(tt.adMarkup) | ||
|
||
if tt.expectedError != "" { | ||
assert.EqualError(t, err, tt.expectedError) | ||
} else { | ||
assert.NoError(t, err) | ||
} | ||
|
||
assert.Equal(t, tt.expectedAdMarkup, adMarkup) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,48 @@ | ||
package smaato | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestExtractAdmRichMedia(t *testing.T) { | ||
type args struct { | ||
adType adMarkupType | ||
adapterResponseAdm string | ||
} | ||
expectedResult := `<div onclick="fetch(decodeURIComponent('%2F%2Fprebid-test.smaatolabs.net%2Ftrack%2Fclick%2F1'),` + | ||
` {cache: 'no-cache'});fetch(decodeURIComponent('%2F%2Fprebid-test.smaatolabs.net%2Ftrack%2Fclick%2F2'),` + | ||
` {cache: 'no-cache'});"><div>hello</div><img src="//prebid-test.smaatolabs.net/track/imp/1" alt="" width="0" height="0"/>` + | ||
`<img src="//prebid-test.smaatolabs.net/track/imp/2" alt="" width="0" height="0"/></div>` | ||
tests := []struct { | ||
testName string | ||
args args | ||
result string | ||
testName string | ||
adMarkup string | ||
expectedAdMarkup string | ||
expectedError string | ||
}{ | ||
{"richmediaTest", args{"Richmedia", "{\"richmedia\":{\"mediadata\":{\"content\":\"<div>hello</div>\"," + | ||
"" + "\"w\":350," + | ||
"\"h\":50},\"impressiontrackers\":[\"//prebid-test.smaatolabs.net/track/imp/1\",\"//prebid-test.smaatolabs.net/track/imp/2\"]," + | ||
"\"clicktrackers\":[\"//prebid-test.smaatolabs.net/track/click/1\",\"//prebid-test.smaatolabs.net/track/click/2\"]}}"}, | ||
expectedResult, | ||
{ | ||
testName: "extract richmedia", | ||
adMarkup: "{\"richmedia\":{\"mediadata\":{\"content\":\"<div>hello</div>\"," + | ||
"" + "\"w\":350," + | ||
"\"h\":50},\"impressiontrackers\":[\"//prebid-test.smaatolabs.net/track/imp/1\",\"//prebid-test.smaatolabs.net/track/imp/2\"]," + | ||
"\"clicktrackers\":[\"//prebid-test.smaatolabs.net/track/click/1\",\"//prebid-test.smaatolabs.net/track/click/2\"]}}", | ||
expectedAdMarkup: `<div onclick="fetch(decodeURIComponent('%2F%2Fprebid-test.smaatolabs.net%2Ftrack%2Fclick%2F1'),` + | ||
` {cache: 'no-cache'});fetch(decodeURIComponent('%2F%2Fprebid-test.smaatolabs.net%2Ftrack%2Fclick%2F2'),` + | ||
` {cache: 'no-cache'});"><div>hello</div><img src="//prebid-test.smaatolabs.net/track/imp/1" alt="" width="0" height="0"/>` + | ||
`<img src="//prebid-test.smaatolabs.net/track/imp/2" alt="" width="0" height="0"/></div>`, | ||
expectedError: "", | ||
}, | ||
{ | ||
testName: "invalid adMarkup", | ||
adMarkup: "{", | ||
expectedAdMarkup: "", | ||
expectedError: "Invalid ad markup {.", | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.testName, func(t *testing.T) { | ||
got, err := renderAdMarkup(tt.args.adType, tt.args.adapterResponseAdm) | ||
if err != nil { | ||
t.Errorf("error rendering ad markup: %v", err) | ||
} | ||
if got != tt.result { | ||
t.Errorf("renderAdMarkup() got = %v, result %v", got, tt.result) | ||
adMarkup, err := extractAdmRichMedia(tt.adMarkup) | ||
|
||
if tt.expectedError != "" { | ||
assert.EqualError(t, err, tt.expectedError) | ||
} else { | ||
assert.NoError(t, err) | ||
} | ||
|
||
assert.Equal(t, tt.expectedAdMarkup, adMarkup) | ||
}) | ||
} | ||
} |
Oops, something went wrong.