This repository has been archived by the owner on Sep 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
routey.spec.js
154 lines (116 loc) · 2.89 KB
/
routey.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
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
'use strict';
var mockery = require('mockery');
var path = require('path');
describe('routey', function () {
var routey;
var mockRouteyInit;
var mockPath;
beforeEach(function () {
mockery.enable();
mockRouteyInit = {
_processDirectory: jasmine.createSpy(),
};
mockPath = {
join: path.join,
basename: path.basename,
resolve: function (path) {
return path;
},
};
mockery.registerMock('./route_init', function () { return mockRouteyInit; });
mockery.registerMock('path', mockPath);
mockery.registerAllowable('./routey');
routey = require('./routey');
});
afterEach(function () {
mockery.deregisterAllowable('./routey');
mockery.deregisterMock('path');
mockery.deregisterMock('./route_init');
mockery.disable();
});
it('undefined config throws exception', function () {
expect(function () {
routey();
}).toThrow();
});
it('unspecified route config path throws exception', function () {
var config = {};
var app = {};
expect(function () {
routey(config, app);
}).toThrow();
});
it('undefined app throws exception', function () {
var config = {};
expect(function () {
routey(config);
}).toThrow();
});
it('external interface calls through to route init', function () {
var parentDir = 'parent';
var childDir = 'child';
var fullPath = parentDir + '/' + childDir;
var parentRoute = '/myparent';
var handlerParams = {};
var handlerConfig = { 'a': 'b' };
var config = {
routeConfigPath: fullPath,
parentRoute: parentRoute,
handlerParams: handlerParams,
handlerConfig: handlerConfig,
};
var app = {};
routey(config, app);
expect(mockRouteyInit._processDirectory).toHaveBeenCalledWith({
name: childDir,
path: fullPath,
parentRoute: parentRoute,
config: {},
parent: null,
handlerParams: handlerParams,
handlerConfig: handlerConfig,
});
});
it('parent route is defaulted when not specified', function () {
var parentDir = 'parent';
var childDir = 'child';
var fullPath = parentDir + '/' + childDir;
var config = {
routeConfigPath: fullPath,
};
var app = {};
routey(config, app);
expect(mockRouteyInit._processDirectory).toHaveBeenCalledWith({
name: childDir,
path: fullPath,
parentRoute: '/',
config: {},
parent: null,
handlerParams: {},
handlerConfig: {},
});
});
it('full path to rest config directory is resolved', function () {
var inputPath = 'whatever';
var config = {
routeConfigPath: inputPath,
};
var parentDir = 'parent';
var childDir = 'child';
var resolvedPath = parentDir + '/' + childDir;
mockPath.resolve = function () {
return resolvedPath;
};
var app = {};
routey(config, app);
expect(mockRouteyInit._processDirectory).toHaveBeenCalledWith({
name: childDir,
path: resolvedPath,
parentRoute: '/',
config: {},
parent: null,
handlerParams: {},
handlerConfig: {},
});
});
});