/
service_test.go
46 lines (37 loc) · 1007 Bytes
/
service_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
// Copyright (c) 2018, Bruno M V Souza <github@b.bmvs.io>. All rights reserved.
// Use of this source code is governed by a BSD-2-Clause license that can be
// found in the LICENSE file.
package user_test
import (
"net/http"
"testing"
"github.com/stretchr/testify/assert"
"gopkg.in/jarcoal/httpmock.v1"
"go.bmvs.io/ynab"
"go.bmvs.io/ynab/api/user"
)
func TestService_GetUser(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
httpmock.RegisterResponder(http.MethodGet, "https://api.youneedabudget.com/v1/user",
func(req *http.Request) (*http.Response, error) {
res := httpmock.NewStringResponse(200, `{
"data": {
"user": {
"id": "aa248caa-eed7-4575-a990-717386438d2c"
}
}
}
`)
res.Header.Add("X-Rate-Limit", "36/200")
return res, nil
},
)
client := ynab.NewClient("")
u, err := client.User().GetUser()
assert.NoError(t, err)
expected := &user.User{
ID: "aa248caa-eed7-4575-a990-717386438d2c",
}
assert.Equal(t, expected, u)
}