-
Notifications
You must be signed in to change notification settings - Fork 1
/
rewrite.spec.js
42 lines (34 loc) · 1.24 KB
/
rewrite.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
const tape = require('tape')
// expose modules to global
global.URLSearchParams = URLSearchParams
// require module
const rewrite = require('./rewrite')
tape('should rewrite path variables', t => {
t.equal(rewrite('/users/:id?sort=:orderBy', { id: 1 }), '/users/1', 'rewrite')
t.end()
})
tape('should rewrite inline variables', t => {
t.equal(rewrite('/users/user:id', { id: 1 }), '/users/user1', 'rewrite')
t.end()
})
tape('should not rewrite without keys', t => {
t.equal(rewrite('https://test/users', { }), 'https://test/users', 'rewrite')
t.end()
})
tape('should not rewrite with port', t => {
t.equal(rewrite('http://test:3030/users', { }), 'http://test:3030/users', 'rewrite')
t.end()
})
tape('should remove unused variables', t => {
t.equal(rewrite('/users/:id?sort=:orderBy'), '/users', 'rewrite w/o params')
t.equal(rewrite('/users/:id?sort=:orderBy', {}), '/users', 'rewrite w/ params')
t.end()
})
tape('should rewrite query params', t => {
t.equal(rewrite('/users/:id?sort=:orderBy', { orderBy: 'name' }), '/users?sort=name', 'rewrite')
t.end()
})
tape('should rewrite array query params', t => {
t.equal(rewrite('/users/:id?sort=:orderBy', { orderBy: ['name', 'id'] }), '/users?sort=name&sort=id', 'rewrite')
t.end()
})