Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Bryan Kaperick
jio
Commits
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
Show 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 */
/*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);
(
function
(
dependencies
,
module
)
{
...
...
@@ -7,699 +8,670 @@
if
(
typeof
define
===
'
function
'
&&
define
.
amd
)
{
return
define
(
dependencies
,
module
);
}
module
(
jIO
,
jio_tests
);
}([
'
jio
'
,
'
jio_tests
'
,
'
localstorage
'
,
'
gidstorage
'
],
function
(
jIO
,
util
)
{
module
(
RSVP
,
jIO
);
}([
'
rsvp
'
,
'
jio
'
,
'
localstorage
'
,
'
gidstorage
'
],
function
(
RSVP
,
jIO
)
{
"
use strict
"
;
function
generateTools
()
{
return
{
clock
:
sinon
.
useFakeTimers
(),
spy
:
util
.
ospy
,
tick
:
util
.
otick
};
}
module
(
"
GID Storage
"
);
test
(
"
Post
"
,
function
(
)
{
var
o
=
generateTools
(
this
);
o
.
localstorage_spec
=
{
"
type
"
:
"
local
"
,
"
username
"
:
"
one
"
,
"
application_name
"
:
"
gid storage post test
"
};
function
success
(
promise
)
{
return
new
RSVP
.
Promise
(
function
(
resolve
,
reject
,
notify
)
{
/*jslint unparam: true*/
promise
.
then
(
resolve
,
resolve
,
notify
);
},
function
()
{
promise
.
cancel
();
});
}
// local jio is going to help us to prepare localstorage for gid tests
o
.
local_jio
=
jIO
.
newJio
(
o
.
localstorage_spec
);
/**
* Test with a memory storage, the responses of gid storage should not be
* related to memory storage ones.
*/
test
(
"
Scenario
"
,
29
,
function
()
{
o
.
jio
=
jIO
.
newJio
({
var
jio
=
jIO
.
createJIO
({
"
type
"
:
"
gid
"
,
"
sub_storage
"
:
o
.
localstorage_spec
,
"
constraints
"
:
{
"
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
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
);
function
postNewDocument
()
{
return
jio
.
post
({
"
created
"
:
"
2013-10-10
"
,
"
title
"
:
"
Unique ID
"
,
"
type
"
:
"
Text
"
});
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
"
}
function
postNewDocumentTest
(
answer
)
{
deepEqual
(
answer
,
{
"
id
"
:
'
{"created":"2013-10-10","title":"Unique ID","type":"Text"}
'
,
"
method
"
:
"
post
"
,
"
result
"
:
"
success
"
,
"
status
"
:
201
,
"
statusText
"
:
"
Created
"
},
"
Post a new document
"
);
}
});
// 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
);
function
getCreatedDocument
()
{
return
jio
.
get
({
"
_id
"
:
'
{"created":"2013-10-10","title":"Unique ID","type":"Text"}
'
});
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
"
}
function
getCreatedDocumentTest
(
answer
)
{
deepEqual
(
answer
,
{
"
data
"
:
{
"
_id
"
:
'
{"created":"2013-10-10","title":"Unique ID","type":"Text"}
'
,
"
created
"
:
"
2013-10-10
"
,
"
title
"
:
"
Unique ID
"
,
"
type
"
:
"
Text
"
},
"
id
"
:
'
{"created":"2013-10-10","title":"Unique ID","type":"Text"}
'
,
"
method
"
:
"
get
"
,
"
result
"
:
"
success
"
,
"
status
"
:
200
,
"
statusText
"
:
"
Ok
"
},
"
Get new document
"
);
}
function
postSpecificDocument
()
{
return
jio
.
post
({
"
_id
"
:
'
{"created":"2013-10-10","title":"Bee","type":"Text"}
'
,
"
created
"
:
"
2013-10-10
"
,
"
title
"
:
"
Bee
"
,
"
type
"
:
"
Text
"
});
}
// 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
);
function
postSpecificDocumentTest
(
answer
)
{
deepEqual
(
answer
,
{
"
id
"
:
'
{"created":"2013-10-10","title":"Bee","type":"Text"}
'
,
"
method
"
:
"
post
"
,
"
result
"
:
"
success
"
,
"
status
"
:
201
,
"
statusText
"
:
"
Created
"
},
"
Post specific document
"
);
}
util
.
closeAndcleanUpJio
(
o
.
local_jio
);
function
listDocuments
()
{
return
jio
.
allDocs
();
}
// Get all document and sort to make comparison easier
o
.
spy
(
o
,
'
value
'
,
{
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
"
:
{
"
total_rows
"
:
2
,
"
rows
"
:
[{
"
id
"
:
"
{
\"
creator
\"
:[
\"
a
\"
]}
"
,
"
id
"
:
'
{"created":"2013-10-10","title":"Unique ID","type":"Text"}
'
,
"
value
"
:
{}
},
{
"
id
"
:
"
{
\"
creator
\"
:[
\"
a
\"
,
\"
b
\"
]}
"
,
"
id
"
:
'
{"created":"2013-10-10","title":"Bee","type":"Text"}
'
,
"
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
);
}]
},
"
method
"
:
"
allDocs
"
,
"
result
"
:
"
success
"
,
"
status
"
:
200
,
"
statusText
"
:
"
Ok
"
},
"
List 2 documents
"
);
}
function
removeCreatedDocument
()
{
return
jio
.
remove
({
"
_id
"
:
'
{"created":"2013-10-10","title":"Unique ID","type":"Text"}
'
});
}
test
(
"
Put
"
,
function
()
{
var
o
=
generateTools
(
this
);
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.
"
);
}
o
.
localstorage_spec
=
{
"
type
"
:
"
local
"
,
"
username
"
:
"
one
"
,
"
application_name
"
:
"
gid storage put test
"
}
;
function
removeSpecificDocument
()
{
return
jio
.
remove
({
"
_id
"
:
'
{"created":"2013-10-10","title":"Bee","type":"Text"}
'
});
}
// local jio is going to help us to prepare localstorage for gid tests
o
.
local_jio
=
jIO
.
newJio
(
o
.
localstorage_spec
);
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.
"
);
}
o
.
jio
=
jIO
.
newJio
({
"
type
"
:
"
gid
"
,
"
sub_storage
"
:
o
.
localstorage_spec
,
"
constraints
"
:
{
"
default
"
:
{
"
creator
"
:
"
list
"
function
listEmptyStorage
()
{
return
jio
.
allDocs
();
}
function
listEmptyStorageTest
(
answer
)
{
deepEqual
(
answer
,
{
"
data
"
:
{
"
total_rows
"
:
0
,
"
rows
"
:
[]
},
"
method
"
:
"
allDocs
"
,
"
result
"
:
"
success
"
,
"
status
"
:
200
,
"
statusText
"
:
"
Ok
"
},
"
List empty storage
"
);
}
});
// 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
);
function
putNewDocument
()
{
return
jio
.
put
({
"
_id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
,
"
created
"
:
"
2013-10-10
"
,
"
title
"
:
"
Hey
"
,
"
type
"
:
"
Text
"
});
}
test
(
"
Remove
"
,
function
()
{
var
o
=
generateTools
(
this
);
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
"
);
}
o
.
localstorage_spec
=
{
"
type
"
:
"
local
"
,
"
username
"
:
"
one
"
,
"
application_name
"
:
"
gid storage remove test
"
}
;
function
getCreatedDocument2
()
{
return
jio
.
get
({
"
_id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
});
}
// local jio is going to help us to prepare localstorage for gid tests
o
.
local_jio
=
jIO
.
newJio
(
o
.
localstorage_spec
);
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
"
);
}
o
.
jio
=
jIO
.
newJio
(
{
"
type
"
:
"
gid
"
,
"
sub_storage
"
:
o
.
localstorage_spec
,
"
constraints
"
:
{
"
default
"
:
{
"
creator
"
:
"
list
"
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
"
);
}
// 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
);
function
updateAttachment
()
{
return
jio
.
putAttachment
({
"
_id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
,
"
_attachment
"
:
"
aa
"
,
"
_data
"
:
"
aab
"
,
"
_content_type
"
:
"
text/plain
"
});
}
test
(
"
putAttachment
"
,
function
()
{
var
o
=
generateTools
(
this
);
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
"
);
}
o
.
localstorage_spec
=
{
"
type
"
:
"
local
"
,
"
username
"
:
"
one
"
,
"
application_name
"
:
"
gid storage put attachment test
"
};
function
createAnotherAttachment
()
{
return
jio
.
putAttachment
({
"
_id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
,
"
_attachment
"
:
"
ab
"
,
"
_data
"
:
"
aba
"
,
"
_content_type
"
:
"
text/plain
"
});
}
// local jio is going to help us to prepare localstorage for gid tests
o
.
local_jio
=
jIO
.
newJio
(
o
.
localstorage_spec
);
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
"
);
}
o
.
jio
=
jIO
.
newJio
({
"
type
"
:
"
gid
"
,
"
sub_storage
"
:
o
.
localstorage_spec
,
"
constraints
"
:
{
"
default
"
:
{
"
creator
"
:
"
list
"
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
"
});
}
// 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 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
);
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
"
);
});
}
test
(
"
getAttachment
"
,
function
()
{
var
o
=
generateTools
(
this
);
function
getSecondAttachment
()
{
return
jio
.
getAttachment
({
"
_id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
,
"
_attachment
"
:
"
ab
"
});
}
o
.
localstorage_spec
=
{
"
type
"
:
"
local
"
,
"
username
"
:
"
one
"
,
"
application_name
"
:
"
gid storage get attachment test
"
};
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
"
);
});
}
// local jio is going to help us to prepare localstorage for gid tests
o
.
local_jio
=
jIO
.
newJio
(
o
.
localstorage_spec
);
function
getLastDocument
()
{
return
jio
.
get
({
"
_id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
});
}
o
.
jio
=
jIO
.
newJio
({
"
type
"
:
"
gid
"
,
"
sub_storage
"
:
o
.
localstorage_spec
,
"
constraints
"
:
{
"
default
"
:
{
"
creator
"
:
"
list
"
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
"
);
}
// 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 get attachment because given gid doesn't respect constraints
o
.
spy
(
o
,
'
status
'
,
400
,
'
get attachment without respecting constraints
'
+
'
-> bad request
'
);
o
.
jio
.
getAttachment
({
"
_id
"
:
"
a
"
,
"
_attachment
"
:
"
body
"
},
o
.
f
);
o
.
tick
(
o
);
// Fail to get an inexistent attachment from a document
o
.
spy
(
o
,
'
status
'
,
404
,
'
Get inexistent attachment
'
);
o
.
jio
.
getAttachment
({
"
_id
"
:
"
{
\"
creator
\"
:[
\"
a
\"
]}
"
,
"
_attachment
"
:
"
body
"
},
o
.
f
);
o
.
tick
(
o
);
// Add an attachment manually to the document 'blue'
o
.
local_jio
.
putAttachment
({
"
_id
"
:
"
blue
"
,
"
_attachment
"
:
"
body
"
,
"
_data
"
:
"
lol
"
,
"
_mimetype
"
:
"
text/plain
"
function
removeSecondAttachment
()
{
return
jio
.
removeAttachment
({
"
_id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
,
"
_attachment
"
:
"
ab
"
});
o
.
clock
.
tick
(
2000
);
util
.
closeAndcleanUpJio
(
o
.
local_jio
);
// Succeed to get the previous attachment
o
.
spy
(
o
,
'
value
'
,
"
lol
"
,
'
Get attachment
'
);
o
.
jio
.
getAttachment
({
"
_id
"
:
"
{
\"
creator
\"
:[
\"
a
\"
]}
"
,
"
_attachment
"
:
"
body
"
},
o
.
f
);
o
.
tick
(
o
);
util
.
closeAndcleanUpJio
(
o
.
jio
);
}
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"}
'
});
}
test
(
"
removeAttachment
"
,
function
()
{
var
o
=
generateTools
(
this
);
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
"
);
}
o
.
localstorage_spec
=
{
"
type
"
:
"
local
"
,
"
username
"
:
"
one
"
,
"
application_name
"
:
"
gid storage remove attachment test
"
};
function
removeSecondAttachmentAgain
()
{
return
success
(
jio
.
removeAttachment
({
"
_id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
,
"
_attachment
"
:
"
ab
"
}));
}
// local jio is going to help us to prepare localstorage for gid tests
o
.
local_jio
=
jIO
.
newJio
(
o
.
localstorage_spec
);
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
"
);
}
o
.
jio
=
jIO
.
newJio
({
"
type
"
:
"
gid
"
,
"
sub_storage
"
:
o
.
localstorage_spec
,
"
constraints
"
:
{
"
default
"
:
{
"
creator
"
:
"
list
"
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
"
);
}
});
// 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
);
o
.
local_jio
.
putAttachment
({
"
_id
"
:
"
blue
"
,
"
_attachment
"
:
"
body
"
,
"
_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
);
function
removeDocument
()
{
return
jio
.
remove
({
"
_id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
});
}
test
(
"
More Constraints
"
,
function
()
{
// This test will use gid storage in a 'real case'
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
"
);
}
var
o
=
generateTools
(
this
);
function
getInexistentFirstAttachment
()
{
return
success
(
jio
.
getAttachment
({
"
_id
"
:
'
{"created":"2013-10-10","title":"Hey","type":"Text"}
'
,
"
_attachment
"
:
"
aa
"
}));
}
o
.
localstorage_spec
=
{
"
type
"
:
"
local
"
,
"
username
"
:
"
one
"
,
"
application_name
"
:
"
gid storage more constraints test
"
};
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
"
);
}
o
.
jio
=
jIO
.
newJio
({
"
type
"
:
"
gid
"
,
"
sub_storage
"
:
o
.
localstorage_spec
,
"
constraints
"
:
{
"
default
"
:
{
"
type
"
:
"
DCMIType
"
,
"
title
"
:
"
string
"
},
"
Text
"
:
{
"
date
"
:
"
date
"
,
"
language
"
:
"
string
"
},
"
Image
"
:
{
"
format
"
:
"
contentType
"
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
"
);
}
});
// 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
"
function
unexpectedError
(
error
)
{
if
(
error
instanceof
Error
)
{
deepEqual
([
error
.
name
+
"
:
"
+
error
.
message
,
error
],
"
UNEXPECTED ERROR
"
,
"
Unexpected error
"
);
}
else
{
deepEqual
(
error
,
"
UNEXPECTED ERROR
"
,
"
Unexpected error
"
);
}
}
},
"
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
);
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
);
util
.
closeAndcleanUpJio
(
o
.
jio
);
});
}));
test/tests.html
View file @
f3294a72
...
...
@@ -29,5 +29,8 @@
<script
src=
"../src/jio.storage/indexstorage.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>
</html>
test/tests.require.js
View file @
f3294a72
...
...
@@ -26,6 +26,9 @@
"
indexstorage
"
:
"
../src/jio.storage/indexstorage
"
,
"
indexstorage_tests
"
:
"
jio.storage/indexstorage.tests
"
,
"
gidstorage
"
:
"
../src/jio.storage/gidstorage
"
,
"
gidstorage_tests
"
:
"
jio.storage/gidstorage.tests
"
,
"
qunit
"
:
"
../lib/qunit/qunit
"
,
"
sinon
"
:
"
../lib/sinon/sinon
"
,
"
sinon_qunit
"
:
"
../lib/sinon/sinon-qunit
"
...
...
@@ -42,6 +45,7 @@
"
complex_queries_tests
"
,
"
localstorage_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