forked from tilemill-project/tilemill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport.test.js
167 lines (159 loc) · 4.57 KB
/
export.test.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
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
var assert = require('assert');
var fs = require('fs');
var path = require('path');
var core;
var tile;
function readJSON(name) {
var json = fs.readFileSync(path.resolve(__dirname + '/fixtures/' + name + '.json'), 'utf8');
return JSON.parse(json);
}
describe('export', function() {
before(function(done) {
require('./support/start').start(function(command) {
core = command.servers['Core'];
tile = command.servers['Tile'];
done();
});
});
after(function(done) {
core.close();
tile.close();
done();
});
var id = Date.now().toString();
var job = readJSON('export-job');
var antiMeridianJob = readJSON('anti-meridian-export-job');
var token = job['bones.token'];
job.id = id;
antiMeridianJob.id = id + 1;
it('PUT should create export job', function(done) {
assert.response(core, {
url: '/api/Export/' + id,
method: 'PUT',
data: JSON.stringify(job),
headers: {
cookie: "bones.token=" + token,
'content-type': "application/json"
}
}, {
body: '{}',
status: 200
}, function (res) {
assert.deepEqual(JSON.parse(res.body), {});
done();
});
});
it('GET should retrieve export job', function(done) {
assert.response(core, {
url: '/api/Export'
}, { status: 200 }, function(res) {
var body = JSON.parse(res.body);
job.status = "processing";
assert.ok(body[0].pid);
assert.ok(body[0].created);
delete job['bones.token'];
delete body[0].created;
delete body[0].pid;
assert.deepEqual(job, body[0]);
done();
});
});
it('DELETE should stop export job', function(done) {
job['bones.token'] = token;
assert.response(core, {
url: '/api/Export/' + id,
method: 'DELETE',
headers: {
cookie: "bones.token=" + token,
'content-type': "application/json"
},
body: JSON.stringify(job)
}, {
body: '{}',
status: 200
}, function (res) {
assert.deepEqual(JSON.parse(res.body), {});
done();
});
});
it('PUT create export job spanning the anti-meridian', function(done) {
assert.response(core, {
url: '/api/Export/' + antiMeridianJob.id,
method: 'PUT',
data: JSON.stringify(antiMeridianJob),
headers: {
cookie: "bones.token=" + token,
'content-type': "application/json"
}
}, {
body: '{}',
status: 200
}, function (res) {
assert.deepEqual(JSON.parse(res.body), {});
done();
});
});
it("GET anti-meridian job to see if it succeeded", function(done) {
function ping() {
assert.response(core, {
url: '/api/Export/' + antiMeridianJob.id,
method: 'GET',
headers: {
cookie: "bones.token=" + token,
'content-type': "application/json"
}
}, {
status: 200
}, function(res) {
var data = JSON.parse(res.body);
if (data.status === 'processing') {
// Don't flood the socket or the test will fail.
setTimeout(ping, 1000);
} else if (data.status === 'error') {
throw new Error(data.error);
} else {
antiMeridianJob.status = "complete";
antiMeridianJob.progress = 1;
console.log(data);
assert.ok(data.pid);
assert.ok(data.created);
delete antiMeridianJob['bones.token'];
delete data.created;
delete data.pid;
delete data.remaining;
delete data.updated;
delete data.rate;
assert.deepEqual(antiMeridianJob, data);
done();
}
});
}
ping();
});
it('DELETE should remove anti-meridian export job', function(done) {
job['bones.token'] = token;
assert.response(core, {
url: '/api/Export/' + antiMeridianJob.id,
method: 'DELETE',
headers: {
cookie: "bones.token=" + token,
'content-type': "application/json"
},
body: JSON.stringify(job)
}, {
body: '{}',
status: 200
}, function (res) {
assert.deepEqual(JSON.parse(res.body), {});
done();
});
});
it('GET should find no export jobs', function(done) {
assert.response(core, {
url: '/api/Export'
}, { status: 200 }, function(res) {
assert.deepEqual([], JSON.parse(res.body));
done();
});
});
});