Skip to content

Instantly share code, notes, and snippets.

@deontologician
Created May 21, 2015 22:45
Show Gist options
  • Save deontologician/24715e686c91ee7dbbdd to your computer and use it in GitHub Desktop.
Save deontologician/24715e686c91ee7dbbdd to your computer and use it in GitHub Desktop.
neumino test
var config = {
host: 'localhost',
port: 31157,
db: 'reqlitetest',
authKey: ''
};
var r = require('./js');
var assert = require('assert');
var connections = {};
var mainConnection;
var TEST_DB = 'test';
var TEST_TABLE = 'neumino';
describe('changes.js', function(){
//NOTE: The order of the tests matters! Append only!
before(function(done) {
setTimeout(function() { // Delay for nodemon to restart the server
r.connect(config).bind({}).then(function(conn) {
// Use the rethinkdb connection to validate the tests
mainConnection = conn;
}).catch(function() { // ignore errors
}).finally(function() {
return this.query.run(connections.rethinkdb);
}).catch(function() { // ignore errors
}).finally(function() {
this.query = r.db(TEST_DB).table(TEST_TABLE).insert([
{id: 1, foo: 10, redundant: 100, optional: 1000},
{id: 2, foo: 20, redundant: 200, optional: 2000},
{id: 3, foo: 30, redundant: 100, optional: 3000},
{id: 4, foo: 40, redundant: 200},
{id: 5, foo: 50, redundant: 100, optional: 5000}
])
return this.query.run(mainConnection);
}).catch(function() { // ignore errors
}).finally(function() {
return this.query.run(connections.rethinkdb);
}).catch(function() { // ignore errors
}).finally(function() {
this.query = r.db(TEST_DB).table(TEST_TABLE).indexCreate('foo');
return this.query.run(mainConnection);
}).catch(function() { // ignore errors
}).finally(function() {
done();
});
}, 500)
});
for(i = 0; i < 200; i++){
it('changes - '+i, function(done) {
var doc = {id: 6, foo: 60, redundant: 200};
var query = r.db(TEST_DB).table(TEST_TABLE).get(6).changes();
query.run(mainConnection).then(function(feed) {
feed.next().then(function(change) {
assert.deepEqual(change, { new_val: null });
return feed.next()
}).then(function(change) {
assert.deepEqual(change, {
new_val: {id: 6, foo: 60, redundant: 200},
old_val: null
})
return feed.close();
}).then(function() {
done();
}).catch(done);
r.db(TEST_DB).table(TEST_TABLE).insert(doc).run(mainConnection).then(function(result) {
}).catch(done);
}).then(function dropData(){
return r.db(TEST_DB).table(TEST_TABLE).delete().run(mainConnection)
}).catch(done);
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment