-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgreenlight_test.go
49 lines (41 loc) · 1.24 KB
/
greenlight_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
41
42
43
44
45
46
47
48
49
package signup
import (
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"time"
)
func TestPostWebhook(t *testing.T) {
t.Run("POSTs a webhook to Greenlight with the signup payload", func(t *testing.T) {
apiKey := "test-api-key"
sessionStartDate, _ := time.Parse(time.RFC822, "14 Mar 22 17:00 UTC")
su := Signup{
NameFirst: "Bob",
NameLast: "Ross",
Email: "[email protected]",
Cell: "555-123-4567",
Referrer: "instagram",
ReferrerResponse: "",
StartDateTime: sessionStartDate,
Cohort: "is-mar-14-22-12pm",
SessionID: "X5TsABhN94yesyMEi",
UserLocation: "Louisiana",
AttendingLocation: "IN_PERSON",
}
mockGreenlightSvr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Sends API Key header
assertEqual(t, r.Header.Get("X-Greenlight-Signup-Api-Key"), apiKey)
// POSTs correct JSON body
var glReq Signup
d := json.NewDecoder(r.Body)
err := d.Decode(&glReq)
assertNilError(t, err)
assertDeepEqual(t, glReq, su)
}))
glSvc := NewGreenlightService(mockGreenlightSvr.URL, apiKey)
err := glSvc.postWebhook(context.Background(), su)
assertNilError(t, err)
})
}