-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgopify_test.go
40 lines (34 loc) · 1.16 KB
/
gopify_test.go
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
package gopify
import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
)
func TestVerifyRequest(t *testing.T) {
gopify := Gopify{
ApiKey: "key",
ApiSecret: "hush",
RedirectUrl: "https://example.com/auth",
Scopes: []string{"read_products"},
}
cases := []struct {
u string
expected int
}{
{"code=0907a61c0c8d55e99db179b68161bc00&hmac=700e2dadb827fcc8609e9d5ce208b2e9cdaab9df07390d2cbca10d7c328fc4bf&shop=some-shop.myshopify.com&state=0.6784241404160823×tamp=1337178173", http.StatusOK},
{"code=0907a61c0c8d55e99db179b68161bc00&hmac=700e2dadb827fcc8609e9d5ce208b2e9cdaab9df07390d2cbca10d7c328fc4bf&shop=some-shop.myshopify.com&state=0.6784241404160823×tamp=133717817", http.StatusUnauthorized},
}
mux := http.DefaultServeMux
h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
mux.Handle("/", gopify.VerifyRequest(h))
for _, c := range cases {
req := httptest.NewRequest(http.MethodGet, fmt.Sprintf("/?%s", c.u), nil)
rec := httptest.NewRecorder()
mux.ServeHTTP(rec, req)
res := rec.Result()
if res.StatusCode != c.expected {
t.Errorf("incorrect response, got %d", res.StatusCode)
}
}
}