/
queue.spec.js
139 lines (114 loc) · 3.34 KB
/
queue.spec.js
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
/* eslint-disable */
import Person from '../lib/api/person';
import Queue from '../lib/api/queue';
import axios from 'axios';
import testImages from './testImages';
let person;
let queue;
const host = API_HOST;
const key = API_KEY;
const frontImage = testImages.frontImage;
const sideImage = testImages.sideImage;
describe('Queue', function () {
beforeAll(() => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 160000;
const axiosInstance = axios.create();
axiosInstance.defaults.headers = {
Authorization: `APIKey ${key}`,
};
person = new Person(host, axiosInstance);
queue = new Queue(host, axiosInstance);
});
describe('constructor', () => {
it('should throw an error if api host is not specified', (done) => {
expect(() => new Queue()).toThrow(new Error('host is not specified'));
return done();
});
it('should throw an error if axios instance is not specified', (done) => {
expect(() => new Queue(host)).toThrow(new Error('axios is not specified'));
return done();
});
});
describe('get', () => {
it('should throw an error if id is not specified', (done) => {
expect(() => queue.get()).toThrow(new Error('id is not specified'));
return done();
});
it('should get tasks by id', (done) => {
return person.create({
gender: 'male',
height: 170,
frontImage,
sideImage,
})
.then((r) => {
expect(typeof r).toEqual('string');
return r;
})
.then((id) => {
return queue.get(id);
})
.then((tasksData) => {
expect(typeof tasksData).toEqual('object');
expect(typeof tasksData.sub_tasks).toEqual('object');
return done();
})
.catch(err => {
expect(err).toBe(null);
return done();
});
});
});
describe('checkStatus', () => {
it('should throw an error if task set id is incorrect', (done) => {
return queue.checkStatus('faketasksetid', 500)
.catch((err) => {
expect(err).toBeTruthy();
return done();
});
});
});
describe('getResults', () => {
it('should throw an error if id is not specified', (done) => {
expect(() => queue.getResults()).toThrow(new Error('id is not specified'));
return done();
});
it('should throw an error if side image was sent as front image or front image as side image', (done) => {
return person.create({
gender: 'male',
height: 170,
frontImage: sideImage,
sideImage: frontImage,
})
.then((taskSetId) => {
expect(typeof taskSetId).toEqual('string');
return queue.getResults(taskSetId);
})
.catch(err => {
expect(err).toBeTruthy();
return done();
});
});
it('should get person object when tasks finish', (done) => {
return person.create({
gender: 'male',
height: 170,
frontImage,
sideImage,
})
.then((taskSetId) => {
expect(typeof taskSetId).toEqual('string');
return queue.getResults(taskSetId);
})
.then((person) => {
expect(typeof person).toEqual('object');
expect(typeof person.front_params).toEqual('object');
return done();
})
.catch(err => {
expect(err).toBe(null);
return done();
});
});
});
});