-
Notifications
You must be signed in to change notification settings - Fork 762
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Smaato: Change server response type (#3734)
- Loading branch information
Ruslan S.
authored
Jul 24, 2024
1 parent
115f773
commit d1596c8
Showing
37 changed files
with
251 additions
and
1,129 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
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) | ||
} |
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 |
---|---|---|
@@ -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) | ||
}) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.