-
Notifications
You must be signed in to change notification settings - Fork 42
/
TileRequest.js
executable file
·131 lines (119 loc) · 4.85 KB
/
TileRequest.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
var TileRequest = require('../lib/TileRequest.js');
var assert = require('chai').assert;
describe('TileRequest', function() {
describe('parse()', function() {
it('should operate normally', function() {
var result;
// leading slash
result = TileRequest.parse('/lyr/1/2/3/[email protected]');
assert.instanceOf(result, TileRequest);
assert.equal(result.layer, 'lyr');
assert.equal(result.filename, '[email protected]');
assert.equal(result.hasFilename, true);
assert.equal(result.z, 1);
assert.equal(result.x, 2);
assert.equal(result.y, 3);
assert.equal(result.method, 'GET');
assert.equal(result.qs, undefined);
assert.deepEqual(result.headers, {});
// no leading slash
result = TileRequest.parse('lyr/1/2/3/[email protected]');
assert.instanceOf(result, TileRequest);
assert.equal(result.layer, 'lyr');
assert.equal(result.filename, '[email protected]');
assert.equal(result.hasFilename, true);
assert.equal(result.z, 1);
assert.equal(result.x, 2);
assert.equal(result.y, 3);
assert.equal(result.method, 'GET');
assert.equal(result.qs, undefined);
assert.deepEqual(result.headers, {});
// query string
result = TileRequest.parse('lyr1/1/2/3/[email protected]?query=1&test=2');
assert.instanceOf(result, TileRequest);
assert.equal(result.layer, 'lyr1');
assert.equal(result.filename, '[email protected]');
assert.equal(result.hasFilename, true);
assert.equal(result.z, 1);
assert.equal(result.x, 2);
assert.equal(result.y, 3);
assert.equal(result.method, 'GET');
assert.equal(result.qs, 'query=1&test=2');
assert.deepEqual(result.headers, {});
// no filename
result = TileRequest.parse('lyr1/1/2/3.png', null, null);
assert.instanceOf(result, TileRequest);
assert.equal(result.layer, 'lyr1');
assert.equal(result.filename, 't.png');
assert.equal(result.hasFilename, false);
assert.equal(result.z, 1);
assert.equal(result.x, 2);
assert.equal(result.y, 3);
assert.equal(result.method, 'GET');
assert.equal(result.qs, undefined);
assert.deepEqual(result.headers, {});
// no filename (with resolution suffix)
result = TileRequest.parse('lyr1/1/2/[email protected]', null, null);
assert.instanceOf(result, TileRequest);
assert.equal(result.layer, 'lyr1');
assert.equal(result.filename, '[email protected]');
assert.equal(result.hasFilename, false);
assert.equal(result.z, 1);
assert.equal(result.x, 2);
assert.equal(result.y, 3);
assert.equal(result.method, 'GET');
assert.equal(result.qs, undefined);
assert.deepEqual(result.headers, {});
// headers
result = TileRequest.parse('lyr1/1/2/3/[email protected]?query=1&test=2', {'x-tilestrata-skipcache': '1'});
assert.instanceOf(result, TileRequest);
assert.deepEqual(result.headers, {'x-tilestrata-skipcache': '1'});
// method
result = TileRequest.parse('lyr1/1/2/3/[email protected]?query=1&test=2', {'x-tilestrata-skipcache': '1'}, 'HEAD');
assert.instanceOf(result, TileRequest);
assert.equal(result.method, 'HEAD');
});
it('should return undefined when unable to parse', function() {
assert.isUndefined(TileRequest.parse());
assert.isUndefined(TileRequest.parse('/a/b/c/d/t.png'));
assert.isUndefined(TileRequest.parse('/a/1/2.png'));
assert.isUndefined(TileRequest.parse('/a/1/2/3.2/t.png'));
assert.isUndefined(TileRequest.parse('/a/1.2/2/3/t.png'));
assert.isUndefined(TileRequest.parse('/a/1/2.4/3/t.png'));
});
});
describe('clone()', function() {
it('should return different, but identical, instance (with filename)', function() {
var original = TileRequest.parse('lyr1/1/2/3/[email protected]?query=1&test=2', {'x-tilestrata-skipcache': '1'}, 'GET');
var clone = original.clone();
assert.instanceOf(clone, TileRequest);
assert.notEqual(clone, original);
assert.equal(clone.layer, 'lyr1');
assert.equal(clone.method, 'GET');
assert.equal(clone.filename, '[email protected]');
assert.equal(clone.z, 1);
assert.equal(clone.x, 2);
assert.equal(clone.y, 3);
assert.equal(clone.qs, 'query=1&test=2');
assert.equal(clone.hasFilename, true);
assert.notEqual(clone.headers, original.headers);
assert.deepEqual(clone.headers, {'x-tilestrata-skipcache': '1'});
});
it('should return different, but identical, instance (without filename)', function() {
var original = TileRequest.parse('lyr1/1/2/[email protected]?query=1&test=2', {'x-tilestrata-skipcache': '1'}, 'GET');
var clone = original.clone();
assert.instanceOf(clone, TileRequest);
assert.notEqual(clone, original);
assert.equal(clone.layer, 'lyr1');
assert.equal(clone.method, 'GET');
assert.equal(clone.filename, '[email protected]');
assert.equal(clone.z, 1);
assert.equal(clone.x, 2);
assert.equal(clone.y, 3);
assert.equal(clone.qs, 'query=1&test=2');
assert.equal(clone.hasFilename, false);
assert.notEqual(clone.headers, original.headers);
assert.deepEqual(clone.headers, {'x-tilestrata-skipcache': '1'});
});
});
});