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
Kirill Smelkov
jio
Commits
96d5d045
Commit
96d5d045
authored
Feb 16, 2015
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add test for LocalStorage
parent
073ebc39
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
247 additions
and
700 deletions
+247
-700
src/jio.storage/localstorage.js
src/jio.storage/localstorage.js
+11
-20
test/jio.storage/localstorage.tests.js
test/jio.storage/localstorage.tests.js
+234
-678
test/tests.html
test/tests.html
+2
-2
No files found.
src/jio.storage/localstorage.js
View file @
96d5d045
...
...
@@ -5,7 +5,7 @@
*/
/*jslint nomen: true */
/*global jIO, localStorage,
window, Blob, Uint8Array
, RSVP */
/*global jIO, localStorage,
Blob
, RSVP */
/**
* JIO Local Storage. Type = 'local'.
...
...
@@ -20,7 +20,7 @@
* @class LocalStorage
*/
(
function
(
jIO
)
{
(
function
(
jIO
,
localStorage
,
Blob
,
RSVP
)
{
"
use strict
"
;
function
LocalStorage
()
{
...
...
@@ -34,47 +34,38 @@
}
}
/**
* Get a document
*
* @method get
* @param {Object} param The given parameters
* @param {Object} options The command options
*/
LocalStorage
.
prototype
.
get
=
function
(
param
)
{
restrictDocumentId
(
param
.
_id
);
var
doc
=
{},
attachments
=
{},
found
=
false
,
key
;
for
(
key
in
localStorage
)
{
if
(
localStorage
.
hasOwnProperty
(
key
))
{
attachments
[
key
]
=
{};
found
=
true
;
}
}
if
(
attachments
.
length
!==
0
)
{
if
(
found
)
{
doc
.
_attachments
=
attachments
;
}
return
doc
;
};
/**
* Get an attachment
*
* @method getAttachment
* @param {Object} param The given parameters
* @param {Object} options The command options
*/
LocalStorage
.
prototype
.
getAttachment
=
function
(
param
)
{
restrictDocumentId
(
param
.
_id
);
var
textstring
=
localStorage
.
getItem
(
param
.
_attachment
);
if
(
textstring
===
null
)
{
throw
new
jIO
.
util
.
jIOError
(
"
Cannot find attachment
"
,
404
);
throw
new
jIO
.
util
.
jIOError
(
"
Cannot find attachment
"
+
param
.
_attachment
,
404
);
}
return
new
Blob
([
textstring
])
;
return
{
data
:
new
Blob
([
textstring
])}
;
};
LocalStorage
.
prototype
.
putAttachment
=
function
(
param
)
{
...
...
@@ -110,4 +101,4 @@
jIO
.
addStorage
(
'
local
'
,
LocalStorage
);
}(
jIO
));
}(
jIO
,
localStorage
,
Blob
,
RSVP
));
test/jio.storage/localstorage.tests.js
View file @
96d5d045
/*jslint
maxlen: 120,
nomen: true */
/*global localStorage,
test_util, console, Blob
*/
(
function
(
jIO
,
localStorage
,
QUnit
)
{
/*jslint nomen: true */
/*global localStorage,
Blob, document
*/
(
function
(
jIO
,
localStorage
,
QUnit
,
Blob
,
document
)
{
"
use strict
"
;
var
test
=
QUnit
.
test
,
stop
=
QUnit
.
stop
,
...
...
@@ -11,7 +11,10 @@
equal
=
QUnit
.
equal
,
module
=
QUnit
.
module
;
module
(
"
localStorage
"
,
{
/////////////////////////////////////////////////////////////////
// localStorage.get
/////////////////////////////////////////////////////////////////
module
(
"
localStorage.get
"
,
{
setup
:
function
()
{
localStorage
.
clear
();
this
.
jio
=
jIO
.
createJIO
({
...
...
@@ -20,21 +23,17 @@
}
});
/////////////////////////////////////////////////////////////////
// localStorage.get
/////////////////////////////////////////////////////////////////
test
(
"
get inexistent document
"
,
function
()
{
test
(
"
get non valid document ID
"
,
function
()
{
stop
();
expect
(
3
);
this
.
jio
.
get
({
"
_id
"
:
"
inexistent
"
})
.
fail
(
function
(
error
)
{
ok
(
error
instanceof
jIO
.
util
.
jIOError
);
equal
(
error
.
message
,
"
Cannot find document
"
);
equal
(
error
.
status_code
,
40
4
);
equal
(
error
.
message
,
"
id inexistent is forbidden (!== /)
"
);
equal
(
error
.
status_code
,
40
0
);
})
.
fail
(
function
(
error
)
{
console
.
error
(
error
);
ok
(
false
,
error
);
})
.
always
(
function
()
{
...
...
@@ -42,18 +41,15 @@
});
});
test
(
"
get document
"
,
function
()
{
var
id
=
"
post1
"
;
localStorage
[
id
]
=
JSON
.
stringify
({
title
:
"
myPost1
"
});
test
(
"
get document without attachment
"
,
function
()
{
var
id
=
"
/
"
;
stop
();
expect
(
1
);
this
.
jio
.
get
({
"
_id
"
:
id
})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
"
title
"
:
"
myPost1
"
"
_id
"
:
"
/
"
},
"
Check document
"
);
})
.
fail
(
function
(
error
)
{
...
...
@@ -65,33 +61,19 @@
});
test
(
"
get document with attachment
"
,
function
()
{
var
id
=
"
putattmt1
"
;
var
id
=
"
/
"
,
attachment
=
"
foo
"
;
stop
();
expect
(
1
);
localStorage
[
id
]
=
JSON
.
stringify
({
"
_id
"
:
id
,
"
_attachments
"
:
{
"
putattmt2
"
:
{
content_type
:
""
,
digest
:
"
sha256-e3b0c44298fc1c149afbf4c8996fb9242
"
+
"
7ae41e4649b934ca495991b7852b855
"
,
length
:
0
}
}
});
localStorage
[
attachment
]
=
"
bar
"
;
this
.
jio
.
get
({
"
_id
"
:
id
})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
"
_id
"
:
id
,
"
_attachments
"
:
{
"
putattmt2
"
:
{
content_type
:
""
,
digest
:
"
sha256-e3b0c44298fc1c149afbf4c8996fb9242
"
+
"
7ae41e4649b934ca495991b7852b855
"
,
length
:
0
}
"
foo
"
:
{}
}
},
"
Check document
"
);
})
...
...
@@ -104,39 +86,29 @@
});
/////////////////////////////////////////////////////////////////
// localStorage.
pos
t
// localStorage.
getAttachmen
t
/////////////////////////////////////////////////////////////////
test
(
"
post without id
"
,
function
()
{
expect
(
1
);
stop
();
this
.
jio
.
post
({})
.
then
(
function
(
uuid
)
{
// ok(util.isUuid(uuid), "Uuid should look like " +
// "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx : " + uuid);
equal
(
localStorage
[
uuid
],
JSON
.
stringify
({
"
_id
"
:
uuid
}));
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
module
(
"
localStorage.getAttachment
"
,
{
setup
:
function
()
{
localStorage
.
clear
();
this
.
jio
=
jIO
.
createJIO
({
"
type
"
:
"
local
"
});
}
});
test
(
"
post non empty document
"
,
function
()
{
expect
(
2
);
test
(
"
get attachment from inexistent document
"
,
function
()
{
stop
();
expect
(
3
);
this
.
jio
.
post
({
"
_id
"
:
"
post1
"
,
"
title
"
:
"
myPost1
"
})
.
then
(
function
(
uuid
)
{
equal
(
uuid
,
"
post1
"
);
equal
(
localStorage
.
post1
,
JSON
.
stringify
({
"
_id
"
:
"
post1
"
,
"
title
"
:
"
myPost1
"
}));
this
.
jio
.
getAttachment
({
"
_id
"
:
"
inexistent
"
,
"
_attachment
"
:
"
a
"
})
.
fail
(
function
(
error
)
{
ok
(
error
instanceof
jIO
.
util
.
jIOError
);
equal
(
error
.
message
,
"
id inexistent is forbidden (!== /)
"
);
equal
(
error
.
status_code
,
400
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
...
...
@@ -146,48 +118,49 @@
});
});
test
(
"
post but document already exists
"
,
function
()
{
var
id
=
"
post1
"
;
localStorage
[
id
]
=
JSON
.
stringify
({
"
_id
"
:
id
,
title
:
"
myPost1
"
});
expect
(
4
);
test
(
"
get inexistent attachment from document
"
,
function
()
{
var
id
=
"
/
"
;
stop
();
expect
(
3
);
this
.
jio
.
post
({
"
_id
"
:
"
post1
"
,
"
title
"
:
"
myPost2
"
})
.
then
(
function
(
result
)
{
ok
(
false
,
result
);
})
this
.
jio
.
getAttachment
({
"
_id
"
:
id
,
"
_attachment
"
:
"
inexistent
"
})
.
fail
(
function
(
error
)
{
ok
(
error
instanceof
jIO
.
util
.
jIOError
);
equal
(
error
.
message
,
"
Cannot create a new document
"
);
equal
(
error
.
status_code
,
409
);
equal
(
localStorage
.
post1
,
JSON
.
stringify
({
"
_id
"
:
"
post1
"
,
"
title
"
:
"
myPost1
"
}));
equal
(
error
.
message
,
"
Cannot find attachment inexistent
"
);
equal
(
error
.
status_code
,
404
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// localStorage.put
/////////////////////////////////////////////////////////////////
test
(
"
put non empty document
"
,
function
()
{
expect
(
2
);
test
(
"
get string attachment from document
"
,
function
()
{
var
id
=
"
/
"
,
value
=
"
azertyuio
\n
pàç_è-('é&
"
,
attachment
=
"
stringattachment
"
;
stop
();
expect
(
4
);
localStorage
[
attachment
]
=
value
;
this
.
jio
.
put
({
"
_id
"
:
"
put1
"
,
"
title
"
:
"
myPut1
"
})
.
then
(
function
(
uuid
)
{
equal
(
uuid
,
"
put1
"
);
equal
(
localStorage
.
put1
,
JSON
.
stringify
({
"
_id
"
:
"
put1
"
,
"
title
"
:
"
myPut1
"
}));
this
.
jio
.
getAttachment
({
"
_id
"
:
id
,
"
_attachment
"
:
attachment
})
.
then
(
function
(
result
)
{
ok
(
result
.
data
instanceof
Blob
,
"
Data is Blob
"
);
deepEqual
(
result
.
data
.
type
,
""
,
"
Check mimetype
"
);
deepEqual
(
result
.
data
.
size
,
24
,
"
Check size
"
);
return
jIO
.
util
.
readBlobAsText
(
result
.
data
);
})
.
then
(
function
(
result
)
{
equal
(
result
.
target
.
result
,
value
,
"
Attachment correctly fetched
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
...
...
@@ -197,22 +170,44 @@
});
});
test
(
"
put when document already exists
"
,
function
()
{
var
id
=
"
put1
"
;
localStorage
[
id
]
=
JSON
.
stringify
({
"
_id
"
:
id
,
title
:
"
myPut1
"
});
expect
(
2
);
test
(
"
get binary string attachment from document
"
,
function
()
{
var
id
=
"
/
"
,
context
=
this
,
imgCanvas
=
document
.
createElement
(
"
canvas
"
),
imgContext
=
imgCanvas
.
getContext
(
"
2d
"
),
data_url
,
value
,
attachment
=
"
stringattachment
"
;
stop
();
expect
(
2
);
imgCanvas
.
width
=
200
;
imgCanvas
.
height
=
200
;
imgContext
.
fillStyle
=
"
blue
"
;
imgContext
.
font
=
"
bold 16px Arial
"
;
imgContext
.
fillText
(
"
Zibri
"
,
100
,
100
);
this
.
jio
.
put
({
"
_id
"
:
id
,
"
title
"
:
"
myPut2
"
})
.
then
(
function
(
uuid
)
{
equal
(
uuid
,
"
put1
"
);
equal
(
localStorage
.
put1
,
JSON
.
stringify
({
"
_id
"
:
"
put1
"
,
"
title
"
:
"
myPut2
"
}));
data_url
=
imgCanvas
.
toDataURL
(
"
image/png
"
);
return
jIO
.
util
.
ajax
({
url
:
data_url
})
.
then
(
function
(
result
)
{
value
=
result
.
target
.
response
;
localStorage
[
attachment
]
=
value
;
return
context
.
jio
.
getAttachment
({
"
_id
"
:
id
,
"
_attachment
"
:
attachment
});
})
.
then
(
function
(
result
)
{
ok
(
result
.
data
instanceof
Blob
,
"
Data is Blob
"
);
return
jIO
.
util
.
readBlobAsText
(
result
.
data
);
})
.
then
(
function
(
result
)
{
equal
(
result
.
target
.
result
,
value
,
"
Attachment correctly fetched
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
...
...
@@ -223,20 +218,30 @@
});
/////////////////////////////////////////////////////////////////
// localStorage.
ge
tAttachment
// localStorage.
pu
tAttachment
/////////////////////////////////////////////////////////////////
test
(
"
get attachment from inexistent document
"
,
function
()
{
module
(
"
localStorage.putAttachment
"
,
{
setup
:
function
()
{
localStorage
.
clear
();
this
.
jio
=
jIO
.
createJIO
({
"
type
"
:
"
local
"
});
}
});
test
(
"
put an attachment to an inexistent document
"
,
function
()
{
stop
();
expect
(
3
);
this
.
jio
.
ge
tAttachment
({
this
.
jio
.
pu
tAttachment
({
"
_id
"
:
"
inexistent
"
,
"
_attachment
"
:
"
a
"
"
_attachment
"
:
"
putattmt2
"
,
"
_data
"
:
""
})
.
fail
(
function
(
error
)
{
ok
(
error
instanceof
jIO
.
util
.
jIOError
);
equal
(
error
.
message
,
"
Cannot find document
"
);
equal
(
error
.
status_code
,
40
4
);
equal
(
error
.
message
,
"
id inexistent is forbidden (!== /)
"
);
equal
(
error
.
status_code
,
40
0
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
...
...
@@ -246,23 +251,21 @@
});
});
test
(
"
get inexistent attachment from document
"
,
function
()
{
var
id
=
"
b
"
;
test
(
"
put string attachment from document
"
,
function
()
{
var
id
=
"
/
"
,
value
=
"
azertyuio
\n
pàç_è-('é&
"
,
attachment
=
"
stringattachment
"
;
stop
();
expect
(
3
);
expect
(
1
);
localStorage
[
id
]
=
JSON
.
stringify
({
"
_id
"
:
id
});
this
.
jio
.
ge
tAttachment
({
this
.
jio
.
pu
tAttachment
({
"
_id
"
:
id
,
"
_attachment
"
:
"
inexistent
"
"
_attachment
"
:
attachment
,
"
_data
"
:
value
})
.
fail
(
function
(
error
)
{
ok
(
error
instanceof
jIO
.
util
.
jIOError
);
equal
(
error
.
message
,
"
Cannot find attachment
"
);
equal
(
error
.
status_code
,
404
);
.
then
(
function
()
{
equal
(
localStorage
[
attachment
],
value
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
...
...
@@ -272,39 +275,41 @@
});
});
test
(
"
get attachment from document
"
,
function
()
{
var
id
=
"
putattmt1
"
,
attachment
=
"
putattmt2
"
;
test
(
"
put binary string attachment from document
"
,
function
()
{
var
id
=
"
/
"
,
context
=
this
,
imgCanvas
=
document
.
createElement
(
"
canvas
"
),
imgContext
=
imgCanvas
.
getContext
(
"
2d
"
),
data_url
,
original_blob
,
value
,
attachment
=
"
stringattachment
"
;
stop
();
expect
(
4
);
expect
(
1
);
localStorage
[
id
]
=
JSON
.
stringify
({
"
_id
"
:
id
,
"
_attachments
"
:
{
"
putattmt2
"
:
{
content_type
:
""
,
digest
:
"
sha256-e3b0c44298fc1c149afbf4c8996fb9242
"
+
"
7ae41e4649b934ca495991b7852b855
"
,
length
:
0
}
}
});
localStorage
[
id
+
'
/
'
+
attachment
]
=
JSON
.
stringify
(
""
);
imgCanvas
.
width
=
200
;
imgCanvas
.
height
=
200
;
this
.
jio
.
getAttachment
({
"
_id
"
:
id
,
"
_attachment
"
:
attachment
imgContext
.
fillStyle
=
"
blue
"
;
imgContext
.
font
=
"
bold 16px Arial
"
;
imgContext
.
fillText
(
"
Zibri
"
,
100
,
100
);
data_url
=
imgCanvas
.
toDataURL
(
"
image/png
"
);
return
jIO
.
util
.
ajax
({
url
:
data_url
})
.
then
(
function
(
result
)
{
ok
(
result
.
data
instanceof
Blob
,
"
Data is Blob
"
);
deepEqual
(
result
.
data
.
type
,
""
,
"
Check mimetype
"
);
deepEqual
(
result
.
data
.
size
,
0
,
"
Check size
"
);
delete
result
.
data
;
deepEqual
(
result
,
{
"
digest
"
:
"
sha256-e3b0c44298fc1c149afbf4c8996fb9242
"
+
"
7ae41e4649b934ca495991b7852b855
"
},
"
Get Attachment, Check Response
"
);
value
=
result
.
target
.
response
;
original_blob
=
new
Blob
([
result
.
target
.
response
],
{
type
:
"
image/png
"
});
return
context
.
jio
.
putAttachment
({
"
_id
"
:
id
,
"
_attachment
"
:
attachment
,
"
_blob
"
:
original_blob
});
})
.
then
(
function
()
{
equal
(
localStorage
[
attachment
],
value
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
...
...
@@ -314,23 +319,29 @@
});
});
/////////////////////////////////////////////////////////////////
// localStorage.
put
Attachment
// localStorage.
remove
Attachment
/////////////////////////////////////////////////////////////////
test
(
"
put an attachment to an inexistent document
"
,
function
()
{
module
(
"
localStorage.removeAttachment
"
,
{
setup
:
function
()
{
this
.
jio
=
jIO
.
createJIO
({
"
type
"
:
"
local
"
});
}
});
test
(
"
remove an attachment to an inexistent document
"
,
function
()
{
stop
();
expect
(
3
);
this
.
jio
.
put
Attachment
({
this
.
jio
.
remove
Attachment
({
"
_id
"
:
"
inexistent
"
,
"
_attachment
"
:
"
putattmt2
"
,
"
_data
"
:
""
"
_attachment
"
:
"
removeattmt2
"
})
.
fail
(
function
(
error
)
{
ok
(
error
instanceof
jIO
.
util
.
jIOError
);
equal
(
error
.
message
,
"
Cannot find document
"
);
equal
(
error
.
status_code
,
40
4
);
ok
(
error
instanceof
jIO
.
util
.
jIOError
,
error
);
equal
(
error
.
message
,
"
id inexistent is forbidden (!== /)
"
);
equal
(
error
.
status_code
,
40
0
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
...
...
@@ -340,38 +351,74 @@
});
});
test
(
"
put an attachment to a document
"
,
function
()
{
var
id
=
"
putattmt1
"
;
localStorage
[
id
]
=
JSON
.
stringify
({
"
_id
"
:
id
,
"
title
"
:
"
myPutAttmt1
"
});
test
(
"
remove an attachment to a document
"
,
function
()
{
var
id
=
"
/
"
,
attachment
=
"
foo
"
;
localStorage
[
attachment
]
=
"
bar
"
;
stop
();
expect
(
3
);
expect
(
1
);
this
.
jio
.
put
Attachment
({
this
.
jio
.
remove
Attachment
({
"
_id
"
:
id
,
"
_attachment
"
:
"
putattmt2
"
,
"
_data
"
:
""
"
_attachment
"
:
attachment
})
.
then
(
function
()
{
ok
(
!
localStorage
.
hasOwnProperty
(
attachment
));
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// localStorage.hasCapacity
/////////////////////////////////////////////////////////////////
module
(
"
localStorage.hasCapacity
"
,
{
setup
:
function
()
{
this
.
jio
=
jIO
.
createJIO
({
"
type
"
:
"
local
"
});
}
});
test
(
"
can list documents
"
,
function
()
{
ok
(
this
.
jio
.
hasCapacity
(
"
list
"
));
});
/////////////////////////////////////////////////////////////////
// localStorage.buildQuery
/////////////////////////////////////////////////////////////////
module
(
"
localStorage.buildQuery
"
,
{
setup
:
function
()
{
this
.
jio
=
jIO
.
createJIO
({
"
type
"
:
"
local
"
});
}
});
test
(
"
only return one document
"
,
function
()
{
stop
();
expect
(
1
);
this
.
jio
.
allDocs
()
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
"
digest
"
:
"
sha256-e3b0c44298fc1c149afbf4c8996fb9242
"
+
"
7ae41e4649b934ca495991b7852b855
"
});
equal
(
localStorage
[
id
],
JSON
.
stringify
({
"
_id
"
:
id
,
"
title
"
:
"
myPutAttmt1
"
,
"
_attachments
"
:
{
"
putattmt2
"
:
{
content_type
:
""
,
digest
:
"
sha256-e3b0c44298fc1c149afbf4c8996fb9242
"
+
"
7ae41e4649b934ca495991b7852b855
"
,
length
:
0
}
deepEqual
(
result
,
{
"
data
"
:
{
"
rows
"
:
[
{
"
id
"
:
"
/
"
,
"
value
"
:
{}
}
],
"
total_rows
"
:
1
}
}));
equal
(
localStorage
[
id
+
'
/putattmt2
'
],
JSON
.
stringify
(
""
));
});
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
...
...
@@ -382,495 +429,4 @@
});
});
// test("Remove & RemoveAttachment", function () {
// expect(4);
// var jio = jIO.createJIO({
// "type": "local",
// "username": "uremove",
// "application_name": "aremove"
// }, {
// "workspace": {}
// });
//
// stop();
//
// jio.put({"_id": "a"}).then(function () {
//
// return jio.putAttachment({"_id": "a", "_attachment": "b", "_data": "c"});
//
// }).then(function () {
//
// return jio.removeAttachment({"_id": "a", "_attachment": "b"});
//
// }).always(function (answer) {
//
// deepEqual(answer, {
// "attachment": "b",
// "id": "a",
// "method": "removeAttachment",
// "result": "success",
// "status": 204,
// "statusText": "No Content"
// }, "Remove existent attachment");
//
// }).then(function () {
//
// // Promise.all always return success
// return RSPV.all([jio.removeAttachment({
// "_id": "a",
// "_attachment": "b"
// })]);
//
// }).always(function (answers) {
//
// deepEqual(answers[0], {
// "attachment": "b",
// "error": "not_found",
// "id": "a",
// "message": "Attachment not found",
// "method": "removeAttachment",
// "reason": "missing attachment",
// "result": "error",
// "status": 404,
// "statusText": "Not Found"
// }, "Remove removed attachment");
//
// }).then(function () {
//
// return jio.remove({"_id": "a"});
//
// }).always(function (answer) {
//
// deepEqual(answer, {
// "id": "a",
// "method": "remove",
// "result": "success",
// "status": 204,
// "statusText": "No Content"
// }, "Remove existent document");
//
// }).then(function () {
//
// return jio.remove({"_id": "a"});
//
// }).always(function (answer) {
//
// deepEqual(answer, {
// "error": "not_found",
// "id": "a",
// "message": "Document not found",
// "method": "remove",
// "reason": "missing",
// "result": "error",
// "status": 404,
// "statusText": "Not Found"
// }, "Remove removed document");
//
// }).always(start);
//
// });
//
// test("AllDocs", function () {
// expect(3);
// var o = {}, jio = jIO.createJIO({
// "type": "local",
// "username": "ualldocs",
// "application_name": "aalldocs"
// }, {
// "workspace": {}
// });
//
// stop();
//
// o.date_a = new Date(0);
// o.date_b = new Date();
//
// // put some document before list them
// RSVP.all([
// jio.put({
// "_id": "a",
// "title": "one",
// "date": o.date_a
// }).then(function () {
// return jio.putAttachment({
// "_id": "a",
// "_attachment": "aa",
// "_data": "aaa"
// });
// }),
// jio.put({"_id": "b", "title": "two", "date": o.date_a}),
// jio.put({"_id": "c", "title": "one", "date": o.date_b}),
// jio.put({"_id": "d", "title": "two", "date": o.date_b})
// ]).then(function () {
//
// // get a list of documents
// return jio.allDocs();
//
// }).always(function (answer) {
//
// // sort answer rows for comparison
// if (answer.data && answer.data.rows) {
// answer.data.rows.sort(function (a, b) {
// return a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
// });
// }
//
// deepEqual(answer, {
// "data": {
// "rows": [{
// "id": "a",
// "key": "a",
// "value": {}
// }, {
// "id": "b",
// "key": "b",
// "value": {}
// }, {
// "id": "c",
// "key": "c",
// "value": {}
// }, {
// "id": "d",
// "key": "d",
// "value": {}
// }],
// "total_rows": 4
// },
// "method": "allDocs",
// "result": "success",
// "status": 200,
// "statusText": "Ok"
// }, "AllDocs");
//
// }).then(function () {
//
// // get a list of documents
// return jio.allDocs({
// "include_docs": true,
// "sort_on": [['title', 'ascending'], ['date', 'descending']],
// "select_list": ['title', 'date'],
// "limit": [1] // ==> equal [1, 3] in this case
// });
//
// }).always(function (answer) {
//
// deepEqual(answer, {
// "data": {
// "rows": [{
// "doc": {
// "_attachments": {
// "aa": {
// "content_type": "",
// "digest": "sha256-9834876dcfb05cb167a5c24953eba58c4" +
// "ac89b1adf57f28f2f9d09af107ee8f0",
// "length": 3
// }
// },
// "_id": "a",
// "date": o.date_a.toJSON(),
// "title": "one"
// },
// "id": "a",
// "key": "a",
// "value": {
// "date": o.date_a.toJSON(),
// "title": "one"
// }
// }, {
// "doc": {
// "_id": "d",
// "date": o.date_b.toJSON(),
// "title": "two"
// },
// "id": "d",
// "key": "d",
// "value": {
// "date": o.date_b.toJSON(),
// "title": "two"
// }
// }, {
// "doc": {
// "_id": "b",
// "date": o.date_a.toJSON(),
// "title": "two"
// },
// "id": "b",
// "key": "b",
// "value": {
// "date": o.date_a.toJSON(),
// "title": "two"
// }
// }],
// "total_rows": 3
// },
// "method": "allDocs",
// "result": "success",
// "status": 200,
// "statusText": "Ok"
// }, "AllDocs include docs + sort on + limit + select_list");
//
// }).then(function () {
//
// // use a query
// return jio.allDocs({
// "query": "title: \"two\"",
// "sort_on": [["date", "descending"]]
// });
//
// }).always(function (answer) {
//
// deepEqual(answer, {
// "data": {
// "rows": [{
// "id": "d",
// "key": "d",
// "value": {}
// }, {
// "id": "b",
// "key": "b",
// "value": {}
// }],
// "total_rows": 2
// },
// "method": "allDocs",
// "result": "success",
// "status": 200,
// "statusText": "Ok"
// }, "AllDocs sort on + query");
//
// }).always(start);
//
// });
//
// test("Check & Repair", function () {
// expect(18);
// var o = {}, jio = jIO.createJIO({
// "type": "local",
// "username": "urepair",
// "application_name": "arepair"
// }, {
// "workspace": {}
// });
//
// stop();
//
// o.putCorruptedDocuments = function () {
// // put a document with a wrong attachment reference
// util.json_localStorage.setItem(
// "jio/localstorage/urepair/arepair/war",
// {"_id": "war", "title": "b", "_attachments": {"aa": {}}}
// );
//
// // put a document with a wrong metadata
// util.json_localStorage.setItem(
// "jio/localstorage/urepair/arepair/meta",
// {"_id": "meta", "title": ["b", ["c", {}], {"blue": "blue"}]}
// );
//
// // put a corrupted document
// util.json_localStorage.setItem(
// "jio/localstorage/urepair/arepair/cor",
// "blue"
// );
// };
//
// // put an unreferenced attachment
// util.json_localStorage.setItem(
// "jio/localstorage/urepair/arepair/unref/aa",
// "attachment content"
// );
// o.putCorruptedDocuments();
//
// RSVP.all([
// jio.check({"_id": "war"}),
// jio.check({"_id": "meta"}),
// jio.check({"_id": "cor"}),
// jio.check({"_id": "inexistent"})
// ]).always(function (answers) {
//
// deepEqual(answers[0], {
// "error": "conflict",
// "id": "war",
// "message": "Attachment \"aa\" of \"war\" is missing",
// "method": "check",
// "reason": "missing attachment",
// "result": "error",
// "status": 409,
// "statusText": "Conflict"
// }, "Check a document with one missing attachment");
//
// deepEqual(answers[1], {
// "error": "conflict",
// "id": "meta",
// "message": "Some metadata might be lost",
// "method": "check",
// "reason": "corrupted",
// "result": "error",
// "status": 409,
// "statusText": "Conflict"
// }, "Check document with wrong metadata");
//
// deepEqual(answers[2], {
// "error": "conflict",
// "id": "cor",
// "message": "Document is unrecoverable",
// "method": "check",
// "reason": "corrupted",
// "result": "error",
// "status": 409,
// "statusText": "Conflict"
// }, "Check corrupted document");
//
// deepEqual(answers[3], {
// "id": "inexistent",
// "method": "check",
// "result": "success",
// "status": 204,
// "statusText": "No Content"
// }, "Check inexistent document");
//
// }).then(function () {
//
// return RSVP.all([
// jio.repair({"_id": "war"}),
// jio.repair({"_id": "meta"}),
// jio.repair({"_id": "cor"}),
// jio.repair({"_id": "inexistent"})
// ]);
//
// }).always(function (answers) {
//
// deepEqual(answers[0], {
// "id": "war",
// "method": "repair",
// "result": "success",
// "status": 204,
// "statusText": "No Content"
// }, "Repair a document with one missing attachment");
//
// deepEqual(answers[1], {
// "id": "meta",
// "method": "repair",
// "result": "success",
// "status": 204,
// "statusText": "No Content"
// }, "Repair document with wrong metadata");
//
// deepEqual(answers[2], {
// "id": "cor",
// "method": "repair",
// "result": "success",
// "status": 204,
// "statusText": "No Content"
// }, "Repair corrupted document");
//
// deepEqual(answers[3], {
// "id": "inexistent",
// "method": "repair",
// "result": "success",
// "status": 204,
// "statusText": "No Content"
// }, "Repair inexistent document");
//
// }).then(function () {
//
// o.getCorruptedDocuments = function () {
// return RSVP.all([
// jio.get({"_id": "war"}),
// jio.get({"_id": "meta"}),
// jio.get({"_id": "cor"}),
// jio.get({"_id": "inexistent"})
// ]);
// };
//
// return o.getCorruptedDocuments();
//
// }).always(function (answers) {
//
// o.testGetAnswers = function (answers) {
//
// deepEqual(answers[0], {
// "data": {
// "_id": "war",
// "title": "b"
// },
// "id": "war",
// "method": "get",
// "result": "success",
// "status": 200,
// "statusText": "Ok"
// }, "Get repaired document with one missing attachment");
//
// deepEqual(answers[1], {
// "data": {
// "_id": "meta",
// "title": "b"
// },
// "id": "meta",
// "method": "get",
// "result": "success",
// "status": 200,
// "statusText": "Ok"
// }, "Get repaired document with wrong metadata");
//
// deepEqual(answers[2], {
// "error": "not_found",
// "id": "cor",
// "message": "Cannot find document",
// "method": "get",
// "reason": "missing",
// "result": "error",
// "status": 404,
// "statusText": "Not Found"
// }, "Get repaired corrupted document");
//
// deepEqual(answers[3], {
// "error": "not_found",
// "id": "inexistent",
// "message": "Cannot find document",
// "method": "get",
// "reason": "missing",
// "result": "error",
// "status": 404,
// "statusText": "Not Found"
// }, "Get repaired inexistent document");
//
// };
//
// o.testGetAnswers(answers);
//
// }).then(function () {
//
// o.putCorruptedDocuments();
//
// return jio.repair({});
//
// }).always(function (answer) {
//
// deepEqual(answer, {
// "method": "repair",
// "result": "success",
// "status": 204,
// "statusText": "No Content"
// }, "Repair all the database");
//
// }).then(function () {
//
// return o.getCorruptedDocuments();
//
// }).always(function (answers) {
//
// o.testGetAnswers(answers);
//
// }).then(function () {
//
// // unreferenced attachment must be removed
// deepEqual(util.json_localStorage.getItem(
// "jio/localstorage/urepair/arepair/unref/aa"
// ), null, "Unreferenced attachment removed");
//
// }).always(start);
//
// });
}(
jIO
,
localStorage
,
QUnit
));
}(
jIO
,
localStorage
,
QUnit
,
Blob
,
document
));
test/tests.html
View file @
96d5d045
...
...
@@ -27,9 +27,9 @@
<script
src=
"jio.storage/memorystorage.tests.js"
></script>
<script
src=
"jio.storage/querystorage.tests.js"
></script>
<script
src=
"jio.storage/localstorage.tests.js"
></script>
<!--script src="jio.storage/localstorage.tests.js"></script>
<script src="jio.storage/davstorage.tests.js"></script>
<!--script src="jio.storage/davstorage.tests.js"></script>
<script src="jio.storage/unionstorage.tests.js"></script>
<script src="jio.storage/querystorage.tests.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