Skip to content

Commit

Permalink
fixing querying for times, adding client tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tryneus committed Dec 18, 2015
1 parent cf670e8 commit fef9c5c
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 5 deletions.
7 changes: 3 additions & 4 deletions client/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function Fusion(host, { secure: secure = true } = {}) {

function createSubscription(queryOptions, userOptions) {
return createRequest((reqId, events) => {
let req = { type: 'subscribe', options: queryOptions, request_id: reqId }
let req = { type: 'subscribe', options: serialize(queryOptions), request_id: reqId }
handshaken.then(() => socket.send(req))
return Subscription({
onResponse: events.onResponse,
Expand All @@ -156,12 +156,11 @@ function Fusion(host, { secure: secure = true } = {}) {
}

function writeOp(opType, collectionName, documents) {
let serializedDocs = serialize(documents)
return send(opType, { data: serializedDocs, collection: collectionName })
return send(opType, { data: serialize(documents), collection: collectionName })
}

function query(data) {
return send('query', data)
return send('query', serialize(data))
}

function endSubscription(requestId) {
Expand Down
1 change: 1 addition & 0 deletions client/test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ var Fusion = require("Fusion");
describe("Testing `upsert`", upsertSuite(getData));
describe("Testing `update`", updateSuite(getData));
describe("Testing `replace`", replaceSuite(getData));
describe("Testing `times`", timesSuite(getData));

}); // Storage API

Expand Down
2 changes: 1 addition & 1 deletion client/test/fusionObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fusionObjectSuite = () => {
// the Fusion object as its argument.
assert.equal(fusion, _fusion);

// The dispose method fires the `disconnected` event (iff the client was
// The dispose method fires the `disconnected` event (if the client was
// connected), then closes all connections and cleans up all resources
// associated with the Fusion object.
_fusion.dispose();
Expand Down
1 change: 1 addition & 0 deletions client/test/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<script src="upsert.js"></script>
<script src="update.js"></script>
<script src="replace.js"></script>
<script src="times.js"></script>

<!-- Test the removal commands -->
<script src="remove.js"></script>
Expand Down
63 changes: 63 additions & 0 deletions client/test/times.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
timesSuite = (getData) => {
return () => {

var data;

before(() => {
data = getData();
});

var range = (count) => Array.from(Array(count).keys());

beforeEach((done) => {
var rows = range(16).map((i) => ({ id: i, value: i % 4, time: new Date(Math.floor(i / 4)) }));
data.store(rows).then((res) => {
assert.isArray(res);
assert.lengthOf(res, 16);
done();
});
});

it("#.find(time: X)", (done) => {
data.find({ time: new Date(0) }).value().then((res) => {
assert.deepEqual({ id: 0, time: new Date(0), value: 0 }, res);
done();
}).catch(done);
});

it("#.find(value: X, time: Y)", (done) => {
data.find({ value: 1, time: new Date(3) }).value().then((res) => {
assert.deepEqual({ id: 13, value: 1, time: new Date(3) }, res);
done();
}).catch(done);
});

it("#.findAll(time: X)", (done) => {
data.findAll({ time: new Date(2) }).value().then((res) => {
assert.deepEqual(range(4).map((i) => ({ id: i + 8, value: i, time: new Date(2) })), res);
done();
}).catch(done);
});

it("#.findAll(value: X, time: Y)", (done) => {
data.findAll({ value: 2, time: new Date(3) }).value().then((res) => {
assert.deepEqual([{ id: 14, value: 2, time: new Date(3) }], res);
done();
}).catch(done);
});

it("#.findAll(value: X).above(time: Y)", (done) => {
data.findAll({ value: 3 }).above({ time: new Date(1) }).value().then((res) => {
assert.deepEqual(range(3).map((i) => ({ id: 3 + (i + 1) * 4, value: 3, time: new Date(i + 1) })), res);
done();
}).catch(done);
});

it("#.findAll(value: X).above(time: Y).below(time: Z)", (done) => {
data.findAll({ value: 2 }).above({ time: new Date(1) }).below({ time: new Date(3) }).value().then((res) => {
assert.deepEqual([{ id: 6, value: 2, time: new Date(1) }, { id: 10, value: 2, time: new Date(2) }], res);
done();
}).catch(done);
});
} // Testing `find`
}

0 comments on commit fef9c5c

Please sign in to comment.