Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jio_mebibou
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
Alexandra Rogova
jio_mebibou
Commits
2129be4e
Commit
2129be4e
authored
Dec 13, 2013
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
revisionstorage remove{,Attachment} tests done
parent
4fb5516e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
282 additions
and
169 deletions
+282
-169
src/jio.storage/revisionstorage.js
src/jio.storage/revisionstorage.js
+4
-4
test/jio.storage/revisionstorage.tests.js
test/jio.storage/revisionstorage.tests.js
+278
-165
No files found.
src/jio.storage/revisionstorage.js
View file @
2129be4e
...
@@ -867,11 +867,11 @@
...
@@ -867,11 +867,11 @@
"
revision_needed
"
:
true
,
"
revision_needed
"
:
true
,
"
remove
"
:
true
"
remove
"
:
true
},
},
function
(
err
)
{
function
(
err
,
response
)
{
if
(
err
)
{
if
(
err
)
{
return
command
.
error
(
err
);
return
command
.
error
(
err
);
}
}
command
.
success
();
command
.
success
(
{
"
rev
"
:
response
.
rev
}
);
}
}
);
);
};
};
...
@@ -890,11 +890,11 @@
...
@@ -890,11 +890,11 @@
"
_attachment
"
:
param
.
_attachment
"
_attachment
"
:
param
.
_attachment
}
}
},
},
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 @
2129be4e
...
@@ -1238,186 +1238,299 @@
...
@@ -1238,186 +1238,299 @@
});
});
// test("Remove
", function () {
test
(
"
Remove & Remove Attachment
"
,
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 remove
"
,
// "username": "urevrem",
"
mode
"
:
"
memory
"
// "application_name": "arevrem"
};
// }
// });
// o.localpath = "jio/localstorage/urevrem/arevrem";
// // 1. remove document without revision
jio
=
jIO
.
createJIO
({
// o.spy(o, "status", 409, "Remove document without revision " +
"
type
"
:
"
revision
"
,
// "-> 409 Conflict");
"
sub_storage
"
:
shared
.
local_storage_description
// o.jio.remove({"_id": "remove1"}, o.f);
},
{
"
workspace
"
:
shared
.
workspace
});
// o.tick(o);
// // 2. remove attachment without revision
jio_local
=
jIO
.
createJIO
(
shared
.
local_storage_description
,
{
// o.spy(o, "status", 409, "Remove attachment without revision " +
"
workspace
"
:
shared
.
workspace
// "-> 409 Conflict");
});
// o.jio.removeAttachment({"_id": "remove1", "_attachment": "remove2"}, o.f);
// o.tick(o);
// // adding a document with attachments
stop
();
// o.doc_myremove1 = {
// "_id": "remove1.1-veryoldrev",
// "title": "myRemove1"
// };
// util.jsonlocalstorage.setItem(o.localpath + "/remove1.1-veryoldrev",
// 1. remove document without revision
// o.doc_myremove1);
success
(
jio
.
remove
({
"
_id
"
:
"
remove1
"
})).
then
(
function
(
answer
)
{
// o.doc_myremove1._id = "remove1.2-oldrev";
deepEqual
(
answer
,
{
// o.attachment_remove2 = {
"
error
"
:
"
conflict
"
,
// "length": 3,
"
id
"
:
"
remove1
"
,
// "digest": "md5-dontcare",
"
message
"
:
"
Document update conflict
"
,
// "content_type": "oh/yeah"
"
method
"
:
"
remove
"
,
// };
"
reason
"
:
"
No document revision was provided
"
,
// o.attachment_remove3 = {
"
result
"
:
"
error
"
,
// "length": 5,
"
status
"
:
409
,
// "digest": "md5-865f5cc7fbd7854902eae9d8211f178a",
"
statusText
"
:
"
Conflict
"
// "content_type": "he/ho"
},
"
Remove document without revision -> 409 Conflict
"
);
// };
// o.doc_myremove1._attachments = {
// 2. remove attachment without revision
// "remove2": o.attachment_remove2,
return
success
(
jio
.
removeAttachment
({
// "remove3": o.attachment_remove3
"
_id
"
:
"
remove1
"
,
// };
"
_attachment
"
:
"
remove2
"
}));
// util.jsonlocalstorage.setItem(o.localpath + "/remove1.2-oldrev",
}).
then
(
function
(
answer
)
{
// o.doc_myremove1);
// util.jsonlocalstorage.setItem(
// o.localpath + "/remove1.2-oldrev/remove2",
// "abc"
// );
// util.jsonlocalstorage.setItem(
// o.localpath + "/remove1.2-oldrev/remove3",
// "defgh"
// );
// // add document tree
// o.doctree = {
// "children": [{
// "rev": "1-veryoldrev",
// "status": "available",
// "children": [{
// "rev": "2-oldrev",
// "status": "available",
// "children": []
// }]
// }]
// };
// util.jsonlocalstorage.setItem(o.localpath + "/remove1.revision_tree.json",
// o.doctree);
// // 3. remove inexistent attachment
// o.spy(o, "status", 404, "Remove inexistent attachment -> 404 Not Found");
// o.jio.removeAttachment({
// "_id": "remove1",
// "_attachment": "remove0",
// "_rev": "2-oldrev"
// }, o.f);
// o.tick(o);
// // 4. remove existing attachment
deepEqual
(
answer
,
{
// o.rev_hash = generateRevisionHash({
"
attachment
"
:
"
remove2
"
,
// "_id": "remove1
",
"
error
"
:
"
conflict
"
,
// "_attachment": "remove2
",
"
id
"
:
"
remove1
"
,
// }, {"start": 2, "ids": ["oldrev", "veryoldrev"]});
"
message
"
:
"
Document update conflict
"
,
// o.spy(o, "value", {
"
method
"
:
"
removeAttachment
"
,
// "ok": true
,
"
reason
"
:
"
No document revision was provided
"
,
// "id": "remove1
",
"
result
"
:
"
error
"
,
// "attachment": "remove2"
,
"
status
"
:
409
,
// "rev": "3-" + o.rev_hash
"
statusText
"
:
"
Conflict
"
// }, "Remove existing attachmen
t");
},
"
Remove attachment without revision -> 409 Conflic
t
"
);
// o.jio.removeAttachment({
// "_id": "remove1",
// adding a document with attachments
// "_attachment": "remove2",
shared
.
doc_myremove1
=
{
// "_rev": "2-oldrev"
"
_id
"
:
"
remove1.1-veryoldrev
"
,
// }, o.f);
"
title
"
:
"
myRemove1
"
// o.tick(o)
;
}
;
// o.doctree = {
return
jio_local
.
put
(
shared
.
doc_myremove1
);
// "_id": "remove1.revision_tree.json",
// "children": [{
// "rev": "1-veryoldrev",
// "status": "available",
// "children": [{
// "rev": "2-oldrev",
// "status": "available",
// "children": [{
// "rev": "3-" + o.rev_hash,
// "status": "available",
// "children": []
// }]
// }]
// }]
// };
// // 5. check if document tree has been updated correctly
}).
then
(
function
()
{
// deepEqual(util.jsonlocalstorage.getItem(
// o.localpath + "/remove1.revision_tree.json"
// ), o.doctree, "Check document tree");
// // 6. check if the attachment still exists
// deepEqual(util.jsonlocalstorage.getItem(
// o.localpath + "/remove1.2-oldrev/remove2"
// ), "abc", "Check attachment -> still exists");
// // 7. check if document is updated
// deepEqual(util.jsonlocalstorage.getItem(
// o.localpath + "/remove1.3-" + o.rev_hash
// ), {
// "_id": "remove1.3-" + o.rev_hash,
// "title": "myRemove1",
// "_attachments": {"remove3": o.attachment_remove3}
// }, "Check document");
// // 8. remove document with wrong revision
// o.spy(o, "status", 409, "Remove document with wrong revision " +
// "-> 409 Conflict");
// o.jio.remove({"_id": "remove1", "_rev": "1-a"}, o.f);
// o.tick(o);
// // 9. remove attachment wrong revision
shared
.
doc_myremove1
.
_id
=
"
remove1.2-oldrev
"
;
// o.spy(o, "status", 409, "Remove attachment with wrong revision " +
shared
.
attachment_remove2
=
{
// "-> 409 Conflict");
"
length
"
:
3
,
// o.jio.removeAttachment({
"
digest
"
:
"
md5-dontcare
"
,
// "_id": "remove1",
"
content_type
"
:
"
oh/yeah
"
// "_attachment": "remove2",
};
// "_rev": "1-a"
shared
.
attachment_remove3
=
{
// }, o.f);
"
length
"
:
5
,
// o.tick(o);
"
digest
"
:
"
sha256-383395a769131d15c1c6fc57c6abdb759ace9809
"
+
"
c1ad20d1f491d90f7f02650e
"
,
"
content_type
"
:
"
he/ho
"
};
shared
.
doc_myremove1
.
_attachments
=
{
"
remove2
"
:
shared
.
attachment_remove2
,
"
remove3
"
:
shared
.
attachment_remove3
};
// // 10. remove document
return
jio_local
.
put
(
shared
.
doc_myremove1
);
// o.last_rev = "3-" + o.rev_hash;
// o.rev_hash = generateRevisionHash(
// {"_id": "remove1"},
// {"start": 3, "ids": [o.rev_hash, "oldrev", "veryoldrev"]},
// true
// );
// o.spy(o, "value", {"ok": true, "id": "remove1", "rev": "4-" + o.rev_hash},
// "Remove document");
// o.jio.remove({"_id": "remove1", "_rev": o.last_rev}, o.f);
// o.tick(o);
// // 11. check document tree
}).
then
(
function
()
{
// o.doctree.children[0].children[0].children[0].children.unshift({
// "rev": "4-" + o.rev_hash,
// "status": "deleted",
// "children": []
// });
// deepEqual(util.jsonlocalstorage.getItem(
// o.localpath + "/remove1.revision_tree.json"
// ), o.doctree, "Check document tree");
// util.closeAndcleanUpJio(o.jio);
return
jio_local
.
putAttachment
({
// });
"
_id
"
:
"
remove1.2-oldrev
"
,
"
_attachment
"
:
"
remove2
"
,
"
_data
"
:
"
abc
"
,
"
_content_type
"
:
"
oh/yeah
"
});
}).
then
(
function
()
{
return
jio_local
.
putAttachment
({
"
_id
"
:
"
remove1.2-oldrev
"
,
"
_attachment
"
:
"
remove3
"
,
"
_data
"
:
"
defgh
"
,
"
_content_type
"
:
"
he/ho
"
});
}).
then
(
function
()
{
// add document tree
shared
.
doctree
=
{
"
_id
"
:
"
remove1.revision_tree.json
"
,
"
children
"
:
JSON
.
stringify
([{
"
rev
"
:
"
1-veryoldrev
"
,
"
status
"
:
"
available
"
,
"
children
"
:
[{
"
rev
"
:
"
2-oldrev
"
,
"
status
"
:
"
available
"
,
"
children
"
:
[]
}]
}])
};
return
jio_local
.
put
(
shared
.
doctree
);
}).
then
(
function
()
{
// 3. remove inexistent attachment
return
success
(
jio
.
removeAttachment
({
"
_id
"
:
"
remove1
"
,
"
_attachment
"
:
"
remove0
"
,
"
_rev
"
:
"
2-oldrev
"
}));
}).
then
(
function
(
answer
)
{
deepEqual
(
answer
,
{
"
attachment
"
:
"
remove0
"
,
"
error
"
:
"
not_found
"
,
"
id
"
:
"
remove1
"
,
"
message
"
:
"
Unable to remove an inexistent attachment
"
,
"
method
"
:
"
removeAttachment
"
,
"
reason
"
:
"
missing
"
,
"
result
"
:
"
error
"
,
"
status
"
:
404
,
"
statusText
"
:
"
Not Found
"
},
"
Remove inexistent attachment -> 404 Not Found
"
);
// 4. remove existing attachment
shared
.
rev_hash
=
generateRevisionHash
({
"
_id
"
:
"
remove1
"
,
"
_attachment
"
:
"
remove2
"
},
{
"
start
"
:
2
,
"
ids
"
:
[
"
oldrev
"
,
"
veryoldrev
"
]});
return
jio
.
removeAttachment
({
"
_id
"
:
"
remove1
"
,
"
_attachment
"
:
"
remove2
"
,
"
_rev
"
:
"
2-oldrev
"
});
}).
then
(
function
(
answer
)
{
deepEqual
(
answer
,
{
"
attachment
"
:
"
remove2
"
,
"
id
"
:
"
remove1
"
,
"
method
"
:
"
removeAttachment
"
,
"
result
"
:
"
success
"
,
"
rev
"
:
"
3-
"
+
shared
.
rev_hash
,
"
status
"
:
204
,
"
statusText
"
:
"
No Content
"
},
"
Remove existing attachment
"
);
shared
.
doctree
=
{
"
_id
"
:
"
remove1.revision_tree.json
"
,
"
children
"
:
JSON
.
stringify
([{
"
rev
"
:
"
1-veryoldrev
"
,
"
status
"
:
"
available
"
,
"
children
"
:
[{
"
rev
"
:
"
2-oldrev
"
,
"
status
"
:
"
available
"
,
"
children
"
:
[{
"
rev
"
:
"
3-
"
+
shared
.
rev_hash
,
"
status
"
:
"
available
"
,
"
children
"
:
[]
}]
}]
}])
};
// 5. check if document tree has been updated correctly
return
jio_local
.
get
({
"
_id
"
:
shared
.
doctree
.
_id
});
}).
then
(
function
(
answer
)
{
deepEqual
(
answer
.
data
,
shared
.
doctree
,
"
Check document tree
"
);
// 6. check if the attachment still exists
return
jio_local
.
getAttachment
({
"
_id
"
:
"
remove1.2-oldrev
"
,
"
_attachment
"
:
"
remove2
"
});
}).
then
(
function
(
answer
)
{
return
tool
.
readBlobAsBinaryString
(
answer
.
data
);
}).
then
(
function
(
event
)
{
deepEqual
(
event
.
target
.
result
,
"
abc
"
,
"
Check attachment -> still exists
"
);
// 7. check if document is updated
return
jio_local
.
get
({
"
_id
"
:
"
remove1.3-
"
+
shared
.
rev_hash
});
}).
then
(
function
(
answer
)
{
deepEqual
(
answer
.
data
,
{
"
_id
"
:
"
remove1.3-
"
+
shared
.
rev_hash
,
"
title
"
:
"
myRemove1
"
,
"
_attachments
"
:
{
"
remove3
"
:
shared
.
attachment_remove3
}
},
"
Check document
"
);
// 8. remove document with wrong revision
return
success
(
jio
.
remove
({
"
_id
"
:
"
remove1
"
,
"
_rev
"
:
"
1-a
"
}));
}).
then
(
function
(
answer
)
{
deepEqual
(
answer
,
{
"
error
"
:
"
conflict
"
,
"
id
"
:
"
remove1
"
,
"
message
"
:
"
Document update conflict
"
,
"
method
"
:
"
remove
"
,
"
reason
"
:
"
Document is missing
"
,
"
result
"
:
"
error
"
,
"
status
"
:
409
,
"
statusText
"
:
"
Conflict
"
},
"
Remove document with wrong revision -> 409 Conflict
"
);
// 9. remove attachment wrong revision
return
success
(
jio
.
removeAttachment
({
"
_id
"
:
"
remove1
"
,
"
_attachment
"
:
"
remove2
"
,
"
_rev
"
:
"
1-a
"
}));
}).
then
(
function
(
answer
)
{
deepEqual
(
answer
,
{
"
attachment
"
:
"
remove2
"
,
"
error
"
:
"
conflict
"
,
"
id
"
:
"
remove1
"
,
"
message
"
:
"
Document update conflict
"
,
"
method
"
:
"
removeAttachment
"
,
"
reason
"
:
"
Document is missing
"
,
"
result
"
:
"
error
"
,
"
status
"
:
409
,
"
statusText
"
:
"
Conflict
"
},
"
Remove attachment with wrong revision -> 409 Conflict
"
);
// 10. remove document
shared
.
last_rev
=
"
3-
"
+
shared
.
rev_hash
;
shared
.
rev_hash
=
generateRevisionHash
(
{
"
_id
"
:
"
remove1
"
},
{
"
start
"
:
3
,
"
ids
"
:
[
shared
.
rev_hash
,
"
oldrev
"
,
"
veryoldrev
"
]},
true
);
return
jio
.
remove
({
"
_id
"
:
"
remove1
"
,
"
_rev
"
:
shared
.
last_rev
});
}).
then
(
function
(
answer
)
{
deepEqual
(
answer
,
{
"
id
"
:
"
remove1
"
,
"
method
"
:
"
remove
"
,
"
result
"
:
"
success
"
,
"
rev
"
:
"
4-
"
+
shared
.
rev_hash
,
"
status
"
:
204
,
"
statusText
"
:
"
No Content
"
},
"
Remove document
"
);
// 11. check document tree
shared
.
doctree
.
children
=
JSON
.
parse
(
shared
.
doctree
.
children
);
shared
.
doctree
.
children
[
0
].
children
[
0
].
children
[
0
].
children
.
unshift
({
"
rev
"
:
"
4-
"
+
shared
.
rev_hash
,
"
status
"
:
"
deleted
"
,
"
children
"
:
[]
});
shared
.
doctree
.
children
=
JSON
.
stringify
(
shared
.
doctree
.
children
);
return
jio_local
.
get
({
"
_id
"
:
shared
.
doctree
.
_id
});
}).
then
(
function
(
answer
)
{
deepEqual
(
answer
.
data
,
shared
.
doctree
,
"
Check document tree
"
);
}).
fail
(
unexpectedError
).
always
(
start
);
});
// test("allDocs", function () {
// test("allDocs", 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