Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
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
Tristan Cavelier
jio
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
Show 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
...
@@ -87,10 +87,31 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -87,10 +87,31 @@ jIO.addStorageType('dav', function (spec, my) {
return
async
;
return
async
;
};
};
priv
.
checkCors
=
function
(){
/**
* Checks if a browser supports cors (cross domain ajax requests)
* @method checkCors
* @return {boolean} true if supported, else false
*/
priv
.
checkCors
=
function
()
{
return
$
.
support
.
cors
;
return
$
.
support
.
cors
;
};
};
/**
* Replaces last "." with "_." in document filenames
* @method underscoreFileExtenisons
* @param {string} url url to clean up
* @return {string} clean_url cleaned up URL
*/
priv
.
underscoreFileExtenisons
=
function
(
url
)
{
var
clean_url
=
url
.
replace
(
/,
\s(\w
+
)
$/
,
"
_.$1
"
);
return
clean_url
;
};
priv
.
restoreDots
=
function
(
url
)
{
var
clean_url
=
url
.
replace
(
/_
\.
/g
,
'
.
'
);
return
clean_url
;
};
// wedDav methods rfc4918 (short summary)
// wedDav methods rfc4918 (short summary)
// COPY Reproduces single resources (files) and collections (directory
// COPY Reproduces single resources (files) and collections (directory
// trees). Will overwrite files (if specified by request) but will
// trees). Will overwrite files (if specified by request) but will
...
@@ -118,11 +139,12 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -118,11 +139,12 @@ jIO.addStorageType('dav', function (spec, my) {
priv
.
putOrPost
=
function
(
command
,
type
)
{
priv
.
putOrPost
=
function
(
command
,
type
)
{
var
doc
=
command
.
getDocId
(),
var
docid
=
command
.
getDocId
(),
secured_docid
;
secured_docid
,
url
;
// no docId
// no docId
if
(
!
(
typeof
doc
===
"
string
"
&&
doc
!==
""
))
{
if
(
!
(
typeof
doc
id
===
"
string
"
&&
docid
!==
""
))
{
that
.
error
({
that
.
error
({
"
status
"
:
405
,
"
status
"
:
405
,
"
statusText
"
:
"
Method Not Allowed
"
,
"
statusText
"
:
"
Method Not Allowed
"
,
...
@@ -146,8 +168,7 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -146,8 +168,7 @@ jIO.addStorageType('dav', function (spec, my) {
}
}
secured_docid
=
priv
.
secureDocId
(
command
.
getDocId
());
secured_docid
=
priv
.
secureDocId
(
command
.
getDocId
());
url
=
priv
.
url
+
'
/
'
+
secured_docid
;
url
=
priv
.
url
+
'
/
'
+
priv
.
underscoreFileExtenisons
(
secured_docid
);
// see if the document exists
// see if the document exists
$
.
ajax
({
$
.
ajax
({
url
:
url
+
'
?_=
'
+
Date
.
now
(),
url
:
url
+
'
?_=
'
+
Date
.
now
(),
...
@@ -161,7 +182,7 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -161,7 +182,7 @@ jIO.addStorageType('dav', function (spec, my) {
)
)
},
},
// xhrFields: {withCredentials: 'true'},
// xhrFields: {withCredentials: 'true'},
success
:
function
(
content
)
{
success
:
function
()
{
if
(
type
===
'
POST
'
)
{
if
(
type
===
'
POST
'
)
{
// POST the document already exists
// POST the document already exists
that
.
error
({
that
.
error
({
...
@@ -172,12 +193,12 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -172,12 +193,12 @@ jIO.addStorageType('dav', function (spec, my) {
"
reason
"
:
"
Document already exists
"
"
reason
"
:
"
Document already exists
"
});
});
return
;
return
;
}
else
{
}
// PUT update document
// PUT update document
$
.
ajax
({
$
.
ajax
({
url
:
url
+
'
?_=
'
+
Date
.
now
()
,
url
:
url
,
type
:
type
,
type
:
type
,
data
:
command
.
getDoc
(
),
data
:
JSON
.
stringify
(
command
.
getDoc
()
),
async
:
true
,
async
:
true
,
crossdomain
:
true
,
crossdomain
:
true
,
headers
:
{
headers
:
{
...
@@ -192,7 +213,7 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -192,7 +213,7 @@ jIO.addStorageType('dav', function (spec, my) {
id
:
command
.
getDocId
()
id
:
command
.
getDocId
()
});
});
},
},
error
:
function
(
type
)
{
error
:
function
(
)
{
that
.
error
({
that
.
error
({
"
status
"
:
409
,
"
status
"
:
409
,
"
statusText
"
:
"
Conflicts
"
,
"
statusText
"
:
"
Conflicts
"
,
...
@@ -200,18 +221,16 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -200,18 +221,16 @@ jIO.addStorageType('dav', function (spec, my) {
"
message
"
:
"
Cannot modify document
"
,
"
message
"
:
"
Cannot modify document
"
,
"
reason
"
:
"
Error trying to write to remote storage
"
"
reason
"
:
"
Error trying to write to remote storage
"
});
});
return
;
}
}
});
});
}
},
},
error
:
function
(
err
)
{
error
:
function
(
err
)
{
if
(
err
.
status
===
404
)
{
// Firefox returns 0 instead of 404 on CORS?
if
(
err
.
status
===
404
||
err
.
status
===
0
)
{
$
.
ajax
({
$
.
ajax
({
url
:
url
+
'
?_=
'
+
Date
.
now
(),
url
:
url
,
// must always use put, POST only seems to work on collections
type
:
'
PUT
'
,
type
:
'
PUT
'
,
data
:
command
.
getDoc
(
),
data
:
JSON
.
stringify
(
command
.
getDoc
()
),
async
:
true
,
async
:
true
,
crossdomain
:
true
,
crossdomain
:
true
,
headers
:
{
headers
:
{
...
@@ -220,13 +239,13 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -220,13 +239,13 @@ jIO.addStorageType('dav', function (spec, my) {
)
)
},
},
// xhrFields: {withCredentials: 'true'},
// xhrFields: {withCredentials: 'true'},
success
:
function
(
response
)
{
success
:
function
()
{
that
.
success
({
that
.
success
({
ok
:
true
,
ok
:
true
,
id
:
command
.
getDocId
()
id
:
command
.
getDocId
()
});
});
},
},
error
:
function
(
type
)
{
error
:
function
()
{
that
.
error
({
that
.
error
({
"
status
"
:
409
,
"
status
"
:
409
,
"
statusText
"
:
"
Conflicts
"
,
"
statusText
"
:
"
Conflicts
"
,
...
@@ -234,7 +253,6 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -234,7 +253,6 @@ jIO.addStorageType('dav', function (spec, my) {
"
message
"
:
"
Cannot modify document
"
,
"
message
"
:
"
Cannot modify document
"
,
"
reason
"
:
"
Error trying to write to remote storage
"
"
reason
"
:
"
Error trying to write to remote storage
"
});
});
return
;
}
}
});
});
...
@@ -247,7 +265,6 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -247,7 +265,6 @@ jIO.addStorageType('dav', function (spec, my) {
"
message
"
:
err
.
message
,
"
message
"
:
err
.
message
,
"
reason
"
:
"
Failed to access remote storage
"
"
reason
"
:
"
Failed to access remote storage
"
});
});
return
;
}
}
}
}
});
});
...
@@ -277,8 +294,12 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -277,8 +294,12 @@ jIO.addStorageType('dav', function (spec, my) {
* @param {object} command The JIO command
* @param {object} command The JIO command
*/
*/
that
.
putAttachment
=
function
(
command
)
{
that
.
putAttachment
=
function
(
command
)
{
var
docid
=
command
.
getDocId
(),
doc
,
var
docid
=
command
.
getDocId
(),
secured_docid
,
secured_attachmentid
,
attachment_url
;
doc
,
url
,
secured_docid
,
secured_attachmentid
,
attachment_url
;
// no docId
// no docId
if
(
!
(
typeof
docid
===
"
string
"
&&
docid
!==
""
))
{
if
(
!
(
typeof
docid
===
"
string
"
&&
docid
!==
""
))
{
...
@@ -304,9 +325,9 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -304,9 +325,9 @@ jIO.addStorageType('dav', function (spec, my) {
return
;
return
;
}
}
secured_docid
=
priv
.
secureDocId
(
docid
);
secured_docid
=
priv
.
secureDocId
(
docid
);
url
=
priv
.
url
+
'
/
'
+
secured_docid
;
url
=
priv
.
url
+
'
/
'
+
priv
.
underscoreFileExtenisons
(
secured_docid
)
;
// see if the underlying document exists
||
// see if the underlying document exists
$
.
ajax
({
$
.
ajax
({
url
:
url
+
'
?_=
'
+
Date
.
now
(),
url
:
url
+
'
?_=
'
+
Date
.
now
(),
type
:
'
GET
'
,
type
:
'
GET
'
,
...
@@ -328,12 +349,11 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -328,12 +349,11 @@ jIO.addStorageType('dav', function (spec, my) {
"
digest
"
:
"
md5-
"
+
command
.
md5SumAttachmentData
(),
"
digest
"
:
"
md5-
"
+
command
.
md5SumAttachmentData
(),
"
length
"
:
command
.
getAttachmentLength
()
"
length
"
:
command
.
getAttachmentLength
()
};
};
// put updated document data
// put updated document data
$
.
ajax
({
$
.
ajax
({
url
:
url
+
'
?_=
'
+
Date
.
now
(),
url
:
url
+
'
?_=
'
+
Date
.
now
(),
type
:
'
PUT
'
,
type
:
'
PUT
'
,
data
:
doc
,
data
:
JSON
.
stringify
(
doc
)
,
async
:
true
,
async
:
true
,
crossdomain
:
true
,
crossdomain
:
true
,
headers
:
{
headers
:
{
...
@@ -344,12 +364,12 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -344,12 +364,12 @@ jIO.addStorageType('dav', function (spec, my) {
// xhrFields: {withCredentials: 'true'},
// xhrFields: {withCredentials: 'true'},
success
:
function
()
{
success
:
function
()
{
secured_attachmentid
=
priv
.
secureDocId
(
command
.
getAttachmentId
());
secured_attachmentid
=
priv
.
secureDocId
(
command
.
getAttachmentId
());
attachment_url
=
url
+
'
/
'
+
secured_attachmentid
;
attachment_url
=
url
+
'
.
'
+
priv
.
underscoreFileExtenisons
(
secured_attachmentid
);
$
.
ajax
({
$
.
ajax
({
url
:
attachment_url
+
'
?_=
'
+
Date
.
now
(),
url
:
attachment_url
+
'
?_=
'
+
Date
.
now
(),
type
:
'
PUT
'
,
type
:
'
PUT
'
,
data
:
command
.
getDoc
(
),
data
:
JSON
.
stringify
(
command
.
getDoc
()
),
async
:
true
,
async
:
true
,
crossdomain
:
true
,
crossdomain
:
true
,
headers
:
{
headers
:
{
...
@@ -358,13 +378,13 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -358,13 +378,13 @@ jIO.addStorageType('dav', function (spec, my) {
)
)
},
},
// xhrFields: {withCredentials: 'true'},
// xhrFields: {withCredentials: 'true'},
success
:
function
(
response
)
{
success
:
function
()
{
that
.
success
({
that
.
success
({
ok
:
true
,
ok
:
true
,
id
:
command
.
getDocId
()
+
'
/
'
+
command
.
getAttachmentId
()
id
:
command
.
getDocId
()
+
'
/
'
+
command
.
getAttachmentId
()
});
});
},
},
error
:
function
(
type
)
{
error
:
function
()
{
that
.
error
({
that
.
error
({
"
status
"
:
409
,
"
status
"
:
409
,
"
statusText
"
:
"
Conflicts
"
,
"
statusText
"
:
"
Conflicts
"
,
...
@@ -376,7 +396,7 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -376,7 +396,7 @@ jIO.addStorageType('dav', function (spec, my) {
}
}
});
});
},
},
error
:
function
(
type
)
{
error
:
function
()
{
that
.
error
({
that
.
error
({
"
status
"
:
409
,
"
status
"
:
409
,
"
statusText
"
:
"
Conflicts
"
,
"
statusText
"
:
"
Conflicts
"
,
...
@@ -408,8 +428,12 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -408,8 +428,12 @@ jIO.addStorageType('dav', function (spec, my) {
* @param {object} command The JIO command
* @param {object} command The JIO command
*/
*/
that
.
get
=
function
(
command
)
{
that
.
get
=
function
(
command
)
{
var
docid
=
command
.
getDocId
(),
doc
,
var
docid
=
command
.
getDocId
(),
secured_docid
,
secured_attachmentid
,
attachment_url
;
doc
,
url
,
secured_docid
,
secured_attachmentid
,
attachment_url
;
// no docId
// no docId
if
(
!
(
typeof
docid
===
"
string
"
&&
docid
!==
""
))
{
if
(
!
(
typeof
docid
===
"
string
"
&&
docid
!==
""
))
{
...
@@ -433,10 +457,15 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -433,10 +457,15 @@ jIO.addStorageType('dav', function (spec, my) {
});
});
return
;
return
;
}
}
secured_docid
=
priv
.
secureDocId
(
command
.
getDocId
());
url
=
priv
.
url
+
'
/
'
+
priv
.
underscoreFileExtenisons
(
secured_docid
);
if
(
typeof
command
.
getAttachmentId
()
===
"
string
"
)
{
if
(
typeof
command
.
getAttachmentId
()
===
"
string
"
)
{
secured_attachmentid
=
priv
.
secureDocId
(
command
.
getAttachmentId
());
secured_attachmentid
=
priv
.
secureDocId
(
command
.
getAttachmentId
());
attachment_url
=
url
+
'
/
'
+
secured_attachmentid
;
attachment_url
=
url
+
'
.
'
+
priv
.
underscoreFileExtenisons
(
secured_attachmentid
);
// get attachment
// get attachment
$
.
ajax
({
$
.
ajax
({
url
:
attachment_url
+
'
?_=
'
+
Date
.
now
(),
url
:
attachment_url
+
'
?_=
'
+
Date
.
now
(),
...
@@ -453,7 +482,7 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -453,7 +482,7 @@ jIO.addStorageType('dav', function (spec, my) {
doc
=
JSON
.
parse
(
response
);
doc
=
JSON
.
parse
(
response
);
that
.
success
(
doc
);
that
.
success
(
doc
);
},
},
error
:
function
(
type
)
{
error
:
function
()
{
that
.
error
({
that
.
error
({
"
status
"
:
404
,
"
status
"
:
404
,
"
statusText
"
:
"
Not Found
"
,
"
statusText
"
:
"
Not Found
"
,
...
@@ -464,8 +493,6 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -464,8 +493,6 @@ jIO.addStorageType('dav', function (spec, my) {
}
}
});
});
}
else
{
}
else
{
secured_docid
=
priv
.
secureDocId
(
command
.
getDocId
());
url
=
priv
.
url
+
'
/
'
+
secured_docid
;
// get document
// get document
$
.
ajax
({
$
.
ajax
({
...
@@ -486,7 +513,7 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -486,7 +513,7 @@ jIO.addStorageType('dav', function (spec, my) {
doc
=
JSON
.
parse
(
response
);
doc
=
JSON
.
parse
(
response
);
that
.
success
(
doc
);
that
.
success
(
doc
);
},
},
error
:
function
(
type
)
{
error
:
function
()
{
that
.
error
({
that
.
error
({
"
status
"
:
404
,
"
status
"
:
404
,
"
statusText
"
:
"
Not Found
"
,
"
statusText
"
:
"
Not Found
"
,
...
@@ -505,9 +532,9 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -505,9 +532,9 @@ jIO.addStorageType('dav', function (spec, my) {
* @param {object} command The JIO command
* @param {object} command The JIO command
*/
*/
that
.
remove
=
function
(
command
)
{
that
.
remove
=
function
(
command
)
{
var
docid
=
command
.
getDocId
(),
doc
,
var
docid
=
command
.
getDocId
(),
doc
,
url
,
secured_docid
,
secured_attachmentid
,
attachment_url
,
secured_docid
,
secured_attachmentid
,
attachment_url
,
attachment_list
=
[],
i
,
j
,
k
=
1
;
attachment_list
=
[],
i
,
j
,
k
=
1
,
deleteAttachment
;
// no docId
// no docId
if
(
!
(
typeof
docid
===
"
string
"
&&
docid
!==
""
))
{
if
(
!
(
typeof
docid
===
"
string
"
&&
docid
!==
""
))
{
...
@@ -518,7 +545,6 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -518,7 +545,6 @@ jIO.addStorageType('dav', function (spec, my) {
"
message
"
:
"
Cannot create document which id is undefined
"
,
"
message
"
:
"
Cannot create document which id is undefined
"
,
"
reason
"
:
"
Document id is undefined
"
"
reason
"
:
"
Document id is undefined
"
});
});
return
;
}
}
// no cors support
// no cors support
if
(
priv
.
checkCors
===
false
)
{
if
(
priv
.
checkCors
===
false
)
{
...
@@ -529,19 +555,21 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -529,19 +555,21 @@ jIO.addStorageType('dav', function (spec, my) {
"
message
"
:
"
Browser does not support cross domain ajax requests
"
,
"
message
"
:
"
Browser does not support cross domain ajax requests
"
,
"
reason
"
:
"
cors is undefined
"
"
reason
"
:
"
cors is undefined
"
});
});
return
;
}
}
secured_docid
=
priv
.
secureDocId
(
command
.
getDocId
());
secured_docid
=
priv
.
secureDocId
(
command
.
getDocId
());
url
=
priv
.
url
+
'
/
'
+
secured_docid
;
url
=
priv
.
url
+
'
/
'
+
priv
.
underscoreFileExtenisons
(
secured_docid
)
;
// remove attachment
if
(
typeof
command
.
getAttachmentId
()
===
"
string
"
)
{
if
(
typeof
command
.
getAttachmentId
()
===
"
string
"
)
{
secured_attachmentid
=
priv
.
secureDocId
(
command
.
getAttachmentId
());
secured_attachmentid
=
priv
.
secureDocId
(
command
.
getAttachmentId
());
attachment_url
=
url
+
'
/
'
+
secured_attachmentid
;
attachment_url
=
url
+
'
.
'
+
priv
.
underscoreFileExtenisons
(
// remove attachment
secured_attachmentid
);
$
.
ajax
({
$
.
ajax
({
url
:
attachment_url
+
'
?_=
'
+
Date
.
now
(),
url
:
attachment_url
+
'
?_=
'
+
Date
.
now
(),
type
:
'
REMOV
E
'
,
type
:
'
DELET
E
'
,
async
:
true
,
async
:
true
,
crossdomain
:
true
,
crossdomain
:
true
,
headers
:
{
headers
:
{
...
@@ -549,7 +577,7 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -549,7 +577,7 @@ jIO.addStorageType('dav', function (spec, my) {
priv
.
username
+
'
:
'
+
priv
.
password
priv
.
username
+
'
:
'
+
priv
.
password
)
)
},
},
success
:
function
(
response
)
{
success
:
function
()
{
// retrieve underlying document
// retrieve underlying document
$
.
ajax
({
$
.
ajax
({
url
:
url
+
'
?_=
'
+
Date
.
now
(),
url
:
url
+
'
?_=
'
+
Date
.
now
(),
...
@@ -578,7 +606,7 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -578,7 +606,7 @@ jIO.addStorageType('dav', function (spec, my) {
$
.
ajax
({
$
.
ajax
({
url
:
url
+
'
?_=
'
+
Date
.
now
(),
url
:
url
+
'
?_=
'
+
Date
.
now
(),
type
:
'
PUT
'
,
type
:
'
PUT
'
,
data
:
doc
,
data
:
JSON
.
stringify
(
doc
)
,
async
:
true
,
async
:
true
,
crossdomain
:
true
,
crossdomain
:
true
,
headers
:
{
headers
:
{
...
@@ -587,13 +615,14 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -587,13 +615,14 @@ jIO.addStorageType('dav', function (spec, my) {
)
)
},
},
// xhrFields: {withCredentials: 'true'},
// xhrFields: {withCredentials: 'true'},
success
:
function
(
response
)
{
success
:
function
()
{
that
.
success
({
that
.
success
({
"
ok
"
:
true
,
"
ok
"
:
true
,
"
id
"
:
command
.
getDocId
()
+
'
/
'
+
command
.
getAttachmentId
()
"
id
"
:
command
.
getDocId
()
+
'
/
'
+
command
.
getAttachmentId
()
});
});
},
},
error
:
function
(
type
)
{
error
:
function
()
{
that
.
error
({
that
.
error
({
"
status
"
:
409
,
"
status
"
:
409
,
"
statusText
"
:
"
Conflicts
"
,
"
statusText
"
:
"
Conflicts
"
,
...
@@ -601,7 +630,6 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -601,7 +630,6 @@ jIO.addStorageType('dav', function (spec, my) {
"
message
"
:
"
Cannot modify document
"
,
"
message
"
:
"
Cannot modify document
"
,
"
reason
"
:
"
Error trying to update document attachments
"
"
reason
"
:
"
Error trying to update document attachments
"
});
});
return
;
}
}
});
});
}
else
{
}
else
{
...
@@ -622,7 +650,7 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -622,7 +650,7 @@ jIO.addStorageType('dav', function (spec, my) {
});
});
}
}
},
},
error
:
function
(
type
)
{
error
:
function
()
{
that
.
error
({
that
.
error
({
"
status
"
:
404
,
"
status
"
:
404
,
"
statusText
"
:
"
Not Found
"
,
"
statusText
"
:
"
Not Found
"
,
...
@@ -633,7 +661,7 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -633,7 +661,7 @@ jIO.addStorageType('dav', function (spec, my) {
}
}
});
});
},
},
error
:
function
(
type
)
{
error
:
function
()
{
that
.
error
({
that
.
error
({
"
status
"
:
404
,
"
status
"
:
404
,
"
statusText
"
:
"
Not Found
"
,
"
statusText
"
:
"
Not Found
"
,
...
@@ -643,9 +671,8 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -643,9 +671,8 @@ jIO.addStorageType('dav', function (spec, my) {
});
});
}
}
});
});
// remove document
}
else
{
}
else
{
secured_docid
=
priv
.
secureDocId
(
command
.
getDocId
());
url
=
priv
.
url
+
'
/
'
+
secured_docid
;
// get document to also remove all attachments
// get document to also remove all attachments
$
.
ajax
({
$
.
ajax
({
...
@@ -660,20 +687,21 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -660,20 +687,21 @@ jIO.addStorageType('dav', function (spec, my) {
)
)
},
},
success
:
function
(
response
)
{
success
:
function
(
response
)
{
var
x
;
doc
=
JSON
.
parse
(
response
);
doc
=
JSON
.
parse
(
response
);
// prepare attachment loop
// prepare attachment loop
if
(
typeof
doc
.
_attachments
===
"
object
"
)
{
if
(
typeof
doc
.
_attachments
===
"
object
"
)
{
// prepare list of attachments
// prepare list of attachments
for
(
i
in
doc
.
_attachments
)
{
for
(
x
in
doc
.
_attachments
)
{
if
(
doc
.
_attachments
.
hasOwnProperty
(
i
))
{
if
(
doc
.
_attachments
.
hasOwnProperty
(
x
))
{
attachment_list
.
push
(
i
);
attachment_list
.
push
(
x
);
}
}
}
}
}
}
// delete document
// delete document
$
.
ajax
({
$
.
ajax
({
url
:
url
+
'
?_=
'
+
Date
.
now
(),
url
:
url
+
'
?_=
'
+
Date
.
now
(),
type
:
'
REMOV
E
'
,
type
:
'
DELET
E
'
,
async
:
true
,
async
:
true
,
crossdomain
:
true
,
crossdomain
:
true
,
headers
:
{
headers
:
{
...
@@ -681,7 +709,7 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -681,7 +709,7 @@ jIO.addStorageType('dav', function (spec, my) {
priv
.
username
+
'
:
'
+
priv
.
password
priv
.
username
+
'
:
'
+
priv
.
password
)
)
},
},
success
:
function
(
response
)
{
success
:
function
()
{
j
=
attachment_list
.
length
;
j
=
attachment_list
.
length
;
// no attachments, done
// no attachments, done
if
(
j
===
0
)
{
if
(
j
===
0
)
{
...
@@ -690,13 +718,10 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -690,13 +718,10 @@ jIO.addStorageType('dav', function (spec, my) {
"
id
"
:
command
.
getDocId
()
"
id
"
:
command
.
getDocId
()
});
});
}
else
{
}
else
{
for
(
i
=
0
;
i
<
j
;
i
+=
1
)
{
deleteAttachment
=
function
(
attachment_url
,
j
,
k
)
{
secured_attachmentid
=
priv
.
secureDocId
(
attachment_list
[
i
]);
attachment_url
=
url
+
'
/
'
+
secured_attachmentid
;
$
.
ajax
({
$
.
ajax
({
url
:
attachment_url
+
'
?_=
'
+
Date
.
now
(),
url
:
attachment_url
+
'
?_=
'
+
Date
.
now
(),
type
:
'
REMOV
E
'
,
type
:
'
DELET
E
'
,
async
:
true
,
async
:
true
,
crossdomain
:
true
,
crossdomain
:
true
,
headers
:
{
headers
:
{
...
@@ -704,9 +729,9 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -704,9 +729,9 @@ jIO.addStorageType('dav', function (spec, my) {
priv
.
username
+
'
:
'
+
priv
.
password
priv
.
username
+
'
:
'
+
priv
.
password
)
)
},
},
success
:
function
(
response
)
{
success
:
function
()
{
// all deleted, return response, need k as async couter
// all deleted, return response, need k as async couter
if
(
j
===
k
){
if
(
j
===
k
)
{
that
.
success
({
that
.
success
({
"
ok
"
:
true
,
"
ok
"
:
true
,
"
id
"
:
command
.
getDocId
()
"
id
"
:
command
.
getDocId
()
...
@@ -715,7 +740,7 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -715,7 +740,7 @@ jIO.addStorageType('dav', function (spec, my) {
k
+=
1
;
k
+=
1
;
}
}
},
},
error
:
function
(
type
)
{
error
:
function
()
{
that
.
error
({
that
.
error
({
"
status
"
:
404
,
"
status
"
:
404
,
"
statusText
"
:
"
Not Found
"
,
"
statusText
"
:
"
Not Found
"
,
...
@@ -726,9 +751,16 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -726,9 +751,16 @@ jIO.addStorageType('dav', function (spec, my) {
}
}
});
});
};
};
for
(
i
=
0
;
i
<
j
;
i
+=
1
)
{
secured_attachmentid
=
priv
.
secureDocId
(
attachment_list
[
i
]);
attachment_url
=
url
+
'
.
'
+
priv
.
underscoreFileExtenisons
(
secured_attachmentid
);
deleteAttachment
(
attachment_url
,
j
,
k
);
}
}
}
},
},
error
:
function
(
type
)
{
error
:
function
()
{
that
.
error
({
that
.
error
({
"
status
"
:
404
,
"
status
"
:
404
,
"
statusText
"
:
"
Not Found
"
,
"
statusText
"
:
"
Not Found
"
,
...
@@ -739,7 +771,7 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -739,7 +771,7 @@ jIO.addStorageType('dav', function (spec, my) {
}
}
});
});
},
},
error
:
function
(
type
)
{
error
:
function
()
{
that
.
error
({
that
.
error
({
"
status
"
:
404
,
"
status
"
:
404
,
"
statusText
"
:
"
Not Found
"
,
"
statusText
"
:
"
Not Found
"
,
...
@@ -769,24 +801,27 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -769,24 +801,27 @@ jIO.addStorageType('dav', function (spec, my) {
// },{...}
// },{...}
// ]
// ]
//}
//}
that
.
allDocs
=
function
(
command
)
{
that
.
allDocs
=
function
(
command
)
{
var
rows
=
[],
url
,
var
rows
=
[],
url
,
am
=
priv
.
newAsyncModule
(),
am
=
priv
.
newAsyncModule
(),
o
=
{};
o
=
{};
o
.
getContent
=
function
(
file
)
{
o
.
getContent
=
function
(
file
)
{
var
docid
=
priv
.
secureDocId
(
file
.
id
),
url
=
priv
.
url
+
'
/
'
+
docid
;
$
.
ajax
({
$
.
ajax
({
url
:
priv
.
url
+
'
/
'
+
priv
.
secureDocId
(
file
.
id
)
+
'
?_=
'
+
Date
.
now
(),
url
:
url
+
'
?_=
'
+
Date
.
now
(),
type
:
'
GET
'
,
type
:
'
GET
'
,
async
:
true
,
async
:
true
,
dataType
:
'
text
'
,
dataType
:
'
text
'
,
headers
:
{
headers
:
{
'
Authorization
'
:
'
Basic
'
+
Base64
.
encode
(
'
Authorization
'
:
'
Basic
'
+
Base64
.
encode
(
priv
.
username
+
'
:
'
+
priv
.
password
)
priv
.
username
+
'
:
'
+
priv
.
password
)
},
},
success
:
function
(
content
)
{
success
:
function
(
content
)
{
file
.
value
.
content
=
content
;
file
.
doc
=
JSON
.
parse
(
content
)
;
rows
.
push
(
file
);
rows
.
push
(
file
);
am
.
call
(
o
,
'
success
'
);
am
.
call
(
o
,
'
success
'
);
},
},
...
@@ -809,7 +844,7 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -809,7 +844,7 @@ jIO.addStorageType('dav', function (spec, my) {
url
:
url
+
'
?_=
'
+
Date
.
now
(),
url
:
url
+
'
?_=
'
+
Date
.
now
(),
type
:
'
PROPFIND
'
,
type
:
'
PROPFIND
'
,
async
:
true
,
async
:
true
,
dataType
:
'
xml
'
,
dataType
:
"
xml
"
,
crossdomain
:
true
,
crossdomain
:
true
,
headers
:
{
headers
:
{
Authorization
:
'
Basic
'
+
Base64
.
encode
(
Authorization
:
'
Basic
'
+
Base64
.
encode
(
...
@@ -817,8 +852,8 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -817,8 +852,8 @@ jIO.addStorageType('dav', function (spec, my) {
),
),
Depth
:
'
1
'
Depth
:
'
1
'
},
},
success
:
function
(
xml
Data
)
{
success
:
function
(
xml
)
{
var
response
=
$
(
xml
Data
).
find
(
'
D
\\
:response, response
'
),
var
response
=
$
(
xml
).
find
(
'
D
\\
:response, response
'
),
len
=
response
.
length
;
len
=
response
.
length
;
if
(
len
===
1
)
{
if
(
len
===
1
)
{
...
@@ -836,10 +871,7 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -836,10 +871,7 @@ jIO.addStorageType('dav', function (spec, my) {
file
.
id
=
priv
.
restoreSlashes
(
file
.
id
);
file
.
id
=
priv
.
restoreSlashes
(
file
.
id
);
file
.
key
=
file
.
id
;
file
.
key
=
file
.
id
;
});
});
// this should probably also filter for the "." in case
if
(
command
.
getOption
(
'
include_docs
'
))
{
// there is a title.revision. Then we could fill value in
// allDocs, too!
if
(
command
.
getOption
(
'
include_content
'
))
{
am
.
call
(
o
,
'
getContent
'
,
[
file
]);
am
.
call
(
o
,
'
getContent
'
,
[
file
]);
}
else
{
}
else
{
rows
.
push
(
file
);
rows
.
push
(
file
);
...
...
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