This repository has been archived by the owner on Mar 6, 2023. It is now read-only.
forked from jazibjohar/intercom-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
company_test.go
67 lines (56 loc) · 2.12 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
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 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) 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
}