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
Bryan Kaperick
jio
Commits
0648b456
Commit
0648b456
authored
Aug 12, 2014
by
Xiaowu Zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add _start&_end test for davstorage
parent
8f7bb38d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
288 additions
and
4 deletions
+288
-4
test/jio.storage/davstorage.tests.js
test/jio.storage/davstorage.tests.js
+288
-4
No files found.
test/jio.storage/davstorage.tests.js
View file @
0648b456
/*jslint indent: 2, maxlen: 80, nomen: true */
/*jslint indent: 2, maxlen: 80, nomen: true */
/*global module, test, stop, start, expect, ok, deepEqual, location, sinon,
/*global module, test, stop, start, expect, ok, deepEqual, location, sinon,
davstorage_spec, RSVP, jIO, test_util, dav_storage, btoa, define,
davstorage_spec, RSVP, jIO, test_util, dav_storage, btoa, define,
setTimeout, clearTimeout */
setTimeout, clearTimeout
, parseInt
*/
// define([module_name], [dependencies], module);
// define([module_name], [dependencies], module);
(
function
(
dependencies
,
module
)
{
(
function
(
dependencies
,
module
)
{
...
@@ -62,7 +62,7 @@
...
@@ -62,7 +62,7 @@
* X-Requested-With, X-HTTP-Method-Override, Accept, Authorization,
* X-Requested-With, X-HTTP-Method-Override, Accept, Authorization,
* Depth"
* Depth"
*/
*/
test
(
"
Scenario
"
,
34
,
function
()
{
test
(
"
Scenario
"
,
48
,
function
()
{
var
server
,
responses
=
[],
shared
=
{},
jio
=
jIO
.
createJIO
(
spec
,
{
var
server
,
responses
=
[],
shared
=
{},
jio
=
jIO
.
createJIO
(
spec
,
{
"
workspace
"
:
{},
"
workspace
"
:
{},
...
@@ -94,7 +94,7 @@
...
@@ -94,7 +94,7 @@
jIO
.
util
.
ajax
=
function
(
param
)
{
jIO
.
util
.
ajax
=
function
(
param
)
{
var
timeout
,
xhr
=
{},
response
=
responses
.
shift
(),
statusTexts
=
{
var
timeout
,
xhr
=
{},
response
=
responses
.
shift
(),
statusTexts
=
{
"
404
"
:
"
Not Found
"
"
404
"
:
"
Not Found
"
};
}
,
start
,
end
,
str
;
if
(
!
Array
.
isArray
(
response
))
{
if
(
!
Array
.
isArray
(
response
))
{
setTimeout
(
function
()
{
setTimeout
(
function
()
{
throw
new
ReferenceError
(
"
Fake server, no response set for
"
+
throw
new
ReferenceError
(
"
Fake server, no response set for
"
+
...
@@ -116,6 +116,17 @@
...
@@ -116,6 +116,17 @@
timeout
=
setTimeout
(
function
()
{
timeout
=
setTimeout
(
function
()
{
/*global Blob*/
/*global Blob*/
if
(
xhr
.
responseType
===
'
blob
'
)
{
if
(
xhr
.
responseType
===
'
blob
'
)
{
if
(
param
.
headers
.
Range
!==
undefined
)
{
str
=
param
.
headers
.
Range
;
start
=
parseInt
(
str
.
substring
(
str
.
indexOf
(
"
=
"
)
+
1
,
str
.
indexOf
(
"
-
"
)),
10
);
if
(
str
.
indexOf
(
"
NaN
"
)
!==
-
1
)
{
response
[
2
]
=
response
[
2
].
substring
(
start
);
}
else
{
end
=
parseInt
(
str
.
substring
(
str
.
indexOf
(
"
-
"
)
+
1
),
10
);
response
[
2
]
=
response
[
2
].
substring
(
start
,
end
+
1
);
}
}
xhr
.
response
=
new
Blob
([
response
[
2
]],
{
xhr
.
response
=
new
Blob
([
response
[
2
]],
{
"
type
"
:
response
[
1
][
"
Content-Type
"
]
||
"
type
"
:
response
[
1
][
"
Content-Type
"
]
||
response
[
1
][
"
Content-type
"
]
||
response
[
1
][
"
Content-type
"
]
||
...
@@ -969,6 +980,179 @@
...
@@ -969,6 +980,179 @@
});
});
}
}
function
getFirstAttachmentRange1
()
{
responses
.
push
([
200
,
{
"
Content-Type
"
:
"
application/octet-stream
"
},
JSON
.
stringify
({
"
_id
"
:
"
a
"
,
"
title
"
:
"
Hoo
"
,
"
_attachments
"
:
{
"
aa
"
:
{
"
content_type
"
:
"
text/plain
"
,
"
digest
"
:
"
sha256-38760eabb666e8e61ee628a17c4090cc5
"
+
"
0728e095ff24218119d51bd22475363
"
,
"
length
"
:
3
},
"
ab
"
:
{
"
content_type
"
:
"
text/plain
"
,
"
digest
"
:
"
sha256-e124adcce1fb2f88e1ea799c3d0820845
"
+
"
ed343e6c739e54131fcb3a56e4bc1bd
"
,
"
length
"
:
3
}
}
})]);
// GET
responses
.
push
([
200
,
{
"
Content-Type
"
:
"
application/octet-stream
"
},
"
aab
"
]);
// GET
return
jio
.
getAttachment
({
"
_id
"
:
"
a
"
,
"
_attachment
"
:
"
aa
"
,
"
_start
"
:
0
});
}
function
getFirstAttachmentRangeTest1
(
answer
)
{
var
blob
=
answer
.
data
;
answer
.
data
=
"
<blob>
"
;
deepEqual
(
answer
,
{
"
attachment
"
:
"
aa
"
,
"
data
"
:
"
<blob>
"
,
"
id
"
:
"
a
"
,
"
digest
"
:
"
sha256-38760eabb666e8e61ee628a17c4090cc5
"
+
"
0728e095ff24218119d51bd22475363
"
,
"
method
"
:
"
getAttachment
"
,
"
result
"
:
"
success
"
,
"
status
"
:
200
,
"
statusText
"
:
"
Ok
"
},
"
Get first attachment with range:_start: 0, _end: undefined
"
);
return
jIO
.
util
.
readBlobAsText
(
blob
).
then
(
function
(
e
)
{
deepEqual
(
blob
.
type
,
"
text/plain
"
,
"
Check blob type
"
);
deepEqual
(
e
.
target
.
result
,
"
aab
"
,
"
Check blob text content
"
);
},
function
(
err
)
{
deepEqual
(
err
,
"
no error
"
,
"
Check blob text content
"
);
});
}
function
getFirstAttachmentRange2
()
{
responses
.
push
([
200
,
{
"
Content-Type
"
:
"
application/octet-stream
"
},
JSON
.
stringify
({
"
_id
"
:
"
a
"
,
"
title
"
:
"
Hoo
"
,
"
_attachments
"
:
{
"
aa
"
:
{
"
content_type
"
:
"
text/plain
"
,
"
digest
"
:
"
sha256-38760eabb666e8e61ee628a17c4090cc5
"
+
"
0728e095ff24218119d51bd22475363
"
,
"
length
"
:
3
},
"
ab
"
:
{
"
content_type
"
:
"
text/plain
"
,
"
digest
"
:
"
sha256-e124adcce1fb2f88e1ea799c3d0820845
"
+
"
ed343e6c739e54131fcb3a56e4bc1bd
"
,
"
length
"
:
3
}
}
})]);
// GET
responses
.
push
([
200
,
{
"
Content-Type
"
:
"
application/octet-stream
"
},
"
aab
"
]);
// GET
return
jio
.
getAttachment
({
"
_id
"
:
"
a
"
,
"
_attachment
"
:
"
aa
"
,
"
_start
"
:
0
,
"
_end
"
:
1
});
}
function
getFirstAttachmentRangeTest2
(
answer
)
{
var
blob
=
answer
.
data
;
answer
.
data
=
"
<blob>
"
;
deepEqual
(
answer
,
{
"
attachment
"
:
"
aa
"
,
"
data
"
:
"
<blob>
"
,
"
id
"
:
"
a
"
,
"
digest
"
:
"
sha256-38760eabb666e8e61ee628a17c4090cc5
"
+
"
0728e095ff24218119d51bd22475363
"
,
"
method
"
:
"
getAttachment
"
,
"
result
"
:
"
success
"
,
"
status
"
:
200
,
"
statusText
"
:
"
Ok
"
},
"
Get first attachment with range: _start:0, _end:1
"
);
return
jIO
.
util
.
readBlobAsText
(
blob
).
then
(
function
(
e
)
{
deepEqual
(
blob
.
type
,
"
text/plain
"
,
"
Check blob type
"
);
deepEqual
(
e
.
target
.
result
,
"
a
"
,
"
Check blob text content
"
);
},
function
(
err
)
{
deepEqual
(
err
,
"
no error
"
,
"
Check blob text content
"
);
});
}
function
getFirstAttachmentRange3
()
{
responses
.
push
([
200
,
{
"
Content-Type
"
:
"
application/octet-stream
"
},
JSON
.
stringify
({
"
_id
"
:
"
a
"
,
"
title
"
:
"
Hoo
"
,
"
_attachments
"
:
{
"
aa
"
:
{
"
content_type
"
:
"
text/plain
"
,
"
digest
"
:
"
sha256-38760eabb666e8e61ee628a17c4090cc5
"
+
"
0728e095ff24218119d51bd22475363
"
,
"
length
"
:
3
},
"
ab
"
:
{
"
content_type
"
:
"
text/plain
"
,
"
digest
"
:
"
sha256-e124adcce1fb2f88e1ea799c3d0820845
"
+
"
ed343e6c739e54131fcb3a56e4bc1bd
"
,
"
length
"
:
3
}
}
})]);
// GET
responses
.
push
([
200
,
{
"
Content-Type
"
:
"
application/octet-stream
"
},
"
aab
"
]);
// GET
return
jio
.
getAttachment
({
"
_id
"
:
"
a
"
,
"
_attachment
"
:
"
aa
"
,
"
_start
"
:
1
,
"
_end
"
:
3
});
}
function
getFirstAttachmentRangeTest3
(
answer
)
{
var
blob
=
answer
.
data
;
answer
.
data
=
"
<blob>
"
;
deepEqual
(
answer
,
{
"
attachment
"
:
"
aa
"
,
"
data
"
:
"
<blob>
"
,
"
id
"
:
"
a
"
,
"
digest
"
:
"
sha256-38760eabb666e8e61ee628a17c4090cc5
"
+
"
0728e095ff24218119d51bd22475363
"
,
"
method
"
:
"
getAttachment
"
,
"
result
"
:
"
success
"
,
"
status
"
:
200
,
"
statusText
"
:
"
Ok
"
},
"
Get first attachment with range:_start:1, _end:3
"
);
return
jIO
.
util
.
readBlobAsText
(
blob
).
then
(
function
(
e
)
{
deepEqual
(
blob
.
type
,
"
text/plain
"
,
"
Check blob type
"
);
deepEqual
(
e
.
target
.
result
,
"
ab
"
,
"
Check blob text content
"
);
},
function
(
err
)
{
deepEqual
(
err
,
"
no error
"
,
"
Check blob text content
"
);
});
}
function
getSecondAttachment
()
{
function
getSecondAttachment
()
{
responses
.
push
([
200
,
{
responses
.
push
([
200
,
{
"
Content-Type
"
:
"
application/octet-stream
"
"
Content-Type
"
:
"
application/octet-stream
"
...
@@ -1009,7 +1193,7 @@
...
@@ -1009,7 +1193,7 @@
"
result
"
:
"
success
"
,
"
result
"
:
"
success
"
,
"
status
"
:
200
,
"
status
"
:
200
,
"
statusText
"
:
"
Ok
"
"
statusText
"
:
"
Ok
"
},
"
Get
first
attachment
"
);
},
"
Get
second
attachment
"
);
return
jIO
.
util
.
readBlobAsText
(
blob
).
then
(
function
(
e
)
{
return
jIO
.
util
.
readBlobAsText
(
blob
).
then
(
function
(
e
)
{
deepEqual
(
blob
.
type
,
"
text/plain
"
,
"
Check blob type
"
);
deepEqual
(
blob
.
type
,
"
text/plain
"
,
"
Check blob type
"
);
deepEqual
(
e
.
target
.
result
,
"
aba
"
,
"
Check blob text content
"
);
deepEqual
(
e
.
target
.
result
,
"
aba
"
,
"
Check blob text content
"
);
...
@@ -1018,6 +1202,100 @@
...
@@ -1018,6 +1202,100 @@
});
});
}
}
function
getSecondAttachmentRange1
()
{
return
success
(
jio
.
getAttachment
({
"
_id
"
:
"
a
"
,
"
_attachment
"
:
"
ab
"
,
"
_start
"
:
-
1
}));
}
function
getSecondAttachmentRangeTest1
(
answer
)
{
deepEqual
(
answer
,
{
"
attachment
"
:
"
ab
"
,
"
error
"
:
"
method_not_allowed
"
,
"
id
"
:
"
a
"
,
"
message
"
:
"
_start and _end must be positive
"
,
"
method
"
:
"
getAttachment
"
,
"
reason
"
:
"
invalide _start,_end
"
,
"
result
"
:
"
error
"
,
"
status
"
:
405
,
"
statusText
"
:
"
Method Not Allowed
"
},
"
Get second attachment with range: _start: -1
"
);
}
function
getSecondAttachmentRange2
()
{
return
success
(
jio
.
getAttachment
({
"
_id
"
:
"
a
"
,
"
_attachment
"
:
"
ab
"
,
"
_start
"
:
1
,
"
_end
"
:
0
}));
}
function
getSecondAttachmentRangeTest2
(
answer
)
{
deepEqual
(
answer
,
{
"
attachment
"
:
"
ab
"
,
"
error
"
:
"
method_not_allowed
"
,
"
id
"
:
"
a
"
,
"
message
"
:
"
start is great then end
"
,
"
method
"
:
"
getAttachment
"
,
"
reason
"
:
"
invalide _start,_end
"
,
"
result
"
:
"
error
"
,
"
status
"
:
405
,
"
statusText
"
:
"
Method Not Allowed
"
},
"
Get second attachment with range: _start: -1
"
);
}
function
getSecondAttachmentRange3
()
{
responses
.
push
([
200
,
{
"
Content-Type
"
:
"
application/octet-stream
"
},
JSON
.
stringify
({
"
_id
"
:
"
a
"
,
"
title
"
:
"
Hoo
"
,
"
_attachments
"
:
{
"
aa
"
:
{
"
content_type
"
:
"
text/plain
"
,
"
digest
"
:
"
sha256-38760eabb666e8e61ee628a17c4090cc5
"
+
"
0728e095ff24218119d51bd22475363
"
,
"
length
"
:
3
},
"
ab
"
:
{
"
content_type
"
:
"
text/plain
"
,
"
digest
"
:
"
sha256-e124adcce1fb2f88e1ea799c3d0820845
"
+
"
ed343e6c739e54131fcb3a56e4bc1bd
"
,
"
length
"
:
3
}
}
})]);
// GET
responses
.
push
([
200
,
{
"
Content-Type
"
:
"
application/octet-stream
"
},
"
aab
"
]);
// GET
return
jio
.
getAttachment
({
"
_id
"
:
"
a
"
,
"
_attachment
"
:
"
ab
"
,
"
_start
"
:
1
,
"
_end
"
:
2
});
}
function
getSecondAttachmentRangeTest3
(
answer
)
{
var
blob
=
answer
.
data
;
answer
.
data
=
"
<blob>
"
;
deepEqual
(
answer
,
{
"
attachment
"
:
"
ab
"
,
"
data
"
:
"
<blob>
"
,
"
id
"
:
"
a
"
,
"
digest
"
:
"
sha256-e124adcce1fb2f88e1ea799c3d0820845
"
+
"
ed343e6c739e54131fcb3a56e4bc1bd
"
,
"
method
"
:
"
getAttachment
"
,
"
result
"
:
"
success
"
,
"
status
"
:
200
,
"
statusText
"
:
"
Ok
"
},
"
Get second attachment with range:_start:1, _end:2
"
);
return
jIO
.
util
.
readBlobAsText
(
blob
).
then
(
function
(
e
)
{
deepEqual
(
blob
.
type
,
"
text/plain
"
,
"
Check blob type
"
);
deepEqual
(
e
.
target
.
result
,
"
a
"
,
"
Check blob text content
"
);
},
function
(
err
)
{
deepEqual
(
err
,
"
no error
"
,
"
Check blob text content
"
);
});
}
function
getLastDocument
()
{
function
getLastDocument
()
{
responses
.
push
([
200
,
{
responses
.
push
([
200
,
{
"
Content-Type
"
:
"
application/octet-stream
"
"
Content-Type
"
:
"
application/octet-stream
"
...
@@ -1348,8 +1626,14 @@
...
@@ -1348,8 +1626,14 @@
then
(
updateLastDocument
).
then
(
updateLastDocumentTest
).
then
(
updateLastDocument
).
then
(
updateLastDocumentTest
).
// getA a 200
// getA a 200
then
(
getFirstAttachment
).
then
(
getFirstAttachmentTest
).
then
(
getFirstAttachment
).
then
(
getFirstAttachmentTest
).
then
(
getFirstAttachmentRange1
).
then
(
getFirstAttachmentRangeTest1
).
then
(
getFirstAttachmentRange2
).
then
(
getFirstAttachmentRangeTest2
).
then
(
getFirstAttachmentRange3
).
then
(
getFirstAttachmentRangeTest3
).
// getA b 200
// getA b 200
then
(
getSecondAttachment
).
then
(
getSecondAttachmentTest
).
then
(
getSecondAttachment
).
then
(
getSecondAttachmentTest
).
then
(
getSecondAttachmentRange1
).
then
(
getSecondAttachmentRangeTest1
).
then
(
getSecondAttachmentRange2
).
then
(
getSecondAttachmentRangeTest2
).
then
(
getSecondAttachmentRange3
).
then
(
getSecondAttachmentRangeTest3
).
// get 200
// get 200
then
(
getLastDocument
).
then
(
getLastDocumentTest
).
then
(
getLastDocument
).
then
(
getLastDocumentTest
).
// removeA b 204
// removeA b 204
...
...
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