forked from intercom/intercom-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
job_test.go
54 lines (46 loc) · 1.21 KB
/
job_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
package intercom
import "testing"
func TestNewJob(t *testing.T) {
repo := &TestJobRepository{t: t}
repo.f = func(job *JobRequest) {
if job.Items[0].Method != JOB_POST.String() {
repo.t.Errorf("Wrong job method")
}
u := job.Items[0].Data.(*User)
if u.Email != "foo@bar.com" {
repo.t.Errorf("Wrong user email")
}
}
user := User{Email: "foo@bar.com"}
js := JobService{Repository: repo}
js.NewUserJob(NewUserJobItem(&user, JOB_POST))
}
func TestAppendJob(t *testing.T) {
repo := &TestJobRepository{t: t}
js := JobService{Repository: repo}
newJob, _ := js.NewUserJob()
repo.f = func(job *JobRequest) {
if job.Items[0].Method != JOB_POST.String() {
repo.t.Errorf("Wrong job method")
}
u := job.Items[0].Data.(*User)
if u.Email != "foo@bar.com" {
repo.t.Errorf("Wrong user email")
}
}
user := User{Email: "foo@bar.com"}
js.AppendUsers(newJob.ID, NewUserJobItem(&user, JOB_POST))
}
type TestJobRepository struct {
t *testing.T
f func(job *JobRequest)
}
func (api *TestJobRepository) save(job *JobRequest) (JobResponse, error) {
if api.f != nil {
api.f(job)
}
return JobResponse{}, nil
}
func (api *TestJobRepository) find(id string) (JobResponse, error) {
return JobResponse{}, nil
}