-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathserve_toilet_test.go
77 lines (56 loc) · 1.67 KB
/
serve_toilet_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
70
71
72
73
74
75
76
77
package main
import (
"encoding/json"
"errors"
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
)
func TestToiletBsaAvailable(t *testing.T) {
exp := []BsaAd{
{
Ad: ad,
Pixel: []string{"pixel"},
ReferralLink: "https://referral.com",
},
}
fetchBsa = func(r *http.Request, propertyId string) (*BsaAd, error) {
return &exp[0], nil
}
req, err := http.NewRequest("GET", "/a/toilet", nil)
assert.Nil(t, err)
rr := httptest.NewRecorder()
router := createApp()
router.ServeHTTP(rr, req)
assert.Equal(t, http.StatusOK, rr.Code, "wrong status code")
var actual []BsaAd
assert.NoError(t, json.NewDecoder(rr.Body).Decode(&actual))
assert.Equal(t, exp, actual, "wrong body")
}
func TestToiletBsaNotAvailable(t *testing.T) {
fetchBsa = bsaNotAvailable
req, err := http.NewRequest("GET", "/a/toilet", nil)
assert.Nil(t, err)
rr := httptest.NewRecorder()
router := createApp()
router.ServeHTTP(rr, req)
assert.Equal(t, http.StatusOK, rr.Code, "wrong status code")
var actual []interface{}
assert.NoError(t, json.NewDecoder(rr.Body).Decode(&actual))
assert.Equal(t, []interface{}{}, actual, "wrong body")
}
func TestToiletBsaNotFail(t *testing.T) {
fetchBsa = func(r *http.Request, propertyId string) (*BsaAd, error) {
return nil, errors.New("error")
}
req, err := http.NewRequest("GET", "/a/toilet", nil)
assert.Nil(t, err)
rr := httptest.NewRecorder()
router := createApp()
router.ServeHTTP(rr, req)
assert.Equal(t, http.StatusOK, rr.Code, "wrong status code")
var actual []interface{}
assert.NoError(t, json.NewDecoder(rr.Body).Decode(&actual))
assert.Equal(t, []interface{}{}, actual, "wrong body")
}