-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckout_test.go
More file actions
79 lines (71 loc) · 2.21 KB
/
Copy pathcheckout_test.go
File metadata and controls
79 lines (71 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package makepay
import (
"strings"
"testing"
)
func TestCheckoutURLs(t *testing.T) {
hosted, err := BuildHostedCheckoutURL("pay_123", CheckoutURLOptions{
BaseURL: "https://pay.example/",
})
if err != nil {
t.Fatal(err)
}
if hosted != "https://pay.example/payment/pay_123" {
t.Fatalf("unexpected hosted URL: %s", hosted)
}
embedded, err := BuildEmbeddedCheckoutURL("pay_123", CheckoutURLOptions{
BaseURL: "https://pay.example/",
ParentOrigin: "https://merchant.example",
})
if err != nil {
t.Fatal(err)
}
if embedded != "https://pay.example/embed/payment/pay_123?parentOrigin=https%3A%2F%2Fmerchant.example" {
t.Fatalf("unexpected embedded URL: %s", embedded)
}
donation, err := BuildHostedDonationURL("spring campaign", CheckoutURLOptions{
BaseURL: "https://pay.example/",
})
if err != nil {
t.Fatal(err)
}
if donation != "https://pay.example/donations/spring%20campaign" {
t.Fatalf("unexpected donation URL: %s", donation)
}
embeddedDonation, err := BuildEmbeddedDonationURL("spring", CheckoutURLOptions{
BaseURL: "https://pay.example/",
ParentOrigin: "https://merchant.example",
})
if err != nil {
t.Fatal(err)
}
if embeddedDonation != "https://pay.example/embed/donations/spring?parentOrigin=https%3A%2F%2Fmerchant.example" {
t.Fatalf("unexpected embedded donation URL: %s", embeddedDonation)
}
if got := BuildModalScriptURL(CheckoutURLOptions{BaseURL: "https://pay.example/"}); got != "https://pay.example/modal/makepay.js" {
t.Fatalf("unexpected modal script URL: %s", got)
}
}
func TestCheckoutHTMLSnippets(t *testing.T) {
button, err := BuildEmbedButtonHTML(`pay_"<&`, EmbedSnippetOptions{
ButtonLabel: "Pay <now>",
})
if err != nil {
t.Fatal(err)
}
if !strings.Contains(button, `data-makepay-payment-link="pay_"<&"`) {
t.Fatalf("payment UID was not escaped: %s", button)
}
if !strings.Contains(button, "Pay <now>") {
t.Fatalf("button label was not escaped: %s", button)
}
iframe, err := BuildIframeHTML("pay_123", EmbedSnippetOptions{
IframeTitle: "Secure checkout",
})
if err != nil {
t.Fatal(err)
}
if !strings.Contains(iframe, `src="https://makepay.io/embed/payment/pay_123"`) {
t.Fatalf("unexpected iframe snippet: %s", iframe)
}
}