-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroute.test
46 lines (28 loc) · 1.55 KB
/
route.test
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
function create(path, object, expect) {
var route = new Route(path).create(object);
eq(route, expect, 'Path - ' + path + ' Object - ' + JSON.stringify(object));
}
function hasAlias(path, object, expect){
eq(new Route(path).hasAliases(object), expect, 'hasAlias Fail ' + path);
}
include.inject('/src/business/Route.js').done(function(){
hasAlias('/rest/user/:id', {id: 1}, true);
hasAlias('/rest/user/?:id', {id: 1}, true);
hasAlias('/rest/user/:_id', {_id: 1}, true);
hasAlias('/rest/user/?:_id', {_id: 1}, true);
hasAlias('/rest/user/:_id', {id: 1}, false);
hasAlias('/rest/user/?:_id', {id: 1}, false);
hasAlias('/rest/:username/:age', {username: 'foo', age: 50}, true);
hasAlias('/rest/:username/:day/:age', {username: 'foo', age: 50}, false);
create('user/:id',{id: 5}, 'user/5');
create('user/{id}',{id: 5}, 'user/5');
create('user/{id}text',{id: 5}, 'user/5text');
create('users?date=:date',{date: 'today'}, 'users?date=today');
create('user/{id}?date=:date',{date: 'today', id: 5}, 'user/5?date=today');
create('user/{id}/{key}?date={date}',{date: 'today', id: 5, key: 'key'}, 'user/5/key?date=today');
create('user/{id}/{key}?date={?date}&name={?name}',{id: 5, key: 'key'}, 'user/5/key');
create('user/{id}/{key}?date={?date}&name={?name}',{id: 5, key: 'key', name: 'x'}, 'user/5/key?name=x');
create('{?id}/{?key}?date={?date}&name={?name}',{id: 5, name: 'x'}, '5?name=x');
create('{?id}/{?key}?date={?date}&name={?name}',{name: 'x'}, '?name=x');
create('?:id/?:key?date={?date}&name={?name}',{name: 'x'}, '?name=x');
});