-
Notifications
You must be signed in to change notification settings - Fork 21
/
live_photos_test.go
69 lines (61 loc) · 1.79 KB
/
live_photos_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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package onfido_test
import (
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"time"
"github.com/gorilla/mux"
"github.com/stretchr/testify/assert"
"github.com/uw-labs/go-onfido"
)
func TestLivePhotos_List(t *testing.T) {
applicantID := "541d040b-89f8-444b-8921-16b1333bf1c6"
createdAt := time.Now()
expected := onfido.LivePhoto{
ID: "541d040b-89f8-444b-8921-16b1333bf1c7",
CreatedAt: &createdAt,
Href: "/v2/live_photos/7410A943-8F00-43D8-98DE-36A774196D86",
DownloadHref: "https://onfido.com/photo/pdf/1234",
FileName: "something.png",
FileSize: 1234,
FileType: "image/png",
}
expectedJSON, err := json.Marshal(struct {
LivePhotos []*onfido.LivePhoto `json:"live_photos"`
}{
LivePhotos: []*onfido.LivePhoto{&expected},
})
if err != nil {
t.Fatal(err)
}
m := mux.NewRouter()
m.HandleFunc("/live_photos", func(w http.ResponseWriter, r *http.Request) {
if r.URL.Query().Get("applicant_id") != applicantID {
t.Fatal("expected applicant id was not in the request")
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
_, wErr := w.Write(expectedJSON)
assert.NoError(t, wErr)
}).Methods("GET")
srv := httptest.NewServer(m)
defer srv.Close()
client := onfido.NewClient("123")
client.Endpoint = srv.URL
it := client.ListLivePhotos(applicantID)
for it.Next(context.Background()) {
c := it.LivePhoto()
assert.Equal(t, expected.ID, c.ID)
assert.True(t, expected.CreatedAt.Equal(*c.CreatedAt))
assert.Equal(t, expected.Href, c.Href)
assert.Equal(t, expected.DownloadHref, c.DownloadHref)
assert.Equal(t, expected.FileName, c.FileName)
assert.Equal(t, expected.FileSize, c.FileSize)
assert.Equal(t, expected.FileType, c.FileType)
}
if it.Err() != nil {
t.Fatal(it.Err())
}
}