|
| 1 | +// Licensed under the Apache License, Version 2.0 (the 'License'); you may not |
| 2 | +// use this file except in compliance with the License. You may obtain a copy of |
| 3 | +// the License at |
| 4 | +// |
| 5 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +// |
| 7 | +// Unless required by applicable law or agreed to in writing, software |
| 8 | +// distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT |
| 9 | +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 | +// License for the specific language governing permissions and limitations under |
| 11 | +// the License. |
| 12 | + |
| 13 | +const Nano = require('..') |
| 14 | +const COUCH_URL = 'http://localhost:5984' |
| 15 | +const CUSTOM_HEADER = 'thequickbrownfox' |
| 16 | +const nano = Nano({ |
| 17 | + url: COUCH_URL, |
| 18 | + requestDefaults: { |
| 19 | + headers: { |
| 20 | + customheader: CUSTOM_HEADER |
| 21 | + } |
| 22 | + } |
| 23 | +}) |
| 24 | +const nock = require('nock') |
| 25 | +const response = { |
| 26 | + db_name: 'db', |
| 27 | + purge_seq: '0-8KhNZEiqhyjKAgBm5Rxs', |
| 28 | + update_seq: '23523-gUFPHo-6PQIAJ_EdrA', |
| 29 | + sizes: { |
| 30 | + file: 18215344, |
| 31 | + external: 5099714, |
| 32 | + active: 6727596 |
| 33 | + }, |
| 34 | + other: { |
| 35 | + data_size: 5099714 |
| 36 | + }, |
| 37 | + doc_del_count: 23000, |
| 38 | + doc_count: 0, |
| 39 | + disk_size: 18215344, |
| 40 | + disk_format_version: 7, |
| 41 | + data_size: 6727596, |
| 42 | + compact_running: false, |
| 43 | + cluster: { |
| 44 | + q: 2, |
| 45 | + n: 1, |
| 46 | + w: 1, |
| 47 | + r: 1 |
| 48 | + }, |
| 49 | + instance_start_time: '0' |
| 50 | +} |
| 51 | + |
| 52 | +afterEach(() => { |
| 53 | + nock.cleanAll() |
| 54 | +}) |
| 55 | + |
| 56 | +test('should be able to fetch the database info - GET /db - nano.db.get', async () => { |
| 57 | + // mocks |
| 58 | + const scope = nock(COUCH_URL) |
| 59 | + .matchHeader('customheader', CUSTOM_HEADER) |
| 60 | + .get('/db') |
| 61 | + .reply(200, response) |
| 62 | + |
| 63 | + // test GET /db |
| 64 | + const p = await nano.db.get('db') |
| 65 | + expect(typeof p).toBe('object') |
| 66 | + expect(p.doc_count).toBe(0) |
| 67 | + expect(p.db_name).toBe('db') |
| 68 | + expect(scope.isDone()).toBe(true) |
| 69 | +}) |
0 commit comments