Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
jio
Commits
f544ed16
Commit
f544ed16
authored
Dec 05, 2013
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
revisionstorage put unit test done
parent
d40e0e8d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
299 additions
and
224 deletions
+299
-224
src/jio.storage/revisionstorage.js
src/jio.storage/revisionstorage.js
+2
-2
test/jio.storage/revisionstorage.tests.js
test/jio.storage/revisionstorage.tests.js
+297
-222
No files found.
src/jio.storage/revisionstorage.js
View file @
f544ed16
...
@@ -810,11 +810,11 @@
...
@@ -810,11 +810,11 @@
metadata
,
metadata
,
option
,
option
,
{},
{},
function
(
err
)
{
function
(
err
,
response
)
{
if
(
err
)
{
if
(
err
)
{
return
command
.
error
(
err
);
return
command
.
error
(
err
);
}
}
command
.
success
();
command
.
success
(
{
"
rev
"
:
response
.
rev
}
);
}
}
);
);
};
};
...
...
test/jio.storage/revisionstorage.tests.js
View file @
f544ed16
...
@@ -393,251 +393,326 @@
...
@@ -393,251 +393,326 @@
});
});
//
test("Put", function () {
test
(
"
Put
"
,
function
()
{
// var o = generateTools()
;
var
shared
=
{},
jio
,
jio_local
;
// o.jio = jIO.newJio({
shared
.
workspace
=
{};
// "type": "revision",
shared
.
local_storage_description
=
{
// "sub_storage": {
"
type
"
:
"
local
"
,
// "type": "local",
"
username
"
:
"
revision put
"
,
// "username": "urevput",
"
mode
"
:
"
memory
"
// "application_name": "arevput"
//"mode": "localStorage"
// }
};
// });
// o.localpath = "jio/localstorage/urevput/arevput";
// // put without id
jio
=
jIO
.
createJIO
({
// // error 20 -> document id required
"
type
"
:
"
revision
"
,
// o.spy(o, "status", 20, "Put without id");
"
sub_storage
"
:
shared
.
local_storage_description
// o.jio.put({}, o.f);
},
{
"
workspace
"
:
shared
.
workspace
});
// o.tick(o);
// // put non empty document
jio_local
=
jIO
.
createJIO
(
shared
.
local_storage_description
,
{
// o.doc = {"_id": "put1", "title": "myPut1"};
"
workspace
"
:
shared
.
workspace
// o.revisions = {"start": 0, "ids": []};
});
// o.rev = "1-" + generateRevisionHash(o.doc, o.revisions);
// o.spy(o, "value", {"ok": true, "id": "put1", "rev": o.rev},
// "Creates a document");
// o.jio.put(o.doc, o.f);
// o.tick(o);
// // check document
stop
();
// o.doc._id = "put1." + o.rev;
// deepEqual(
// util.jsonlocalstorage.getItem(o.localpath + "/put1." + o.rev),
// o.doc,
// "Check document"
// );
// // check document tree
// put non empty document
// o.doc_tree = {
shared
.
doc
=
{
"
_id
"
:
"
put1
"
,
"
title
"
:
"
myPut1
"
};
// "_id": "put1.revision_tree.json",
shared
.
revisions
=
{
"
start
"
:
0
,
"
ids
"
:
[]};
// "children": [{
shared
.
rev
=
"
1-
"
+
generateRevisionHash
(
shared
.
doc
,
shared
.
revisions
);
// "rev": o.rev,
jio
.
put
(
shared
.
doc
).
then
(
function
(
answer
)
{
// "status": "available",
// "children": []
// }]
// };
// deepEqual(
// util.jsonlocalstorage.getItem(
// o.localpath + "/put1.revision_tree.json"
// ),
// o.doc_tree,
// "Check document tree"
// );
// // put without rev and document already exists
deepEqual
(
answer
,
{
// o.doc = {"_id": "put1", "title": "myPut2"};
"
id
"
:
"
put1
"
,
// o.rev = "1-" + generateRevisionHash(o.doc, o.revisions);
"
method
"
:
"
put
"
,
// o.spy(o, "value", {"ok": true, "id": "put1", "rev": o.rev},
"
result
"
:
"
success
"
,
// "Put same document without revision");
"
rev
"
:
shared
.
rev
,
// o.jio.put(o.doc, o.f);
"
status
"
:
204
,
// o.tick(o);
"
statusText
"
:
"
No Content
"
// XXX should 201 Created
},
"
Create a document
"
);
// o.doc_tree.children.unshift({
// check document
// "rev": o.rev,
shared
.
doc
.
_id
=
"
put1.
"
+
shared
.
rev
;
// "status": "available",
return
jio_local
.
get
({
"
_id
"
:
shared
.
doc
.
_id
});
// "children": []
// });
// // put + revision
}).
then
(
function
(
answer
)
{
// o.doc = {"_id": "put1", "_rev": o.rev, "title": "myPut2"};
// o.revisions = {"start": 1, "ids": [o.rev.split('-')[1]]};
// o.rev = "2-" + generateRevisionHash(o.doc, o.revisions);
// o.spy(o, "value", {"id": "put1", "ok": true, "rev": o.rev},
// "Put + revision");
// o.jio.put(o.doc, o.f);
// o.tick(o);
// // check document
deepEqual
(
answer
.
data
,
shared
.
doc
,
"
Check document
"
);
// o.doc._id = "put1." + o.rev;
// delete o.doc._rev;
// deepEqual(
// util.jsonlocalstorage.getItem(o.localpath + "/put1." + o.rev),
// o.doc,
// "Check document"
// );
// // check document tree
// check document tree
// o.doc_tree.children[0].children.unshift({
shared
.
doc_tree
=
{
// "rev": o.rev,
"
_id
"
:
"
put1.revision_tree.json
"
,
// "status": "available",
"
children
"
:
[{
// "children": []
"
rev
"
:
shared
.
rev
,
// });
"
status
"
:
"
available
"
,
// deepEqual(
"
children
"
:
[]
// util.jsonlocalstorage.getItem(
}]
// o.localpath + "/put1.revision_tree.json"
};
// ),
shared
.
doc_tree
.
children
=
JSON
.
stringify
(
shared
.
doc_tree
.
children
);
// o.doc_tree,
// "Check document tree"
// );
// // put + wrong revision
return
jio_local
.
get
({
"
_id
"
:
shared
.
doc_tree
.
_id
});
// o.doc = {"_id": "put1", "_rev": "3-wr3", "title": "myPut3"};
// o.revisions = {"start": 3, "ids": ["wr3"]};
// o.rev = "4-" + generateRevisionHash(o.doc, o.revisions);
// o.spy(o, "value", {"id": "put1", "ok": true, "rev": o.rev},
// "Put + wrong revision");
// o.jio.put(o.doc, o.f);
// o.tick(o);
// // check document
}).
then
(
function
(
answer
)
{
// o.doc._id = "put1." + o.rev;
// delete o.doc._rev;
// deepEqual(
// util.jsonlocalstorage.getItem(o.localpath + "/put1." + o.rev),
// o.doc,
// "Check document"
// );
// // check document tree
deepEqual
(
answer
.
data
,
shared
.
doc_tree
,
"
Check document tree
"
);
// o.doc_tree.children.unshift({
// "rev": "3-wr3",
// "status": "missing",
// "children": [{
// "rev": o.rev,
// "status": "available",
// "children": []
// }]
// });
// deepEqual(
// util.jsonlocalstorage.getItem(
// o.localpath + "/put1.revision_tree.json"
// ),
// o.doc_tree,
// "Check document tree"
// );
// // put + revision history
// put without rev and document already exists
// o.doc = {
shared
.
doc
=
{
"
_id
"
:
"
put1
"
,
"
title
"
:
"
myPut2
"
};
// "_id": "put1",
shared
.
rev
=
"
1-
"
+
generateRevisionHash
(
shared
.
doc
,
shared
.
revisions
);
// //"_revs": ["3-rh3", "2-rh2", "1-rh1"], // same as below
return
jio
.
put
(
shared
.
doc
);
// "_revs": {"start": 3, "ids": ["rh3", "rh2", "rh1"]},
// "title": "myPut3"
// };
// o.spy(o, "value", {"id": "put1", "ok": true, "rev": "3-rh3"},
// "Put + revision history");
// o.jio.put(o.doc, o.f);
// o.tick(o);
// // check document
}).
then
(
function
(
answer
)
{
// o.doc._id = "put1.3-rh3";
// delete o.doc._revs;
// deepEqual(
// util.jsonlocalstorage.getItem(o.localpath + "/put1.3-rh3"),
// o.doc,
// "Check document"
// );
// // check document tree
deepEqual
(
answer
,
{
// o.doc_tree.children.unshift({
"
id
"
:
"
put1
"
,
// "rev": "1-rh1",
"
method
"
:
"
put
"
,
// "status": "missing",
"
result
"
:
"
success
"
,
// "children": [{
"
rev
"
:
shared
.
rev
,
// "rev": "2-rh2",
"
status
"
:
204
,
// "status": "missing",
"
statusText
"
:
"
No Content
"
// XXX should be 201 Created
// "children": [{
},
"
Put same document without revision
"
);
// "rev": "3-rh3",
// "status": "available",
// "children": []
// }]
// }]
// });
// deepEqual(
// util.jsonlocalstorage.getItem(
// o.localpath + "/put1.revision_tree.json"
// ),
// o.doc_tree,
// "Check document tree"
// );
// // add attachment
// o.doc._attachments = {
// "att1": {
// "length": 1,
// "content_type": "text/plain",
// "digest": "md5-0cc175b9c0f1b6a831c399e269772661"
// },
// "att2": {
// "length": 2,
// "content_type": "dont/care",
// "digest": "md5-5360af35bde9ebd8f01f492dc059593c"
// }
// };
// util.jsonlocalstorage.setItem(o.localpath + "/put1.3-rh3", o.doc);
// util.jsonlocalstorage.setItem(o.localpath + "/put1.3-rh3/att1", "a");
// util.jsonlocalstorage.setItem(o.localpath + "/put1.3-rh3/att2", "bc");
// // put + revision with attachment
// o.attachments = o.doc._attachments;
// o.doc = {"_id": "put1", "_rev": "3-rh3", "title": "myPut4"};
// o.revisions = {"start": 3, "ids": ["rh3", "rh2", "rh1"]};
// o.rev = "4-" + generateRevisionHash(o.doc, o.revisions);
// o.spy(o, "value", {"id": "put1", "ok": true, "rev": o.rev},
// "Put + revision (document contains attachments)");
// o.jio.put(o.doc, o.f);
// o.tick(o);
// // check document
shared
.
doc_tree
.
children
=
JSON
.
parse
(
shared
.
doc_tree
.
children
);
// o.doc._id = "put1." + o.rev;
shared
.
doc_tree
.
children
.
unshift
({
// o.doc._attachments = o.attachments;
"
rev
"
:
shared
.
rev
,
// delete o.doc._rev;
"
status
"
:
"
available
"
,
// deepEqual(
"
children
"
:
[]
// util.jsonlocalstorage.getItem(o.localpath + "/put1." + o.rev),
});
// o.doc,
shared
.
doc_tree
.
children
=
JSON
.
stringify
(
shared
.
doc_tree
.
children
);
// "Check document"
// );
// // check attachments
// put + revision
// deepEqual(
shared
.
doc
=
{
"
_id
"
:
"
put1
"
,
"
_rev
"
:
shared
.
rev
,
"
title
"
:
"
myPut2
"
};
// util.jsonlocalstorage.getItem(o.localpath + "/put1." + o.rev + "/att1"),
shared
.
revisions
=
{
"
start
"
:
1
,
"
ids
"
:
[
shared
.
rev
.
split
(
'
-
'
)[
1
]]};
// "a",
shared
.
rev
=
"
2-
"
+
generateRevisionHash
(
shared
.
doc
,
shared
.
revisions
);
// "Check Attachment"
return
jio
.
put
(
shared
.
doc
);
// );
// deepEqual(
// util.jsonlocalstorage.getItem(o.localpath + "/put1." + o.rev + "/att2"),
// "bc",
// "Check Attachment"
// );
// // check document tree
}).
then
(
function
(
answer
)
{
// o.doc_tree.children[0].children[0].children[0].children.unshift({
// "rev": o.rev,
// "status": "available",
// "children": []
// });
// deepEqual(
// util.jsonlocalstorage.getItem(
// o.localpath + "/put1.revision_tree.json"
// ),
// o.doc_tree,
// "Check document tree"
// );
// util.closeAndcleanUpJio(o.jio);
deepEqual
(
answer
,
{
"
id
"
:
"
put1
"
,
"
method
"
:
"
put
"
,
"
result
"
:
"
success
"
,
"
rev
"
:
shared
.
rev
,
"
status
"
:
204
,
"
statusText
"
:
"
No Content
"
},
"
Put + revision
"
);
// });
// check document
shared
.
doc
.
_id
=
"
put1.
"
+
shared
.
rev
;
delete
shared
.
doc
.
_rev
;
return
jio_local
.
get
({
"
_id
"
:
shared
.
doc
.
_id
});
}).
then
(
function
(
answer
)
{
deepEqual
(
answer
.
data
,
shared
.
doc
,
"
Check document
"
);
// check document tree
shared
.
doc_tree
.
children
=
JSON
.
parse
(
shared
.
doc_tree
.
children
);
shared
.
doc_tree
.
children
[
0
].
children
.
unshift
({
"
rev
"
:
shared
.
rev
,
"
status
"
:
"
available
"
,
"
children
"
:
[]
});
shared
.
doc_tree
.
children
=
JSON
.
stringify
(
shared
.
doc_tree
.
children
);
return
jio_local
.
get
({
"
_id
"
:
shared
.
doc_tree
.
_id
});
}).
then
(
function
(
answer
)
{
deepEqual
(
answer
.
data
,
shared
.
doc_tree
,
"
Check document tree
"
);
// put + wrong revision
shared
.
doc
=
{
"
_id
"
:
"
put1
"
,
"
_rev
"
:
"
3-wr3
"
,
"
title
"
:
"
myPut3
"
};
shared
.
revisions
=
{
"
start
"
:
3
,
"
ids
"
:
[
"
wr3
"
]};
shared
.
rev
=
"
4-
"
+
generateRevisionHash
(
shared
.
doc
,
shared
.
revisions
);
return
jio
.
put
(
shared
.
doc
);
}).
then
(
function
(
answer
)
{
deepEqual
(
answer
,
{
"
id
"
:
"
put1
"
,
"
method
"
:
"
put
"
,
"
result
"
:
"
success
"
,
"
rev
"
:
shared
.
rev
,
"
status
"
:
204
,
"
statusText
"
:
"
No Content
"
},
"
Put + wrong revision
"
);
// check document
shared
.
doc
.
_id
=
"
put1.
"
+
shared
.
rev
;
delete
shared
.
doc
.
_rev
;
return
jio_local
.
get
({
"
_id
"
:
shared
.
doc
.
_id
});
}).
then
(
function
(
answer
)
{
deepEqual
(
answer
.
data
,
shared
.
doc
,
"
Check document
"
);
// check document tree
shared
.
doc_tree
.
children
=
JSON
.
parse
(
shared
.
doc_tree
.
children
);
shared
.
doc_tree
.
children
.
unshift
({
"
rev
"
:
"
3-wr3
"
,
"
status
"
:
"
missing
"
,
"
children
"
:
[{
"
rev
"
:
shared
.
rev
,
"
status
"
:
"
available
"
,
"
children
"
:
[]
}]
});
shared
.
doc_tree
.
children
=
JSON
.
stringify
(
shared
.
doc_tree
.
children
);
return
jio_local
.
get
({
"
_id
"
:
shared
.
doc_tree
.
_id
});
}).
then
(
function
(
answer
)
{
deepEqual
(
answer
.
data
,
shared
.
doc_tree
,
"
Check document tree
"
);
// put + revision history
shared
.
doc
=
{
"
_id
"
:
"
put1
"
,
//"_revs": ["3-rh3", "2-rh2", "1-rh1"], // same as below
"
_revs
"
:
{
"
start
"
:
3
,
"
ids
"
:
[
"
rh3
"
,
"
rh2
"
,
"
rh1
"
]},
"
title
"
:
"
myPut3
"
};
return
jio
.
put
(
shared
.
doc
);
}).
then
(
function
(
answer
)
{
deepEqual
(
answer
,
{
"
id
"
:
"
put1
"
,
"
method
"
:
"
put
"
,
"
result
"
:
"
success
"
,
"
rev
"
:
"
3-rh3
"
,
"
status
"
:
204
,
"
statusText
"
:
"
No Content
"
},
"
Put + revision history
"
);
// check document
shared
.
doc
.
_id
=
"
put1.3-rh3
"
;
delete
shared
.
doc
.
_revs
;
return
jio_local
.
get
({
"
_id
"
:
shared
.
doc
.
_id
});
}).
then
(
function
(
answer
)
{
deepEqual
(
answer
.
data
,
shared
.
doc
,
"
Check document
"
);
// check document tree
shared
.
doc_tree
.
children
=
JSON
.
parse
(
shared
.
doc_tree
.
children
);
shared
.
doc_tree
.
children
.
unshift
({
"
rev
"
:
"
1-rh1
"
,
"
status
"
:
"
missing
"
,
"
children
"
:
[{
"
rev
"
:
"
2-rh2
"
,
"
status
"
:
"
missing
"
,
"
children
"
:
[{
"
rev
"
:
"
3-rh3
"
,
"
status
"
:
"
available
"
,
"
children
"
:
[]
}]
}]
});
shared
.
doc_tree
.
children
=
JSON
.
stringify
(
shared
.
doc_tree
.
children
);
return
jio_local
.
get
({
"
_id
"
:
shared
.
doc_tree
.
_id
});
}).
then
(
function
(
answer
)
{
deepEqual
(
answer
.
data
,
shared
.
doc_tree
,
"
Check document tree
"
);
// add attachment
shared
.
doc
.
_attachments
=
{
"
att1
"
:
{
"
length
"
:
1
,
"
content_type
"
:
"
text/plain
"
,
"
digest
"
:
"
sha256-ca978112ca1bbdcafac231b39a23dc4da
"
+
"
786eff8147c4e72b9807785afee48bb
"
},
"
att2
"
:
{
"
length
"
:
2
,
"
content_type
"
:
"
dont/care
"
,
"
digest
"
:
"
sha256-1e0bbd6c686ba050b8eb03ffeedc64fdc
"
+
"
9d80947fce821abbe5d6dc8d252c5ac
"
}
};
return
RSVP
.
all
([
jio_local
.
putAttachment
({
"
_id
"
:
"
put1.3-rh3
"
,
"
_attachment
"
:
"
att1
"
,
"
_data
"
:
"
a
"
,
"
_mimetype
"
:
"
text/plain
"
}),
jio_local
.
putAttachment
({
"
_id
"
:
"
put1.3-rh3
"
,
"
_attachment
"
:
"
att2
"
,
"
_data
"
:
"
bc
"
,
"
_mimetype
"
:
"
dont/care
"
})]);
}).
then
(
function
()
{
// put + revision with attachment
shared
.
attachments
=
shared
.
doc
.
_attachments
;
shared
.
doc
=
{
"
_id
"
:
"
put1
"
,
"
_rev
"
:
"
3-rh3
"
,
"
title
"
:
"
myPut4
"
};
shared
.
revisions
=
{
"
start
"
:
3
,
"
ids
"
:
[
"
rh3
"
,
"
rh2
"
,
"
rh1
"
]};
shared
.
rev
=
"
4-
"
+
generateRevisionHash
(
shared
.
doc
,
shared
.
revisions
);
return
jio
.
put
(
shared
.
doc
);
}).
then
(
function
(
answer
)
{
deepEqual
(
answer
,
{
"
id
"
:
"
put1
"
,
"
method
"
:
"
put
"
,
"
result
"
:
"
success
"
,
"
rev
"
:
shared
.
rev
,
"
status
"
:
204
,
"
statusText
"
:
"
No Content
"
},
"
Put + revision (document contains attachments)
"
);
// check document
shared
.
doc
.
_id
=
"
put1.
"
+
shared
.
rev
;
shared
.
doc
.
_attachments
=
shared
.
attachments
;
delete
shared
.
doc
.
_rev
;
return
jio_local
.
get
({
"
_id
"
:
shared
.
doc
.
_id
});
}).
then
(
function
(
answer
)
{
deepEqual
(
answer
.
data
,
shared
.
doc
,
"
Check document
"
);
// check attachments
return
RSVP
.
all
([
jio_local
.
getAttachment
({
"
_id
"
:
"
put1.
"
+
shared
.
rev
,
"
_attachment
"
:
"
att1
"
}),
jio_local
.
getAttachment
({
"
_id
"
:
"
put1.
"
+
shared
.
rev
,
"
_attachment
"
:
"
att2
"
})]);
}).
then
(
function
(
answers
)
{
deepEqual
(
answers
[
0
].
data
.
type
,
"
text/plain
"
,
"
Check attachment 1 type
"
);
deepEqual
(
answers
[
1
].
data
.
type
,
"
dont/care
"
,
"
Check attachment 2 type
"
);
return
RSVP
.
all
([
jIO
.
util
.
readBlobAsBinaryString
(
answers
[
0
].
data
),
jIO
.
util
.
readBlobAsBinaryString
(
answers
[
1
].
data
)
]);
}).
then
(
function
(
answers
)
{
deepEqual
(
answers
[
0
].
target
.
result
,
"
a
"
,
"
Check attachment 1 content
"
);
deepEqual
(
answers
[
1
].
target
.
result
,
"
bc
"
,
"
Check attachment 2 content
"
);
// check document tree
shared
.
doc_tree
.
children
=
JSON
.
parse
(
shared
.
doc_tree
.
children
);
shared
.
doc_tree
.
children
[
0
].
children
[
0
].
children
[
0
].
children
.
unshift
({
"
rev
"
:
shared
.
rev
,
"
status
"
:
"
available
"
,
"
children
"
:
[]
});
shared
.
doc_tree
.
children
=
JSON
.
stringify
(
shared
.
doc_tree
.
children
);
return
jio_local
.
get
({
"
_id
"
:
shared
.
doc_tree
.
_id
});
}).
then
(
function
(
answer
)
{
deepEqual
(
answer
.
data
,
shared
.
doc_tree
,
"
Check document tree
"
);
}).
fail
(
unexpectedError
).
always
(
start
);
});
// test("Put Attachment", function () {
// test("Put Attachment", function () {
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment