Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fetch instead of axios #314

Open
wants to merge 46 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
a30e3a5
working with fetch
Dec 12, 2022
fffb593
fix cookie renewal bug
Dec 12, 2022
5cbf072
removed unwanted request/axios code
Dec 13, 2022
529f506
tidy up
Dec 13, 2022
b91594c
remove tough-cookie and its patch
Dec 14, 2022
cb06484
log headers object instead of map
Dec 14, 2022
ae36ca6
http/https bug fix
Dec 14, 2022
1ad4561
added typescript parsing
Dec 14, 2022
fbed7ab
bug fixes for node16.8
Dec 14, 2022
6d800c3
custom agent and agentOptions with tests
Dec 14, 2022
2b5e5af
tidy up
Dec 15, 2022
a8a0825
show warning when requestDefaults is supplied
Dec 16, 2022
c329cc1
added description of each agentOptions attribute
Dec 16, 2022
c40a4a3
added missing test file
Dec 16, 2022
d14ff63
ensure "fetch" works on 16/18/19
Dec 20, 2022
f5280d5
fix test
Dec 20, 2022
aa9506d
nvm use 16.18.1
Dec 20, 2022
f692e14
rebase from main
Jan 9, 2023
3208204
remove node 14 support
Jan 9, 2023
7e8ffb8
upgrade undici to 5.15.0
Jan 11, 2023
999c6af
merge in latest changes
Jan 11, 2023
cffcd42
merge in latest changes
Jan 11, 2023
5a4ff3f
rebase on 10.1.2
Jan 26, 2023
0e7c06b
dependency bump
Feb 14, 2023
aba321c
fix cookie handling bug
Feb 14, 2023
e0c738a
dependency bump
Mar 6, 2023
aa4cc70
bump undici
Mar 24, 2023
46e08ba
dependency bump
May 22, 2023
c181a39
add node 20 to testing matrix
May 22, 2023
9c42fc3
pre v11 release tidy up
Sep 18, 2023
cead34a
prepare for merge
Sep 19, 2023
e16ad54
latest dependencies
Jan 2, 2024
6ee2510
allow clean merge
Aug 14, 2024
b7c560c
add Node v22 to the CI - it's been that long
Aug 14, 2024
47d4663
Update NOTICE
glynnbird Nov 4, 2024
c62d508
use contentType instead of ct
Nov 4, 2024
4f05cdb
beefed up the "breaking change" nature of Nano 11 for Node 16 (and ol…
Nov 4, 2024
e95b56b
assertion failures are rendered differently in Node 22, so the tests …
Nov 4, 2024
ff29111
added migration guide
Nov 4, 2024
e0a42f7
strip callback support from Nano and remove any tests that tested the…
Nov 7, 2024
ab4fa5d
remove callback references from the README
Nov 7, 2024
493ab27
update Typescript definitions to remove callback references
Nov 7, 2024
72bcb2f
remove the examples as they are ancient and beyond redemption
Nov 7, 2024
e412086
added callback notice to the migration guide
Nov 7, 2024
5c18b75
comment why we do body = '' when there is not response body
Nov 14, 2024
37feafc
Remove support for callbacks
Nov 25, 2024
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
100 changes: 100 additions & 0 deletions test/database.changes.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Licensed under the Apache License, Version 2.0 (the 'License'); you may not
glynnbird marked this conversation as resolved.
Show resolved Hide resolved
// use this file except in compliance with the License. You may obtain a copy of
// the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.

const test = require('node:test')
const assert = require('node:assert/strict')
const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
const Nano = require('..')
const nano = Nano(COUCH_URL)

const response = {
results: [
{
seq: '1-nC1J',
id: 'c42ddf1272c7d05b2dc45b6962000b10',
changes: [
{
rev: '1-23202479633c2b380f79507a776743d5'
}
]
}
],
last_seq: '1-C1J',
pending: 0
}
const errResponse = {
error: 'not_found',
reason: 'Database does not exist.'
}

test('should be able to fetch the changes - GET /db/_changes - nano.db.changes', async () => {
// mocks
mockPool
.intercept({ path: '/db/_changes' })
.reply(200, response, JSON_HEADERS)

// test GET /db/_changes
const p = await nano.db.changes('db')
assert.deepEqual(p, response)
mockAgent.assertNoPendingInterceptors()
})

test('should be able to fetch the changes with opts - GET /db/_changes - nano.db.changes', async () => {
// mocks
const opts = { include_docs: true, feed: 'continuous' }
mockPool
.intercept({ path: '/db/_changes?include_docs=true&feed=continuous' })
.reply(200, response, JSON_HEADERS)

// test GET /db/_changes
const p = await nano.db.changes('db', opts)
assert.deepEqual(p, response)
mockAgent.assertNoPendingInterceptors()
})

test('should be able to handle a missing database - GET /db/_changes - nano.db.changes', async () => {
// mocks
mockPool
.intercept({ path: '/db/_changes' })
.reply(404, errResponse, JSON_HEADERS)

// test GET /db/_changes
await assert.rejects(nano.db.changes('db'), { message: 'Database does not exist.' })
mockAgent.assertNoPendingInterceptors()
})

test('should not attempt invalid parameters - nano.db.changes', async () => {
await assert.rejects(nano.db.changes(), { message: 'Invalid parameters' })
await assert.rejects(nano.db.changes(''), { message: 'Invalid parameters' })
})

test('should detect missing parameters (callback) - nano.db.changes', async () => {
return new Promise((resolve, reject) => {
nano.db.changes(undefined, undefined, (err, data) => {
assert.notEqual(err, null)
resolve()
})
})
})

test('should be able to fetch the changes from db.changes - GET /db/_changes - db.changes', async () => {
// mocks
mockPool
.intercept({ path: '/db/_changes' })
.reply(200, response, JSON_HEADERS)

// test GET /db/_changes
const db = nano.db.use('db')
const p = await db.changes()
assert.deepEqual(p, response)
mockAgent.assertNoPendingInterceptors()
})