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
Yaxel Perez
jio
Commits
2584d101
Commit
2584d101
authored
Oct 18, 2013
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
davstorage.tests.js fallback to sinon created to pass tests without real server
parent
34875bba
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
75 additions
and
9 deletions
+75
-9
test/jio.storage/davstorage.tests.js
test/jio.storage/davstorage.tests.js
+75
-9
No files found.
test/jio.storage/davstorage.tests.js
View file @
2584d101
...
@@ -59,16 +59,82 @@
...
@@ -59,16 +59,82 @@
if
(
use_fake_server
)
{
if
(
use_fake_server
)
{
/*jslint regexp: true */
/*jslint regexp: true */
server
=
sinon
.
fakeServer
.
create
();
// server = sinon.fakeServer.create();
server
.
autoRespond
=
true
;
// server.autoRespond = true;
server
.
autoRespondAfter
=
5
;
// server.autoRespondAfter = 5;
server
.
respondWith
(
/.*/
,
function
(
xhr
)
{
// server.respondWith(/.*/, function (xhr) {
var
response
=
responses
.
shift
();
// var response = responses.shift();
if
(
response
)
{
// if (response) {
return
xhr
.
respond
.
apply
(
xhr
,
response
);
// return xhr.respond.apply(xhr, response);
// }
// ok(false, "No response associated to the latest request!");
// });
//////////////////////////////
// Awaiting for some sinon js improvements to manage 'blob' xhr response
// type. This hack overrides the jIO util ajax method which is used by
// dav storage connector to do http requests. To restore the sinon js
// fake server, just uncomment the above lines.
server
=
{
restore
:
function
()
{
return
;
}};
jIO
.
util
.
ajax
=
function
(
param
)
{
var
timeout
,
xhr
=
{},
response
=
responses
.
shift
(),
statusTexts
=
{
"
404
"
:
"
Not Found
"
};
if
(
!
Array
.
isArray
(
response
))
{
setTimeout
(
function
()
{
throw
new
ReferenceError
(
"
Fake server, no response set for
"
+
JSON
.
stringify
(
param
,
null
,
'
'
));
});
}
}
ok
(
false
,
"
No response associated to the latest request!
"
);
xhr
.
readyState
=
1
;
});
xhr
.
setRequestHeader
=
function
()
{
return
;
};
xhr
.
getResponseHeader
=
function
(
name
)
{
return
response
[
1
][
name
];
};
return
new
RSVP
.
Promise
(
function
(
resolve
,
reject
,
notify
)
{
var
k
;
xhr
.
readyState
=
4
;
xhr
.
status
=
response
[
0
];
xhr
.
statusText
=
statusTexts
[
response
[
0
]];
xhr
.
responseType
=
param
.
dataType
||
""
;
timeout
=
setTimeout
(
function
()
{
/*global Blob*/
if
(
xhr
.
responseType
===
'
blob
'
)
{
xhr
.
response
=
new
Blob
([
response
[
2
]],
{
"
type
"
:
response
[
1
][
"
Content-Type
"
]
||
response
[
1
][
"
Content-type
"
]
||
response
[
1
][
"
content-type
"
]
||
''
});
}
else
if
(
xhr
.
responseType
===
'
json
'
)
{
xhr
.
responseText
=
response
[
2
];
try
{
xhr
.
response
=
JSON
.
parse
(
xhr
.
responseText
);
}
catch
(
e
)
{
// XXX
xhr
.
responseText
=
undefined
;
xhr
.
status
=
0
;
xhr
.
statusText
=
"
Parse Error
"
;
// XXX
}
}
else
{
xhr
.
response
=
xhr
.
responseText
=
response
[
2
];
}
// XXX ArrayBuffer
if
(
xhr
.
status
>=
400
||
xhr
.
status
===
0
)
{
return
reject
({
"
target
"
:
xhr
});
}
resolve
({
"
target
"
:
xhr
});
},
10
);
// XXX on error (if necessary)
// XXX on progress
if
(
typeof
param
.
beforeSend
===
'
function
'
)
{
param
.
beforeSend
(
xhr
);
}
},
function
()
{
clearTimeout
(
timeout
);
});
};
}
else
{
}
else
{
responses
.
push
=
function
()
{
responses
.
push
=
function
()
{
return
;
return
;
...
...
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