Permalink
Browse files

Make time optional when putting events.

If the time is not specified, the server's current time is used instead.
  • Loading branch information...
1 parent 581e07d commit dee500719b7fe9638e66d7d46d390bd23895af66 @mbostock mbostock committed Apr 24, 2012
Showing with 31 additions and 11 deletions.
  1. +1 −1 lib/cube/event.js
  2. +30 −10 test/collector-test.js
View
@@ -28,7 +28,7 @@ exports.putter = function(db) {
timesToInvalidateByTierByType = {};
function putter(request, callback) {
- var time = new Date(request.time),
+ var time = "time" in request ? new Date(request.time) : new Date(),
type = request.type;
// Validate the date and type.
View
@@ -12,13 +12,6 @@ var port = ++test.port, server = cube.server({
"http-port": port
});
-var obj = { type: "test"
- , time: (new Date).toISOString()
- , data: { foo: "bar" }
- };
-var arr = [obj];
-var num = 42;
-
server.register = cube.collector.register;
server.start();
@@ -35,7 +28,13 @@ suite.addBatch(test.batch({
suite.addBatch(test.batch({
"POST /event/put with a JSON object": {
- topic: test.request({method: "POST", port: port, path: "/1.0/event/put"}, JSON.stringify(obj)),
+ topic: test.request({method: "POST", port: port, path: "/1.0/event/put"}, JSON.stringify({
+ type: "test",
+ time: new Date,
+ data: {
+ foo: "bar"
+ }
+ })),
"responds with status 400": function(response) {
assert.equal(response.statusCode, 400);
assert.deepEqual(JSON.parse(response.body), {error: "TypeError: Object #<Object> has no method 'forEach'"});
@@ -45,7 +44,13 @@ suite.addBatch(test.batch({
suite.addBatch(test.batch({
"POST /event/put with a JSON array": {
- topic: test.request({method: "POST", port: port, path: "/1.0/event/put"}, JSON.stringify(arr)),
+ topic: test.request({method: "POST", port: port, path: "/1.0/event/put"}, JSON.stringify([{
+ type: "test",
+ time: new Date,
+ data: {
+ foo: "bar"
+ }
+ }])),
"responds with status 200": function(response) {
assert.equal(response.statusCode, 200);
assert.deepEqual(JSON.parse(response.body), {});
@@ -55,12 +60,27 @@ suite.addBatch(test.batch({
suite.addBatch(test.batch({
"POST /event/put with a JSON number": {
- topic: test.request({method: "POST", port: port, path: "/1.0/event/put"}, JSON.stringify(num)),
+ topic: test.request({method: "POST", port: port, path: "/1.0/event/put"}, JSON.stringify(42)),
"responds with status 400": function(response) {
assert.equal(response.statusCode, 400);
assert.deepEqual(JSON.parse(response.body), {error: "TypeError: Object 42 has no method 'forEach'"});
}
}
}));
+suite.addBatch(test.batch({
+ "POST /event/put without an associated time": {
+ topic: test.request({method: "POST", port: port, path: "/1.0/event/put"}, JSON.stringify([{
+ type: "test",
+ data: {
+ foo: "bar"
+ }
+ }])),
+ "responds with status 200": function(response) {
+ assert.equal(response.statusCode, 200);
+ assert.deepEqual(JSON.parse(response.body), {});
+ }
+ }
+}));
+
suite.export(module);

0 comments on commit dee5007

Please sign in to comment.