/
archaeologist.js
112 lines (97 loc) · 3.72 KB
/
archaeologist.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
var expect = require('expect.js'),
nock = require('nock'),
modulePath = '../lib/archaeologist';
describe("Archaeologist", function() {
var Archaeologist = require(modulePath),
arc = new Archaeologist();
it("exists", function () {
expect(typeof Archaeologist).to.eql('function');
});
describe("#settings", function () {
it("exists as an object on a PhlPacComplaints instance", function () {
expect(typeof arc.settings).to.eql('object');
});
it("houses configuration settings", function () {
expect(arc.settings.apiHost).to.eql(undefined);
expect(arc.settings.apiPathBase).to.eql(undefined);
expect(arc.settings.defaultResultOptions).to.eql({
returnCountOnly: false,
returnIdsOnly: false,
returnGeometry: true,
maxAllowableOffset: '',
outputSpatialReference: '',
outFields: '*',
f: 'json'
});
});
it("can be extended on instantiation", function () {
var arcInst = new Archaeologist({
apiHost: 'http://fakehost.com',
apiPathBase: '/fake/path'
});
expect(arcInst.settings.apiHost).to.eql('http://fakehost.com');
expect(arcInst.settings.apiPathBase).to.eql('/fake/path');
});
describe("#defaultResultOptions", function () {
it("exists as a property on 'settings'", function () {
var arcInst = new Archaeologist({
apiHost: 'http://fakehost.com',
apiPathBase: '/fake/path',
defaultResultOptions: {
foo: 'bar',
baz: 'bim'
}
});
expect(typeof arc.settings.defaultResultOptions).to.eql('object');
});
it("can be extended on instantiation", function () {
var arcInst = new Archaeologist({
apiHost: 'http://fakehost.com',
apiPathBase: '/fake/path',
defaultResultOptions: {
foo: 'bar',
baz: 'bim'
}
});
expect(arcInst.settings.defaultResultOptions.foo).to.eql('bar');
expect(arcInst.settings.defaultResultOptions.baz).to.eql('bim');
expect(arcInst.settings.defaultResultOptions.f).to.eql('json');
});
});
});
describe("#get", function () {
var arcInst = new Archaeologist({
apiHost: 'http://somehost.com',
apiPathBase: '/some/path/base'
});
it("exists as a method on an Archaeologist instance", function () {
expect(typeof arcInst.get).to.eql('function');
});
it("makes an API call to the proper endpoint, appending the object it's passed as a request params string, and also including default result options if none are specified", function (done) {
nock('http://somehost.com')
.get("/some/path/base?foo=bar&returnCountOnly=false&returnIdsOnly=false&returnGeometry=true&maxAllowableOffset=&outputSpatialReference=&outFields=*&f=json")
.reply(200, {resp: 'fakeResponse'});
arcInst.get({foo: 'bar'}, function(err, data) {
expect(data).to.eql({resp: 'fakeResponse'});
done();
});
});
it("makes the correct API call if its default result options have been overridden", function (done) {
nock('http://somehost.com')
.get("/some/path/base?foo=bar&returnCountOnly=true&returnIdsOnly=true&returnGeometry=false&maxAllowableOffset=blah&outputSpatialReference=blah&outFields=foo,+bar&f=json")
.reply(200, {resp: 'fakeResponse'});
arcInst.get({
foo: 'bar',
returnCountOnly: true,
returnIdsOnly: true,
returnGeometry: false,
maxAllowableOffset: 'blah',
outputSpatialReference: 'blah',
outFields: ['foo', 'bar']
}, function(err, data) {
expect(data).to.eql({resp: 'fakeResponse'});
done();
});
});
});
});