forked from ds82/google-static-map
/
test.spec.js
83 lines (61 loc) · 2.13 KB
/
test.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
'use strict';
var proxy = require('proxyquire');
var stubs = {
googlemaps: jasmine.createSpyObj('googlemaps', ['staticMap']),
request: jasmine.createSpy('request'),
'@noCallThru': true
};
describe('google-static-map', function() {
var uut;
describe('without auto-setting a key', function() {
beforeEach(function() {
uut = proxy('./index', stubs );
});
it('should not work without a api key', function() {
expect( uut ).toThrow(new Error('You must provide a google api console key'));
});
it('should provide a method to set a global api key', function() {
expect( uut.set ).toBeDefined();
uut = uut.set('some-key');
expect( uut ).not.toThrow( jasmine.any( Error ));
});
});
describe('with auto-setting a key', function() {
beforeEach(function() {
uut = proxy('./index', stubs ).set('some-key');
});
it('should get/set config options', function() {
var map = uut();
var set;
['zoom', 'resolution', 'mapType', 'markers', 'style'].forEach(function( key ) {
set = key + ' ' + key;
expect( map.config[key] ).toEqual( map[key]() );
var chain = map[key]( set );
expect( map.config[key] ).toEqual( set );
expect( chain ).toEqual( map );
});
});
it('should relay staticMap call to googlemaps module', function() {
var map = uut();
var testAddress = 'Some Address, Some Country';
var staticMapReturn = 'http://some.where';
var requestReturn = 'request-return-value';
stubs.googlemaps.staticMap.andReturn( staticMapReturn );
stubs.request.andReturn( requestReturn );
var stream = map.address( testAddress ).staticMap().done();
expect( stream ).toEqual('request-return-value');
expect( stubs.googlemaps.staticMap ).toHaveBeenCalledWith(
testAddress,
map.config.zoom,
map.config.resolution,
false,
false,
map.config.mapType,
map.config.markers,
map.config.style,
map.config.paths
);
expect( stubs.request ).toHaveBeenCalledWith( staticMapReturn );
});
});
});