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
33f6cd32
Commit
33f6cd32
authored
Jan 21, 2013
by
Sven Franck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
webDav Storage: bugfixes, jslint passing
parent
cf646d92
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
320 additions
and
262 deletions
+320
-262
src/jio.storage/davstorage.js
src/jio.storage/davstorage.js
+237
-205
test/jiotests.js
test/jiotests.js
+83
-57
No files found.
src/jio.storage/davstorage.js
View file @
33f6cd32
This diff is collapsed.
Click to expand it.
test/jiotests.js
View file @
33f6cd32
...
@@ -2044,23 +2044,7 @@ test ("Post", function () {
...
@@ -2044,23 +2044,7 @@ test ("Post", function () {
o
.
clock
.
tick
(
5000
);
o
.
clock
.
tick
(
5000
);
o
.
server
.
respond
();
o
.
server
.
respond
();
// as all custom headers trigger preflight requests, the test also
// need to simulate CORS (cross domain ajax with preflight)
// custom header may be authentication for example
o
.
jio
.
stop
();
o
.
jio
.
stop
();
// do the same tests live webDav-Server simulating CORS!
/* also check for equality
deepEqual(
localstorage.getItem("jio/localstorage/uput/aput/put1"),
{
"_id": "put1",
"title": "myPut1"
},
"Check document"
);
*/
});
});
test
(
"
Put
"
,
function
(){
test
(
"
Put
"
,
function
(){
...
@@ -2100,10 +2084,6 @@ test ("Put", function(){
...
@@ -2100,10 +2084,6 @@ test ("Put", function(){
o
.
server
.
respond
();
o
.
server
.
respond
();
o
.
jio
.
stop
();
o
.
jio
.
stop
();
// do the same tests live webDav-Server/simulate CORS
// check for credentials in sinon
});
});
test
(
"
PutAttachment
"
,
function
(){
test
(
"
PutAttachment
"
,
function
(){
...
@@ -2128,9 +2108,9 @@ test ("PutAttachment", function(){
...
@@ -2128,9 +2108,9 @@ test ("PutAttachment", function(){
o
.
clock
.
tick
(
5000
);
o
.
clock
.
tick
(
5000
);
// putAttachment without underlying document => not found
// putAttachment without underlying document => not found
o
.
addFakeServerResponse
(
"
GET
"
,
"
putattmtx
"
,
404
,
"
HTML RESPONSE
"
);
o
.
addFakeServerResponse
(
"
GET
"
,
"
putattmtx
"
,
22
,
"
HTML RESPONSE
"
);
o
.
spy
(
o
,
"
status
"
,
404
,
"
PutAttachment without document
"
);
o
.
spy
(
o
,
"
status
"
,
22
,
"
PutAttachment without document
"
);
o
.
jio
.
putAttachment
({
"
id
"
:
"
putattmtx
/
putattmt2
"
},
o
.
f
);
o
.
jio
.
putAttachment
({
"
id
"
:
"
putattmtx
.
putattmt2
"
},
o
.
f
);
o
.
clock
.
tick
(
5000
);
o
.
clock
.
tick
(
5000
);
o
.
server
.
respond
();
o
.
server
.
respond
();
...
@@ -2138,34 +2118,25 @@ test ("PutAttachment", function(){
...
@@ -2138,34 +2118,25 @@ test ("PutAttachment", function(){
o
.
answer
=
JSON
.
stringify
({
"
_id
"
:
"
putattmt1
"
,
"
title
"
:
"
myPutAttm1
"
});
o
.
answer
=
JSON
.
stringify
({
"
_id
"
:
"
putattmt1
"
,
"
title
"
:
"
myPutAttm1
"
});
o
.
addFakeServerResponse
(
"
GET
"
,
"
putattmt1
"
,
200
,
o
.
answer
);
o
.
addFakeServerResponse
(
"
GET
"
,
"
putattmt1
"
,
200
,
o
.
answer
);
o
.
addFakeServerResponse
(
"
PUT
"
,
"
putattmt1
"
,
201
,
"
HTML RESPONSE
"
);
o
.
addFakeServerResponse
(
"
PUT
"
,
"
putattmt1
"
,
201
,
"
HTML RESPONSE
"
);
o
.
addFakeServerResponse
(
"
PUT
"
,
"
putattmt1
/
putattmt2
"
,
201
,
"
HTML RESPONSE
"
);
o
.
addFakeServerResponse
(
"
PUT
"
,
"
putattmt1
.
putattmt2
"
,
201
,
"
HTML RESPONSE
"
);
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
putattmt1/putattmt2
"
},
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
putattmt1/putattmt2
"
},
"
PutAttachment with document, without data
"
);
"
PutAttachment with document, without data
"
);
o
.
jio
.
putAttachment
({
"
id
"
:
"
putattmt1/putattmt2
"
},
o
.
f
);
o
.
jio
.
putAttachment
({
"
id
"
:
"
putattmt1/putattmt2
"
},
o
.
f
);
o
.
clock
.
tick
(
5000
);
o
.
clock
.
tick
(
5000
);
o
.
server
.
respond
();
o
.
server
.
respond
();
// check document
// check attachment
// update attachment
// update attachment
o
.
answer
=
JSON
.
stringify
({
"
_id
"
:
"
putattmt1
"
,
"
title
"
:
"
myPutAttm1
"
});
o
.
answer
=
JSON
.
stringify
({
"
_id
"
:
"
putattmt1
"
,
"
title
"
:
"
myPutAttm1
"
});
o
.
addFakeServerResponse
(
"
GET
"
,
"
putattmt1
"
,
200
,
o
.
answer
);
o
.
addFakeServerResponse
(
"
GET
"
,
"
putattmt1
"
,
200
,
o
.
answer
);
o
.
addFakeServerResponse
(
"
PUT
"
,
"
putattmt1
"
,
201
,
"
HTML RESPONSE
"
);
o
.
addFakeServerResponse
(
"
PUT
"
,
"
putattmt1
"
,
201
,
"
HTML RESPONSE
"
);
o
.
addFakeServerResponse
(
"
PUT
"
,
"
putattmt1
/
putattmt2
"
,
201
,
"
HTML RESPONSE
"
);
o
.
addFakeServerResponse
(
"
PUT
"
,
"
putattmt1
.
putattmt2
"
,
201
,
"
HTML RESPONSE
"
);
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
putattmt1/putattmt2
"
},
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
putattmt1/putattmt2
"
},
"
Update Attachment, with data
"
);
"
Update Attachment, with data
"
);
o
.
jio
.
putAttachment
({
"
id
"
:
"
putattmt1/putattmt2
"
,
"
data
"
:
"
abc
"
},
o
.
f
);
o
.
jio
.
putAttachment
({
"
id
"
:
"
putattmt1/putattmt2
"
,
"
data
"
:
"
abc
"
},
o
.
f
);
o
.
clock
.
tick
(
5000
);
o
.
clock
.
tick
(
5000
);
o
.
server
.
respond
();
o
.
server
.
respond
();
// check document
// check attachment
o
.
jio
.
stop
();
o
.
jio
.
stop
();
// do the same tests live webDav-Server/simulate CORS
// check for credentials in sinon
});
});
test
(
"
Get
"
,
function
(){
test
(
"
Get
"
,
function
(){
...
@@ -2187,7 +2158,7 @@ test ("Get", function(){
...
@@ -2187,7 +2158,7 @@ test ("Get", function(){
o
.
server
.
respond
();
o
.
server
.
respond
();
// get inexistent attachment
// get inexistent attachment
o
.
addFakeServerResponse
(
"
GET
"
,
"
get1
/
get2
"
,
404
,
"
HTML RESPONSE
"
);
o
.
addFakeServerResponse
(
"
GET
"
,
"
get1
.
get2
"
,
404
,
"
HTML RESPONSE
"
);
o
.
spy
(
o
,
"
status
"
,
404
,
"
Get non existing attachment
"
);
o
.
spy
(
o
,
"
status
"
,
404
,
"
Get non existing attachment
"
);
o
.
jio
.
get
(
"
get1/get2
"
,
o
.
f
);
o
.
jio
.
get
(
"
get1/get2
"
,
o
.
f
);
o
.
clock
.
tick
(
5000
);
o
.
clock
.
tick
(
5000
);
...
@@ -2202,7 +2173,7 @@ test ("Get", function(){
...
@@ -2202,7 +2173,7 @@ test ("Get", function(){
o
.
server
.
respond
();
o
.
server
.
respond
();
// get inexistent attachment (document exists)
// get inexistent attachment (document exists)
o
.
addFakeServerResponse
(
"
GET
"
,
"
get3
/
getx
"
,
404
,
"
HTML RESPONSE
"
);
o
.
addFakeServerResponse
(
"
GET
"
,
"
get3
.
getx
"
,
404
,
"
HTML RESPONSE
"
);
o
.
spy
(
o
,
"
status
"
,
404
,
"
Get non existing attachment (doc exists)
"
);
o
.
spy
(
o
,
"
status
"
,
404
,
"
Get non existing attachment (doc exists)
"
);
o
.
jio
.
get
(
"
get3/getx
"
,
o
.
f
);
o
.
jio
.
get
(
"
get3/getx
"
,
o
.
f
);
o
.
clock
.
tick
(
5000
);
o
.
clock
.
tick
(
5000
);
...
@@ -2210,7 +2181,7 @@ test ("Get", function(){
...
@@ -2210,7 +2181,7 @@ test ("Get", function(){
// get attachment
// get attachment
o
.
answer
=
JSON
.
stringify
({
"
_id
"
:
"
get4
"
,
"
title
"
:
"
some attachment
"
});
o
.
answer
=
JSON
.
stringify
({
"
_id
"
:
"
get4
"
,
"
title
"
:
"
some attachment
"
});
o
.
addFakeServerResponse
(
"
GET
"
,
"
get3
/
get4
"
,
200
,
o
.
answer
);
o
.
addFakeServerResponse
(
"
GET
"
,
"
get3
.
get4
"
,
200
,
o
.
answer
);
o
.
spy
(
o
,
"
value
"
,
{
"
_id
"
:
"
get4
"
,
"
title
"
:
"
some attachment
"
},
o
.
spy
(
o
,
"
value
"
,
{
"
_id
"
:
"
get4
"
,
"
title
"
:
"
some attachment
"
},
"
Get attachment
"
);
"
Get attachment
"
);
o
.
jio
.
get
(
"
get3/get4
"
,
o
.
f
);
o
.
jio
.
get
(
"
get3/get4
"
,
o
.
f
);
...
@@ -2218,9 +2189,6 @@ test ("Get", function(){
...
@@ -2218,9 +2189,6 @@ test ("Get", function(){
o
.
server
.
respond
();
o
.
server
.
respond
();
o
.
jio
.
stop
();
o
.
jio
.
stop
();
// do the same tests live webDav-Server/simulate CORS
// check for credentials in sinon
});
});
test
(
"
Remove
"
,
function
(){
test
(
"
Remove
"
,
function
(){
...
@@ -2242,7 +2210,7 @@ test ("Remove", function(){
...
@@ -2242,7 +2210,7 @@ test ("Remove", function(){
o
.
server
.
respond
();
o
.
server
.
respond
();
// remove inexistent document/attachment
// remove inexistent document/attachment
o
.
addFakeServerResponse
(
"
GET
"
,
"
remove1
/
remove2
"
,
404
,
"
HTML RESPONSE
"
);
o
.
addFakeServerResponse
(
"
GET
"
,
"
remove1
.
remove2
"
,
404
,
"
HTML RESPONSE
"
);
o
.
spy
(
o
,
"
status
"
,
404
,
"
Remove inexistent document/attachment
"
);
o
.
spy
(
o
,
"
status
"
,
404
,
"
Remove inexistent document/attachment
"
);
o
.
jio
.
remove
({
"
_id
"
:
"
remove1/remove2
"
},
o
.
f
);
o
.
jio
.
remove
({
"
_id
"
:
"
remove1/remove2
"
},
o
.
f
);
o
.
clock
.
tick
(
5000
);
o
.
clock
.
tick
(
5000
);
...
@@ -2251,7 +2219,7 @@ test ("Remove", function(){
...
@@ -2251,7 +2219,7 @@ test ("Remove", function(){
// remove document
// remove document
o
.
answer
=
JSON
.
stringify
({
"
_id
"
:
"
remove3
"
,
"
title
"
:
"
some doc
"
});
o
.
answer
=
JSON
.
stringify
({
"
_id
"
:
"
remove3
"
,
"
title
"
:
"
some doc
"
});
o
.
addFakeServerResponse
(
"
GET
"
,
"
remove3
"
,
200
,
o
.
answer
);
o
.
addFakeServerResponse
(
"
GET
"
,
"
remove3
"
,
200
,
o
.
answer
);
o
.
addFakeServerResponse
(
"
REMOV
E
"
,
"
remove3
"
,
200
,
"
HTML RESPONSE
"
);
o
.
addFakeServerResponse
(
"
DELET
E
"
,
"
remove3
"
,
200
,
"
HTML RESPONSE
"
);
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
remove3
"
},
"
Remove document
"
);
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
remove3
"
},
"
Remove document
"
);
o
.
jio
.
remove
({
"
_id
"
:
"
remove3
"
},
o
.
f
);
o
.
jio
.
remove
({
"
_id
"
:
"
remove3
"
},
o
.
f
);
o
.
clock
.
tick
(
5000
);
o
.
clock
.
tick
(
5000
);
...
@@ -2270,7 +2238,7 @@ test ("Remove", function(){
...
@@ -2270,7 +2238,7 @@ test ("Remove", function(){
// remove attachment
// remove attachment
o
.
addFakeServerResponse
(
"
GET
"
,
"
remove4
"
,
200
,
o
.
answer
);
o
.
addFakeServerResponse
(
"
GET
"
,
"
remove4
"
,
200
,
o
.
answer
);
o
.
addFakeServerResponse
(
"
PUT
"
,
"
remove4
"
,
201
,
"
HTML RESPONSE
"
);
o
.
addFakeServerResponse
(
"
PUT
"
,
"
remove4
"
,
201
,
"
HTML RESPONSE
"
);
o
.
addFakeServerResponse
(
"
REMOVE
"
,
"
remove4/
remove5
"
,
200
,
"
HTML RESPONSE
"
);
o
.
addFakeServerResponse
(
"
DELETE
"
,
"
remove4.
remove5
"
,
200
,
"
HTML RESPONSE
"
);
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
remove4/remove5
"
},
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
remove4/remove5
"
},
"
Remove attachment
"
);
"
Remove attachment
"
);
o
.
jio
.
remove
({
"
_id
"
:
"
remove4/remove5
"
},
o
.
f
);
o
.
jio
.
remove
({
"
_id
"
:
"
remove4/remove5
"
},
o
.
f
);
...
@@ -2297,10 +2265,10 @@ test ("Remove", function(){
...
@@ -2297,10 +2265,10 @@ test ("Remove", function(){
});
});
// remove document with multiple attachments
// remove document with multiple attachments
o
.
addFakeServerResponse
(
"
GET
"
,
"
remove6
"
,
200
,
o
.
answer
);
o
.
addFakeServerResponse
(
"
GET
"
,
"
remove6
"
,
200
,
o
.
answer
);
o
.
addFakeServerResponse
(
"
REMOVE
"
,
"
remove6/
remove7
"
,
200
,
"
HTML RESPONSE
"
);
o
.
addFakeServerResponse
(
"
DELETE
"
,
"
remove6.
remove7
"
,
200
,
"
HTML RESPONSE
"
);
o
.
addFakeServerResponse
(
"
REMOVE
"
,
"
remove6/
remove8
"
,
200
,
"
HTML RESPONSE
"
);
o
.
addFakeServerResponse
(
"
DELETE
"
,
"
remove6.
remove8
"
,
200
,
"
HTML RESPONSE
"
);
o
.
addFakeServerResponse
(
"
REMOVE
"
,
"
remove6/
remove9
"
,
200
,
"
HTML RESPONSE
"
);
o
.
addFakeServerResponse
(
"
DELETE
"
,
"
remove6.
remove9
"
,
200
,
"
HTML RESPONSE
"
);
o
.
addFakeServerResponse
(
"
REMOV
E
"
,
"
remove6
"
,
200
,
"
HTML RESPONSE
"
);
o
.
addFakeServerResponse
(
"
DELET
E
"
,
"
remove6
"
,
200
,
"
HTML RESPONSE
"
);
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
remove6
"
},
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
remove6
"
},
"
Remove document with multiple attachments
"
);
"
Remove document with multiple attachments
"
);
o
.
jio
.
remove
({
"
_id
"
:
"
remove6
"
},
o
.
f
);
o
.
jio
.
remove
({
"
_id
"
:
"
remove6
"
},
o
.
f
);
...
@@ -2308,9 +2276,6 @@ test ("Remove", function(){
...
@@ -2308,9 +2276,6 @@ test ("Remove", function(){
o
.
server
.
respond
();
o
.
server
.
respond
();
o
.
jio
.
stop
();
o
.
jio
.
stop
();
// do the same tests live webDav-Server/simulate CORS
// check for credentials in sinon
});
});
test
(
"
AllDocs
"
,
function
()
{
test
(
"
AllDocs
"
,
function
()
{
...
@@ -2341,21 +2306,82 @@ test ("AllDocs", function () {
...
@@ -2341,21 +2306,82 @@ test ("AllDocs", function () {
o
.
server
.
respond
();
o
.
server
.
respond
();
// allDocs with option include
// allDocs with option include
o
.
all1
=
JSON
.
stringify
({
"
_id
"
:
"
allDocs1
"
,
"
title
"
:
"
a doc title
"
});
o
.
all1
=
{
"
_id
"
:
"
allDocs1
"
,
"
title
"
:
"
a doc title
"
};
o
.
all2
=
JSON
.
stringify
({
"
_id
"
:
"
allDocs2
"
,
"
title
"
:
"
another doc title
"
});
o
.
all2
=
{
"
_id
"
:
"
allDocs2
"
,
"
title
"
:
"
another doc title
"
};
o
.
addFakeServerResponse
(
"
GET
"
,
"
alldocs1
"
,
200
,
o
.
all1
);
o
.
thisShouldBeTheAnswer
=
{
o
.
addFakeServerResponse
(
"
GET
"
,
"
alldocs2
"
,
200
,
o
.
all2
);
"
rows
"
:
[
{
"
id
"
:
"
alldocs1
"
,
"
key
"
:
"
alldocs1
"
,
"
value
"
:
{},
"
doc
"
:
o
.
all1
},
{
"
id
"
:
"
alldocs2
"
,
"
key
"
:
"
alldocs2
"
,
"
value
"
:
{},
"
doc
"
:
o
.
all2
}
],
"
total_rows
"
:
2
}
o
.
addFakeServerResponse
(
"
GET
"
,
"
alldocs1
"
,
200
,
JSON
.
stringify
(
o
.
all1
));
o
.
addFakeServerResponse
(
"
GET
"
,
"
alldocs2
"
,
200
,
JSON
.
stringify
(
o
.
all2
));
o
.
spy
(
o
,
"
value
"
,
o
.
thisShouldBeTheAnswer
,
"
allDocs (include_docs)
"
);
o
.
spy
(
o
,
"
value
"
,
o
.
thisShouldBeTheAnswer
,
"
allDocs (include_docs)
"
);
o
.
jio
.
allDocs
({
"
include_docs
"
:
true
},
o
.
f
);
o
.
jio
.
allDocs
({
"
include_docs
"
:
true
},
o
.
f
);
o
.
clock
.
tick
(
5000
);
o
.
clock
.
tick
(
5000
);
o
.
server
.
respond
();
o
.
server
.
respond
();
// do the same tests live webDav-Server/simulate CORS
// check for credentials in sinon
o
.
jio
.
stop
();
o
.
jio
.
stop
();
});
});
// NOTES: this test is for a live webDav server on localstorage
// see the documentation how to setup an apache2 webDav-server
// tests cannot be run subsequently, so only do one test at a time
/*
test ("webDav Live Server setup", function () {
var o = generateTools(this);
// turn off fakeserver - otherwise no requests will be made
o.server.restore();
o.jio = JIO.newJio({
"type": "dav",
"username": "davlive",
"password": "checkpwd",
"url": "http://127.0.1.1/dav"
});
// not used, check console for responses
// o.spy(o, "value", {"id": "_id_", "ok": true}, "Live Webdav");
// post a new document
o.jio.post({"_id": "one.json", "title": "hello"}), o.f);
o.clock.tick(5000);
// modify document
o.jio.put({"_id": "one.json", "title": "hello modified"}), o.f);
o.clock.tick(5000);
// add attachment
o.jio.putAttachment({
"id": "one.json/att.txt",
"mimetype": "text/plain",
"content":"there2"
}, o.f);
// test allDocs
o.jio.allDocs({"include_docs":true},
function(s){console.log(s);},
function ( e ) {console.log(e);
}, o.f);
o.clock.tick(5000);
// get Attachment
o.jio.get("one.json/att.txt", o.f);
o.clock.tick(5000);
// remove Attachment
o.jio.remove("one.json/att.txt", o.f.);
o.clock.tick(5000);
// remove Document
o.jio.remove("one.json", o.f.);
o.clock.tick(5000);
o.jio.stop();
});
*/
/*
/*
module ('Jio ReplicateStorage');
module ('Jio ReplicateStorage');
...
...
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