Commit 79d7f77b authored by Bryan Kaperick's avatar Bryan Kaperick

One additional invalid document name to check for and a temporary fix for...

One additional invalid document name to check for and a temporary fix for remove operations sometimes being incorrectly ordered.
parent aa6ed5aa
......@@ -4,13 +4,14 @@
"use strict";
// Used to distinguish between operations done within the same millisecond
var unique_timestamp = function () {
var unique_timestamp = function (time) {
// XXX: replace this with UUIDStorage function call to S4() when it becomes
// publicly accessible
var uuid = ('0000' + Math.floor(Math.random() * 0x10000)
.toString(16)).slice(-4),
timestamp = Date.now().toString();
//timestamp = Date.now().toString();
timestamp = time.toString();
return timestamp + "-" + uuid;
};
......@@ -99,15 +100,19 @@
};
HistoryStorage.prototype.put = function (id, data) {
if (data.hasOwnProperty("_timestamp")) {
throw new jIO.util.jIOError(
"Document cannot have metadata attribute '_timestamp'",
422
);
}
var timestamp = unique_timestamp(),
if (data.hasOwnProperty("_doc_id")) {
throw new jIO.util.jIOError(
"Document cannot have metadata attribute '_doc_id'",
422
);
}
var timestamp = unique_timestamp(Date.now()),
metadata = {
// XXX: remove this attribute once query can sort_on id
timestamp: timestamp,
......@@ -124,7 +129,7 @@
};
HistoryStorage.prototype.remove = function (id) {
var timestamp = unique_timestamp(),
var timestamp = unique_timestamp(Date.now() - 1),
metadata = {
// XXX: remove this attribute once query can sort_on id
timestamp: timestamp,
......@@ -186,7 +191,7 @@
};
HistoryStorage.prototype.putAttachment = function (id, name, blob) {
var timestamp = unique_timestamp(),
var timestamp = unique_timestamp(Date.now()),
metadata = {
// XXX: remove this attribute once query can sort_on id
timestamp: timestamp,
......@@ -268,26 +273,7 @@
throw error;
});
}
return substorage.get(id)
.push(function (result) {
if (result.op === "putAttachment") {
return substorage.getAttachment(id, result.name);
}
throw new jIO.util.jIOError(
"HistoryStorage: cannot find object '" + id + "' (removed)",
404
);
},
function (error) {
if (error.status_code === 404 &&
error instanceof jIO.util.jIOError) {
throw new jIO.util.jIOError(
"HistoryStorage: cannot find object '" + id + "'",
404
);
}
throw error;
})
return substorage.getAttachment(id, name)
.push(undefined, function (error) {
if (error.status_code === 404 &&
error instanceof jIO.util.jIOError) {
......@@ -302,7 +288,7 @@
};
HistoryStorage.prototype.removeAttachment = function (id, name) {
var timestamp = unique_timestamp(),
var timestamp = unique_timestamp(Date.now()),
metadata = {
// XXX: remove this attribute once query can sort_on id
timestamp: timestamp,
......
......@@ -63,12 +63,13 @@
test("Testing proper adding/removing attachments",
function () {
stop();
expect(7);
expect(9);
var jio = this.jio,
timestamps = this.jio.__storage._timestamps,
blob2 = this.blob2,
blob1 = this.blob1,
other_blob = this.other_blob;
other_blob = this.other_blob,
otherother_blob = new Blob(['abcabc']);
jio.put("doc", {title: "foo0"})
.push(function () {
......@@ -83,6 +84,16 @@
.push(function () {
return jio.putAttachment("doc", "other_attacheddata", other_blob);
})
.push(function () {
return jio.putAttachment(
"doc",
"otherother_attacheddata",
otherother_blob
);
})
.push(function () {
return jio.removeAttachment("doc", "otherother_attacheddata");
})
.push(function () {
return jio.get("doc");
})
......@@ -142,6 +153,18 @@
"Other document successfully queried"
);
})
.push(function () {
return jio.getAttachment("doc", "otherother_attacheddata");
})
.push(function () {
ok(false, "This query should have thrown a 404 error");
},
function (error) {
ok(error instanceof jIO.util.jIOError, "Correct type of error");
deepEqual(error.status_code,
404,
"Error if you try to get a removed attachment");
})
.fail(function (error) {
//console.log(error);
ok(false, error);
......@@ -372,7 +395,7 @@
test("Handling bad input",
function () {
stop();
expect(2);
expect(4);
var jio = this.jio,
BADINPUT_ERRCODE = 422;
......@@ -380,6 +403,21 @@
"_timestamp": 3,
"other_attr": "other_val"
})
.push(function () {
ok(false, "This statement should not be reached");
}, function (error) {
ok(error instanceof jIO.util.jIOError, "Correct type of error");
deepEqual(error.status_code,
BADINPUT_ERRCODE,
"Can't save a document with a reserved keyword"
);
})
.push(function () {
return jio.put("doc", {
"_doc_id": 3,
"other_attr": "other_val"
});
})
.push(function () {
ok(false, "This statement should not be reached");
}, function (error) {
......@@ -390,7 +428,7 @@
);
})
.fail(function (error) {
//console.log(error);
//console.log(error);
ok(false, error);
})
.always(function () {start(); });
......@@ -467,6 +505,8 @@
subtitle: "s3"
}, "Get returns latest revision");
return jio.get(timestamps.doc[0]);
}, function (err) {
ok(false, err);
})
.push(function (result) {
deepEqual(result, {
......@@ -481,6 +521,8 @@
subtitle: "s1"
}, "Get returns second version");
return jio.get(timestamps.doc[2]);
}, function (err) {
ok(false, err);
})
.push(function (result) {
deepEqual(result, {
......@@ -488,6 +530,8 @@
subtitle: "s2"
}, "Get returns third version");
return jio.get(timestamps.doc[3]);
}, function (err) {
ok(false, err);
})
.push(function () {
ok(false, "This should have thrown a 404 error");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment