-
Notifications
You must be signed in to change notification settings - Fork 79
/
company_test.go
87 lines (73 loc) · 2.93 KB
/
company_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
78
79
80
81
82
83
84
85
86
87
package intercom
import (
"testing"
)
func TestCompanyFindByID(t *testing.T) {
company, _ := (&CompanyService{Repository: TestCompanyAPI{t: t}}).FindByID("46adad3f09126dca")
if company.ID != "46adad3f09126dca" {
t.Errorf("Company not found")
}
}
func TestCompanyFindByName(t *testing.T) {
company, _ := (&CompanyService{Repository: TestCompanyAPI{t: t}}).FindByName("My Co")
if company.Name != "My Co" {
t.Errorf("Company not found")
}
}
func TestCompanyFindByCompanyID(t *testing.T) {
company, _ := (&CompanyService{Repository: TestCompanyAPI{t: t}}).FindByCompanyID("134d")
if company.CompanyID != "134d" {
t.Errorf("Company not found")
}
}
func TestCompanyList(t *testing.T) {
companyList, _ := (&CompanyService{Repository: TestCompanyAPI{t: t}}).List(PageParams{})
companies := companyList.Companies
if companies[0].ID != "46adad3f09126dca" {
t.Errorf("Company not listed")
}
}
func TestCompanyListUsersByID(t *testing.T) {
companyUserList, _ := (&CompanyService{Repository: TestCompanyAPI{t: t}}).ListUsersByID("46adad3f09126dca", PageParams{})
users := companyUserList.Users
if users[0].Companies.Companies[0].ID != "46adad3f09126dca" {
t.Errorf("User not listed")
}
}
func TestCompanyListUsersByCompanyID(t *testing.T) {
companyUserList, _ := (&CompanyService{Repository: TestCompanyAPI{t: t}}).ListUsersByCompanyID("134d", PageParams{})
users := companyUserList.Users
if users[0].Companies.Companies[0].CompanyID != "134d" {
t.Errorf("User not listed")
}
}
func TestCompanySave(t *testing.T) {
companyService := CompanyService{Repository: TestCompanyAPI{t: t}}
company := Company{ID: "46adad3f09126dca", CustomAttributes: map[string]interface{}{"is_cool": true}}
companyService.Save(&company)
}
type TestCompanyAPI struct {
t *testing.T
}
func (t TestCompanyAPI) find(params CompanyIdentifiers) (Company, error) {
return Company{ID: params.ID, Name: params.Name, CompanyID: params.CompanyID}, nil
}
func (t TestCompanyAPI) list(params companyListParams) (CompanyList, error) {
return CompanyList{Companies: []Company{Company{ID: "46adad3f09126dca", Name: "My Co", CompanyID: "aa123"}}}, nil
}
func (t TestCompanyAPI) listUsers(id string, params companyUserListParams) (UserList, error) {
return UserList{Users: []User{User{Companies: &CompanyList{Companies: []Company{Company{ID: id, CompanyID: params.CompanyID}}}}}}, nil
}
func (t TestCompanyAPI) scroll(scrollParam string) (CompanyList, error) {
return CompanyList{Companies: []Company{Company{ID: "46adad3f09126dca", Name: "My Co", CompanyID: "aa123"}}}, nil
}
func (t TestCompanyAPI) save(company *Company) (Company, error) {
if company.ID != "46adad3f09126dca" {
t.t.Errorf("Company ID was %s, expected 46adad3f09126dca", company.ID)
}
expectedCAs := map[string]interface{}{"is_cool": true}
if company.CustomAttributes["is_cool"] != expectedCAs["is_cool"] {
t.t.Errorf("Custom attributes was %v, expected %v", company.CustomAttributes, expectedCAs)
}
return Company{}, nil
}