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
Boris Kocherov
jio
Commits
891be93a
Commit
891be93a
authored
Dec 27, 2012
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jiotests updated
parent
a42b4948
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
753 additions
and
974 deletions
+753
-974
test/jiotests.js
test/jiotests.js
+751
-973
test/jiotests_withoutrequirejs.html
test/jiotests_withoutrequirejs.html
+2
-1
No files found.
test/jiotests.js
View file @
891be93a
(
function
()
{
var
thisfun
=
function
(
loader
)
{
(
function
()
{
var
thisfun
=
function
(
loader
)
{
var
JIO
=
loader
.
JIO
,
var
JIO
=
loader
.
JIO
,
LocalOrCookieStorage
=
loader
.
LocalOrCookieStorage
,
sjcl
=
loader
.
sjcl
,
sjcl
=
loader
.
sjcl
,
Base64
=
loader
.
Base64
,
Base64
=
loader
.
Base64
,
$
=
loader
.
jQuery
;
$
=
loader
.
jQuery
;
...
@@ -19,12 +18,28 @@ contains = function (array,content) {
...
@@ -19,12 +18,28 @@ contains = function (array,content) {
}
}
return
false
;
return
false
;
},
},
clean_up_local_storage_function
=
function
(){
// localStorage wrapper
var
k
,
storageObject
=
LocalOrCookieStorage
.
getAll
();
localstorage
=
{
clear
:
function
()
{
return
localStorage
.
clear
();
},
getItem
:
function
(
item
)
{
var
value
=
localStorage
.
getItem
(
item
);
return
value
===
null
?
null
:
JSON
.
parse
(
value
);
},
setItem
:
function
(
item
,
value
)
{
return
localStorage
.
setItem
(
item
,
JSON
.
stringify
(
value
));
},
removeItem
:
function
(
item
)
{
return
localStorage
.
removeItem
(
item
);
}
},
cleanUpLocalStorage
=
function
(){
var
k
,
storageObject
=
localstorage
.
getAll
();
for
(
k
in
storageObject
)
{
for
(
k
in
storageObject
)
{
var
splitk
=
k
.
split
(
'
/
'
);
var
splitk
=
k
.
split
(
'
/
'
);
if
(
splitk
[
0
]
===
'
jio
'
)
{
if
(
splitk
[
0
]
===
'
jio
'
)
{
LocalOrCookieStorage
.
delet
eItem
(
k
);
localstorage
.
remov
eItem
(
k
);
}
}
}
}
var
d
=
document
.
createElement
(
'
div
'
);
var
d
=
document
.
createElement
(
'
div
'
);
...
@@ -34,11 +49,10 @@ clean_up_local_storage_function = function(){
...
@@ -34,11 +49,10 @@ clean_up_local_storage_function = function(){
localStorage
.
clear
();
localStorage
.
clear
();
},
},
base_tick
=
30000
,
base_tick
=
30000
,
basic
_test_function_g
enerator
=
function
(
o
,
res
,
value
,
message
)
{
basic
TestFunctionG
enerator
=
function
(
o
,
res
,
value
,
message
)
{
return
function
(
err
,
val
)
{
return
function
(
err
,
val
)
{
var
jobstatus
=
(
err
?
'
fail
'
:
'
done
'
),
var
jobstatus
=
(
err
?
'
fail
'
:
'
done
'
);
val
=
(
isEmptyObject
(
value
)
&&
isUUID
(
val
.
_id
)
)
?
{}
:
val
;
switch
(
res
)
{
switch
(
res
)
{
case
'
status
'
:
case
'
status
'
:
...
@@ -56,15 +70,15 @@ basic_test_function_generator = function(o,res,value,message) {
...
@@ -56,15 +70,15 @@ basic_test_function_generator = function(o,res,value,message) {
deepEqual
(
val
,
value
,
message
);
deepEqual
(
val
,
value
,
message
);
};
};
},
},
basic
_spy_f
unction
=
function
(
o
,
res
,
value
,
message
,
fun
)
{
basic
SpyF
unction
=
function
(
o
,
res
,
value
,
message
,
fun
)
{
fun
=
fun
||
'
f
'
;
fun
=
fun
||
'
f
'
;
o
[
fun
]
=
basic
_test_function_g
enerator
(
o
,
res
,
value
,
message
);
o
[
fun
]
=
basic
TestFunctionG
enerator
(
o
,
res
,
value
,
message
);
o
.
t
.
spy
(
o
,
fun
);
o
.
t
.
spy
(
o
,
fun
);
},
},
basic
_tick_f
unction
=
function
(
o
)
{
basic
TickF
unction
=
function
(
o
)
{
var
tick
,
fun
,
i
=
1
;
var
tick
,
fun
,
i
=
1
;
tick
=
1000
;
tick
=
1000
0
;
fun
=
fun
||
'
f
'
;
fun
=
fun
||
'
f
'
;
if
(
typeof
arguments
[
i
]
===
'
number
'
)
{
if
(
typeof
arguments
[
i
]
===
'
number
'
)
{
...
@@ -83,7 +97,7 @@ basic_tick_function = function (o) {
...
@@ -83,7 +97,7 @@ basic_tick_function = function (o) {
}
}
},
},
// debug function to show custumized log at the bottom of the page
// debug function to show custumized log at the bottom of the page
my
_l
og
=
function
(
html_string
)
{
my
L
og
=
function
(
html_string
)
{
document
.
querySelector
(
'
div#log
'
).
innerHTML
+=
html_string
+
'
<hr/>
'
;
document
.
querySelector
(
'
div#log
'
).
innerHTML
+=
html_string
+
'
<hr/>
'
;
},
},
getXML
=
function
(
url
)
{
getXML
=
function
(
url
)
{
...
@@ -95,181 +109,88 @@ getXML = function (url) {
...
@@ -95,181 +109,88 @@ getXML = function (url) {
objectifyDocumentArray
=
function
(
array
)
{
objectifyDocumentArray
=
function
(
array
)
{
var
obj
=
{},
k
;
var
obj
=
{},
k
;
for
(
k
=
0
;
k
<
array
.
length
;
k
+=
1
)
{
for
(
k
=
0
;
k
<
array
.
length
;
k
+=
1
)
{
obj
[
array
[
k
].
id
]
=
array
[
k
];
obj
[
array
[
k
].
_
id
]
=
array
[
k
];
}
}
return
obj
;
return
obj
;
},
},
addFileToLocalStorage
=
function
(
user
,
appid
,
file
)
{
getLastJob
=
function
(
id
)
{
var
i
,
l
,
found
=
false
,
filenamearray
,
return
(
localstorage
.
getItem
(
"
jio/job_array/
"
+
id
)
||
[
undefined
]).
pop
();
userarray
=
LocalOrCookieStorage
.
getItem
(
'
jio/local_user_array
'
)
||
[];
for
(
i
=
0
,
l
=
userarray
.
length
;
i
<
l
;
i
+=
1
)
{
if
(
userarray
[
i
]
===
user
)
{
found
=
true
;
}
}
if
(
!
found
)
{
userarray
.
push
(
user
);
LocalOrCookieStorage
.
setItem
(
'
jio/local_user_array
'
,
userarray
);
LocalOrCookieStorage
.
setItem
(
'
jio/local_file_name_array/
'
+
user
+
'
/
'
+
appid
,[
file
.
_id
]);
}
else
{
filenamearray
=
LocalOrCookieStorage
.
getItem
(
'
jio/local_file_name_array/
'
+
user
+
'
/
'
+
appid
)
||
[];
filenamearray
.
push
(
file
.
_id
);
LocalOrCookieStorage
.
setItem
(
'
jio/local_file_name_array/
'
+
user
+
'
/
'
+
appid
,
filenamearray
);
LocalOrCookieStorage
.
setItem
(
'
jio/local/
'
+
user
+
'
/
'
+
appid
+
'
/
'
+
file
.
_id
,
file
);
}
LocalOrCookieStorage
.
setItem
(
'
jio/local/
'
+
user
+
'
/
'
+
appid
+
'
/
'
+
file
.
_id
,
file
);
},
removeFileFromLocalStorage
=
function
(
user
,
appid
,
file
)
{
var
i
,
l
,
newarray
=
[],
filenamearray
=
LocalOrCookieStorage
.
getItem
(
'
jio/local_file_name_array/
'
+
user
+
'
/
'
+
appid
)
||
[];
for
(
i
=
0
,
l
=
filenamearray
.
length
;
i
<
l
;
i
+=
1
)
{
if
(
filenamearray
[
i
]
!==
file
.
_id
)
{
newarray
.
push
(
filenamearray
[
i
]);
}
}
LocalOrCookieStorage
.
setItem
(
'
jio/local_file_name_array/
'
+
user
+
'
/
'
+
appid
,
newarray
);
LocalOrCookieStorage
.
deleteItem
(
'
jio/local/
'
+
user
+
'
/
'
+
appid
+
'
/
'
+
file
.
_id
);
},
},
makeRevsAccordingToRevsInfo
=
function
(
revs
,
revs_info
)
{
generateTools
=
function
(
sinon
)
{
var
i
,
j
;
var
o
=
{};
for
(
i
=
0
;
i
<
revs
.
start
;
i
+=
1
)
{
o
.
t
=
sinon
;
for
(
j
=
0
;
j
<
revs_info
.
length
;
j
+=
1
)
{
o
.
clock
=
o
.
t
.
sandbox
.
useFakeTimers
();
var
id
=
revs_info
[
j
].
rev
.
split
(
'
-
'
);
id
.
shift
();
id
=
id
.
join
(
'
-
'
);
o
.
clock
.
tick
(
base_tick
);
if
(
revs
.
ids
[
i
]
===
id
)
{
o
.
spy
=
basicSpyFunction
;
revs
.
ids
[
i
]
=
revs_info
[
j
].
rev
.
split
(
'
-
'
)[
0
];
o
.
tick
=
basicTickFunction
;
o
.
testLastJobLabel
=
function
(
label
,
mess
)
{
deepEqual
(
getLastJob
(
o
.
jio
.
getId
()).
command
.
label
,
label
,
mess
);
};
o
.
testLastJobId
=
function
(
id
,
mess
)
{
deepEqual
(
getLastJob
(
o
.
jio
.
getId
()).
id
,
id
,
mess
);
};
o
.
testLastJobWaitForTime
=
function
(
mess
)
{
ok
(
getLastJob
(
o
.
jio
.
getId
()).
status
.
waitfortime
>
0
,
mess
);
};
o
.
testLastJobWaitForJob
=
function
(
job_id_array
,
mess
)
{
deepEqual
(
getLastJob
(
o
.
jio
.
getId
()).
status
.
waitforjob
,
job_id_array
,
mess
);
};
o
.
waitUntilAJobExists
=
function
(
timeout
)
{
var
cpt
=
0
while
(
true
)
{
if
(
getLastJob
(
o
.
jio
.
getId
())
!==
undefined
)
{
break
;
break
;
}
}
if
(
timeout
>=
cpt
)
{
ok
(
false
,
"
no job added to the queue
"
);
break
;
}
}
o
.
clock
.
tick
(
25
);
cpt
+=
25
;
}
}
},
};
checkRev
=
function
(
rev
)
{
o
.
waitUntilLastJobIs
=
function
(
state
)
{
if
(
typeof
rev
===
'
string
'
)
{
while
(
true
)
{
if
(
rev
.
split
(
'
-
'
).
length
>
1
&&
if
(
getLastJob
(
o
.
jio
.
getId
())
===
undefined
)
{
parseInt
(
rev
.
split
(
'
-
'
)[
0
],
10
)
>
0
)
{
ok
(
false
,
"
a job is never called
"
);
return
rev
;
break
;
}
}
return
'
ERROR: not a good revision!
'
;
},
checkConflictRow
=
function
(
row
)
{
var
fun
;
if
(
typeof
row
===
'
object
'
)
{
if
(
row
.
value
&&
typeof
row
.
value
.
_solveConflict
===
'
function
'
)
{
fun
=
row
.
value
.
_solveConflict
;
row
.
value
.
_solveConflict
=
'
function
'
;
}
}
return
fun
;
},
getHashFromRev
=
function
(
rev
)
{
var
id
=
rev
;
if
(
typeof
id
===
'
string
'
)
{
id
=
id
.
split
(
'
-
'
);
id
.
shift
();
id
=
id
.
join
(
'
-
'
);
}
return
id
;
},
revs_infoContains
=
function
(
revs_info
,
rev
)
{
var
i
;
if
(
typeof
revs_info
!==
'
object
'
)
{
return
undefined
;
}
for
(
i
=
0
;
i
<
revs_info
.
length
||
0
;
i
+=
1
)
{
if
(
revs_info
[
i
].
rev
&&
revs_info
[
i
].
rev
===
rev
)
{
return
true
;
}
}
return
false
;
},
isUUID
=
function
(
_id
){
var
re
=
/^
[
0-9a-f
]{8}(
-
[
0-9a-f
]{4}){3}
-
[
0-9a-f
]{12}
$/
;
if
(
re
.
test
(
_id
)
){
return
true
;
}
else
{
return
false
;
}
},
isEmptyObject
=
function
(
obj
)
{
var
key
;
if
(
obj
.
length
&&
obj
.
length
>
0
){
return
false
;
}
if
(
obj
.
length
&&
obj
.
length
===
0
){
return
true
;
}
}
for
(
key
in
obj
)
{
if
(
getLastJob
(
o
.
jio
.
getId
()).
status
.
label
===
state
)
{
if
(
hasOwnProperty
.
call
(
obj
,
key
)){
break
;
return
false
;
}
}
o
.
clock
.
tick
(
25
);
}
}
return
true
;
};
},
return
o
;
};
//// end tools
//// end tools
//// test methods ////
//// test methods ////
checkReply
=
function
(
o
,
tick
,
fun
){
basic_tick_function
(
o
,
tick
,
fun
);
},
checkFile
=
function
(
response
,
o
,
tick
,
value
,
fun
)
{
o
.
tmp
=
localstorage
.
getItem
(
'
jio/local/
'
+
o
.
username
+
'
/jiotests/
'
+
response
.
id
+
'
/
'
+
response
.
rev
);
// remove everything not needed for basic response
o
.
tmp
.
ok
=
true
;
delete
o
.
tmp
.
_revisions
;
delete
o
.
tmp
.
_revs_info
;
delete
o
.
tmp
.
content
;
if
(
o
.
tmp
)
{
deepEqual
(
o
.
tmp
,{
"
ok
"
:
response
.
ok
,
"
_id
"
:
response
.
id
,
"
_rev
"
:
response
.
rev
,
},
'
document was created or updated
'
);
}
else
{
ok
(
false
,
'
document was not created or updated
'
);
}
},
checkTreeNode
=
function
(
response
,
o
,
tick
,
value
,
fun
)
{
o
.
tmp
=
localstorage
.
getItem
(
'
jio/local/
'
+
o
.
username
+
'
/jiotests/
'
+
response
.
id
+
'
/revision_tree
'
);
if
(
o
.
tmp
)
{
deepEqual
(
o
.
tmp
,
o
.
buildTestTree
,
'
tree node was created
'
);
}
else
{
ok
(
false
,
'
tree node was not created
'
);
}
};
//// QUnit Tests ////
//// QUnit Tests ////
module
(
'
Jio Global tests
'
);
module
(
'
Jio Global tests
'
);
test
(
"
Jio simple methods
"
,
function
()
{
test
(
"
Jio simple methods
"
,
function
()
{
var
clock
=
this
.
sandbox
.
useFakeTimers
();
clock
.
tick
(
base_tick
);
// Test Jio simple methods
// Test Jio simple methods
// It checks if we can create several instance of jio at the same
// It checks if we can create several instance of jio at the same
// time. Checks if they don't overlap informations, if they are
// time. Checks if they don't overlap informations, if they are
// started and stopped correctly and if they are ready when they
// started and stopped correctly and if they are ready when they
// have to be ready.
// have to be ready.
var
o
=
{};
var
o
=
generateTools
(
this
);
o
.
jio
=
JIO
.
newJio
();
o
.
jio
=
JIO
.
newJio
();
ok
(
o
.
jio
,
'
a new jio -> 1
'
);
ok
(
o
.
jio
,
'
a new jio -> 1
'
);
...
@@ -312,917 +233,776 @@ test ( "Jio simple methods", function () {
...
@@ -312,917 +233,776 @@ test ( "Jio simple methods", function () {
// o.jio.stop();
// o.jio.stop();
// });
// });
module
(
'
Jio Dummy Storages
'
);
module
(
"
Jio Dummy Storages
"
);
test
(
'
All tests
'
,
function
()
{
test
(
"
All requests ok
"
,
function
()
{
// Tests all dummy storages from jio.dummystorages.js
// Tests the request methods and the response with dummy storages
// It is simple tests, but they will be used by replicate storage later
// for sync operation.
var
o
=
{};
o
.
t
=
this
;
o
.
clock
=
o
.
t
.
sandbox
.
useFakeTimers
();
var
o
=
generateTools
(
this
);
o
.
clock
.
tick
(
base_tick
);
o
.
spy
=
basic_spy_function
;
o
.
tick
=
basic_tick_function
;
// All Ok Dummy Storage
// All Ok Dummy Storage
o
.
jio
=
JIO
.
newJio
({
'
type
'
:
'
dummyallok
'
});
o
.
jio
=
JIO
.
newJio
({
"
type
"
:
"
dummyallok
"
});
// post empty
// post empty document, some storage can create there own id (like couchdb
o
.
jio
.
post
({},
// generates uuid). In this case, the dummy storage write an undefined id.
function
(
err
,
response
)
{
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
undefined
},
o
.
spy
(
o
,
'
value
'
,{
"
ok
"
:
true
,
"
id
"
:
response
.
id
,
"
rev
"
:
response
.
rev
},
"
Post document with empty id
"
);
'
dummyallok post/create empty object
'
);
o
.
jio
.
post
({},
o
.
f
);
o
.
f
(
response
);
});
o
.
tick
(
o
);
o
.
tick
(
o
);
// post
// post non empty document
o
.
jio
.
post
({
"
content
"
:
"
basic_content
"
},
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
file
"
},
"
Post non empty document
"
);
function
(
err
,
response
)
{
o
.
jio
.
post
({
"
_id
"
:
"
file
"
,
"
title
"
:
"
myFile
"
},
o
.
f
);
o
.
spy
(
o
,
'
value
'
,{
"
ok
"
:
true
,
"
id
"
:
response
.
id
,
"
rev
"
:
response
.
rev
},
'
dummyallok post/create object
'
);
o
.
f
(
response
);
});
o
.
tick
(
o
);
o
.
tick
(
o
);
// put
// put without id
o
.
jio
.
put
({
"
_id
"
:
"
file
"
,
"
content
"
:
"
basic_content
"
},
// error 20 -> document id required
function
(
err
,
response
)
{
o
.
spy
(
o
,
"
status
"
,
20
,
"
Put document with empty id
"
);
o
.
spy
(
o
,
'
value
'
,{
"
ok
"
:
true
,
"
id
"
:
"
file
"
,
"
rev
"
:
response
.
rev
},
o
.
jio
.
put
({},
o
.
f
);
'
dummyallok put create object
'
);
o
.
f
(
response
);
});
o
.
tick
(
o
);
o
.
tick
(
o
);
/*
// put non empty document
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
file
"
},
"
Put non empty document
"
);
o
.
jio
.
put
({
"
_id
"
:
"
file
"
,
"
title
"
:
"
myFile
"
},
o
.
f
);
o
.
tick
(
o
);
// load
// put an attachment without attachment id
o.spy(o,'value',{_id:'file',content:'content',_last_modified:15000,
// error 22 -> attachment id required
_creation_date:10000},'dummyallok loading');
o
.
spy
(
o
,
"
status
"
,
22
,
o.jio.get('file',o.f);
"
Put attachment without id
"
);
o
.
jio
.
putAttachment
({
"
id
"
:
"
file
"
,
"
data
"
:
"
0123456789
"
,
"
mimetype
"
:
"
text/plain
"
},
o
.
f
);
o
.
tick
(
o
);
o
.
tick
(
o
);
// remove
// put an attachment
o.spy(o,'value',{ok:true,id:"file"},'dummyallok removing');
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
file/attmt
"
},
o.jio.remove({_id:'file'},o.f);
"
Put attachment
"
);
o
.
jio
.
putAttachment
({
"
id
"
:
"
file/attmt
"
,
"
data
"
:
"
0123456789
"
,
"
mimetype
"
:
"
text/plain
"
},
o
.
f
);
o
.
tick
(
o
);
o
.
tick
(
o
);
// get list
// get document
o.spy (o,'value',{
o
.
spy
(
o
,
"
value
"
,
{
"
_id
"
:
"
file
"
,
"
title
"
:
"
get_title
"
},
"
Get document
"
);
total_rows:2,
o
.
jio
.
get
(
"
file
"
,
o
.
f
);
rows:[{
id:'file',key:'file',
value:{
content:'filecontent',
_last_modified:15000,
_creation_date:10000
}
},{
id:'memo',key:'memo',
value:{
content:'memocontent',
_last_modified:25000,
_creation_date:20000
}
}]
},'dummyallok getting list');
o.jio.allDocs({metadata_only:false},o.f);
o
.
tick
(
o
);
o
.
tick
(
o
);
o.jio.stop();
// get attachment
o
.
spy
(
o
,
"
value
"
,
"
0123456789
"
,
"
Get attachment
"
);
o
.
jio
.
get
(
"
file/attmt
"
,
o
.
f
);
o
.
tick
(
o
);
// remove document
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
file
"
},
"
Remove document
"
);
o
.
jio
.
remove
({
"
_id
"
:
"
file
"
},
o
.
f
);
o
.
tick
(
o
);
// remove attachment
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
file/attmt
"
},
"
Remove attachment
"
);
o
.
jio
.
remove
({
"
_id
"
:
"
file/attmt
"
},
o
.
f
);
o
.
tick
(
o
);
// alldocs
// error 405 -> Method not allowed
o
.
spy
(
o
,
"
status
"
,
405
,
"
AllDocs fail
"
);
o
.
jio
.
allDocs
(
o
.
f
);
o
.
tick
(
o
);
o.jio = JIO.newJio({'type':'dummyallok'});
// save
o.spy(o,'value',{ok:true,id:'file'},'dummyallok saving1','f');
o.spy(o,'value',{ok:true,id:'file2'},'dummyallok saving2','f2');
o.spy(o,'value',{ok:true,id:'file3'},'dummyallok saving3','f3');
o.jio.put({_id:'file',content:'content'},o.f);
o.jio.put({_id:'file2',content:'content2'},o.f2);
o.jio.put({_id:'file3',content:'content3'},o.f3);
o.tick(o, 1000, 'f');
o.tick(o, 'f2');
o.tick(o, 'f3');
o
.
jio
.
stop
();
o
.
jio
.
stop
();
});
test
(
"
All requests fail
"
,
function
()
{
// Tests the request methods and the err object with dummy storages
// All Fail Dummy Storage
var
o
=
generateTools
(
this
);
o.jio = JIO.newJio({'type':'dummyallfail'});
// save
// All Ok Dummy Storage
o.spy (o,'status',0,'dummyallfail saving');
o
.
jio
=
JIO
.
newJio
({
"
type
"
:
"
dummyallfail
"
});
o.jio.put({_id:'file',content:'content'},o.f);
// post empty document
// error 0 -> unknown
o
.
spy
(
o
,
"
status
"
,
0
,
"
Post document with empty id
"
);
o
.
jio
.
post
({},
o
.
f
);
o
.
tick
(
o
);
// test if the job still exists
if
(
getLastJob
(
o
.
jio
.
getId
())
!==
undefined
)
{
ok
(
false
,
"
The job is not removed from the job queue
"
);
}
// post non empty document
o
.
spy
(
o
,
"
status
"
,
0
,
"
Post non empty document
"
);
o
.
jio
.
post
({
"
_id
"
:
"
file
"
,
"
title
"
:
"
myFile
"
},
o
.
f
);
o
.
tick
(
o
);
o
.
tick
(
o
);
// load
o.spy (o,'status',0,'dummyallfail loading');
// put without id
o.jio.get('file',o.f);
// error 20 -> document id required
o
.
spy
(
o
,
"
status
"
,
20
,
"
Put document with empty id
"
);
o
.
jio
.
put
({},
o
.
f
);
o
.
tick
(
o
);
o
.
tick
(
o
);
// remove
o.spy (o,'status',0,'dummyallfail removing');
// put non empty document
o.jio.remove({_id:'file'},o.f);
o
.
spy
(
o
,
"
status
"
,
0
,
"
Put non empty document
"
);
o
.
jio
.
put
({
"
_id
"
:
"
file
"
,
"
title
"
:
"
myFile
"
},
o
.
f
);
o
.
tick
(
o
);
// put an attachment without attachment id
// error 22 -> attachment id required
o
.
spy
(
o
,
"
status
"
,
22
,
"
Put attachment without id
"
);
o
.
jio
.
putAttachment
({
"
id
"
:
"
file
"
,
"
data
"
:
"
0123456789
"
,
"
mimetype
"
:
"
text/plain
"
},
o
.
f
);
o
.
tick
(
o
);
// put an attachment
o
.
spy
(
o
,
"
status
"
,
0
,
"
Put attachment
"
);
o
.
jio
.
putAttachment
({
"
id
"
:
"
file/attmt
"
,
"
data
"
:
"
0123456789
"
,
"
mimetype
"
:
"
text/plain
"
},
o
.
f
);
o
.
tick
(
o
);
// get document
o
.
spy
(
o
,
"
status
"
,
0
,
"
Get document
"
);
o
.
jio
.
get
(
"
file
"
,
o
.
f
);
o
.
tick
(
o
);
o
.
tick
(
o
);
// get list
o.spy (o,'status',0,'dummyallfail getting list');
// get attachment
o
.
spy
(
o
,
"
status
"
,
0
,
"
Get attachment
"
);
o
.
jio
.
get
(
"
file/attmt
"
,
o
.
f
);
o
.
tick
(
o
);
// remove document
o
.
spy
(
o
,
"
status
"
,
0
,
"
Remove document
"
);
o
.
jio
.
remove
({
"
_id
"
:
"
file
"
},
o
.
f
);
o
.
tick
(
o
);
// remove attachment
o
.
spy
(
o
,
"
status
"
,
0
,
"
Remove attachment
"
);
o
.
jio
.
remove
({
"
_id
"
:
"
file/attmt
"
},
o
.
f
);
o
.
tick
(
o
);
// alldocs
// error 405 -> Method not allowed
o
.
spy
(
o
,
"
status
"
,
405
,
"
AllDocs fail
"
);
o
.
jio
.
allDocs
(
o
.
f
);
o
.
jio
.
allDocs
(
o
.
f
);
o
.
tick
(
o
);
o
.
tick
(
o
);
o
.
jio
.
stop
();
o
.
jio
.
stop
();
});
// All Not Found Dummy Storage
test
(
"
All document not found
"
,
function
()
{
o.jio = JIO.newJio({'type':'dummyallnotfound'});
// Tests the request methods without document
// save
o.spy(o,'value',{ok:true,id:'file'},'dummyallnotfound saving');
var
o
=
generateTools
(
this
);
o.jio.put({_id:'file',content:'content'},o.f);
// All Ok Dummy Storage
o
.
jio
=
JIO
.
newJio
({
"
type
"
:
"
dummyallnotfound
"
});
// post document
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
file
"
},
"
Post document
"
);
o
.
jio
.
post
({
"
_id
"
:
"
file
"
,
"
title
"
:
"
myFile
"
},
o
.
f
);
o
.
tick
(
o
);
o
.
tick
(
o
);
// load
o.spy(o,'status',404,'dummyallnotfound loading')
// put document
o.jio.get('file',o.f);
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
file
"
},
"
Put document
"
);
o
.
jio
.
put
({
"
_id
"
:
"
file
"
,
"
title
"
:
"
myFile
"
},
o
.
f
);
o
.
tick
(
o
);
o
.
tick
(
o
);
// remove
o.spy(o,'value',{ok:true,id:'file'},'dummyallnotfound removing');
// put an attachment without attachment id
o.jio.remove({_id:'file'},o.f);
// error 22 -> attachment id required
o
.
spy
(
o
,
"
status
"
,
22
,
"
Put attachment without id
"
);
o
.
jio
.
putAttachment
({
"
id
"
:
"
file
"
,
"
data
"
:
"
0123456789
"
,
"
mimetype
"
:
"
text/plain
"
},
o
.
f
);
o
.
tick
(
o
);
// put an attachment
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
file/attmt
"
},
"
Put attachment
"
);
o
.
jio
.
putAttachment
({
"
id
"
:
"
file/attmt
"
,
"
data
"
:
"
0123456789
"
,
"
mimetype
"
:
"
text/plain
"
},
o
.
f
);
o
.
tick
(
o
);
// get document
o
.
spy
(
o
,
"
status
"
,
404
,
"
Get document
"
);
o
.
jio
.
get
(
"
file
"
,
o
.
f
);
o
.
tick
(
o
);
// get attachment
o
.
spy
(
o
,
"
status
"
,
404
,
"
Get attachment
"
);
o
.
jio
.
get
(
"
file/attmt
"
,
o
.
f
);
o
.
tick
(
o
);
o
.
tick
(
o
);
// get list
o.spy(o,'status',404,'dummyallnotfound getting list');
// remove document
o.jio.allDocs (o.f);
o
.
spy
(
o
,
"
status
"
,
404
,
"
Remove document
"
);
o
.
jio
.
remove
({
"
_id
"
:
"
file
"
},
o
.
f
);
o
.
tick
(
o
);
o
.
tick
(
o
);
// remove attachment
o
.
spy
(
o
,
"
status
"
,
404
,
"
Remove attachment
"
);
o
.
jio
.
remove
({
"
_id
"
:
"
file/attmt
"
},
o
.
f
);
o
.
tick
(
o
);
o
.
jio
.
stop
();
o
.
jio
.
stop
();
});
test
(
"
All document found
"
,
function
()
{
// Tests the request methods with document
var
o
=
generateTools
(
this
);
// All Ok Dummy Storage
o
.
jio
=
JIO
.
newJio
({
"
type
"
:
"
dummyallfound
"
});
// post non empty document
o
.
spy
(
o
,
"
status
"
,
409
,
"
Post document
"
);
o
.
jio
.
post
({
"
_id
"
:
"
file
"
,
"
title
"
:
"
myFile
"
},
o
.
f
);
o
.
tick
(
o
);
*/
// put non empty document
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
file
"
},
"
Put non empty document
"
);
o
.
jio
.
put
({
"
_id
"
:
"
file
"
,
"
title
"
:
"
myFile
"
},
o
.
f
);
o
.
tick
(
o
);
// put an attachment without attachment id
// error 22 -> attachment id required
o
.
spy
(
o
,
"
status
"
,
22
,
"
Put attachment without id
"
);
o
.
jio
.
putAttachment
({
"
id
"
:
"
file
"
,
"
data
"
:
"
0123456789
"
,
"
mimetype
"
:
"
text/plain
"
},
o
.
f
);
o
.
tick
(
o
);
// put an attachment
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
file/attmt
"
},
"
Put attachment
"
);
o
.
jio
.
putAttachment
({
"
id
"
:
"
file/attmt
"
,
"
data
"
:
"
0123456789
"
,
"
mimetype
"
:
"
text/plain
"
},
o
.
f
);
o
.
tick
(
o
);
// get document
o
.
spy
(
o
,
"
value
"
,
{
"
_id
"
:
"
file
"
,
"
title
"
:
"
get_title
"
},
"
Get document
"
);
o
.
jio
.
get
(
"
file
"
,
o
.
f
);
o
.
tick
(
o
);
// get attachment
o
.
spy
(
o
,
"
value
"
,
"
0123456789
"
,
"
Get attachment
"
);
o
.
jio
.
get
(
"
file/attmt
"
,
o
.
f
);
o
.
tick
(
o
);
// remove document
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
file
"
},
"
Remove document
"
);
o
.
jio
.
remove
({
"
_id
"
:
"
file
"
},
o
.
f
);
o
.
tick
(
o
);
// remove attachment
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
file/attmt
"
},
"
Remove attachment
"
);
o
.
jio
.
remove
({
"
_id
"
:
"
file/attmt
"
},
o
.
f
);
o
.
tick
(
o
);
o
.
jio
.
stop
();
});
});
/*
module (
'Jio Job Managing'
);
module
(
"
Jio Job Managing
"
);
test (
'Simple Job Elimination'
, function () {
test
(
"
Several Jobs at the same time
"
,
function
()
{
var clock = this.sandbox.useFakeTimers(); clock.tick(base_tick);
var o =
{}, id = 0
;
var
o
=
generateTools
(
this
)
;
o.f1 = this.spy(); o.f2 = this.spy();
o
.
jio
=
JIO
.
newJio
({
"
type
"
:
"
dummyallok
"
});
o.
jio = JIO.newJio({type:'dummyallok',applicationname:'jiotests'}
);
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
file
"
},
"
job1
"
,
"
f
"
);
id = o.jio.getId(
);
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
file2
"
},
"
job2
"
,
"
f2
"
);
o.
jio.put({_id:'file',content:'content'},
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
file3
"
},
"
job3
"
,
"
f3
"
);
{max_retry:1},o.f1
);
o
.
jio
.
put
({
"
_id
"
:
"
file
"
,
"
content
"
:
"
content
"
},
o
.
f
);
o
k(LocalOrCookieStorage.getItem('jio/job_array/'+id)[0],
o
.
jio
.
put
({
"
_id
"
:
"
file2
"
,
"
content
"
:
"
content2
"
},
o
.
f2
);
'job creation'
);
o
.
jio
.
put
({
"
_id
"
:
"
file3
"
,
"
content
"
:
"
content3
"
},
o
.
f3
);
o.
jio.remove({_id:'file'},{max_retry:1},o.f2
);
o
.
tick
(
o
,
1000
,
"
f
"
);
o.t
mp = LocalOrCookieStorage.getItem('jio/job_array/'+id)[0]
;
o
.
t
ick
(
o
,
"
f2
"
)
;
deepEqual(o.tmp.command.label,'remove','job elimination'
);
o
.
tick
(
o
,
"
f3
"
);
o
.
jio
.
stop
();
o
.
jio
.
stop
();
});
});
test ('Simple Job Replacement', function () {
test
(
"
Similar Jobs at the same time (Replace)
"
,
function
()
{
// Test if the second job write over the first one
var o = {};
var
o
=
generateTools
(
this
);
o.clock = this.sandbox.useFakeTimers();
o.clock.tick(base_tick);
o
.
jio
=
JIO
.
newJio
({
"
type
"
:
"
dummyallok
"
});
o.id = 0;
o
.
spy
(
o
,
"
status
"
,
12
,
"
job1 replaced
"
,
"
f
"
);
o.f1 = function (err,val) {
o
.
spy
(
o
,
"
status
"
,
12
,
"
job2 replaced
"
,
"
f2
"
);
if (err) {
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
file
"
},
"
job3 ok
"
,
"
f3
"
);
o.err = err;
o
.
jio
.
put
({
"
_id
"
:
"
file
"
,
"
content
"
:
"
content
"
},
o
.
f
);
} else {
o
.
jio
.
put
({
"
_id
"
:
"
file
"
,
"
content
"
:
"
content
"
},
o
.
f2
);
o.err = {status:'done'};
o
.
jio
.
put
({
"
_id
"
:
"
file
"
,
"
content
"
:
"
content
"
},
o
.
f3
);
}
o
.
tick
(
o
,
1000
,
"
f
"
);
};
o
.
tick
(
o
,
"
f2
"
);
this.spy(o,'f1');
o
.
tick
(
o
,
"
f3
"
);
o.f2 = this.spy();
o.jio = JIO.newJio({type:'dummyallok',applicationname:'jiotests'});
o.id = o.jio.getId();
o.jio.put({_id:'file',content:'content'},o.f1);
o.clock.tick(10);
o.jio.put({_id:'file',content:'content'},o.f2);
deepEqual(LocalOrCookieStorage.getItem(
'jio/job_array/'+o.id)[0].date,base_tick + 10,
'The first job date have to be equal to the second job date.');
o.clock.tick(1000);
deepEqual([o.f1.calledOnce,o.err.status],[true,12],
'callback for the first save request -> result fail');
ok(o.f2.calledOnce,'second callback is called once');
o
.
jio
.
stop
();
o
.
jio
.
stop
();
o.jio = JIO.newJio({type:'dummyallok',applicationname:'jiotests'});
});
o.ok1 = 0;
o.jio.get('file1',function (err,val) {
test
(
"
One document aim jobs at the same time (Wait for job(s))
"
,
function
()
{
deepEqual (err || val,
{_id:'file1',content:'content',
var
o
=
generateTools
(
this
);
_creation_date:10000,_last_modified:15000},
'First load');
o
.
jio
=
JIO
.
newJio
({
"
type
"
:
"
dummyallok
"
});
o.ok1 ++;
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
file
"
},
"
job1
"
,
"
f
"
);
});
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
file
"
},
"
job2
"
,
"
f2
"
);
o.ok2 = 0;
o
.
spy
(
o
,
"
value
"
,
{
"
_id
"
:
"
file
"
,
"
title
"
:
"
get_title
"
},
"
job3
"
,
"
f3
"
);
o.jio.get('file2',function (err,val) {
deepEqual (err || val,
o
.
jio
.
post
({
"
_id
"
:
"
file
"
,
"
content
"
:
"
content
"
},
o
.
f
);
{_id:'file2',content:'content',
o
.
testLastJobWaitForJob
(
undefined
,
"
job1 is not waiting for someone
"
);
_creation_date:10000,_last_modified:15000},
'Second load must not replace the first one');
o
.
jio
.
put
({
"
_id
"
:
"
file
"
,
"
content
"
:
"
content
"
},
o
.
f2
);
o.ok2 ++;
o
.
testLastJobWaitForJob
([
1
],
"
job2 is waiting
"
);
});
o.clock.tick(1000);
o
.
jio
.
get
(
"
file
"
,
o
.
f3
);
if (o.ok1 !== 1) {
o
.
testLastJobWaitForJob
([
1
,
2
],
"
job3 is waiting
"
);
ok (false,'no response / too much response');
}
o
.
tick
(
o
,
1000
,
"
f
"
);
if (o.ok2 !== 1) {
o
.
tick
(
o
,
"
f2
"
);
ok (false,'no response / too much response');
o
.
tick
(
o
,
"
f3
"
);
}
o
.
jio
.
stop
();
o
.
jio
.
stop
();
});
});
test ('Simple Job Waiting', function () {
test
(
"
One document aim jobs at the same time (Elimination)
"
,
function
()
{
// Test if the second job doesn't erase the first on going one
var o = {};
var
o
=
generateTools
(
this
);
o.clock = this.sandbox.useFakeTimers();
o.clock.tick(base_tick);
o.id = 0;
o.f = function (err,val) {
deepEqual(err || val,{ok:true,id:'file'},'job 1 result');
};
o.f3 = o.f; this.spy(o,'f3');
o.f4 = o.f; this.spy(o,'f4');
o.checkCallback = function (fun_name,message) {
if (!o[fun_name].calledOnce) {
if (o[fun_name].called) {
ok(false, 'too much response');
} else {
ok(false, 'no response');
}
} else {
ok(true,message);
}
};
o.jio = JIO.newJio({type:'dummyallok',applicationname:'jiotests'});
o
.
jio
=
JIO
.
newJio
({
"
type
"
:
"
dummyallok
"
});
o.id = o.jio.getId();
o
.
spy
(
o
,
"
status
"
,
10
,
"
job1 stopped
"
,
"
f
"
);
o.jio.put({_id:'file',content:'content'},o.f3);
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
file
"
},
"
job2
"
,
"
f2
"
);
o.clock.tick(200);
o.jio.put({_id:'file',content:'content1'},o.f4);
o.
tmp0 = LocalOrCookieStorage.getItem('jio/job_array/'+o.id)[0]
;
o
.
jio
.
post
({
"
_id
"
:
"
file
"
,
"
content
"
:
"
content
"
},
o
.
f
)
;
o.t
mp1 = LocalOrCookieStorage.getItem('jio/job_array/'+o.id)[1]
;
o
.
t
estLastJobLabel
(
"
post
"
,
"
job1 exists
"
)
;
ok(o.tmp0 && o.tmp0.id === 1,'job 1 exists');
o
.
jio
.
remove
({
"
_id
"
:
"
file
"
},
o
.
f2
);
deepEqual(o.tmp0.status.label,'on going','job 1 is on going');
o
.
testLastJobLabel
(
"
remove
"
,
"
job1 does not exist anymore
"
);
ok(o.tmp1 && o.tmp1.id === 2,'job 2 exists');
deepEqual(o.tmp1.status.label,'wait','job 2 waiting');
deepEqual(o.tmp1.status.waitforjob,[1],
'job 2 must wait for the first to end');
o.clock.tick(1000);
o
.
tick
(
o
,
1000
,
"
f
"
);
o.checkCallback('f3','first request passed');
o
.
tick
(
o
,
"
f2
"
);
o.checkCallback('f4','restore waiting job');
o
.
jio
.
stop
();
});
test
(
"
One document aim jobs at the same time (Not Acceptable)
"
,
function
()
{
var
o
=
generateTools
(
this
);
o
.
jio
=
JIO
.
newJio
({
"
type
"
:
"
dummyallok
"
});
o
.
spy
(
o
,
"
value
"
,
{
"
_id
"
:
"
file
"
,
"
title
"
:
"
get_title
"
},
"
job1
"
,
"
f
"
);
o
.
spy
(
o
,
"
status
"
,
11
,
"
job2 is not acceptable
"
,
"
f2
"
);
o
.
jio
.
get
(
"
file
"
,
o
.
f
);
o
.
testLastJobId
(
1
,
"
job1 added to queue
"
);
o
.
waitUntilLastJobIs
(
"
on going
"
);
o
.
jio
.
get
(
"
file
"
,
o
.
f2
);
o
.
testLastJobId
(
1
,
"
job2 not added
"
);
o
.
tick
(
o
,
1000
,
"
f
"
);
o
.
tick
(
o
,
"
f2
"
);
o
.
jio
.
stop
();
o
.
jio
.
stop
();
});
});
test ('Simple Time Waiting' , function () {
test
(
"
Server will be available soon (Wait for time)
"
,
function
()
{
// Test if the job that have fail wait until a certain moment to restart.
// It will use the dummyall3tries, which will work after the 3rd try.
var o = {}, clock = this.sandbox.useFakeTimers(), id = 0;
var
o
=
generateTools
(
this
);
clock.tick(base_tick);
o
.
max_retry
=
3
;
o.f = function (err,val) {
if (err) {
o
.
jio
=
JIO
.
newJio
({
"
type
"
:
"
dummyall3tries
"
});
o.res = err;
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
file
"
},
"
job1
"
,
"
f
"
);
} else {
o.res = val;
o
.
jio
.
put
({
"
_id
"
:
"
file
"
,
"
content
"
:
"
content
"
},
}
{
"
max_retry
"
:
o
.
max_retry
},
o
.
f
);
};
for
(
o
.
i
=
0
;
o
.
i
<
o
.
max_retry
-
1
;
o
.
i
+=
1
)
{
this.spy(o,'f');
o
.
waitUntilLastJobIs
(
"
on going
"
);
o.jio = JIO.newJio({type:'dummyall3tries',applicationname:'jiotests'});
o
.
waitUntilLastJobIs
(
"
wait
"
);
o.jio.put({_id:'file',content:'content'},{max_retry:3},o.f);
o
.
testLastJobWaitForTime
(
"
job1 is waiting for time
"
);
clock.tick(10000);
if (!o.f.calledOnce) {
if (o.f.called) {
ok(false,'callback called too much times.');
} else {
ok(false,'no response.');
}
}
}
deepEqual(o.res,{ok:true,id:'file'},'job done.');
o
.
tick
(
o
,
1000
,
"
f
"
);
o
.
jio
.
stop
();
o
.
jio
.
stop
();
});
});
module (
'Jio Restore'
);
module
(
"
Jio Restore
"
);
test ('Restore old Jio', function() {
test
(
"
Restore old Jio
"
,
function
()
{
var o = {};
o.clock = this.sandbox.useFakeTimers();
var
o
=
generateTools
(
this
);
o.f = function() {
ok(false,'must never be called!');
o
.
jio
=
JIO
.
newJio
({
};
"
type
"
:
"
dummyall3tries
"
,
this.spy(o,'f');
"
applicationname
"
:
"
jiotests
"
o.jio = JIO.newJio({type:'dummyall3tries',applicationname:'jiotests'});
});
o.id = o.jio.getId();
ok(true,'create jio, id = ' + o.id);
o
.
jio_id
=
o
.
jio
.
getId
();
o.jio.put({_id:'file',content:'content'},{max_retry:3},o.f);
o.clock.tick(1000);
o
.
jio
.
put
({
"
_id
"
:
"
file
"
,
"
title
"
:
"
myFile
"
},
{
"
max_retry
"
:
3
},
o
.
f
);
o
.
waitUntilLastJobIs
(
"
on going
"
);
o
.
jio
.
close
();
o
.
jio
.
close
();
o.jio = JIO.newJio({type:'dummyallok',applicationname:'jiotests'});
o.clock.tick(11000); // 10 sec
o
.
jio
=
JIO
.
newJio
({
deepEqual(LocalOrCookieStorage.getItem('jio/job_array/'+o.id),null,
"
type
"
:
"
dummyallok
"
,
'job array list must be empty');
"
applicationname
"
:
"
jiotests
"
o.tmp1 = LocalOrCookieStorage.getItem('jio/job_array/'+o.jio.getId());
});
if (o.tmp1.length > 0) {
o
.
waitUntilAJobExists
(
30000
);
// timeout 30 sec
deepEqual([o.tmp1[0].command.label,o.tmp1[0].command.doc._id,
o
.
testLastJobLabel
(
"
put
"
,
"
Job restored
"
);
o.tmp1[0].command.doc.content],
o
.
clock
.
tick
(
1000
);
['put','file','content'],
ok
(
getLastJob
(
o
.
jio
.
getId
())
===
undefined
,
'job which id is id = ' +o.jio.getId()+', restored the jio');
"
Job executed
"
);
} else {
ok (false, 'The recovered job must exists');
}
o
.
jio
.
stop
();
o
.
jio
.
stop
();
});
});
*/
module
(
"
Jio LocalStorage
"
);
module
(
'
Jio LocalStorage
'
);
test
(
"
Post
"
,
function
(){
// ============================== POST ==========================
var
o
=
generateTools
(
this
);
test
(
'
Post
'
,
function
(){
// runs following assertions
o
.
jio
=
JIO
.
newJio
({
// 1) POST with id - should be an error
"
type
"
:
"
local
"
,
// 2) POST with attachment - should be an error
"
username
"
:
"
upost
"
,
// 3) POST CREATE with content
"
applicationname
"
:
"
apost
"
// 4) check that document is created with UUID.revision
});
// 5) check that document revision tree is created
// 6) POST UPDATE
var
o
=
{};
// post without id
o
.
t
=
this
;
o
.
spy
(
o
,
"
status
"
,
405
,
"
Post without id
"
);
o
.
clock
=
o
.
t
.
sandbox
.
useFakeTimers
(),
o
.
jio
.
post
({},
o
.
f
);
localstorage
=
{
o
.
tick
(
o
);
getItem
:
function
(
item
)
{
return
JSON
.
parse
(
localStorage
.
getItem
(
item
));
// post non empty document
},
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
post1
"
},
"
Post
"
);
setItem
:
function
(
item
,
value
)
{
o
.
jio
.
post
({
"
_id
"
:
"
post1
"
,
"
title
"
:
"
myPost1
"
},
o
.
f
);
return
localStorage
.
setItem
(
item
,
JSON
.
stringify
(
value
));
o
.
tick
(
o
);
deepEqual
(
localstorage
.
getItem
(
"
jio/localstorage/upost/apost/post1
"
),
{
"
_id
"
:
"
post1
"
,
"
title
"
:
"
myPost1
"
},
},
deleteItem
:
function
(
item
)
{
"
Check document
"
delete
localStorage
[
item
];
);
}
};
// post but document already exists
o
.
spy
(
o
,
"
status
"
,
409
,
"
Post but document already exists
"
);
o
.
jio
.
post
({
"
_id
"
:
"
post1
"
,
"
title
"
:
"
myPost2
"
},
o
.
f
);
o
.
tick
(
o
);
o
.
clock
.
tick
(
base_tick
);
o
.
spy
=
basic_spy_function
;
o
.
clean
=
clean_up_local_storage_function
();
o
.
username
=
'
MrPost
'
;
o
.
testRevisionStorage
=
[];
// let's go
o
.
jio
=
JIO
.
newJio
({
type
:
'
local
'
,
username
:
o
.
username
,
applicationname
:
'
jiotests
'
});
// ========================================
// 1) POST with id
o
.
jio
.
post
({
"
_id
"
:
'
file
'
,
"
content
"
:
'
content
'
},
function
(
err
,
response
){
o
.
spy
(
o
,
'
value
'
,{
"
error
"
:
'
forbidden
'
,
"
message
"
:
'
Forbidden
'
,
"
reason
"
:
'
ID cannot be supplied with a POST request. Please use PUT
'
,
"
status
"
:
403
,
"
statusText
"
:
'
Forbidden
'
},
'
POST with id = 403 forbidden
'
);
o
.
f
(
err
);
});
checkReply
(
o
,
null
,
true
);
o
.
clock
.
tick
(
base_tick
);
// ========================================
// 2) POST attachment
o
.
jio
.
post
({
"
_id
"
:
'
file/ABC
'
,
"
mimetype
"
:
'
text/html
'
,
"
content
"
:
'
<b>hello</b>
'
},
function
(
err
,
response
){
o
.
spy
(
o
,
'
value
'
,{
"
error
"
:
'
forbidden
'
,
"
message
"
:
'
Forbidden
'
,
"
reason
"
:
'
Attachment cannot be added with a POST request
'
,
"
status
"
:
403
,
"
statusText
"
:
'
Forbidden
'
},
'
POST attachment = 403 forbidden
'
);
o
.
f
(
err
);
});
checkReply
(
o
,
null
,
true
);
o
.
clock
.
tick
(
base_tick
);
// ========================================
// 3) POST content
o
.
jio
.
post
({
"
content
"
:
'
content
'
},
function
(
err
,
response
)
{
o
.
spy
(
o
,
'
value
'
,{
"
ok
"
:
true
,
"
id
"
:
response
.
id
,
"
rev
"
:
response
.
rev
},
'
POST content = ok
'
);
o
.
f
(
response
);
// store falseRevision
o
.
falseRevision
=
response
.
rev
;
// build tree manually
o
.
testRevisionStorage
.
push
(
response
.
rev
);
o
.
buildTestTree
=
{
"
kids
"
:[],
"
rev
"
:
o
.
testRevisionStorage
[
0
],
"
status
"
:
'
available
'
,
"
type
"
:
'
leaf
'
};
// 4) check if document is created and correct
checkFile
(
response
,
o
,
null
,
true
);
// 5) check if document tree is created and correct
checkTreeNode
(
response
,
o
,
null
,
true
);
});
checkReply
(
o
,
null
,
true
);
o
.
clock
.
tick
(
base_tick
);
// END POST
o
.
jio
.
stop
();
o
.
jio
.
stop
();
o
.
clean
;
});
});
// ============================== PUT ==========================
test
(
"
Put
"
,
function
(){
test
(
'
Put
'
,
function
(){
var
o
=
generateTools
(
this
);
// runs following assertions
// 1) PUT without ID = 409
o
.
jio
=
JIO
.
newJio
({
// 2) PUT with wrong ID/rev = 404
"
type
"
:
"
local
"
,
// 3) PUT CREATE response
"
username
"
:
"
uput
"
,
// 4) check file was created
"
applicationname
"
:
"
aput
"
// 5) check tree was created
});
// 6) PUT UPDATE response
// 7) check file was replaced
// put without id
// 8) check tree was updated
o
.
spy
(
o
,
"
status
"
,
20
,
"
Put without id
"
);
// 9) PUT UPDATE 2 response
o
.
jio
.
put
({},
o
.
f
);
// 10) check file was replaced
o
.
tick
(
o
);
// 11) check tree was updated
// 12) PUT UPDATE false revision = 409
// put non empty document
// 13) SYNC-PUT no revs_info = 409
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
put1
"
},
"
Creates a document
"
);
// 14) SYNC-PUT revs_info response
o
.
jio
.
put
({
"
_id
"
:
"
put1
"
,
"
title
"
:
"
myPut1
"
},
o
.
f
);
// 15) check if file created
o
.
tick
(
o
);
// 16) check if tree was merged
// 17) SYNC-PUT revs_info dead leaf response
// check document
// 18) check that file was NOT created
deepEqual
(
// 19) check that tree was updated
localstorage
.
getItem
(
"
jio/localstorage/uput/aput/put1
"
),
{
var
fake_rev_0
,
"
_id
"
:
"
put1
"
,
fake_rev_1
,
"
title
"
:
"
myPut1
"
fake_rev_2
,
fake_id_0
,
fake_id_1
,
fake_id_2
,
o
=
{};
o
.
t
=
this
;
o
.
clock
=
o
.
t
.
sandbox
.
useFakeTimers
();
o
.
falseRevision
;
localstorage
=
{
getItem
:
function
(
item
)
{
return
JSON
.
parse
(
localStorage
.
getItem
(
item
));
},
},
setItem
:
function
(
item
,
value
)
{
"
Check document
"
return
localStorage
.
setItem
(
item
,
JSON
.
stringify
(
value
));
);
// put but document already exists
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
put1
"
},
"
Update the document
"
);
o
.
jio
.
put
({
"
_id
"
:
"
put1
"
,
"
title
"
:
"
myPut2
"
},
o
.
f
);
o
.
tick
(
o
);
// check document
deepEqual
(
localstorage
.
getItem
(
"
jio/localstorage/uput/aput/put1
"
),
{
"
_id
"
:
"
put1
"
,
"
title
"
:
"
myPut2
"
},
},
deleteItem
:
function
(
item
)
{
"
Check document
"
delete
localStorage
[
item
];
);
}
};
o
.
clock
.
tick
(
base_tick
);
o
.
jio
.
stop
();
o
.
spy
=
basic_spy_function
;
o
.
clean
=
clean_up_local_storage_function
();
o
.
username
=
'
MrPutt
'
;
o
.
testRevisionStorage
=
[];
// let's go
o
.
jio
=
JIO
.
newJio
({
type
:
'
local
'
,
username
:
o
.
username
,
applicationname
:
'
jiotests
'
});
// ========================================
// 1) PUT without ID
o
.
jio
.
put
({
"
content
"
:
'
content
'
},
function
(
err
,
response
){
o
.
spy
(
o
,
'
value
'
,{
"
error
"
:
'
conflict
'
,
"
message
"
:
'
Document update conflict.
'
,
"
reason
"
:
'
Missing Document ID and or Revision
'
,
"
status
"
:
409
,
"
statusText
"
:
'
Conflict
'
},
'
PUT without id = 409 Conflict
'
);
o
.
f
(
err
);
});
checkReply
(
o
,
null
,
true
);
o
.
clock
.
tick
(
base_tick
);
// ========================================
// 2) PUT wrong id/rev
o
.
jio
.
put
({
"
content
"
:
'
content
'
,
"
_id
"
:
'
myDoc
'
,
"
_rev
"
:
'
1-ABCDEFG
'
},
function
(
err
,
response
){
o
.
spy
(
o
,
'
value
'
,{
"
error
"
:
'
not found
'
,
"
message
"
:
'
Document not found.
'
,
"
reason
"
:
'
Document not found, please check revision and/or ID
'
,
"
status
"
:
404
,
"
statusText
"
:
'
Not found
'
},
'
PUT with wrong id/revision = 404 Not found
'
);
o
.
f
(
err
);
});
checkReply
(
o
,
null
,
true
);
o
.
clock
.
tick
(
base_tick
);
// ========================================
// 3) PUT content
o
.
jio
.
put
({
"
content
"
:
'
content
'
,
"
_id
"
:
'
myDoc
'
},
function
(
err
,
response
)
{
o
.
spy
(
o
,
'
value
'
,{
"
ok
"
:
true
,
"
id
"
:
response
.
id
,
"
rev
"
:
response
.
rev
},
'
PUT content = ok
'
);
o
.
f
(
response
);
o
.
falseRevision
=
response
.
rev
;
o
.
testRevisionStorage
.
unshift
(
response
.
rev
);
o
.
buildTestTree
=
{
"
kids
"
:[],
"
rev
"
:
o
.
testRevisionStorage
[
0
],
"
status
"
:
'
available
'
,
"
type
"
:
'
leaf
'
};
// ========================================
// 4) check file was created
checkFile
(
response
,
o
,
null
,
true
);
// ========================================
// 5) check tree was created
checkTreeNode
(
response
,
o
,
null
,
true
);
});
checkReply
(
o
,
null
,
true
);
o
.
clock
.
tick
(
base_tick
);
// ========================================
// 6) PUT UPDATE (modify content)
o
.
jio
.
put
({
"
content
"
:
'
content_modified
'
,
"
_id
"
:
'
myDoc
'
,
"
_rev
"
:
o
.
testRevisionStorage
[
0
]},
function
(
err
,
response
)
{
o
.
spy
(
o
,
'
value
'
,{
"
ok
"
:
true
,
"
id
"
:
response
.
id
,
"
rev
"
:
response
.
rev
},
'
PUT content = ok
'
);
o
.
f
(
response
);
o
.
testRevisionStorage
.
unshift
(
response
.
rev
);
o
.
buildTestTree
=
{
"
kids
"
:[{
"
kids
"
:[],
"
rev
"
:
o
.
testRevisionStorage
[
0
],
"
status
"
:
'
available
'
,
"
type
"
:
'
leaf
'
}],
"
rev
"
:
o
.
testRevisionStorage
[
1
],
"
status
"
:
'
deleted
'
,
"
type
"
:
'
branch
'
};
// ========================================
// 7) check document was replaced
checkFile
(
response
,
o
,
null
,
true
);
// ========================================
// 8) check tree was updated
checkTreeNode
(
response
,
o
,
null
,
true
);
});
checkReply
(
o
,
null
,
true
);
o
.
clock
.
tick
(
base_tick
);
// ========================================
// 9. update document (modify again)
o
.
jio
.
put
({
"
content
"
:
'
content_modified_again
'
,
"
_id
"
:
'
myDoc
'
,
"
_rev
"
:
o
.
testRevisionStorage
[
0
]},
function
(
err
,
response
)
{
o
.
spy
(
o
,
'
value
'
,{
"
ok
"
:
true
,
"
id
"
:
response
.
id
,
"
rev
"
:
response
.
rev
},
'
PUT content = ok
'
);
o
.
f
(
response
);
o
.
testRevisionStorage
.
unshift
(
response
.
rev
);
o
.
buildTestTree
=
{
"
kids
"
:[{
"
kids
"
:[{
"
kids
"
:[],
"
rev
"
:
o
.
testRevisionStorage
[
0
],
"
status
"
:
'
available
'
,
"
type
"
:
'
leaf
'
}],
"
rev
"
:
o
.
testRevisionStorage
[
1
],
"
status
"
:
'
deleted
'
,
"
type
"
:
'
branch
'
}],
"
rev
"
:
o
.
testRevisionStorage
[
2
],
"
status
"
:
'
deleted
'
,
"
type
"
:
'
branch
'
};
// 10) check document was replaced
checkFile
(
response
,
o
,
null
,
true
);
// 11) check tree was updated
checkTreeNode
(
response
,
o
,
null
,
true
);
});
test
(
"
PutAttachment
"
,
function
(){
var
o
=
generateTools
(
this
);
o
.
jio
=
JIO
.
newJio
({
"
type
"
:
"
local
"
,
"
username
"
:
"
uputattmt
"
,
"
applicationname
"
:
"
aputattmt
"
});
});
checkReply
(
o
,
null
,
true
);
o
.
clock
.
tick
(
base_tick
);
// putAttachment without doc id
// ========================================
// error 20 -> document id required
// 12) PUT false revision
o
.
spy
(
o
,
"
status
"
,
20
,
"
PutAttachment without doc id
"
);
o
.
jio
.
put
({
"
content
"
:
'
content_modified_false
'
,
o
.
jio
.
putAttachment
({},
o
.
f
);
"
_id
"
:
'
myDoc
'
,
o
.
tick
(
o
);
"
_rev
"
:
o
.
falseRevision
},
function
(
err
,
response
){
o
.
spy
(
o
,
'
value
'
,{
// putAttachment without attmt id
"
error
"
:
'
conflict
'
,
// error 22 -> attachment id required
"
message
"
:
'
Document update conflict.
'
,
o
.
spy
(
o
,
"
status
"
,
22
,
"
PutAttachment without attmt id
"
);
"
reason
"
:
o
.
jio
.
putAttachment
({
"
id
"
:
"
putattmt1
"
},
o
.
f
);
'
Revision supplied is not the latest revision
'
,
o
.
tick
(
o
);
"
status
"
:
409
,
"
statusText
"
:
'
Conflict
'
// putAttachment without document
},
'
PUT false revision = 409 Conflict
'
);
// error 404 -> not found
o
.
f
(
err
);
o
.
spy
(
o
,
"
status
"
,
404
,
"
PutAttachment without document
"
);
});
o
.
jio
.
putAttachment
({
"
id
"
:
"
putattmt1/putattmt2
"
},
o
.
f
);
checkReply
(
o
,
null
,
true
);
o
.
tick
(
o
);
o
.
clock
.
tick
(
base_tick
);
// ========================================
// adding a document
// 13) SYNC-PUT no revs_info
localstorage
.
setItem
(
"
jio/localstorage/uputattmt/aputattmt/putattmt1
"
,
{
o
.
jio
.
put
({
"
content
"
:
'
content_modified_false
'
,
"
_id
"
:
"
putattmt1
"
,
"
_id
"
:
'
myDoc
'
,
"
title
"
:
"
myPutAttmt1
"
"
_rev
"
:
'
1-abcdefg
'
},
function
(
err
,
response
){
o
.
spy
(
o
,
'
value
'
,{
"
error
"
:
'
conflict
'
,
"
message
"
:
'
Document update conflict.
'
,
"
reason
"
:
'
Missing revs_info required for sync-put
'
,
"
status
"
:
409
,
"
statusText
"
:
'
Conflict
'
},
'
PUT no sync info = 409 Conflict
'
);
o
.
f
(
err
);
});
});
checkReply
(
o
,
null
,
true
);
o
.
clock
.
tick
(
base_tick
);
// add a new document version with fake revs_info
// putAttachment with document
// the new document has the same origin and first edit,
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
putattmt1/putattmt2
"
},
// then it was changed to a new version (3-a9d...),
"
PutAttachment with document, without data
"
);
// which was changed to a fourth version (4-b5bb...),
o
.
jio
.
putAttachment
({
"
id
"
:
"
putattmt1/putattmt2
"
},
o
.
f
);
// the tree must merge on o.testRevisionStorage[1]
o
.
tick
(
o
);
// and add the two new dummy revisions into the final
// tree. Also the new document should be stored
// check document
// in local storage.
deepEqual
(
fake_rev_2
=
o
.
testRevisionStorage
[
2
];
localstorage
.
getItem
(
"
jio/localstorage/uputattmt/aputattmt/putattmt1
"
),
fake_rev_1
=
o
.
testRevisionStorage
[
1
];
fake_rev_0
=
o
.
testRevisionStorage
[
0
];
fake_id_2
=
o
.
testRevisionStorage
[
2
].
split
(
'
-
'
)[
1
];
fake_id_1
=
o
.
testRevisionStorage
[
1
].
split
(
'
-
'
)[
1
];
fake_id_0
=
o
.
testRevisionStorage
[
0
].
split
(
'
-
'
)[
1
];
// ========================================
// 14) PUT UPDATE A TREE using revs_info
o
.
jio
.
put
({
"
content
"
:
'
a_new_version
'
,
"
_id
"
:
'
myDoc
'
,
"
_rev
"
:
"
4-b5bb2f1657ac5ac270c14b2335e51ef1ffccc0a7259e14bce46380d6c446eb89
"
,
"
_revs_info
"
:[
{
"
rev
"
:
"
4-b5bb2f1657ac5ac270c14b2335e51ef1ffccc0a7259e14bce46380d6c446eb89
"
,
"
status
"
:
"
available
"
},
{
"
rev
"
:
"
3-a9dac9ff5c8e1b2fce58e5397e9b6a8de729d5c6eff8f26a7b71df6348986123
"
,
"
status
"
:
"
deleted
"
},
{
"
rev
"
:
fake_rev_1
,
"
status
"
:
"
deleted
"
},
{
"
rev
"
:
fake_rev_0
,
"
status
"
:
"
deleted
"
}
],
"
_revisions
"
:{
"
start
"
:
4
,
"
ids
"
:[
"
b5bb2f1657ac5ac270c14b2335e51ef1ffccc0a7259e14bce46380d6c446eb89
"
,
"
a9dac9ff5c8e1b2fce58e5397e9b6a8de729d5c6eff8f26a7b71df6348986123
"
,
fake_id_1
,
fake_id_0
]}
},
function
(
err
,
response
)
{
o
.
buildTestTree
=
{
"
kids
"
:[
{
{
"
kids
"
:[
"
_id
"
:
"
putattmt1
"
,
{
"
kids
"
:[],
"
rev
"
:
o
.
testRevisionStorage
[
0
],
"
status
"
:
'
available
'
,
"
type
"
:
'
leaf
'
},
"
title
"
:
"
myPutAttmt1
"
,
{
"
kids
"
:[{
"
_attachments
"
:
{
"
kids
"
:[],
"
putattmt2
"
:
{
"
rev
"
:
"
4-b5bb2f1657ac5ac270c14b2335e51ef1ffccc0a7259e14bce46380d6c446eb89
"
,
"
length
"
:
0
,
"
status
"
:
'
available
'
,
"
type
"
:
'
leaf
'
// md5("")
}],
"
digest
"
:
"
md5-d41d8cd98f00b204e9800998ecf8427e
"
"
rev
"
:
"
3-a9dac9ff5c8e1b2fce58e5397e9b6a8de729d5c6eff8f26a7b71df6348986123
"
,
}
"
status
"
:
'
deleted
'
,
"
type
"
:
'
branch
'
}
}],
"
rev
"
:
o
.
testRevisionStorage
[
1
],
"
status
"
:
'
deleted
'
,
"
type
"
:
'
branch
'
}],
"
rev
"
:
o
.
testRevisionStorage
[
2
],
"
status
"
:
'
deleted
'
,
"
type
"
:
'
branch
'
};
o
.
spy
(
o
,
'
value
'
,{
"
ok
"
:
true
,
"
id
"
:
response
.
id
,
"
rev
"
:
response
.
rev
},
'
PUT SYNC = ok
'
);
o
.
f
(
response
);
// 15) check document was stored
checkFile
(
response
,
o
,
null
,
true
);
// 16) check tree was updated
checkTreeNode
(
response
,
o
,
null
,
true
);
});
checkReply
(
o
,
null
,
true
);
o
.
clock
.
tick
(
base_tick
);
// ========================================
// 17) PUT UPDATE (deleted tree)
o
.
jio
.
put
({
"
content
"
:
'
a_deleted_version
'
,
"
_id
"
:
'
myDoc
'
,
"
_rev
"
:
"
3-05210795b6aa8cb5e1e7f021960d233cf963f1052b1a41777ca1a2aff8fd4b61
"
,
"
_revs_info
"
:[
{
"
rev
"
:
"
3-05210795b6aa8cb5e1e7f021960d233cf963f1052b1a41777ca1a2aff8fd4b61
"
,
"
status
"
:
"
deleted
"
},
{
"
rev
"
:
"
2-67ac10df5b7e2582f2ea2344b01c68d461f44b98fef2c5cba5073cc3bdb5a844
"
,
"
status
"
:
"
deleted
"
},
{
"
rev
"
:
fake_rev_2
,
"
status
"
:
"
deleted
"
}
],
"
_revisions
"
:{
"
start
"
:
3
,
"
ids
"
:[
"
05210795b6aa8cb5e1e7f021960d233cf963f1052b1a41777ca1a2aff8fd4b61
"
,
"
67ac10df5b7e2582f2ea2344b01c68d461f44b98fef2c5cba5073cc3bdb5a844
"
,
fake_id_2
]}
},
function
(
err
,
response
)
{
o
.
buildTestTree
=
{
"
kids
"
:[{
"
kids
"
:[
{
"
kids
"
:[],
"
rev
"
:
o
.
testRevisionStorage
[
0
],
"
status
"
:
'
available
'
,
"
type
"
:
'
leaf
'
},
},
{
"
kids
"
:[{
"
Check document
"
"
kids
"
:[],
);
"
rev
"
:
"
4-b5bb2f1657ac5ac270c14b2335e51ef1ffccc0a7259e14bce46380d6c446eb89
"
,
"
status
"
:
'
available
'
,
"
type
"
:
'
leaf
'
// check attachment
}],
deepEqual
(
"
rev
"
:
"
3-a9dac9ff5c8e1b2fce58e5397e9b6a8de729d5c6eff8f26a7b71df6348986123
"
,
localstorage
.
getItem
(
"
status
"
:
'
deleted
'
,
"
jio/localstorage/uputattmt/aputattmt/putattmt1/putattmt2
"
),
"
type
"
:
'
branch
'
""
,
"
Check attachment
"
}],
);
"
rev
"
:
o
.
testRevisionStorage
[
1
],
"
status
"
:
'
deleted
'
,
// update attachment
"
type
"
:
'
branch
'
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
putattmt1/putattmt2
"
},
},{
"
Update Attachment, with data
"
);
"
kids
"
:[
o
.
jio
.
putAttachment
({
"
id
"
:
"
putattmt1/putattmt2
"
,
"
data
"
:
"
abc
"
},
o
.
f
);
o
.
tick
(
o
);
// check document
deepEqual
(
localstorage
.
getItem
(
"
jio/localstorage/uputattmt/aputattmt/putattmt1
"
),
{
{
"
kids
"
:[],
"
_id
"
:
"
putattmt1
"
,
"
rev
"
:
"
3-05210795b6aa8cb5e1e7f021960d233cf963f1052b1a41777ca1a2aff8fd4b61
"
,
"
title
"
:
"
myPutAttmt1
"
,
"
status
"
:
'
deleted
'
,
"
_attachments
"
:
{
"
type
"
:
'
leaf
'
"
putattmt2
"
:
{
}],
"
length
"
:
3
,
"
rev
"
:
"
2-67ac10df5b7e2582f2ea2344b01c68d461f44b98fef2c5cba5073cc3bdb5a844
"
,
// md5("abc")
"
status
"
:
'
deleted
'
,
"
digest
"
:
"
md5-900150983cd24fb0d6963f7d28e17f72
"
"
typ
"
:
'
branch
'
}
}],
}
"
rev
"
:
o
.
testRevisionStorage
[
2
],
},
"
status
"
:
'
deleted
'
,
"
Check document
"
"
type
"
:
'
branch
'
);
};
o
.
spy
(
o
,
'
value
'
,{
"
ok
"
:
true
,
"
id
"
:
response
.
id
,
// check attachment
"
rev
"
:
response
.
rev
},
'
PUT SYNC dead leaf = ok
'
);
deepEqual
(
o
.
f
(
response
);
localstorage
.
getItem
(
// 18) check document was stored
"
jio/localstorage/uputattmt/aputattmt/putattmt1/putattmt2
"
),
checkFile
(
response
,
o
,
null
,
true
);
"
abc
"
,
"
Check attachment
"
// 19) check tree was updated
);
checkTreeNode
(
response
,
o
,
null
,
true
);
});
checkReply
(
o
,
null
,
true
);
o
.
clock
.
tick
(
base_tick
);
// END PUT
o
.
jio
.
stop
();
o
.
jio
.
stop
();
o
.
clean
;
});
});
test
(
"
Get
"
,
function
(){
// ====================== PUTATTACHMENT ==========================
var
o
=
generateTools
(
this
);
test
(
'
PutAttachment
'
,
function
(){
// runs following assertions
o
.
jio
=
JIO
.
newJio
({
// 1) PUTATTACHMENT with wrong id/rev1
"
type
"
:
"
local
"
,
// 2) PUTATTACHMENT without id/rev1
"
username
"
:
"
uget
"
,
"
applicationname
"
:
"
aget
"
});
var
o
=
{};
// get unexistant document
o
.
t
=
this
;
o
.
spy
(
o
,
"
status
"
,
404
,
"
Get unexistant document
"
);
o
.
clock
=
o
.
t
.
sandbox
.
useFakeTimers
();
o
.
jio
.
get
(
"
get1
"
,
o
.
f
);
o
.
falseRevision
;
o
.
tick
(
o
);
localstorage
=
{
getItem
:
function
(
item
)
{
// get unexistant attachment
return
JSON
.
parse
(
localStorage
.
getItem
(
item
));
o
.
spy
(
o
,
"
status
"
,
404
,
"
Get unexistant attachment
"
);
},
o
.
jio
.
get
(
"
get1/get2
"
,
o
.
f
);
setItem
:
function
(
item
,
value
)
{
o
.
tick
(
o
);
return
localStorage
.
setItem
(
item
,
JSON
.
stringify
(
value
));
},
// adding a document
deleteItem
:
function
(
item
)
{
o
.
doc_get1
=
{
delete
localStorage
[
item
];
"
_id
"
:
"
get1
"
,
"
title
"
:
"
myGet1
"
};
localstorage
.
setItem
(
"
jio/localstorage/uget/aget/get1
"
,
o
.
doc_get1
);
// get document
o
.
spy
(
o
,
"
value
"
,
o
.
doc_get1
,
"
Get document
"
);
o
.
jio
.
get
(
"
get1
"
,
o
.
f
);
o
.
tick
(
o
);
// get unexistant attachment (document exists)
o
.
spy
(
o
,
"
status
"
,
404
,
"
Get unexistant attachment (document exists)
"
);
o
.
jio
.
get
(
"
get1/get2
"
,
o
.
f
);
o
.
tick
(
o
);
// adding an attachment
o
.
doc_get1
[
"
_attachments
"
]
=
{
"
get2
"
:
{
"
length
"
:
2
,
// md5("de")
"
digest
"
:
"
md5-5f02f0889301fd7be1ac972c11bf3e7d
"
}
}
};
};
localstorage
.
setItem
(
"
jio/localstorage/uget/aget/get1
"
,
o
.
doc_get1
);
localstorage
.
setItem
(
"
jio/localstorage/uget/aget/get1/get2
"
,
"
de
"
);
// get attachment
o
.
spy
(
o
,
"
value
"
,
"
de
"
,
"
Get attachment
"
);
o
.
jio
.
get
(
"
get1/get2
"
,
o
.
f
);
o
.
tick
(
o
);
o
.
jio
.
stop
();
o
.
clock
.
tick
(
base_tick
);
o
.
spy
=
basic_spy_function
;
o
.
clean
=
clean_up_local_storage_function
();
o
.
username
=
'
MrPuttAttachment
'
;
o
.
testRevisionStorage
=
[];
// let's go
o
.
jio
=
JIO
.
newJio
({
type
:
'
local
'
,
username
:
o
.
username
,
applicationname
:
'
jiotests
'
});
// ========================================
// 1) PUTATTACHMENT with wrong id/rev
o
.
jio
.
putAttachment
(
"
ABC/DEF
"
,
"
A-1aaa
"
,
"
<b>hello</b>
"
,
"
text/html
"
,
function
(
err
,
response
){
o
.
spy
(
o
,
'
value
'
,{
"
error
"
:
'
not found
'
,
"
message
"
:
'
Document not found.
'
,
"
reason
"
:
'
Document not found, please check document ID
'
,
"
status
"
:
404
,
"
statusText
"
:
'
Not found
'
},
'
PUTATTACHMENT without id = 404 NOT FOUND
'
);
o
.
f
(
err
);
});
checkReply
(
o
,
null
,
true
);
// ========================================
// 2) PUTATTACHMENT with wrong id/rev
/*
o.jio.putAttachment("ABC/DEF","text/html","<b>hello</b>",function(err, response){
o.spy (o,'value',{
"error": 'not found',
"message": 'Document not found.',
"reason": 'Document not found, please check document ID',
"status": 404,
"statusText": 'Not found'
},'PUTATTACHMENT without id = 404 NOT FOUND');
o.f(err);
});
checkReply(o,null,true);
*/
});
});
/*
test
(
"
Remove
"
,
function
(){
test ('Document load', function () {
// Test if LocalStorage can load documents.
// We launch a loading from localstorage and we check if the file is
// realy loaded.
var o = {}; o.clock = this.sandbox.useFakeTimers(); o.t = this;
var
o
=
generateTools
(
this
);
o.clock.tick(base_tick);
o.spy = basic_spy_function;
o.tick = basic_tick_function;
o.jio = JIO.newJio({
type:'local',username:'MrLoadName',
o
.
jio
=
JIO
.
newJio
({
applicationname:'jiotests'});
"
type
"
:
"
local
"
,
// save and check document existence
"
username
"
:
"
uremove
"
,
o.doc = {_id:'file',content:'content',
"
applicationname
"
:
"
aremove
"
_last_modified:1234,_creation_date:1000}
;
})
;
o.spy(o,'status',404,'loading document failure');
// remove unexistant document
o.jio.get('file',o.f);
o
.
spy
(
o
,
"
status
"
,
404
,
"
Remove unexistant document
"
);
o
.
jio
.
remove
({
"
_id
"
:
"
remove1
"
},
o
.
f
);
o
.
tick
(
o
);
o
.
tick
(
o
);
addFileToLocalStorage('MrLoadName','jiotests',o.doc);
// remove unexistant document/attachment
o.spy(o,
'value',o.doc,'loading document success'
);
o
.
spy
(
o
,
"
status
"
,
404
,
"
Remove unexistant document/attachment
"
);
o.jio.
get('file',
o.f);
o
.
jio
.
remove
({
"
_id
"
:
"
remove1/remove2
"
},
o
.
f
);
o
.
tick
(
o
);
o
.
tick
(
o
);
o.jio.stop();
// adding a document
});
localstorage
.
setItem
(
"
jio/localstorage/uremove/aremove/remove1
"
,
{
*//*
"
_id
"
:
"
remove1
"
,
test ('Get document list', function () {
"
title
"
:
"
myRemove1
"
// Test if LocalStorage can get a list of documents.
});
// We create 2 documents inside localStorage to check them.
var o = {}; o.clock = this.sandbox.useFakeTimers(); o.t = this;
// remove document
o.clock.tick(base_tick);
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
remove1
"
},
"
Remove document
"
);
o.mytest = function (value){
o
.
jio
.
remove
({
"
_id
"
:
"
remove1
"
},
o
.
f
);
o.f = function (err,val) {
o
.
tick
(
o
);
if (val) {
deepEqual (objectifyDocumentArray(val.rows),
// check document
objectifyDocumentArray(value),'getting list');
ok
(
localstorage
.
getItem
(
"
jio/localstorage/uremove/aremove/remove1
"
)
===
null
,
} else {
"
Check documuent
"
);
deepEqual (err,value,'getting list');
}
// adding a document + attmt
};
localstorage
.
setItem
(
"
jio/localstorage/uremove/aremove/remove1
"
,
{
o.t.spy(o,'f');
"
_id
"
:
"
remove1
"
,
o.jio.allDocs(o.f);
"
title
"
:
"
myRemove1
"
,
o.clock.tick(1000);
"
_attachments
"
:
{
if (!o.f.calledOnce) {
"
remove2
"
:
{
if (o.f.called) {
"
length
"
:
4
,
ok(false, 'too much results');
"
digest
"
:
"
md5-blahblah
"
} else {
ok(false, 'no response');
}
}
};
o.jio = JIO.newJio({type:'local',username:'MrListName',
applicationname:'jiotests'});
o.doc1 = {_id:'file',content:'content',
_last_modified:1,_creation_date:0};
o.doc2 = {_id:'memo',content:'test',
_last_modified:5,_creation_date:2};
addFileToLocalStorage ('MrListName','jiotests',o.doc1);
addFileToLocalStorage ('MrListName','jiotests',o.doc2);
o.mytest ([{
id:o.doc2._id,key:o.doc2._id,
value:{
_creation_date:o.doc2._creation_date,
_last_modified:o.doc2._last_modified
}
}
},{
id:o.doc1._id,key:o.doc1._id,
value:{
_last_modified:o.doc1._last_modified,
_creation_date:o.doc1._creation_date
}
}
}]);
});
localstorage
.
setItem
(
"
jio/localstorage/uremove/aremove/remove1/remove2
"
,
"
fghi
"
);
// remove attachment
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
remove1
"
},
"
Remove attachment
"
);
o
.
jio
.
remove
({
"
_id
"
:
"
remove1
"
},
o
.
f
);
o
.
tick
(
o
);
o
.
jio
.
stop
();
o
.
jio
.
stop
();
});
});
*//*
test ('Document remove', function () {
// Test if LocalStorage can remove documents.
// We launch a remove from localstorage and we check if the file is
// realy removed.
var o = {}; o.clock = this.sandbox.useFakeTimers(); o.t = this;
o.clock.tick(base_tick);
o.spy = basic_spy_function;
o.tick = function () {
basic_tick_function.apply(basic_tick_function,arguments);
// check if the file is still there
o.tmp = LocalOrCookieStorage.getItem (
'jio/local/MrRemoveName/jiotests/file');
ok (!o.tmp, 'check no content');
};
o.jio = JIO.newJio({type:'local',username:'MrRemoveName',
test
(
"
AllDocs
"
,
function
(){
applicationname:'jiotests'});
// test removing a file
var
o
=
generateTools
(
this
);
o.spy (o,'value',{ok:true,id:'file'},'removing document');
addFileToLocalStorage ('MrRemoveName','jiotests',{_id:'file'});
o
.
jio
=
JIO
.
newJio
({
o.jio.remove({_id:'file'},o.f);
"
type
"
:
"
local
"
,
o.tick (o);
"
username
"
:
"
ualldocs
"
,
"
applicationname
"
:
"
aalldocs
"
});
// alldocs
// error 405 -> method not allowed
o
.
spy
(
o
,
"
status
"
,
405
,
"
Method not allowed
"
);
o
.
jio
.
allDocs
(
o
.
f
);
o
.
tick
(
o
);
o
.
jio
.
stop
();
o
.
jio
.
stop
();
});
});
*/
/*
/*
module ('Jio DAVStorage');
module ('Jio DAVStorage');
...
@@ -2818,7 +2598,6 @@ if (window.requirejs) {
...
@@ -2818,7 +2598,6 @@ if (window.requirejs) {
paths
:
{
paths
:
{
jiotestsloader
:
'
./jiotests.loader
'
,
jiotestsloader
:
'
./jiotests.loader
'
,
LocalOrCookieStorage
:
'
./testlocalorcookiestorage
'
,
jQueryAPI
:
'
../lib/jquery/jquery
'
,
jQueryAPI
:
'
../lib/jquery/jquery
'
,
jQuery
:
'
../js/jquery.requirejs_module
'
,
jQuery
:
'
../js/jquery.requirejs_module
'
,
JIO
:
'
../src/jio
'
,
JIO
:
'
../src/jio
'
,
...
@@ -2832,8 +2611,7 @@ if (window.requirejs) {
...
@@ -2832,8 +2611,7 @@ if (window.requirejs) {
});
});
require
([
'
jiotestsloader
'
],
thisfun
);
require
([
'
jiotestsloader
'
],
thisfun
);
}
else
{
}
else
{
thisfun
({
LocalOrCookieStorage
:
LocalOrCookieStorage
,
thisfun
({
JIO
:
jIO
,
JIO
:
jIO
,
sjcl
:
sjcl
,
sjcl
:
sjcl
,
Base64
:
Base64
,
Base64
:
Base64
,
jQuery
:
jQuery
});
jQuery
:
jQuery
});
...
...
test/jiotests_withoutrequirejs.html
View file @
891be93a
...
@@ -11,8 +11,9 @@
...
@@ -11,8 +11,9 @@
<script
type=
"text/javascript"
src=
"../lib/sinon/sinon.js"
></script>
<script
type=
"text/javascript"
src=
"../lib/sinon/sinon.js"
></script>
<script
type=
"text/javascript"
src=
"../lib/sinon/sinon-qunit.js"
></script>
<script
type=
"text/javascript"
src=
"../lib/sinon/sinon-qunit.js"
></script>
<script
type=
"text/javascript"
src=
"../lib/jquery/jquery.min.js"
></script>
<script
type=
"text/javascript"
src=
"../lib/jquery/jquery.min.js"
></script>
<script
type=
"text/javascript"
src=
"./testlocalorcookiestorage.js"
></script>
<script
type=
"text/javascript"
src=
"./browserlocalstorage.stub.js"
></script>
<script
type=
"text/javascript"
src=
"../lib/md5/md5.js"
></script>
<script
type=
"text/javascript"
src=
"../jio.js"
></script>
<script
type=
"text/javascript"
src=
"../jio.js"
></script>
<script
type=
"text/javascript"
src=
"../lib/base64/base64.js"
></script>
<script
type=
"text/javascript"
src=
"../lib/base64/base64.js"
></script>
...
...
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