Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let bocha = require('bocha');
let sinon = require('sinon');
let testCase = bocha.testCase;
let assert = bocha.assert;
let nock = require('nock');
module.exports = testCase('simple-crud', {
setUp() {
this.nock = nock('http://myserver.com');
},
tearDown() {
nock.cleanAll();
},
'get: entity that exists': async function () {
this.nock
.get('/main/F1').reply(200, {
_id: 'F1',
_rev: '1-2',
type: 'fish'
});
let bocha = require('bocha');
let testCase = bocha.testCase;
let assert = bocha.assert;
let nock = require('nock');
let SmartDb = require('../lib/SmartDb.js');
module.exports = testCase('generate-id', {
setUp() {
this.nock = nock('http://myserver.com');
},
tearDown() {
nock.cleanAll();
},
'can generate ID on save': async function () {
this.nock.put('/main/S1A', { name: 'Shark', type: 'fish' }).reply(200, {
id: 'S1A',
rev: 'S1B'
});
let db = createDb({
let bocha = require('bocha');
let sinon = require('sinon');
let testCase = bocha.testCase;
let assert = bocha.assert;
let refute = bocha.refute;
let nock = require('nock');
module.exports = testCase('event-hooks', {
setUp() {
this.nock = nock('http://myserver.com');
},
tearDown() {
nock.cleanAll();
},
'preInsert: can manipulate doc before merge': function (done) {
this.nock
.get('/main/F1').reply(200, {
_id: 'F1',
_rev: 'F1R',
type: 'fish'
let bocha = require('bocha');
let sinon = require('sinon');
let testCase = bocha.testCase;
let assert = bocha.assert;
let refute = bocha.refute;
let nock = require('nock');
module.exports = testCase('cache-provider', {
setUp() {
this.nock = nock('http://myserver.com');
},
tearDown() {
nock.cleanAll();
},
'can use provider to get cached item': async function () {
let db = createDb({
databases: [
{
url: 'http://myserver.com/animals',
entities: {
let bocha = require('bocha');
let testCase = bocha.testCase;
let assert = bocha.assert;
let nock = require('nock');
module.exports = testCase('auth', {
setUp() {
this.nock = nock('http://myserver.com');
},
tearDown() {
nock.cleanAll();
},
'get: when giving auth and error appears, should NOT show authentication info': async function () {
this.nock
.get('/animals/F1').reply(500);
let db = createDb({
databases: [
{
url: 'http://admin:12345@myserver.com/animals',
let bocha = require('bocha');
let sinon = require('sinon');
let testCase = bocha.testCase;
let assert = bocha.assert;
let nock = require('nock');
let SmartDb = require('../lib/SmartDb.js');
module.exports = testCase('cache', {
setUp() {
this.nock = nock('http://myserver.com');
},
tearDown() {
nock.cleanAll();
},
'getting entity twice with cacheMaxSize set, should get from cache': async function () {
this.nock
.get('/animals/F1').reply(200, { _id: 'F1', _rev: 'F1R1', type: 'fish' })
.get('/animals/F1').reply(200, { _id: 'F1', _rev: 'F1R2', type: 'fish' });
let db = createDb({
databases: [
let bocha = require('bocha');
let testCase = bocha.testCase;
let assert = bocha.assert;
let nock = require('nock');
module.exports = testCase('views', {
setUp() {
this.nock = nock('http://myserver.com');
},
tearDown() {
nock.cleanAll();
},
'view: without specified rewrite': async function () {
this.nock
.get('/animals/_design/fish/_view/getSharks?include_docs=true').reply(200, {
rows: [
{ doc: { _id: 'F1', name: 'Great white' } }
]
});
let bocha = require('bocha');
let sinon = require('sinon');
let testCase = bocha.testCase;
let assert = bocha.assert;
let refute = bocha.refute;
let smartdb = require('../lib/smartdb.js');
module.exports = testCase('fake', {
'can fake get()': async function () {
let fakeDb = createFake({
entities: [
{ _id: 'F1', type: 'fish', name: 'Shark' }
]
});
let doc = await fakeDb.get('fish', 'F1');
assert.equals(doc, { _id: 'F1', type: 'fish', name: 'Shark' });
},
'updateWithRetry() can update entity': async function () {
let bocha = require('bocha');
let testCase = bocha.testCase;
let assert = bocha.assert;
let refute = bocha.refute;
let nock = require('nock');
module.exports = testCase('views', {
setUp() {
this.nock = nock('http://myserver.com');
},
tearDown() {
nock.cleanAll();
},
'list: without rewrite': async function () {
this.nock
.get('/animals/_design/fish/_list/myList/myView?group=true').reply(200, '<b>Shark</b>');
let db = createDb({
databases: [
{
let bocha = require('bocha');
let testCase = bocha.testCase;
let assert = bocha.assert;
let nock = require('nock');
module.exports = testCase('auth', {
setUp() {
this.nock = nock('http://myserver.com');
},
tearDown() {
nock.cleanAll();
},
'getBulk': {
'two entities that exist': async function () {
this.nock
.post('/main/_all_docs', { keys: ['F1', 'F2'] })
.query({ include_docs: 'true' })
.reply(200, {
rows: [