|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | | -var Foo = require('../scripts/foo'); |
| 3 | +var Promise = require('sporks/scripts/promise'), |
| 4 | + Cluster = require('../scripts'), |
| 5 | + sporks = require('sporks'), |
| 6 | + Slouch = require('couch-slouch'); |
4 | 7 |
|
5 | 8 | describe('node and browser', function () { |
6 | 9 |
|
7 | | - it('should test in both node and the browser', function () { |
8 | | - // TODO: insert tests that can be tested in both node and the browser |
9 | | - var foo = new Foo(); |
10 | | - return foo.bar().then(function (thing) { |
11 | | - thing.should.eql('yar'); |
| 10 | + var slouch = null, |
| 11 | + id = 0, |
| 12 | + cluster = null; |
| 13 | + |
| 14 | + var data = { |
| 15 | + test_db1: [{ |
| 16 | + _id: '1', |
| 17 | + foo: 'bar' |
| 18 | + }, |
| 19 | + { |
| 20 | + _id: '2', |
| 21 | + yar: 'nar' |
| 22 | + }, |
| 23 | + ], |
| 24 | + test_db2: [{ |
| 25 | + _id: '3', |
| 26 | + foo: 'star' |
| 27 | + }, |
| 28 | + { |
| 29 | + _id: '4', |
| 30 | + yar: 'raar' |
| 31 | + }, |
| 32 | + ] |
| 33 | + }; |
| 34 | + |
| 35 | + var createDocs = function (db, docs) { |
| 36 | + var promises = []; |
| 37 | + docs.forEach(function (doc) { |
| 38 | + promises.push(slouch.doc.create(db, doc)); |
| 39 | + }); |
| 40 | + return Promise.all(promises); |
| 41 | + }; |
| 42 | + |
| 43 | + var createDatabase = function (db, docs) { |
| 44 | + return slouch.db.create(db).then(function () { |
| 45 | + return createDocs(db, docs); |
| 46 | + }); |
| 47 | + }; |
| 48 | + |
| 49 | + var createData = function () { |
| 50 | + var promises = []; |
| 51 | + sporks.each(data, function (docs, db) { |
| 52 | + promises.push(createDatabase(db + '_' + id, docs)); |
| 53 | + }); |
| 54 | + return Promise.all(promises); |
| 55 | + }; |
| 56 | + |
| 57 | + var destroyData = function () { |
| 58 | + var promises = []; |
| 59 | + sporks.each(data, function (docs, db) { |
| 60 | + promises.push(slouch.db.destroy(db + '_' + id)); |
| 61 | + }); |
| 62 | + return Promise.all(promises); |
| 63 | + }; |
| 64 | + |
| 65 | + beforeEach(function () { |
| 66 | + slouch = new Slouch('http://admin:admin@localhost:5984'); |
| 67 | + |
| 68 | + // Use a unique id as back to back creation/deletion of the same DBs can lead to problems |
| 69 | + id++; |
| 70 | + |
| 71 | + return createData(); |
| 72 | + }); |
| 73 | + |
| 74 | + afterEach(function () { |
| 75 | + return destroyData(); |
| 76 | + }); |
| 77 | + |
| 78 | + it('should replicate', function () { |
| 79 | + var cluster = new Cluster({ |
| 80 | + source: 'http://admin:admin@localhost:5984', |
| 81 | + target: 'http://admin:admin@localhost:5984' |
12 | 82 | }); |
| 83 | + return cluster.replicate(); |
13 | 84 | }); |
14 | 85 |
|
| 86 | + // it('should skip when replicating', function () { |
| 87 | + // var cluster = new Cluster({ |
| 88 | + // source: 'http://admin:admin@localhost:5984', |
| 89 | + // target: 'http://admin:admin@localhost:5984', |
| 90 | + // skip: ['_global_changes', '_replicator', '_users'] |
| 91 | + // }); |
| 92 | + // return cluster.replicate(); |
| 93 | + // }); |
| 94 | + |
| 95 | + // it('should support custom concurrency when replicating', function () { |
| 96 | + // |
| 97 | + // }); |
| 98 | + |
15 | 99 | }); |
0 commit comments