-
Notifications
You must be signed in to change notification settings - Fork 12
/
job_test.go
176 lines (137 loc) · 3.48 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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package revai
import (
"context"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
const testMetadata = "test-metadata"
const testMediaURL = "https://support.rev.com/hc/en-us/article_attachments/200043975/FTC_Sample_1_-_Single.mp3"
const testJobID = "nLCyv9wIz7gQ"
func TestJobService_SubmitFile(t *testing.T) {
f, err := os.Open("./testdata/img.jpg")
if err != nil {
t.Error(err)
return
}
defer f.Close()
params := &NewFileJobParams{
Media: f,
Filename: f.Name(),
}
ctx := context.Background()
newJob, err := testClient.Job.SubmitFile(ctx, params)
if err != nil {
t.Error(err)
return
}
assert.NotNil(t, newJob.ID, "new job id should not be nil")
assert.Equal(t, "in_progress", newJob.Status, "response status should be in_progress")
}
func TestJobService_SubmitFileWithOption(t *testing.T) {
f, err := os.Open("./testdata/img.jpg")
if err != nil {
t.Error(err)
return
}
defer f.Close()
params := &NewFileJobParams{
Media: f,
Filename: f.Name(),
JobOptions: &JobOptions{
Metadata: testMetadata,
CustomVocabularies: []JobOptionCustomVocabulary{
{
Phrases: []string{
"Paul McCartney",
"Amelia Earhart",
"Weiss-Bergman",
"BLM",
},
},
},
},
}
ctx := context.Background()
newJob, err := testClient.Job.SubmitFile(ctx, params)
if err != nil {
t.Error(err)
return
}
assert.NotNil(t, newJob.ID, "new job id should not be nil")
assert.Equal(t, testMetadata, newJob.Metadata, "meta data should be set")
assert.Equal(t, "in_progress", newJob.Status, "response status should be in_progress")
}
func TestJobService_SubmitURL(t *testing.T) {
params := &NewURLJobParams{
MediaURL: testMediaURL,
}
ctx := context.Background()
newJob, err := testClient.Job.SubmitURL(ctx, params)
if err != nil {
t.Error(err)
return
}
assert.NotNil(t, newJob.ID, "new job id should not be nil")
assert.Equal(t, "in_progress", newJob.Status, "response status should be in_progress")
}
func TestJobService_SubmitWithOption(t *testing.T) {
params := &NewURLJobParams{
MediaURL: testMediaURL,
Metadata: testMetadata,
}
ctx := context.Background()
newJob, err := testClient.Job.SubmitURL(ctx, params)
if err != nil {
t.Error(err)
return
}
assert.NotNil(t, newJob.ID, "new job id should not be nil")
assert.Equal(t, testMetadata, newJob.Metadata, "meta data should be set")
assert.Equal(t, "in_progress", newJob.Status, "response status should be in_progress")
}
func TestJobService_Get(t *testing.T) {
params := &GetJobParams{
ID: testJob.ID,
}
ctx := context.Background()
newJob, err := testClient.Job.Get(ctx, params)
if err != nil {
t.Error(err)
return
}
assert.NotNil(t, newJob.ID, "new job id should not be nil")
}
func TestJobService_Delete(t *testing.T) {
deletableJob := makeTestJob()
params := &DeleteJobParams{
ID: deletableJob.ID,
}
ctx := context.Background()
if err := testClient.Job.Delete(ctx, params); err != nil {
t.Error(err)
return
}
}
func TestJobService_List(t *testing.T) {
params := &ListJobParams{}
ctx := context.Background()
jobs, err := testClient.Job.List(ctx, params)
if err != nil {
t.Error(err)
return
}
assert.NotNil(t, jobs, "jobs should not be nil")
}
func TestJobService_ListWithLimit(t *testing.T) {
params := &ListJobParams{
Limit: 2,
}
ctx := context.Background()
jobs, err := testClient.Job.List(ctx, params)
if err != nil {
t.Error(err)
return
}
assert.Equal(t, 2, len(jobs), "it returns 2 jobs when limit is set to 2")
}