Skip to content
This repository was archived by the owner on Jan 19, 2022. It is now read-only.

allow for nested opts parameter in options #6

Merged
merged 1 commit into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function searchStream (query, opts = {}) {
quality: 0.65,
popularity: 0.98,
maintenance: 0.5,
...opts.opts, // this is to support the cli's --searchopts parameter
...opts
}

Expand Down
29 changes: 29 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,35 @@ test('basic test', t => {
})
})

test('basic test supports nested options', t => {
const query = qs.stringify({
text: 'oo',
size: 20,
from: 1,
quality: 0.65,
popularity: 0.98,
maintenance: 0.5
})
tnock(t, REG).get(`/-/v1/search?${query}`).once().reply(200, {
objects: [
{ package: { name: 'cool', version: '1.0.0' } },
{ package: { name: 'foo', version: '2.0.0' } }
]
})

// this test is to ensure we don't break the nested opts parameter
// that the cli supplies when a user passes --searchopts=
return search('oo', { ...OPTS, opts: { from: 1 } }).then(results => {
t.similar(results, [{
name: 'cool',
version: '1.0.0'
}, {
name: 'foo',
version: '2.0.0'
}], 'got back an array of search results')
})
})

test('search.stream', t => {
const query = qs.stringify({
text: 'oo',
Expand Down