-
Notifications
You must be signed in to change notification settings - Fork 29
/
test.js
185 lines (168 loc) · 5.46 KB
/
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
'use strict';
var test = require('tap').test;
var nock = require('nock');
var fs = require('fs');
var vt2geojson = require('./');
var tile1 = nock('http://api.mapbox.com')
.get('/9/150/194.mvt')
.reply(200, fs.readFileSync('fixtures/9-150-194.mvt'));
var tile2 = nock('http://a.tiles.mapbox.com/v4/mapbox.mapbox-streets-v7')
.get('/16/46886/30383.mvt')
.reply(200, fs.readFileSync('fixtures/16-46886-30383.mvt'));
var invalidTokenRequest = nock('http://invalid.mapbox.com')
.get('/16/46886/30383.mvt')
.reply(401);
var fourohfour = nock('http://404.mapbox.com')
.get('/16/46886/0.mvt')
.reply(404);
test('fails without uri', function (t) {
vt2geojson({}, function (err, result) {
t.ok(err);
t.equal(err.message, 'No URI found. Please provide a valid URI to your vector tile.');
t.notOk(result);
t.end();
});
});
test('fails without zxy', function (t) {
vt2geojson({
uri: './fixtures/9-150-194.mvt',
layer: 'state_label'
}, function (err, result) {
t.ok(err);
t.equal(err.message, 'Could not determine tile z, x, and y from "./fixtures/9-150-194.mvt"; specify manually with -z <z> -x <x> -y <y>', 'expected error message');
t.notOk(result);
t.end();
});
});
test('fails with 401 response: invalid token', function (t) {
vt2geojson({
uri: 'http://invalid.mapbox.com/16/46886/30383.mvt',
layer: 'state_label'
}, function (err, result) {
t.ok(err);
t.ok(/Invalid Token/.test(err.message), 'expected error message');
t.end();
});
});
test('fails 404 response', function (t) {
vt2geojson({
uri: 'http://404.mapbox.com/16/46886/0.mvt',
layer: 'state_label'
}, function (err, result) {
t.ok(err);
t.ok(/Error retrieving data from/.test(err.message), 'expected error message');
t.end();
});
});
test('url', function (t) {
vt2geojson({
uri: 'http://api.mapbox.com/9/150/194.mvt',
layer: 'state_label'
}, function (err, result) {
t.ifError(err);
t.deepEqual(result.type, 'FeatureCollection');
t.deepEqual(result.features[0].properties.name, 'New Jersey');
t.deepEqual(result.features[0].geometry, {
type: 'Point',
coordinates: [-74.38928604125977, 40.15027547340139]
});
t.end();
});
});
test('undefined layer', function (t) {
vt2geojson({
uri: 'http://a.tiles.mapbox.com/v4/mapbox.mapbox-streets-v7/16/46886/30383.mvt',
layer: 'water'
}, function (err, result) {
t.ifError(err);
t.deepEqual(result.type, 'FeatureCollection');
t.deepEqual(result.features.length, 0);
t.end();
});
});
test('local file: relative', function (t) {
vt2geojson({
uri: './fixtures/9-150-194.mvt',
layer: 'state_label',
z: 9,
x: 150,
y: 194
}, function (err, result) {
t.ifError(err);
t.deepEqual(result.type, 'FeatureCollection');
t.deepEqual(result.features[0].properties.name, 'New Jersey');
t.deepEqual(result.features[0].geometry, {
type: 'Point',
coordinates: [-74.38928604125977, 40.15027547340139]
});
t.end();
});
});
test('local file: absolute uri with file: protocol', function (t) {
vt2geojson({
uri: 'file://./fixtures/9-150-194.mvt',
layer: 'state_label',
z: 9,
x: 150,
y: 194
}, function (err, result) {
t.ifError(err);
t.deepEqual(result.type, 'FeatureCollection');
t.deepEqual(result.features[0].properties.name, 'New Jersey');
t.deepEqual(result.features[0].geometry, {
type: 'Point',
coordinates: [-74.38928604125977, 40.15027547340139]
});
t.end();
});
});
test('local file with directory zxy directory structure', function (t) {
vt2geojson({
uri: './fixtures/9/150/194.mvt',
layer: 'state_label'
}, function (err, result) {
t.ifError(err);
t.deepEqual(result.type, 'FeatureCollection');
t.deepEqual(result.features[0].properties.name, 'New Jersey');
t.deepEqual(result.features[0].geometry, {
type: 'Point',
coordinates: [-74.38928604125977, 40.15027547340139]
});
t.end();
});
});
test('local file gzipped', function (t) {
vt2geojson({
uri: './fixtures/9-150-194.mvt.gz',
layer: 'state_label',
z: 9,
x: 150,
y: 194
}, function (err, result) {
t.ifError(err);
t.deepEqual(result.type, 'FeatureCollection');
t.deepEqual(result.features[0].properties.name, 'New Jersey');
t.deepEqual(result.features[0].geometry, {
type: 'Point',
coordinates: [-74.38928604125977, 40.15027547340139]
});
t.end();
});
});
test('multiple layers adds property to preserve layer name', function (t) {
vt2geojson({
uri: './fixtures/16-46886-30383.mvt',
z: 16,
x: 46886,
y: 30383,
layer: ['landuse', 'poi_label']
}, function (err, result) {
t.equal(result.type, 'FeatureCollection', 'expected type');
t.equal(result.features.length, 112, 'expected number of features');
result.features.forEach(function(f) {
var val = (f.properties.vt_layer === 'landuse' || f.properties.vt_layer === 'poi_label') ? true : false;
t.ok(val, 'expected property value');
});
t.end();
});
});