Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jio-main
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
Hardik Juneja
jio-main
Commits
1b82849f
Commit
1b82849f
authored
Feb 17, 2015
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for DocumentStorage
parent
96d5d045
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
501 additions
and
19 deletions
+501
-19
src/jio.storage/documentstorage.js
src/jio.storage/documentstorage.js
+22
-19
test/jio.storage/documentstorage.tests.js
test/jio.storage/documentstorage.tests.js
+479
-0
No files found.
src/jio.storage/documentstorage.js
View file @
1b82849f
/*jslint nomen: true*/
/*global
console,
Blob, atob, btoa*/
/*global Blob, atob, btoa*/
(
function
(
jIO
,
Blob
,
atob
,
btoa
)
{
"
use strict
"
;
...
...
@@ -35,7 +35,7 @@
"
_attachment
"
:
getSubAttachmentIdFromParam
(
param
)
})
.
push
(
function
(
blob
)
{
return
jIO
.
util
.
readBlobAsText
(
blob
);
return
jIO
.
util
.
readBlobAsText
(
blob
.
data
);
})
.
push
(
function
(
text
)
{
return
JSON
.
parse
(
text
.
target
.
result
);
...
...
@@ -54,8 +54,15 @@
if
(
document
.
_attachments
.
hasOwnProperty
(
key
))
{
if
(
ATTACHMENT_REGEXP
.
test
(
key
))
{
exec
=
ATTACHMENT_REGEXP
.
exec
(
key
);
if
(
atob
(
exec
[
1
])
===
param
.
_id
)
{
attachments
[
atob
(
exec
[
2
])]
=
{};
try
{
if
(
atob
(
exec
[
1
])
===
param
.
_id
)
{
attachments
[
atob
(
exec
[
2
])]
=
{};
}
}
catch
(
error
)
{
// Check if unable to decode base64 data
if
(
!
error
instanceof
ReferenceError
)
{
throw
error
;
}
}
}
}
...
...
@@ -67,17 +74,6 @@
});
};
DocumentStorage
.
prototype
.
post
=
function
(
param
)
{
var
doc_id
=
param
.
_id
;
if
(
doc_id
===
undefined
)
{
doc_id
=
jIO
.
util
.
generateUuid
();
}
param
.
_id
=
doc_id
;
return
this
.
put
(
param
);
};
DocumentStorage
.
prototype
.
put
=
function
(
param
)
{
var
doc_id
=
param
.
_id
;
...
...
@@ -116,10 +112,17 @@
for
(
key
in
document
.
_attachments
)
{
if
(
document
.
_attachments
.
hasOwnProperty
(
key
))
{
if
(
DOCUMENT_REGEXP
.
test
(
key
))
{
result
.
push
({
id
:
atob
(
DOCUMENT_REGEXP
.
exec
(
key
)[
1
]),
value
:
{}
});
try
{
result
.
push
({
id
:
atob
(
DOCUMENT_REGEXP
.
exec
(
key
)[
1
]),
value
:
{}
});
}
catch
(
error
)
{
// Check if unable to decode base64 data
if
(
!
error
instanceof
ReferenceError
)
{
throw
error
;
}
}
}
}
}
...
...
test/jio.storage/documentstorage.tests.js
0 → 100644
View file @
1b82849f
This diff is collapsed.
Click to expand it.
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