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
Guillaume Royer
jio
Commits
f3294a72
Commit
f3294a72
authored
Nov 21, 2013
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gidstorage.tests.js added
parent
f4aa93ab
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
655 additions
and
676 deletions
+655
-676
test/jio.storage/gidstorage.tests.js
test/jio.storage/gidstorage.tests.js
+647
-675
test/tests.html
test/tests.html
+3
-0
test/tests.require.js
test/tests.require.js
+5
-1
No files found.
test/jio.storage/gidstorage.tests.js
View file @
f3294a72
/*jslint indent: 2, maxlen: 80, nomen: true */
/*jslint indent: 2, maxlen: 80, nomen: true */
/*global define, jIO, jio_tests, test, ok, deepEqual, sinon */
/*global define, jIO, test_util, RSVP, test, ok, deepEqual, sinon, module, stop,
start */
// define([module_name], [dependencies], module);
// define([module_name], [dependencies], module);
(
function
(
dependencies
,
module
)
{
(
function
(
dependencies
,
module
)
{
...
@@ -7,699 +8,670 @@
...
@@ -7,699 +8,670 @@
if
(
typeof
define
===
'
function
'
&&
define
.
amd
)
{
if
(
typeof
define
===
'
function
'
&&
define
.
amd
)
{
return
define
(
dependencies
,
module
);
return
define
(
dependencies
,
module
);
}
}
module
(
jIO
,
jio_tests
);
module
(
RSVP
,
jIO
);
}([
'
jio
'
,
'
jio_tests
'
,
'
localstorage
'
,
'
gidstorage
'
],
function
(
jIO
,
util
)
{
}([
'
rsvp
'
,
'
jio
'
,
'
localstorage
'
,
'
gidstorage
'
],
function
(
RSVP
,
jIO
)
{
"
use strict
"
;
"
use strict
"
;
function
generateTools
()
{
return
{
clock
:
sinon
.
useFakeTimers
(),
spy
:
util
.
ospy
,
tick
:
util
.
otick
};
}
module
(
"
GID Storage
"
);
module
(
"
GID Storage
"
);
test
(
"
Post
"
,
function
()
{
function
success
(
promise
)
{
var
o
=
generateTools
(
this
);
return
new
RSVP
.
Promise
(
function
(
resolve
,
reject
,
notify
)
{
/*jslint unparam: true*/
o
.
localstorage_spec
=
{
promise
.
then
(
resolve
,
resolve
,
notify
);
"
type
"
:
"
local
"
,
},
function
()
{
"
username
"
:
"
one
"
,
promise
.
cancel
();
"
application_name
"
:
"
gid storage post test
"
};
// local jio is going to help us to prepare localstorage for gid tests
o
.
local_jio
=
jIO
.
newJio
(
o
.
localstorage_spec
);
o
.
jio
=
jIO
.
newJio
({
"
type
"
:
"
gid
"
,
"
sub_storage
"
:
o
.
localstorage_spec
,
"
constraints
"
:
{
"
default
"
:
{
"
creator
"
:
"
list
"
}
}
});
// preparing localstorage with documents
o
.
local_jio
.
put
({
"
_id
"
:
"
blue
"
,
"
creator
"
:
"
a
"
,
"
title
"
:
"
earth
"
});
o
.
local_jio
.
put
({
"
_id
"
:
"
green
"
,
"
creator
"
:
[
"
ac
"
,
"
b
"
],
"
title
"
:
"
wind
"
});
o
.
clock
.
tick
(
2000
);
util
.
closeAndcleanUpJio
(
o
.
local_jio
);
// Fail to post a document because metadata doesn't respect constraints
// XXX check reason
o
.
spy
(
o
,
'
status
'
,
400
,
'
Post document without respecting constraints
'
+
'
-> bad request
'
);
o
.
jio
.
post
({},
o
.
f
);
o
.
tick
(
o
);
// Fail to post a document but a document already exists
o
.
spy
(
o
,
'
status
'
,
409
,
'
Post existent document -> conflict
'
);
o
.
jio
.
post
({
"
creator
"
:
"
a
"
,
"
title
"
:
"
water
"
},
o
.
f
);
o
.
tick
(
o
);
// Succeed to post because no document with the same gid has been found
o
.
spy
(
o
,
'
value
'
,
{
"
id
"
:
"
{
\"
creator
\"
:[
\"
a%
\"
]}
"
,
"
ok
"
:
true
},
'
Post respecting constraints
'
);
o
.
jio
.
post
({
"
creator
"
:
"
a%
"
,
"
title
"
:
"
fire
"
},
o
.
f
);
o
.
tick
(
o
);
// Fail to post because this document has been uploaded right before
o
.
spy
(
o
,
'
status
'
,
409
,
'
Post same document respecting constraints
'
+
'
-> conflicts
'
);
o
.
jio
.
post
({
"
creator
"
:
"
a%
"
,
"
title
"
:
"
space
"
},
o
.
f
);
o
.
tick
(
o
);
util
.
closeAndcleanUpJio
(
o
.
jio
);
});
test
(
"
Get
"
,
function
()
{
var
o
=
generateTools
(
this
);
o
.
localstorage_spec
=
{
"
type
"
:
"
local
"
,
"
username
"
:
"
one
"
,
"
application_name
"
:
"
gid storage get test
"
};
// local jio is going to help us to prepare localstorage for gid tests
o
.
local_jio
=
jIO
.
newJio
(
o
.
localstorage_spec
);
o
.
jio
=
jIO
.
newJio
({
"
type
"
:
"
gid
"
,
"
sub_storage
"
:
o
.
localstorage_spec
,
"
constraints
"
:
{
"
default
"
:
{
"
creator
"
:
"
list
"
}
}
});
// preparing localstorage with documents
o
.
local_jio
.
put
({
"
_id
"
:
"
blue
"
,
"
creator
"
:
"
a
"
,
"
title
"
:
"
earth
"
});
o
.
local_jio
.
put
({
"
_id
"
:
"
red
"
,
"
creator
"
:
[
"
ac
"
,
"
b
"
],
"
title
"
:
"
wind
"
});
o
.
clock
.
tick
(
2000
);
util
.
closeAndcleanUpJio
(
o
.
local_jio
);
// Fail to get document because _id doesn't respect constraints
o
.
spy
(
o
,
'
status
'
,
400
,
'
Get document without respecting constraints
'
+
'
-> bad request
'
);
o
.
jio
.
get
({
"
_id
"
:
"
a
"
},
o
.
f
);
o
.
tick
(
o
);
// Fail to get because no document with the same gid has been found
o
.
spy
(
o
,
'
status
'
,
404
,
'
Get inexistent document
'
);
o
.
jio
.
get
({
"
_id
"
:
"
{
\"
creator
\"
:[
\"
c
\"
]}
"
},
o
.
f
);
o
.
tick
(
o
);
// Succeed to get, gid is good, document found
o
.
spy
(
o
,
'
value
'
,
{
"
_id
"
:
"
{
\"
creator
\"
:[
\"
b
\"
]}
"
,
"
creator
"
:
[
"
ac
"
,
"
b
"
],
"
title
"
:
"
wind
"
},
'
Get document
'
);
o
.
jio
.
get
({
"
_id
"
:
"
{
\"
creator
\"
:[
\"
b
\"
]}
"
},
o
.
f
);
o
.
tick
(
o
);
util
.
closeAndcleanUpJio
(
o
.
jio
);
});
test
(
"
AllDocs
"
,
function
()
{
var
o
=
generateTools
(
this
);
o
.
localstorage_spec
=
{
"
type
"
:
"
local
"
,
"
username
"
:
"
one
"
,
"
application_name
"
:
"
gid storage allDocs test
"
};
// local jio is going to help us to prepare localstorage for gid tests
o
.
local_jio
=
jIO
.
newJio
(
o
.
localstorage_spec
);
o
.
jio
=
jIO
.
newJio
({
"
type
"
:
"
gid
"
,
"
sub_storage
"
:
o
.
localstorage_spec
,
"
constraints
"
:
{
"
default
"
:
{
"
creator
"
:
"
list
"
}
}
});
// preparing localstorage with documents
o
.
local_jio
.
put
({
"
_id
"
:
"
green
"
,
"
creator
"
:
[
"
a
"
],
"
title
"
:
"
earth
"
});
o
.
local_jio
.
put
({
"
_id
"
:
"
red
"
,
"
creator
"
:
[
"
a
"
,
"
b
"
],
"
title
"
:
"
water
"
});
o
.
local_jio
.
put
({
"
_id
"
:
"
yellow
"
,
"
creator
"
:
[
"
c
"
,
"
d
"
],
"
title
"
:
"
wind
"
});
o
.
local_jio
.
put
({
"
_id
"
:
"
purple
"
,
"
creator
"
:
[
"
s
"
,
"
d
"
],
"
title
"
:
"
fire
"
});
o
.
local_jio
.
put
({
"
_id
"
:
"
blue
"
,
"
title
"
:
"
space
"
});
o
.
clock
.
tick
(
3000
);
util
.
closeAndcleanUpJio
(
o
.
local_jio
);
// Get all document and sort to make comparison easier
o
.
spy
(
o
,
'
value
'
,
{
"
rows
"
:
[{
"
id
"
:
"
{
\"
creator
\"
:[
\"
a
\"
]}
"
,
"
value
"
:
{}
},
{
"
id
"
:
"
{
\"
creator
\"
:[
\"
a
\"
,
\"
b
\"
]}
"
,
"
value
"
:
{}
},
{
"
id
"
:
"
{
\"
creator
\"
:[
\"
c
\"
,
\"
d
\"
]}
"
,
"
value
"
:
{}
},
{
"
id
"
:
"
{
\"
creator
\"
:[
\"
s
\"
,
\"
d
\"
]}
"
,
"
value
"
:
{}
}],
"
total_rows
"
:
4
},
'
Get all docs
'
);
o
.
jio
.
allDocs
({
"
sort_on
"
:
[[
"
creator
"
,
"
ascending
"
]]
},
o
.
f
);
o
.
tick
(
o
);
// Get all document with complex queries
o
.
spy
(
o
,
'
value
'
,
{
"
rows
"
:
[{
"
id
"
:
"
{
\"
creator
\"
:[
\"
s
\"
,
\"
d
\"
]}
"
,
"
value
"
:
{
"
creator
"
:
[
"
s
"
,
"
d
"
]}
}],
"
total_rows
"
:
1
},
'
Get all docs with complex query
'
);
o
.
jio
.
allDocs
({
"
query
"
:
'
creator: "d"
'
,
"
select_list
"
:
[
"
creator
"
],
"
limit
"
:
[
1
,
1
],
"
sort_on
"
:
[[
"
creator
"
,
"
ascending
"
]]
},
o
.
f
);
o
.
tick
(
o
);
util
.
closeAndcleanUpJio
(
o
.
jio
);
});
test
(
"
Put
"
,
function
()
{
var
o
=
generateTools
(
this
);
o
.
localstorage_spec
=
{
"
type
"
:
"
local
"
,
"
username
"
:
"
one
"
,
"
application_name
"
:
"
gid storage put test
"
};
// local jio is going to help us to prepare localstorage for gid tests
o
.
local_jio
=
jIO
.
newJio
(
o
.
localstorage_spec
);
o
.
jio
=
jIO
.
newJio
({
"
type
"
:
"
gid
"
,
"
sub_storage
"
:
o
.
localstorage_spec
,
"
constraints
"
:
{
"
default
"
:
{
"
creator
"
:
"
list
"
}
}
});
// preparing localstorage with documents
o
.
local_jio
.
put
({
"
_id
"
:
"
blue
"
,
"
creator
"
:
"
a
"
,
"
title
"
:
"
earth
"
});
o
.
local_jio
.
put
({
"
_id
"
:
"
green
"
,
"
creator
"
:
[
"
ac
"
,
"
b
"
],
"
title
"
:
"
wind
"
});
o
.
clock
.
tick
(
2000
);
// Fail to put document because id does not respect constraints
o
.
spy
(
o
,
'
status
'
,
400
,
'
Put document without respecting constraints
'
+
'
-> bad request
'
);
o
.
jio
.
put
({
"
_id
"
:
"
a
"
,
"
creator
"
:
"
a
"
,
"
title
"
:
"
fire
"
},
o
.
f
);
o
.
tick
(
o
);
// Fail to put because gid given != gid generated by the constraints
o
.
spy
(
o
,
'
status
'
,
400
,
'
Put document without respecting constraints
'
+
'
-> bad request
'
);
o
.
jio
.
put
({
"
_id
"
:
"
{
\"
creator
\"
:[
\"
a
\"
]}
"
,
"
creator
"
:
"
b
"
,
"
title
"
:
"
water
"
},
o
.
f
);
o
.
tick
(
o
);
// Succeed to update a document with its gid
o
.
spy
(
o
,
'
value
'
,
{
"
ok
"
:
true
,
"
id
"
:
"
{
\"
creator
\"
:[
\"
a
\"
]}
"
},
'
Update document
'
);
o
.
jio
.
put
({
"
_id
"
:
"
{
\"
creator
\"
:[
\"
a
\"
]}
"
,
"
creator
"
:
"
a
"
,
"
title
"
:
"
space
"
},
o
.
f
);
o
.
tick
(
o
);
// Succeed to create a document, the gid given is good
o
.
spy
(
o
,
'
value
'
,
{
"
ok
"
:
true
,
"
id
"
:
"
{
\"
creator
\"
:[
\"
c
\"
]}
"
},
'
Create document
'
);
o
.
jio
.
put
({
"
_id
"
:
"
{
\"
creator
\"
:[
\"
c
\"
]}
"
,
"
creator
"
:
"
c
"
,
"
title
"
:
"
magma
"
},
o
.
f
);
o
.
tick
(
o
);
// Check if the local storage document is well updated to make sure the
// second put did not update the wrong document.
o
.
spy
(
o
,
'
value
'
,
{
"
_id
"
:
"
blue
"
,
"
creator
"
:
"
a
"
,
"
title
"
:
"
space
"
},
"
Check sub documents
"
);
o
.
local_jio
.
get
({
"
_id
"
:
"
blue
"
},
o
.
f
);
o
.
tick
(
o
);
util
.
closeAndcleanUpJio
(
o
.
local_jio
);
util
.
closeAndcleanUpJio
(
o
.
jio
);
});
test
(
"
Remove
"
,
function
()
{
var
o
=
generateTools
(
this
);
o
.
localstorage_spec
=
{
"
type
"
:
"
local
"
,
"
username
"
:
"
one
"
,
"
application_name
"
:
"
gid storage remove test
"
};
// local jio is going to help us to prepare localstorage for gid tests
o
.
local_jio
=
jIO
.
newJio
(
o
.
localstorage_spec
);
o
.
jio
=
jIO
.
newJio
({
"
type
"
:
"
gid
"
,
"
sub_storage
"
:
o
.
localstorage_spec
,
"
constraints
"
:
{
"
default
"
:
{
"
creator
"
:
"
list
"
}
}
});
// preparing localstorage with documents
o
.
local_jio
.
put
({
"
_id
"
:
"
blue
"
,
"
creator
"
:
"
a
"
,
"
title
"
:
"
earth
"
});
o
.
local_jio
.
put
({
"
_id
"
:
"
green
"
,
"
creator
"
:
[
"
ac
"
,
"
b
"
],
"
title
"
:
"
wind
"
});
o
.
clock
.
tick
(
2000
);
util
.
closeAndcleanUpJio
(
o
.
local_jio
);
// Fail to remove document because given gid does not respect constraints
o
.
spy
(
o
,
'
status
'
,
400
,
'
Remove document without respecting constraints
'
+
'
-> bad request
'
);
o
.
jio
.
remove
({
"
_id
"
:
"
a
"
},
o
.
f
);
o
.
tick
(
o
);
// Succeed to remove
o
.
spy
(
o
,
'
value
'
,
{
"
ok
"
:
true
,
"
id
"
:
"
{
\"
creator
\"
:[
\"
b
\"
]}
"
},
'
Remove document
'
);
o
.
jio
.
remove
({
"
_id
"
:
"
{
\"
creator
\"
:[
\"
b
\"
]}
"
},
o
.
f
);
o
.
tick
(
o
);
// Fail to remove the same document. This test checks also that only one
// document matches the gid constraints
o
.
spy
(
o
,
'
status
'
,
404
,
'
Remove inexistent document
'
);
o
.
jio
.
remove
({
"
_id
"
:
"
{
\"
creator
\"
:[
\"
b
\"
]}
"
},
o
.
f
);
o
.
tick
(
o
);
util
.
closeAndcleanUpJio
(
o
.
jio
);
});
test
(
"
putAttachment
"
,
function
()
{
var
o
=
generateTools
(
this
);
o
.
localstorage_spec
=
{
"
type
"
:
"
local
"
,
"
username
"
:
"
one
"
,
"
application_name
"
:
"
gid storage put attachment test
"
};
// local jio is going to help us to prepare localstorage for gid tests
o
.
local_jio
=
jIO
.
newJio
(
o
.
localstorage_spec
);
o
.
jio
=
jIO
.
newJio
({
"
type
"
:
"
gid
"
,
"
sub_storage
"
:
o
.
localstorage_spec
,
"
constraints
"
:
{
"
default
"
:
{
"
creator
"
:
"
list
"
}
}
});
});
}
// preparing localstorage with documents
/**
o
.
local_jio
.
put
({
"
_id
"
:
"
blue
"
,
"
creator
"
:
"
a
"
,
"
title
"
:
"
earth
"
});
* Test with a memory storage, the responses of gid storage should not be
o
.
local_jio
.
put
({
"
_id
"
:
"
green
"
,
"
creator
"
:
[
"
ac
"
,
"
b
"
],
"
title
"
:
"
wind
"
});
* related to memory storage ones.
o
.
clock
.
tick
(
2000
);
*/
test
(
"
Scenario
"
,
29
,
function
()
{
// Fail to put attachment because given gid doesn't respect constraints
o
.
spy
(
o
,
'
status
'
,
400
,
'
put attachment without respecting constraints
'
+
'
-> bad request
'
);
o
.
jio
.
putAttachment
({
"
_id
"
:
"
a
"
,
"
_attachment
"
:
"
body
"
,
"
_data
"
:
"
abc
"
,
"
_mimetype
"
:
"
text/plain
"
},
o
.
f
);
o
.
tick
(
o
);
// Succeed to put an attachment to a document
o
.
spy
(
o
,
'
value
'
,
{
"
ok
"
:
true
,
"
id
"
:
"
{
\"
creator
\"
:[
\"
b
\"
]}
"
,
"
attachment
"
:
"
body
"
},
'
put attachment
'
);
o
.
jio
.
putAttachment
({
"
_id
"
:
"
{
\"
creator
\"
:[
\"
b
\"
]}
"
,
"
_attachment
"
:
"
body
"
,
"
_data
"
:
"
abc
"
,
"
_mimetype
"
:
"
text/plain
"
},
o
.
f
);
o
.
tick
(
o
);
// Check if the local storage document really have the new attachment
o
.
spy
(
o
,
'
value
'
,
"
abc
"
,
"
Check attachment
"
);
o
.
local_jio
.
getAttachment
({
"
_id
"
:
"
green
"
,
"
_attachment
"
:
"
body
"
},
o
.
f
);
o
.
tick
(
o
);
// Succeed to update an attachment
o
.
spy
(
o
,
'
value
'
,
{
"
ok
"
:
true
,
"
id
"
:
"
{
\"
creator
\"
:[
\"
b
\"
]}
"
,
"
attachment
"
:
"
body
"
},
'
put attachment
'
);
o
.
jio
.
putAttachment
({
"
_id
"
:
"
{
\"
creator
\"
:[
\"
b
\"
]}
"
,
"
_attachment
"
:
"
body
"
,
"
_data
"
:
"
def
"
,
"
_mimetype
"
:
"
text/plain
"
},
o
.
f
);
o
.
tick
(
o
);
// Check if the local storage attachment really changed
o
.
spy
(
o
,
'
value
'
,
"
def
"
,
"
Check attachment
"
);
o
.
local_jio
.
getAttachment
({
"
_id
"
:
"
green
"
,
"
_attachment
"
:
"
body
"
},
o
.
f
);
o
.
tick
(
o
);
util
.
closeAndcleanUpJio
(
o
.
local_jio
);
util
.
closeAndcleanUpJio
(
o
.
jio
);
});
test
(
"
getAttachment
"
,
function
()
{
var
o
=
generateTools
(
this
);
o
.
localstorage_spec
=
{
"
type
"
:
"
local
"
,
"
username
"
:
"
one
"
,
"
application_name
"
:
"
gid storage get attachment test
"
};
// local jio is going to help us to prepare localstorage for gid tests
o
.
local_jio
=
jIO
.
newJio
(
o
.
localstorage_spec
);
o
.
jio
=
jIO
.
newJio
({
var
jio
=
jIO
.
createJIO
({
"
type
"
:
"
gid
"
,
"
type
"
:
"
gid
"
,
"
sub_storage
"
:
o
.
localstorage_spec
,
"
constraints
"
:
{
"
constraints
"
:
{
"
default
"
:
{
"
default
"
:
{
"
creator
"
:
"
list
"
"
created
"
:
"
date
"
,
"
title
"
:
"
string
"
,
"
type
"
:
"
DCMIType
"
}
}
},
"
sub_storage
"
:
{
"
type
"
:
"
local
"
,
"
username
"
:
"
gidtest
"
,
"
application_name
"
:
"
jiotests
"
,
"
mode
"
:
"
memory
"
}
}
},
{
"
workspace
"
:
{},
"
max_retry
"
:
2
});
});
// preparing localstorage with documents
function
postNewDocument
()
{
o
.
local_jio
.
put
({
"
_id
"
:
"
blue
"
,
"
creator
"
:
"
a
"
,
"
title
"
:
"
earth
"
});
return
jio
.
post
({
o
.
local_jio
.
put
({
"
_id
"
:
"
green
"
,
"
creator
"
:
[
"
ac
"
,
"
b
"
],
"
title
"
:
"
wind
"
});
"
created
"
:
"
2013-10-10
"
,
o
.
clock
.
tick
(
2000
);
"
title
"
:
"
Unique ID
"
,
"
type
"
:
"
Text
"
// Fail to get attachment because given gid doesn't respect constraints
});
o
.
spy
(
o
,
'
status
'
,
400
,
'
get attachment without respecting constraints
'
+
}
'
-> bad request
'
);
o
.
jio
.
getAttachment
({
function
postNewDocumentTest
(
answer
)
{
"
_id
"
:
"
a
"
,
deepEqual
(
answer
,
{
"
_attachment
"
:
"
body
"
"
id
"
:
'
{"created":"2013-10-10","title":"Unique ID","type":"Text"}
'
,
},
o
.
f
);
"
method
"
:
"
post
"
,
o
.
tick
(
o
);
"
result
"
:
"
success
"
,
"
status
"
:
201
,
// Fail to get an inexistent attachment from a document
"
statusText
"
:
"
Created
"
o
.
spy
(
o
,
'
status
'
,
404
,
'
Get inexistent attachment
'
);
},
"
Post a new document
"
);
o
.
jio
.
getAttachment
({
}
"
_id
"
:
"
{
\"
creator
\"
:[
\"
a
\"
]}
"
,
"
_attachment
"
:
"
body
"
function
getCreatedDocument
()
{
},
o
.
f
);
return
jio
.
get
({
o
.
tick
(
o
);
"
_id
"
:
'
{"created":"2013-10-10","title":"Unique ID","type":"Text"}
'
});
// Add an attachment manually to the document 'blue'
}
o
.
local_jio
.
putAttachment
({
"
_id
"
:
"
blue
"
,
function
getCreatedDocumentTest
(
answer
)
{
"
_attachment
"
:
"
body
"
,
deepEqual
(
answer
,
{
"
_data
"
:
"
lol
"
,
"
data
"
:
{
"
_mimetype
"
:
"
text/plain
"
"
_id
"
:
'
{"created":"2013-10-10","title":"Unique ID","type":"Text"}
'
,
});
"
created
"
:
"
2013-10-10
"
,
o
.
clock
.
tick
(
2000
);
"
title
"
:
"
Unique ID
"
,
util
.
closeAndcleanUpJio
(
o
.
local_jio
);
"
type
"
:
"
Text
"
},
// Succeed to get the previous attachment
"
id
"
:
'
{"created":"2013-10-10","title":"Unique ID","type":"Text"}
'
,
o
.
spy
(
o
,
'
value
'
,
"
lol
"
,
'
Get attachment
'
);
"
method
"
:
"
get
"
,
o
.
jio
.
getAttachment
({
"
result
"
:
"
success
"
,
"
_id
"
:
"
{
\"
creator
\"
:[
\"
a
\"
]}
"
,
"
status
"
:
200
,
"
_attachment
"
:
"
body
"
"
statusText
"
:
"
Ok
"
},
o
.
f
);
},
"
Get new document
"
);
o
.
tick
(
o
);
}
util
.
closeAndcleanUpJio
(
o
.
jio
);
function
postSpecificDocument
()
{
});
return
jio
.
post
({
"
_id
"
:
'
{"created":"2013-10-10","title":"Bee","type":"Text"}
'
,
test
(
"
removeAttachment
"
,
function
()
{
"
created
"
:
"
2013-10-10
"
,
var
o
=
generateTools
(
this
);
"
title
"
:
"
Bee
"
,
"
type
"
:
"
Text
"
o
.
localstorage_spec
=
{
});
"
type
"
:
"
local
"
,
}
"
username
"
:
"
one
"
,
"
application_name
"
:
"
gid storage remove attachment test
"
function
postSpecificDocumentTest
(
answer
)
{
};
deepEqual
(
answer
,
{
"
id
"
:
'
{"created":"2013-10-10","title":"Bee","type":"Text"}
'
,
// local jio is going to help us to prepare localstorage for gid tests
"
method
"
:
"
post
"
,
o
.
local_jio
=
jIO
.
newJio
(
o
.
localstorage_spec
);
"
result
"
:
"
success
"
,
"
status
"
:
201
,
o
.
jio
=
jIO
.
newJio
({
"
statusText
"
:
"
Created
"
"
type
"
:
"
gid
"
,
},
"
Post specific document
"
);
"
sub_storage
"
:
o
.
localstorage_spec
,
}
"
constraints
"
:
{
"
default
"
:
{
function
listDocuments
()
{
"
creator
"
:
"
list
"
return
jio
.
allDocs
();
}
}
function
list2DocumentsTest
(
answer
)
{
if
(
answer
&&
answer
.
data
&&
Array
.
isArray
(
answer
.
data
.
rows
))
{
answer
.
data
.
rows
.
sort
(
function
(
a
)
{
return
a
.
id
===
"
b
"
?
1
:
0
;
});
}
}
});
deepEqual
(
answer
,
{
"
data
"
:
{
// preparing localstorage with documents
"
total_rows
"
:
2
,
o
.
local_jio
.
put
({
"
_id
"
:
"
blue
"
,
"
creator
"
:
"
a
"
,
"
title
"
:
"
earth
"
});
"
rows
"
:
[{
o
.
local_jio
.
put
({
"
_id
"
:
"
green
"
,
"
creator
"
:
[
"
ac
"
,
"
b
"
],
"
title
"
:
"
wind
"
});
"
id
"
:
'
{"created":"2013-10-10","title":"Unique ID","type":"Text"}
'
,
o
.
clock
.
tick
(
2000
);
"
value
"
:
{}
o
.
local_jio
.
putAttachment
({
},
{
"
_id
"
:
"
blue
"
,
"
id
"
:
'
{"created":"2013-10-10","title":"Bee","type":"Text"}
'
,
"
_attachment
"
:
"
body
"
,
"
value
"
:
{}
"
_data
"
:
"
lol
"
,
}]
"
_mimetype
"
:
"
text/plain
"
});
o
.
clock
.
tick
(
2000
);
// Fail to remove attachment because given gid doesn't respect constraints
o
.
spy
(
o
,
'
status
'
,
400
,
'
Remove attachment without respecting
'
+
'
constraints -> bad request
'
);
o
.
jio
.
removeAttachment
({
"
_id
"
:
"
a
"
,
"
_attachment
"
:
"
body
"
,
"
_data
"
:
"
abc
"
,
"
_mimetype
"
:
"
text/plain
"
},
o
.
f
);
o
.
tick
(
o
);
// Succeed to remove an attachment from a document
o
.
spy
(
o
,
'
value
'
,
{
"
ok
"
:
true
,
"
id
"
:
"
{
\"
creator
\"
:[
\"
a
\"
]}
"
,
"
attachment
"
:
"
body
"
},
'
Remove attachment
'
);
o
.
jio
.
removeAttachment
({
"
_id
"
:
"
{
\"
creator
\"
:[
\"
a
\"
]}
"
,
"
_attachment
"
:
"
body
"
},
o
.
f
);
o
.
tick
(
o
);
// Check if the local storage document doesn't have attachment anymore
o
.
spy
(
o
,
'
status
'
,
404
,
"
Check attachment
"
);
o
.
local_jio
.
getAttachment
({
"
_id
"
:
"
green
"
,
"
_attachment
"
:
"
body
"
},
o
.
f
);
o
.
tick
(
o
);
// Fail to remove the same attachment because it's already removed
o
.
spy
(
o
,
'
status
'
,
404
,
'
Remove attachment
'
);
o
.
jio
.
removeAttachment
({
"
_id
"
:
"
{
\"
creator
\"
:[
\"
b
\"
]}
"
,
"
_attachment
"
:
"
body
"
,
"
_data
"
:
"
def
"
,
"
_mimetype
"
:
"
text/plain
"
},
o
.
f
);
o
.
tick
(
o
);
util
.
closeAndcleanUpJio
(
o
.
local_jio
);
util
.
closeAndcleanUpJio
(
o
.
jio
);
});
test
(
"
More Constraints
"
,
function
()
{
// This test will use gid storage in a 'real case'
var
o
=
generateTools
(
this
);
o
.
localstorage_spec
=
{
"
type
"
:
"
local
"
,
"
username
"
:
"
one
"
,
"
application_name
"
:
"
gid storage more constraints test
"
};
o
.
jio
=
jIO
.
newJio
({
"
type
"
:
"
gid
"
,
"
sub_storage
"
:
o
.
localstorage_spec
,
"
constraints
"
:
{
"
default
"
:
{
"
type
"
:
"
DCMIType
"
,
"
title
"
:
"
string
"
},
},
"
Text
"
:
{
"
method
"
:
"
allDocs
"
,
"
date
"
:
"
date
"
,
"
result
"
:
"
success
"
,
"
language
"
:
"
string
"
"
status
"
:
200
,
"
statusText
"
:
"
Ok
"
},
"
List 2 documents
"
);
}
function
removeCreatedDocument
()
{
return
jio
.
remove
({
"
_id
"
:
'
{"created":"2013-10-10","title":"Unique ID","type":"Text"}
'
});
}
function
removeCreatedDocumentTest
(
answer
)
{
deepEqual
(
answer
,
{
"
id
"
:
'
{"created":"2013-10-10","title":"Unique ID","type":"Text"}
'
,
"
method
"
:
"
remove
"
,
"
result
"
:
"
success
"
,
"
status
"
:
204
,
"
statusText
"
:
"
No Content
"
},
"
Remove first document.
"
);
}
function
removeSpecificDocument
()
{
return
jio
.
remove
({
"
_id
"
:
'
{"created":"2013-10-10","title":"Bee","type":"Text"}
'
});
}
function
removeSpecificDocumentTest
(
answer
)
{
deepEqual
(
answer
,
{
"
id
"
:
'
{"created":"2013-10-10","title":"Bee","type":"Text"}
'
,
"
method
"
:
"
remove
"
,
"
result
"
:
"
success
"
,
"
status
"
:
204
,
"
statusText
"
:
"
No Content
"
},
"
Remove second document.
"
);
}
function
listEmptyStorage
()
{
return
jio
.
allDocs
();
}
function
listEmptyStorageTest
(
answer
)
{
deepEqual
(
answer
,
{
"
data
"
:
{
"
total_rows
"
:
0
,
"
rows
"
:
[]
},
},
"
Image
"
:
{
"
method
"
:
"
allDocs
"
,
"
format
"
:
"
contentType
"
"
result
"
:
"
success
"
,
}
"
status
"
:
200
,
"
statusText
"
:
"
Ok
"
},
"
List empty storage
"
);
}
function
putNewDocument
()
{
return
jio
.
put
({
"
_id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
,
"
created
"
:
"
2013-10-10
"
,
"
title
"
:
"
Hey
"
,
"
type
"
:
"
Text
"
});
}
function
putNewDocumentTest
(
answer
)
{
deepEqual
(
answer
,
{
"
id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
,
"
method
"
:
"
put
"
,
"
result
"
:
"
success
"
,
"
status
"
:
201
,
"
statusText
"
:
"
Created
"
},
"
Put new document
"
);
}
function
getCreatedDocument2
()
{
return
jio
.
get
({
"
_id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
});
}
function
getCreatedDocument2Test
(
answer
)
{
deepEqual
(
answer
,
{
"
data
"
:
{
"
_id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
,
"
created
"
:
"
2013-10-10
"
,
"
title
"
:
"
Hey
"
,
"
type
"
:
"
Text
"
},
"
id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
,
"
method
"
:
"
get
"
,
"
result
"
:
"
success
"
,
"
status
"
:
200
,
"
statusText
"
:
"
Ok
"
},
"
Get new document
"
);
}
function
postSameDocument
()
{
return
success
(
jio
.
post
({
"
created
"
:
"
2013-10-10
"
,
"
title
"
:
"
Hey
"
,
"
type
"
:
"
Text
"
}));
}
function
postSameDocumentTest
(
answer
)
{
deepEqual
(
answer
,
{
"
error
"
:
"
conflict
"
,
"
message
"
:
"
Cannot post document
"
,
"
method
"
:
"
post
"
,
"
reason
"
:
"
Document already exists
"
,
"
result
"
:
"
error
"
,
"
status
"
:
409
,
"
statusText
"
:
"
Conflict
"
},
"
Unable to post the same document (conflict)
"
);
}
function
createAttachment
()
{
return
jio
.
putAttachment
({
"
_id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
,
"
_attachment
"
:
"
aa
"
,
"
_data
"
:
"
aaa
"
,
"
_content_type
"
:
"
text/plain
"
});
}
function
createAttachmentTest
(
answer
)
{
deepEqual
(
answer
,
{
"
attachment
"
:
"
aa
"
,
"
digest
"
:
"
sha256-9834876dcfb05cb167a5c24953eba58c4
"
+
"
ac89b1adf57f28f2f9d09af107ee8f0
"
,
"
id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
,
"
method
"
:
"
putAttachment
"
,
"
result
"
:
"
success
"
,
"
status
"
:
201
,
"
statusText
"
:
"
Created
"
},
"
Create new attachment
"
);
}
function
updateAttachment
()
{
return
jio
.
putAttachment
({
"
_id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
,
"
_attachment
"
:
"
aa
"
,
"
_data
"
:
"
aab
"
,
"
_content_type
"
:
"
text/plain
"
});
}
function
updateAttachmentTest
(
answer
)
{
deepEqual
(
answer
,
{
"
attachment
"
:
"
aa
"
,
"
digest
"
:
"
sha256-38760eabb666e8e61ee628a17c4090cc5
"
+
"
0728e095ff24218119d51bd22475363
"
,
"
id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
,
"
method
"
:
"
putAttachment
"
,
"
result
"
:
"
success
"
,
"
status
"
:
204
,
"
statusText
"
:
"
No Content
"
},
"
Update last attachment
"
);
}
function
createAnotherAttachment
()
{
return
jio
.
putAttachment
({
"
_id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
,
"
_attachment
"
:
"
ab
"
,
"
_data
"
:
"
aba
"
,
"
_content_type
"
:
"
text/plain
"
});
}
function
createAnotherAttachmentTest
(
answer
)
{
deepEqual
(
answer
,
{
"
attachment
"
:
"
ab
"
,
"
digest
"
:
"
sha256-e124adcce1fb2f88e1ea799c3d0820845
"
+
"
ed343e6c739e54131fcb3a56e4bc1bd
"
,
"
id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
,
"
method
"
:
"
putAttachment
"
,
"
result
"
:
"
success
"
,
"
status
"
:
201
,
"
statusText
"
:
"
Created
"
},
"
Create another attachment
"
);
}
function
updateLastDocument
()
{
return
jio
.
put
({
"
_id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
,
"
created
"
:
"
2013-10-10
"
,
"
title
"
:
"
Hey
"
,
"
type
"
:
"
Text
"
,
"
modified
"
:
"
2013-10-11
"
});
}
function
updateLastDocumentTest
(
answer
)
{
deepEqual
(
answer
,
{
"
id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
,
"
method
"
:
"
put
"
,
"
result
"
:
"
success
"
,
"
status
"
:
204
,
"
statusText
"
:
"
No Content
"
},
"
Update document metadata
"
);
}
function
getFirstAttachment
()
{
return
jio
.
getAttachment
({
"
_id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
,
"
_attachment
"
:
"
aa
"
});
}
function
getFirstAttachmentTest
(
answer
)
{
var
blob
=
answer
.
data
;
answer
.
data
=
"
<blob>
"
;
deepEqual
(
answer
,
{
"
attachment
"
:
"
aa
"
,
"
data
"
:
"
<blob>
"
,
"
digest
"
:
"
sha256-38760eabb666e8e61ee628a17c4090cc5
"
+
"
0728e095ff24218119d51bd22475363
"
,
"
id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
,
"
method
"
:
"
getAttachment
"
,
"
result
"
:
"
success
"
,
"
status
"
:
200
,
"
statusText
"
:
"
Ok
"
},
"
Get first attachment
"
);
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
getSecondAttachment
()
{
return
jio
.
getAttachment
({
"
_id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
,
"
_attachment
"
:
"
ab
"
});
}
function
getSecondAttachmentTest
(
answer
)
{
var
blob
=
answer
.
data
;
answer
.
data
=
"
<blob>
"
;
deepEqual
(
answer
,
{
"
attachment
"
:
"
ab
"
,
"
data
"
:
"
<blob>
"
,
"
digest
"
:
"
sha256-e124adcce1fb2f88e1ea799c3d0820845
"
+
"
ed343e6c739e54131fcb3a56e4bc1bd
"
,
"
id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
,
"
method
"
:
"
getAttachment
"
,
"
result
"
:
"
success
"
,
"
status
"
:
200
,
"
statusText
"
:
"
Ok
"
},
"
Get first attachment
"
);
return
jIO
.
util
.
readBlobAsText
(
blob
).
then
(
function
(
e
)
{
deepEqual
(
blob
.
type
,
"
text/plain
"
,
"
Check blob type
"
);
deepEqual
(
e
.
target
.
result
,
"
aba
"
,
"
Check blob text content
"
);
},
function
(
err
)
{
deepEqual
(
err
,
"
no error
"
,
"
Check blob text content
"
);
});
}
function
getLastDocument
()
{
return
jio
.
get
({
"
_id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
});
}
function
getLastDocumentTest
(
answer
)
{
deepEqual
(
answer
,
{
"
data
"
:
{
"
_id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
,
"
created
"
:
"
2013-10-10
"
,
"
modified
"
:
"
2013-10-11
"
,
"
title
"
:
"
Hey
"
,
"
type
"
:
"
Text
"
,
"
_attachments
"
:
{
"
aa
"
:
{
"
content_type
"
:
"
text/plain
"
,
"
digest
"
:
"
sha256-38760eabb666e8e61ee628a17c4090cc5
"
+
"
0728e095ff24218119d51bd22475363
"
,
"
length
"
:
3
},
"
ab
"
:
{
"
content_type
"
:
"
text/plain
"
,
"
digest
"
:
"
sha256-e124adcce1fb2f88e1ea799c3d0820845
"
+
"
ed343e6c739e54131fcb3a56e4bc1bd
"
,
"
length
"
:
3
}
}
},
"
id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
,
"
method
"
:
"
get
"
,
"
result
"
:
"
success
"
,
"
status
"
:
200
,
"
statusText
"
:
"
Ok
"
},
"
Get last document metadata
"
);
}
function
removeSecondAttachment
()
{
return
jio
.
removeAttachment
({
"
_id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
,
"
_attachment
"
:
"
ab
"
});
}
function
removeSecondAttachmentTest
(
answer
)
{
deepEqual
(
answer
,
{
"
attachment
"
:
"
ab
"
,
"
id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
,
"
method
"
:
"
removeAttachment
"
,
"
result
"
:
"
success
"
,
"
status
"
:
204
,
"
statusText
"
:
"
No Content
"
},
"
Remove second document
"
);
}
function
getInexistentSecondAttachment
()
{
return
success
(
jio
.
getAttachment
({
"
_id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
,
"
_attachment
"
:
"
ab
"
}));
}
function
getInexistentSecondAttachmentTest
(
answer
)
{
deepEqual
(
answer
,
{
"
attachment
"
:
"
ab
"
,
"
error
"
:
"
not_found
"
,
"
id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
,
"
message
"
:
"
Cannot get attachment
"
,
"
method
"
:
"
getAttachment
"
,
"
reason
"
:
"
missing attachment
"
,
"
result
"
:
"
error
"
,
"
status
"
:
404
,
"
statusText
"
:
"
Not Found
"
},
"
Get inexistent second attachment
"
);
}
function
getOneAttachmentDocument
()
{
return
jio
.
get
({
"
_id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
});
}
function
getOneAttachmentDocumentTest
(
answer
)
{
deepEqual
(
answer
,
{
"
data
"
:
{
"
_attachments
"
:
{
"
aa
"
:
{
"
content_type
"
:
"
text/plain
"
,
"
digest
"
:
"
sha256-38760eabb666e8e61ee628a17c4090cc5
"
+
"
0728e095ff24218119d51bd22475363
"
,
"
length
"
:
3
}
},
"
_id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
,
"
created
"
:
"
2013-10-10
"
,
"
modified
"
:
"
2013-10-11
"
,
"
title
"
:
"
Hey
"
,
"
type
"
:
"
Text
"
},
"
id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
,
"
method
"
:
"
get
"
,
"
result
"
:
"
success
"
,
"
status
"
:
200
,
"
statusText
"
:
"
Ok
"
},
"
Get document metadata
"
);
}
function
removeSecondAttachmentAgain
()
{
return
success
(
jio
.
removeAttachment
({
"
_id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
,
"
_attachment
"
:
"
ab
"
}));
}
function
removeSecondAttachmentAgainTest
(
answer
)
{
deepEqual
(
answer
,
{
"
attachment
"
:
"
ab
"
,
"
error
"
:
"
not_found
"
,
"
id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
,
"
message
"
:
"
Cannot remove attachment
"
,
"
method
"
:
"
removeAttachment
"
,
"
reason
"
:
"
missing attachment
"
,
"
result
"
:
"
error
"
,
"
status
"
:
404
,
"
statusText
"
:
"
Not Found
"
},
"
Remove inexistent attachment
"
);
}
function
getInexistentDocument
()
{
return
success
(
jio
.
get
({
"
_id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
}));
}
function
getInexistentDocumentTest
(
answer
)
{
deepEqual
(
answer
,
{
"
error
"
:
"
not_found
"
,
"
id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
,
"
message
"
:
"
Cannot get document
"
,
"
method
"
:
"
get
"
,
"
reason
"
:
"
missing
"
,
"
result
"
:
"
error
"
,
"
status
"
:
404
,
"
statusText
"
:
"
Not Found
"
},
"
Get inexistent document
"
);
}
function
removeDocument
()
{
return
jio
.
remove
({
"
_id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
});
}
function
removeDocumentTest
(
answer
)
{
deepEqual
(
answer
,
{
"
id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
,
"
method
"
:
"
remove
"
,
"
result
"
:
"
success
"
,
"
status
"
:
204
,
"
statusText
"
:
"
No Content
"
},
"
Remove document and its attachments
"
);
}
function
getInexistentFirstAttachment
()
{
return
success
(
jio
.
getAttachment
({
"
_id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
,
"
_attachment
"
:
"
aa
"
}));
}
function
getInexistentFirstAttachmentTest
(
answer
)
{
deepEqual
(
answer
,
{
"
attachment
"
:
"
aa
"
,
"
error
"
:
"
not_found
"
,
"
id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
,
"
message
"
:
"
Cannot get attachment
"
,
"
method
"
:
"
getAttachment
"
,
"
reason
"
:
"
Document already exists
"
,
"
result
"
:
"
error
"
,
"
status
"
:
404
,
"
statusText
"
:
"
Not Found
"
},
"
Get inexistent first attachment
"
);
}
function
removeInexistentDocument
()
{
return
success
(
jio
.
remove
({
"
_id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
}));
}
function
removeInexistentDocumentTest
(
answer
)
{
deepEqual
(
answer
,
{
"
error
"
:
"
not_found
"
,
"
id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
,
"
message
"
:
"
Cannot remove document
"
,
"
method
"
:
"
remove
"
,
"
reason
"
:
"
missing
"
,
"
result
"
:
"
error
"
,
"
status
"
:
404
,
"
statusText
"
:
"
Not Found
"
},
"
Remove already removed document
"
);
}
function
unexpectedError
(
error
)
{
if
(
error
instanceof
Error
)
{
deepEqual
([
error
.
name
+
"
:
"
+
error
.
message
,
error
],
"
UNEXPECTED ERROR
"
,
"
Unexpected error
"
);
}
else
{
deepEqual
(
error
,
"
UNEXPECTED ERROR
"
,
"
Unexpected error
"
);
}
}
});
}
stop
();
// # Post new documents, list them and remove them
// post a 201
postNewDocument
().
then
(
postNewDocumentTest
).
// get 200
then
(
getCreatedDocument
).
then
(
getCreatedDocumentTest
).
// post b 201
then
(
postSpecificDocument
).
then
(
postSpecificDocumentTest
).
// // check b 204
// then(checkDocument).then(checkDocumentTest).
// // check storage 204
// then(checkStorage).then(checkStorageTest).
// allD 200 2 documents
then
(
listDocuments
).
then
(
list2DocumentsTest
).
// remove a 204
then
(
removeCreatedDocument
).
then
(
removeCreatedDocumentTest
).
// remove b 204
then
(
removeSpecificDocument
).
then
(
removeSpecificDocumentTest
).
// allD 200 empty storage
then
(
listEmptyStorage
).
then
(
listEmptyStorageTest
).
// # Create and update documents, and some attachment and remove them
// put 201
then
(
putNewDocument
).
then
(
putNewDocumentTest
).
// get 200
then
(
getCreatedDocument2
).
then
(
getCreatedDocument2Test
).
// post 409
then
(
postSameDocument
).
then
(
postSameDocumentTest
).
// putA a 204
then
(
createAttachment
).
then
(
createAttachmentTest
).
// putA a 204
then
(
updateAttachment
).
then
(
updateAttachmentTest
).
// putA b 204
then
(
createAnotherAttachment
).
then
(
createAnotherAttachmentTest
).
// put 204
then
(
updateLastDocument
).
then
(
updateLastDocumentTest
).
// getA a 200
then
(
getFirstAttachment
).
then
(
getFirstAttachmentTest
).
// getA b 200
then
(
getSecondAttachment
).
then
(
getSecondAttachmentTest
).
// get 200
then
(
getLastDocument
).
then
(
getLastDocumentTest
).
// removeA b 204
then
(
removeSecondAttachment
).
then
(
removeSecondAttachmentTest
).
// getA b 404
then
(
getInexistentSecondAttachment
).
then
(
getInexistentSecondAttachmentTest
).
// get 200
then
(
getOneAttachmentDocument
).
then
(
getOneAttachmentDocumentTest
).
// removeA b 404
then
(
removeSecondAttachmentAgain
).
then
(
removeSecondAttachmentAgainTest
).
// remove 204
then
(
removeDocument
).
then
(
removeDocumentTest
).
// getA a 404
then
(
getInexistentFirstAttachment
).
then
(
getInexistentFirstAttachmentTest
).
// get 404
then
(
getInexistentDocument
).
then
(
getInexistentDocumentTest
).
// remove 404
then
(
removeInexistentDocument
).
then
(
removeInexistentDocumentTest
).
// end
fail
(
unexpectedError
).
always
(
start
);
// Post a text document. This test also checks if the gid is well
// created. Indeed, the json string "id" of the response is a dict with keys
// inserted in alphabetic order, so that a gid is universal. It also checks
// document types list management. It checks 'string', 'DCMIType' and 'date'
// metadata types.
o
.
spy
(
o
,
'
value
'
,
{
"
ok
"
:
true
,
"
id
"
:
"
{
\"
date
\"
:
\"
2012-12-12
\"
,
\"
language
\"
:
\"
fr
\"
,
"
+
"
\"
title
\"
:
\"
Texte pour ce test
\"
,
\"
type
\"
:
\"
Text
\"
}
"
},
'
Post a text document
'
);
o
.
jio
.
post
({
"
type
"
:
[
"
Text
"
,
"
web page
"
],
"
title
"
:
{
"
lang
"
:
"
fr
"
,
"
content
"
:
"
Texte pour ce test
"
},
"
date
"
:
"
2012-12-12
"
,
"
modified
"
:
"
2012-12-12
"
,
"
format
"
:
"
text/html
"
,
"
language
"
:
"
fr
"
},
o
.
f
);
o
.
tick
(
o
);
// Put the associated attachment
o
.
spy
(
o
,
'
value
'
,
{
"
ok
"
:
true
,
"
id
"
:
"
{
\"
date
\"
:
\"
2012-12-12
\"
,
\"
language
\"
:
\"
fr
\"
,
"
+
"
\"
title
\"
:
\"
Texte pour ce test
\"
,
\"
type
\"
:
\"
Text
\"
}
"
,
"
attachment
"
:
"
body
"
},
'
Put text content as body
'
);
o
.
jio
.
putAttachment
({
"
_id
"
:
"
{
\"
date
\"
:
\"
2012-12-12
\"
,
\"
language
\"
:
\"
fr
\"
,
"
+
"
\"
title
\"
:
\"
Texte pour ce test
\"
,
\"
type
\"
:
\"
Text
\"
}
"
,
"
_attachment
"
:
"
body
"
,
"
_data
"
:
"
<h1>Mon document html.</h1>
"
,
"
_mimetype
"
:
"
text/html
"
},
o
.
f
);
o
.
tick
(
o
);
// Post an image. It checks 'string', 'DCMIType' and 'contentType' metadata
// types.
o
.
spy
(
o
,
'
value
'
,
{
"
ok
"
:
true
,
"
id
"
:
"
{
\"
format
\"
:
\"
text/svg+xml
\"
,
"
+
"
\"
title
\"
:
\"
My image title
\"
,
\"
type
\"
:
\"
Image
\"
}
"
},
'
Post an image document
'
);
o
.
jio
.
post
({
"
type
"
:
"
Image
"
,
"
title
"
:
"
My image title
"
,
"
date
"
:
"
2012-12-13
"
,
"
modified
"
:
"
2012-12-13
"
,
"
format
"
:
"
text/svg+xml
"
},
o
.
f
);
o
.
tick
(
o
);
// Put the associated attachment
o
.
spy
(
o
,
'
value
'
,
{
"
ok
"
:
true
,
"
id
"
:
"
{
\"
format
\"
:
\"
text/svg+xml
\"
,
"
+
"
\"
title
\"
:
\"
My image title
\"
,
\"
type
\"
:
\"
Image
\"
}
"
,
"
attachment
"
:
"
body
"
},
'
Put text content as body
'
);
o
.
jio
.
putAttachment
({
"
_id
"
:
"
{
\"
format
\"
:
\"
text/svg+xml
\"
,
"
+
"
\"
title
\"
:
\"
My image title
\"
,
\"
type
\"
:
\"
Image
\"
}
"
,
"
_attachment
"
:
"
body
"
,
"
_data
"
:
"
<svg/>
"
,
"
_mimetype
"
:
"
text/svg+xml
"
},
o
.
f
);
o
.
tick
(
o
);
// Get the html document
o
.
spy
(
o
,
'
value
'
,
{
"
_id
"
:
"
{
\"
date
\"
:
\"
2012-12-12
\"
,
\"
language
\"
:
\"
fr
\"
,
"
+
"
\"
title
\"
:
\"
Texte pour ce test
\"
,
\"
type
\"
:
\"
Text
\"
}
"
,
"
type
"
:
[
"
Text
"
,
"
web page
"
],
"
title
"
:
{
"
lang
"
:
"
fr
"
,
"
content
"
:
"
Texte pour ce test
"
},
"
date
"
:
"
2012-12-12
"
,
"
modified
"
:
"
2012-12-12
"
,
"
format
"
:
"
text/html
"
,
"
language
"
:
"
fr
"
,
"
_attachments
"
:
{
"
body
"
:
{
"
length
"
:
27
,
"
digest
"
:
"
md5-6f40c762ca7a8fac52567f12ce5441ef
"
,
"
content_type
"
:
"
text/html
"
}
}
},
"
Get html metadata
"
);
o
.
jio
.
get
({
"
_id
"
:
"
{
\"
date
\"
:
\"
2012-12-12
\"
,
\"
language
\"
:
\"
fr
\"
,
"
+
"
\"
title
\"
:
\"
Texte pour ce test
\"
,
\"
type
\"
:
\"
Text
\"
}
"
,
},
o
.
f
);
o
.
tick
(
o
);
// Get a list of documents
o
.
spy
(
o
,
'
value
'
,
{
"
rows
"
:
[{
"
id
"
:
"
{
\"
format
\"
:
\"
text/svg+xml
\"
,
"
+
"
\"
title
\"
:
\"
My image title
\"
,
\"
type
\"
:
\"
Image
\"
}
"
,
"
value
"
:
{}
},
{
"
id
"
:
"
{
\"
date
\"
:
\"
2012-12-12
\"
,
\"
language
\"
:
\"
fr
\"
,
"
+
"
\"
title
\"
:
\"
Texte pour ce test
\"
,
\"
type
\"
:
\"
Text
\"
}
"
,
"
value
"
:
{}
}],
"
total_rows
"
:
2
},
'
Get a document list
'
);
o
.
jio
.
allDocs
({
"
sort_on
"
:
[[
"
title
"
,
"
ascending
"
]]},
o
.
f
);
o
.
tick
(
o
);
util
.
closeAndcleanUpJio
(
o
.
jio
);
});
});
}));
}));
test/tests.html
View file @
f3294a72
...
@@ -29,5 +29,8 @@
...
@@ -29,5 +29,8 @@
<script
src=
"../src/jio.storage/indexstorage.js"
></script>
<script
src=
"../src/jio.storage/indexstorage.js"
></script>
<script
src=
"jio.storage/indexstorage.tests.js"
></script>
<script
src=
"jio.storage/indexstorage.tests.js"
></script>
<script
src=
"../src/jio.storage/gidstorage.js"
></script>
<script
src=
"../test/jio.storage/gidstorage.tests.js"
></script>
</body>
</body>
</html>
</html>
test/tests.require.js
View file @
f3294a72
...
@@ -26,6 +26,9 @@
...
@@ -26,6 +26,9 @@
"
indexstorage
"
:
"
../src/jio.storage/indexstorage
"
,
"
indexstorage
"
:
"
../src/jio.storage/indexstorage
"
,
"
indexstorage_tests
"
:
"
jio.storage/indexstorage.tests
"
,
"
indexstorage_tests
"
:
"
jio.storage/indexstorage.tests
"
,
"
gidstorage
"
:
"
../src/jio.storage/gidstorage
"
,
"
gidstorage_tests
"
:
"
jio.storage/gidstorage.tests
"
,
"
qunit
"
:
"
../lib/qunit/qunit
"
,
"
qunit
"
:
"
../lib/qunit/qunit
"
,
"
sinon
"
:
"
../lib/sinon/sinon
"
,
"
sinon
"
:
"
../lib/sinon/sinon
"
,
"
sinon_qunit
"
:
"
../lib/sinon/sinon-qunit
"
"
sinon_qunit
"
:
"
../lib/sinon/sinon-qunit
"
...
@@ -42,6 +45,7 @@
...
@@ -42,6 +45,7 @@
"
complex_queries_tests
"
,
"
complex_queries_tests
"
,
"
localstorage_tests
"
,
"
localstorage_tests
"
,
"
davstorage_tests
"
,
"
davstorage_tests
"
,
"
indexstorage_tests
"
"
indexstorage_tests
"
,
"
gidstorage_tests
"
]);
]);
}());
}());
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