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
Alexandra Rogova
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
Hide 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*/
/*jslint nomen: true*/
/*global jIO, RSVP, Blob, Uint8Array, DOMParser*/
/*global jIO, RSVP, Blob, Uint8Array, DOMParser
, XMLSerializer
*/
(
function
(
jIO
,
Uint8Array
,
Blob
,
RSVP
,
DOMParser
)
{
(
function
(
jIO
,
Uint8Array
,
Blob
,
RSVP
,
DOMParser
,
XMLSerializer
)
{
"
use strict
"
;
"
use strict
"
;
var
content_type_dict
=
{
var
content_type_dict
=
{
"
application/x-asc-text
"
:
"
docy
"
,
"
application/x-asc-text
"
:
"
docy
"
,
"
application/x-asc-presentation
"
:
""
,
"
application/x-asc-presentation
"
:
""
,
"
application/x-asc-spreadsheet
"
:
""
"
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
)
{
function
b64toBlob
(
b64Data
,
contentType
,
sliceSize
)
{
contentType
=
contentType
||
''
;
contentType
=
contentType
||
''
;
...
@@ -47,28 +60,27 @@
...
@@ -47,28 +60,27 @@
.
push
(
function
(
result
)
{
.
push
(
function
(
result
)
{
// WIP: use something cleaner
// WIP: use something cleaner
var
file
=
result
.
target
.
result
.
split
(
'
base64,
'
)[
1
],
var
file
=
result
.
target
.
result
.
split
(
'
base64,
'
)[
1
],
xml
=
'
<?xml version="1.0" encoding="UTF-8"?><methodCall>
'
+
xml
=
newXml
(),
'
<methodName>convertFile</methodName><params>
'
+
string_list
=
xml
.
getElementsByTagName
(
'
string
'
);
'
<param><value><string>
'
+
file
+
'
</string></value></param>
'
+
string_list
[
0
].
textContent
=
file
;
'
<param><value><string>
'
+
from
+
'
</string></value></param>
'
+
string_list
[
1
].
textContent
=
from
;
'
<param><value><string>
'
+
to
+
string_list
[
2
].
textContent
=
to
;
'
</string></value></param></params></methodCall>
'
;
return
jIO
.
util
.
ajax
({
return
jIO
.
util
.
ajax
({
type
:
'
POST
'
,
type
:
'
POST
'
,
url
:
storage
.
_url
,
url
:
storage
.
_url
,
data
:
xml
data
:
serializer
.
serializeToString
(
xml
)
});
});
})
})
.
push
(
function
(
result
)
{
.
push
(
function
(
result
)
{
var
data
=
(
new
DOMParser
()
.
parseFromString
(
var
data
=
parser
.
parseFromString
(
result
.
target
.
responseText
,
result
.
target
.
responseText
,
"
application/xml
"
"
application/xml
"
)
)
,
),
content
=
data
.
getElementsByTagName
(
'
string
'
)
[
0
].
textContent
;
content
=
data
.
getElementsByTagName
(
'
string
'
);
if
(
content
!==
undefined
)
{
if
(
content
.
length
>
0
)
{
return
b64toBlob
(
content
,
to
);
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 @@
...
@@ -275,4 +287,4 @@
jIO
.
addStorage
(
'
cloudoo
'
,
CloudooStorage
);
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 @@
...
@@ -381,7 +381,7 @@
test
(
"
getAttachment convert from docy to docx
"
,
function
()
{
test
(
"
getAttachment convert from docy to docx
"
,
function
()
{
stop
();
stop
();
expect
(
1
0
);
expect
(
1
2
);
var
blob
=
new
Blob
([
"
documentauformatdocy
"
]),
var
blob
=
new
Blob
([
"
documentauformatdocy
"
]),
server
=
this
.
server
,
server
=
this
.
server
,
...
@@ -434,6 +434,8 @@
...
@@ -434,6 +434,8 @@
this
.
jio
.
getAttachment
(
"
bar
"
,
"
data?docx
"
)
this
.
jio
.
getAttachment
(
"
bar
"
,
"
data?docx
"
)
.
then
(
function
(
result
)
{
.
then
(
function
(
result
)
{
equal
(
server
.
requests
.
length
,
1
);
equal
(
server
.
requests
.
length
,
1
);
equal
(
server
.
requests
[
0
].
method
,
"
POST
"
);
equal
(
server
.
requests
[
0
].
url
,
cloudoo_url
);
equal
(
equal
(
server
.
requests
[
0
].
requestBody
,
server
.
requests
[
0
].
requestBody
,
'
<?xml version="1.0" encoding="UTF-8"?><methodCall>
'
+
'
<?xml version="1.0" encoding="UTF-8"?><methodCall>
'
+
...
@@ -452,6 +454,59 @@
...
@@ -452,6 +454,59 @@
start
();
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
// 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