-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.js
37 lines (32 loc) · 1.25 KB
/
search.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
'use strict'
const assert = require('assert')
const context = require('../../test-helpers/context')
describe('ctx.search=', () => {
it('should replace the search', () => {
const ctx = context({ url: '/store/shoes' })
ctx.search = '?page=2&color=blue'
assert.strictEqual(ctx.url, '/store/shoes?page=2&color=blue')
assert.strictEqual(ctx.search, '?page=2&color=blue')
})
it('should update ctx.querystring and ctx.query', () => {
const ctx = context({ url: '/store/shoes' })
ctx.search = '?page=2&color=blue'
assert.strictEqual(ctx.url, '/store/shoes?page=2&color=blue')
assert.strictEqual(ctx.querystring, 'page=2&color=blue')
assert.strictEqual(ctx.query.page, '2')
assert.strictEqual(ctx.query.color, 'blue')
})
it('should change .url but not .originalUrl', () => {
const ctx = context({ url: '/store/shoes' })
ctx.search = '?page=2&color=blue'
assert.strictEqual(ctx.url, '/store/shoes?page=2&color=blue')
assert.strictEqual(ctx.originalUrl, '/store/shoes')
assert.strictEqual(ctx.request.originalUrl, '/store/shoes')
})
describe('when missing', () => {
it('should return ""', () => {
const ctx = context({ url: '/store/shoes' })
assert.strictEqual(ctx.search, '')
})
})
})