|
1
|
|
|
|
|
2
|
|
|
'use strict'; |
|
3
|
|
|
|
|
4
|
|
|
const nock = require('nock'); |
|
5
|
|
|
|
|
6
|
|
|
const RIGHT_KEY = '83309-RIGHT_KEY'; |
|
7
|
|
|
const WRONG_KEY = '83309-WRONG_KEY'; |
|
8
|
|
|
const BASE_URL = 'https://api.sandcage.com/0.2'; |
|
9
|
|
|
|
|
10
|
|
|
module.exports = { |
|
11
|
|
|
RIGHT_KEY, |
|
12
|
|
|
WRONG_KEY, |
|
13
|
|
|
initNock() { |
|
14
|
|
|
nock(BASE_URL) |
|
15
|
|
|
.post('/get-info', { |
|
16
|
|
|
key: RIGHT_KEY |
|
17
|
|
|
}) |
|
18
|
|
|
.reply(200, { |
|
19
|
|
|
"request_id": "req_B8r09x8SucENLdGmHD8s08HDZDOEon", |
|
20
|
|
|
"status": "success", |
|
21
|
|
|
"files": [ |
|
22
|
|
|
{ |
|
23
|
|
|
"reference_id": "", |
|
24
|
|
|
"file_token": "file_1_j85f3_63bo8b5cx06r_zg6ub9z9ls3sbq", |
|
25
|
|
|
"directory": "img/", |
|
26
|
|
|
"filename": "logo.png", |
|
27
|
|
|
"type": "image/png", |
|
28
|
|
|
"size": 24794, |
|
29
|
|
|
"action": "save", |
|
30
|
|
|
"status": "processed", |
|
31
|
|
|
"url": "http://www.example.com/img/logo.jpg" |
|
32
|
|
|
}, |
|
33
|
|
|
{ |
|
34
|
|
|
"reference_id": "yqqp1wa", |
|
35
|
|
|
"file_token": "file_tps0fb_skcz04xdn44sceog00i0ukcvkt", |
|
36
|
|
|
"directory": "img/", |
|
37
|
|
|
"filename": "header.png", |
|
38
|
|
|
"type": "image/png", |
|
39
|
|
|
"size": 0, |
|
40
|
|
|
"action": "resize", |
|
41
|
|
|
"status": "pending" |
|
42
|
|
|
}, |
|
43
|
|
|
{ |
|
44
|
|
|
"reference_id": "", |
|
45
|
|
|
"file_token": "file_5g7vfnmdh_65f1267b1vjshlzzo8wn74gn", |
|
46
|
|
|
"directory": "img/", |
|
47
|
|
|
"filename": "banner.png", |
|
48
|
|
|
"type": "image/png", |
|
49
|
|
|
"size": 0, |
|
50
|
|
|
"action": "crop", |
|
51
|
|
|
"status": "error" |
|
52
|
|
|
} |
|
53
|
|
|
] |
|
54
|
|
|
}); |
|
55
|
|
|
|
|
56
|
|
|
nock(BASE_URL) |
|
57
|
|
|
.post('/get-info', { |
|
58
|
|
|
key: WRONG_KEY |
|
59
|
|
|
}) |
|
60
|
|
|
.reply(403, {}); |
|
61
|
|
|
|
|
62
|
|
|
nock(BASE_URL) |
|
63
|
|
|
.post('/list-files', { |
|
64
|
|
|
key: RIGHT_KEY, |
|
65
|
|
|
directory: 'img/' |
|
66
|
|
|
}) |
|
67
|
|
|
.reply(200, { |
|
68
|
|
|
"request_id": "req_ip8B_DLdOOcXQ1NDDshim_Vg4GNytCfLlhIt", |
|
69
|
|
|
"status": "success", |
|
70
|
|
|
"files": [ |
|
71
|
|
|
{ |
|
72
|
|
|
"reference_id": "xrw7d", |
|
73
|
|
|
"file_token": "file_wjcdrmz5wfbfhfqyt4lqfpq7oc8o0gm2illz", |
|
74
|
|
|
"directory": "img/", |
|
75
|
|
|
"filename": "logo.png", |
|
76
|
|
|
"type": "image/png", |
|
77
|
|
|
"size": 5662912, |
|
78
|
|
|
"status": "processed", |
|
79
|
|
|
"url": "http://www.example.com/img/logo.jpg" |
|
80
|
|
|
}, |
|
81
|
|
|
{ |
|
82
|
|
|
"reference_id": "ggdnn1t", |
|
83
|
|
|
"file_token": "file_cptoev9ldt5ld1jchsawg_5fy9r3gp", |
|
84
|
|
|
"directory": "img/", |
|
85
|
|
|
"filename": "header.png", |
|
86
|
|
|
"type": "image/png", |
|
87
|
|
|
"size": 0, |
|
88
|
|
|
"status": "pending" |
|
89
|
|
|
}, |
|
90
|
|
|
{ |
|
91
|
|
|
"reference_id": "k3h_k", |
|
92
|
|
|
"file_token": "file_v5m610__lcnel8dx5d_nla3gw8lq16yubp6u33", |
|
93
|
|
|
"directory": "img/", |
|
94
|
|
|
"filename": "banner.png", |
|
95
|
|
|
"type": "image/png", |
|
96
|
|
|
"size": 0, |
|
97
|
|
|
"status": "error" |
|
98
|
|
|
} |
|
99
|
|
|
] |
|
100
|
|
|
}); |
|
101
|
|
|
|
|
102
|
|
|
nock(BASE_URL) |
|
103
|
|
|
.post('/list-files', { |
|
104
|
|
|
key: WRONG_KEY |
|
105
|
|
|
}) |
|
106
|
|
|
.reply(403, {}); |
|
107
|
|
|
|
|
108
|
|
|
nock(BASE_URL) |
|
109
|
|
|
.post('/schedule-tasks', { |
|
110
|
|
|
key: RIGHT_KEY |
|
111
|
|
|
}) |
|
112
|
|
|
.reply(200, { |
|
113
|
|
|
"request_id": "req_T4PfpZBHU4KET2At8yw8m0zydZg3Ck5", |
|
114
|
|
|
"status": "success", |
|
115
|
|
|
"tasks": [ |
|
116
|
|
|
{ |
|
117
|
|
|
"src_url": "http://cdn.sandcage.com/p/a/img/logo.jpg", |
|
118
|
|
|
"reference_id": "", |
|
119
|
|
|
"file_token": "file_f1f457p1j4vvcenskf3bbrdhzq2ixdzv", |
|
120
|
|
|
"filename": "6b51hwgvl7d_u6wrouffcyxr1osh7r_yp0_k8wy_zkpf_56fs36oa_ss5zs9nmw5wyc3w", |
|
121
|
|
|
"actions": "save" |
|
122
|
|
|
}, |
|
123
|
|
|
{ |
|
124
|
|
|
"src_url": "http://cdn.sandcage.com/p/a/img/logo.jpg", |
|
125
|
|
|
"reference_id": "", |
|
126
|
|
|
"file_token": "file_wao7cfkfqr1cm4ymutjm9ktkzl0fbosqemux9e", |
|
127
|
|
|
"filename": "hello_world.jpg", |
|
128
|
|
|
"actions": "resize", |
|
129
|
|
|
"width": 200 |
|
130
|
|
|
}, |
|
131
|
|
|
{ |
|
132
|
|
|
"src_url": "http://cdn.sandcage.com/p/a/img/logo.jpg", |
|
133
|
|
|
"reference_id": "", |
|
134
|
|
|
"file_token": "file_ytez6iecs9474qdlz1dpx8hgaybbw3f4_8jp5ghl", |
|
135
|
|
|
"filename": "y_w8n1hfv146ysn3uk77vmbl5k4c3n72yx16r66xxogmqfafctsnm5t78v18", |
|
136
|
|
|
"actions": "crop", |
|
137
|
|
|
"coords": "10,10,50,50" |
|
138
|
|
|
}, |
|
139
|
|
|
{ |
|
140
|
|
|
"src_url": "http://cdn.sandcage.com/p/a/img/logo.jpg", |
|
141
|
|
|
"reference_id": "123456789", |
|
142
|
|
|
"file_token": "file_21ighpvrwr63k872ylplrl3zcbb2ti2vmgfv", |
|
143
|
|
|
"filename": "2c82w6zhr7h3f6st56zu9hlnizlpq175wy_vqzs5bpt4dww9ug548rtfho66", |
|
144
|
|
|
"actions": "rotate", |
|
145
|
|
|
"degrees": 90 |
|
146
|
|
|
}, |
|
147
|
|
|
{ |
|
148
|
|
|
"src_url": "http://cdn.sandcage.com/p/a/img/logo.jpg", |
|
149
|
|
|
"reference_id": "123456789", |
|
150
|
|
|
"file_token": "file_3b1m23xlmy0_pj9_6m7ubhgkevail8_", |
|
151
|
|
|
"filename": "76okzsy395hl55b6xw5q_5dqpxy3o7s4ab7gxsx2v1b0i0ny", |
|
152
|
|
|
"actions": "cover", |
|
153
|
|
|
"height": 30, |
|
154
|
|
|
"width": 30, |
|
155
|
|
|
"cover": "bottom,right" |
|
156
|
|
|
}, |
|
157
|
|
|
{ |
|
158
|
|
|
"src_url": "http://cdn.sandcage.com/p/a/img/header_404.png", |
|
159
|
|
|
"reference_id": "", |
|
160
|
|
|
"file_token": "file_yq1x03oe923gp2o2_hqa_rh_k24v7tyqxp", |
|
161
|
|
|
"filename": "xy92p11rg9qavk_o9_vsxdtwz3fsop5hml31xwci_qzouiol2ln939rf2g84px20", |
|
162
|
|
|
"actions": "resize", |
|
163
|
|
|
"height": 30 |
|
164
|
|
|
} |
|
165
|
|
|
] |
|
166
|
|
|
}); |
|
167
|
|
|
|
|
168
|
|
|
nock(BASE_URL) |
|
169
|
|
|
.post('/schedule_tasks', { |
|
170
|
|
|
key: WRONG_KEY |
|
171
|
|
|
}) |
|
172
|
|
|
.reply(403, {}); |
|
173
|
|
|
|
|
174
|
|
|
nock(BASE_URL) |
|
175
|
|
|
.post('/destroy-files', { |
|
176
|
|
|
key: RIGHT_KEY |
|
177
|
|
|
}) |
|
178
|
|
|
.reply(200, { |
|
179
|
|
|
"request_id": "req_ca0aOKSPQ_UoBgwU6BFIB7g2TnZ6CivhFuLR_q", |
|
180
|
|
|
"status": "success" |
|
181
|
|
|
}); |
|
182
|
|
|
|
|
183
|
|
|
nock(BASE_URL) |
|
184
|
|
|
.post('/destroy-files', { |
|
185
|
|
|
key: WRONG_KEY |
|
186
|
|
|
}) |
|
187
|
|
|
.reply(403, {}); |
|
188
|
|
|
|
|
189
|
|
|
|
|
190
|
|
|
} |
|
191
|
|
|
}; |