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
Hamza
jio
Commits
0bce7aa0
Commit
0bce7aa0
authored
Feb 28, 2018
by
Vincent Bechu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[cloudoostorage] add test on failed conversion
parent
81600fca
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
85 additions
and
18 deletions
+85
-18
src/jio.storage/cloudoostorage.js
src/jio.storage/cloudoostorage.js
+29
-17
test/jio.storage/cloudoostorage.tests.js
test/jio.storage/cloudoostorage.tests.js
+56
-1
No files found.
src/jio.storage/cloudoostorage.js
View file @
0bce7aa0
/*jslint nomen: true*/
/*global jIO, RSVP, Blob, Uint8Array, DOMParser*/
(
function
(
jIO
,
Uint8Array
,
Blob
,
RSVP
,
DOMParser
)
{
/*global jIO, RSVP, Blob, Uint8Array, DOMParser
, XMLSerializer
*/
(
function
(
jIO
,
Uint8Array
,
Blob
,
RSVP
,
DOMParser
,
XMLSerializer
)
{
"
use strict
"
;
var
content_type_dict
=
{
"
application/x-asc-text
"
:
"
docy
"
,
"
application/x-asc-presentation
"
:
""
,
"
application/x-asc-spreadsheet
"
:
""
};
},
parser
=
new
DOMParser
(),
serializer
=
new
XMLSerializer
();
function
newXml
()
{
return
parser
.
parseFromString
(
'
<?xml version="1.0" encoding="UTF-8"?><methodCall>
'
+
'
<methodName>convertFile</methodName><params>
'
+
'
<param><value><string></string></value></param>
'
+
'
<param><value><string></string></value></param>
'
+
'
<param><value><string></string></value></param></params></methodCall>
'
,
'
text/xml
'
);
}
function
b64toBlob
(
b64Data
,
contentType
,
sliceSize
)
{
contentType
=
contentType
||
''
;
...
...
@@ -47,28 +60,27 @@
.
push
(
function
(
result
)
{
// WIP: use something cleaner
var
file
=
result
.
target
.
result
.
split
(
'
base64,
'
)[
1
],
xml
=
'
<?xml version="1.0" encoding="UTF-8"?><methodCall>
'
+
'
<methodName>convertFile</methodName><params>
'
+
'
<param><value><string>
'
+
file
+
'
</string></value></param>
'
+
'
<param><value><string>
'
+
from
+
'
</string></value></param>
'
+
'
<param><value><string>
'
+
to
+
'
</string></value></param></params></methodCall>
'
;
xml
=
newXml
(),
string_list
=
xml
.
getElementsByTagName
(
'
string
'
);
string_list
[
0
].
textContent
=
file
;
string_list
[
1
].
textContent
=
from
;
string_list
[
2
].
textContent
=
to
;
return
jIO
.
util
.
ajax
({
type
:
'
POST
'
,
url
:
storage
.
_url
,
data
:
xml
data
:
serializer
.
serializeToString
(
xml
)
});
})
.
push
(
function
(
result
)
{
var
data
=
(
new
DOMParser
()
.
parseFromString
(
var
data
=
parser
.
parseFromString
(
result
.
target
.
responseText
,
"
application/xml
"
)
)
,
content
=
data
.
getElementsByTagName
(
'
string
'
)
[
0
].
textContent
;
if
(
content
!==
undefined
)
{
return
b64toBlob
(
content
,
to
);
),
content
=
data
.
getElementsByTagName
(
'
string
'
);
if
(
content
.
length
>
0
)
{
return
b64toBlob
(
content
[
0
].
textContent
,
to
);
}
throw
new
jIO
.
util
.
jIOError
(
'
conversion failed
'
,
40
0
);
throw
new
jIO
.
util
.
jIOError
(
'
conversion failed
'
,
40
4
);
});
}
...
...
@@ -275,4 +287,4 @@
jIO
.
addStorage
(
'
cloudoo
'
,
CloudooStorage
);
}(
jIO
,
Uint8Array
,
Blob
,
RSVP
,
DOMParser
));
}(
jIO
,
Uint8Array
,
Blob
,
RSVP
,
DOMParser
,
XMLSerializer
));
test/jio.storage/cloudoostorage.tests.js
View file @
0bce7aa0
...
...
@@ -381,7 +381,7 @@
test
(
"
getAttachment convert from docy to docx
"
,
function
()
{
stop
();
expect
(
1
0
);
expect
(
1
2
);
var
blob
=
new
Blob
([
"
documentauformatdocy
"
]),
server
=
this
.
server
,
...
...
@@ -434,6 +434,8 @@
this
.
jio
.
getAttachment
(
"
bar
"
,
"
data?docx
"
)
.
then
(
function
(
result
)
{
equal
(
server
.
requests
.
length
,
1
);
equal
(
server
.
requests
[
0
].
method
,
"
POST
"
);
equal
(
server
.
requests
[
0
].
url
,
cloudoo_url
);
equal
(
server
.
requests
[
0
].
requestBody
,
'
<?xml version="1.0" encoding="UTF-8"?><methodCall>
'
+
...
...
@@ -452,6 +454,59 @@
start
();
});
});
test
(
"
getAttachment convert from docy to docx failed
"
,
function
()
{
stop
();
expect
(
4
);
var
blob
=
new
Blob
([
"
documentauformatdocy
"
]);
this
.
server
.
respondWith
(
"
POST
"
,
cloudoo_url
,
[
200
,
{
"
Content-Type
"
:
"
text/xml
"
},
'
<?xml version="1.0" encoding="UTF-8"?>
'
]);
Storage200
.
prototype
.
getAttachment
=
function
(
id
,
name
)
{
equal
(
id
,
"
bar
"
,
"
getAttachment 200 called
"
);
if
(
name
===
"
data?docx
"
)
{
throw
new
jIO
.
util
.
jIOError
(
"
can't find
"
,
404
);
}
return
blob
;
};
Storage200
.
prototype
.
get
=
function
(
id
)
{
if
(
id
===
"
cloudoo/bar/data
"
)
{
throw
new
jIO
.
util
.
jIOError
(
"
can't find
"
,
404
);
}
if
(
id
===
"
bar
"
)
{
return
{
content_type
:
"
application/x-asc-text
"
};
}
equal
(
id
,
""
,
"
get 200 called
"
);
return
{};
};
Storage200
.
prototype
.
put
=
function
(
id
,
doc
)
{
equal
(
id
,
"
cloudoo/bar/data
"
,
"
put 200 called
"
);
deepEqual
(
doc
,
{
"
attachment_id
"
:
"
data
"
,
"
convert_dict
"
:
{
"
docx
"
:
false
},
"
doc_id
"
:
"
bar
"
,
"
format
"
:
"
docy
"
,
"
portal_type
"
:
"
Conversion Info
"
},
"
put doc 200 called
"
);
return
id
;
};
this
.
jio
.
getAttachment
(
"
bar
"
,
"
data?docx
"
)
.
fail
(
function
(
error
)
{
equal
(
error
.
message
,
"
conversion failed
"
,
"
check conversion failed
"
);
equal
(
error
.
status_code
,
404
,
"
check error status code
"
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// CryptStorage.putAttachment
/////////////////////////////////////////////////////////////////
...
...
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