Skip to content

Commit

Permalink
Smaato: Change server response type
Browse files Browse the repository at this point in the history
  • Loading branch information
Enigo committed Jul 23, 2024
1 parent 0f5a1fe commit b2188fa
Show file tree
Hide file tree
Showing 37 changed files with 251 additions and 1,129 deletions.
21 changes: 21 additions & 0 deletions adapters/smaato/banner.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package smaato

import (
"fmt"
"net/url"
"strings"
)

func extractAdmBanner(adMarkup string, curls []string) string {
var clickEvent string
if len(curls) > 0 {
var clicks strings.Builder
for _, clicktracker := range curls {
clicks.WriteString("fetch(decodeURIComponent('" + url.QueryEscape(clicktracker) + "'.replace(/\\+/g, ' ')), " +
"{cache: 'no-cache'});")
}
clickEvent = fmt.Sprintf(`onclick=%s`, clicks.String())
}

return fmt.Sprintf(`<div style="cursor:pointer" %s>%s</div>`, clickEvent, adMarkup)
}
42 changes: 42 additions & 0 deletions adapters/smaato/banner_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package smaato

import (
"github.com/stretchr/testify/assert"
"testing"
)

func TestExtractAdmBanner(t *testing.T) {
tests := []struct {
testName string
adMarkup string
curls []string
expectedAdMarkup string
}{
{
testName: "extract_banner_without_curls",
adMarkup: `<a rel="nofollow" href="https://prebid.net/click"><img src="https://prebid.net/images/image.png" alt="" width="480" height="320" /></a>`,
expectedAdMarkup: `<div style="cursor:pointer" ><a rel="nofollow" href="https://prebid.net/click"><img src="https://prebid.net/images/image.png" alt="" width="480" height="320" /></a></div>`,
curls: []string{},
},
{
testName: "extract_banner_with_nil_curls",
adMarkup: `<a rel="nofollow" href="https://prebid.net/click"><img src="https://prebid.net/images/image.png" alt="" width="480" height="320" /></a>`,
expectedAdMarkup: `<div style="cursor:pointer" ><a rel="nofollow" href="https://prebid.net/click"><img src="https://prebid.net/images/image.png" alt="" width="480" height="320" /></a></div>`,
curls: nil,
},
{
testName: "extract_banner_with_curls",
adMarkup: `<a rel="nofollow" href="https://prebid.net/click"><img src="https://prebid.net/images/image.png" alt="" width="480" height="320" /></a>`,
expectedAdMarkup: `<div style="cursor:pointer" onclick=fetch(decodeURIComponent('curls.net'.replace(/\+/g, ' ')), {cache: 'no-cache'});><a rel="nofollow" href="https://prebid.net/click"><img src="https://prebid.net/images/image.png" alt="" width="480" height="320" /></a></div>`,
curls: []string{"curls.net"},
},
}

for _, tt := range tests {
t.Run(tt.testName, func(t *testing.T) {
adMarkup := extractAdmBanner(tt.adMarkup, tt.curls)

assert.Equal(t, tt.expectedAdMarkup, adMarkup)
})
}
}
50 changes: 0 additions & 50 deletions adapters/smaato/image.go

This file was deleted.

51 changes: 0 additions & 51 deletions adapters/smaato/image_test.go

This file was deleted.

50 changes: 0 additions & 50 deletions adapters/smaato/richmedia.go

This file was deleted.

48 changes: 0 additions & 48 deletions adapters/smaato/richmedia_test.go

This file was deleted.

Loading

0 comments on commit b2188fa

Please sign in to comment.