fix(http): Fix all requests defaulting to Get
Honor method parameter passed to http.request(). Closes #5309 Closes #5397
This commit is contained in:
parent
46fc153f39
commit
e1d7bdcfe7
|
@ -16,9 +16,9 @@ function mergeOptions(defaultOpts, providedOpts, method, url): RequestOptions {
|
|||
var newOptions = defaultOpts;
|
||||
if (isPresent(providedOpts)) {
|
||||
// Hack so Dart can used named parameters
|
||||
newOptions = newOptions.merge(new RequestOptions({
|
||||
method: providedOpts.method,
|
||||
url: providedOpts.url,
|
||||
return newOptions.merge(new RequestOptions({
|
||||
method: providedOpts.method || method,
|
||||
url: providedOpts.url || url,
|
||||
search: providedOpts.search,
|
||||
headers: providedOpts.headers,
|
||||
body: providedOpts.body
|
||||
|
|
|
@ -151,6 +151,19 @@ export function main() {
|
|||
.subscribe((res) => {});
|
||||
}));
|
||||
|
||||
it('should accept a fully-qualified request as its only parameter',
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
backend.connections.subscribe(c => {
|
||||
expect(c.request.url).toBe('https://google.com');
|
||||
expect(c.request.method).toBe(RequestMethods.Post);
|
||||
c.mockRespond(new Response(new ResponseOptions({body: 'Thank you'})));
|
||||
async.done();
|
||||
});
|
||||
http.request(new Request(new RequestOptions(
|
||||
{url: 'https://google.com', method: RequestMethods.Post})))
|
||||
.subscribe((res) => {});
|
||||
}));
|
||||
|
||||
|
||||
it('should perform a get request for given url if only passed a string',
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
|
@ -162,6 +175,34 @@ export function main() {
|
|||
});
|
||||
}));
|
||||
|
||||
it('should perform a post request for given url if options include a method',
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
backend.connections.subscribe(c => {
|
||||
expect(c.request.method).toEqual(RequestMethods.Post);
|
||||
c.mockRespond(baseResponse);
|
||||
});
|
||||
let requestOptions = new RequestOptions({method: RequestMethods.Post});
|
||||
http.request('http://basic.connection', requestOptions)
|
||||
.subscribe(res => {
|
||||
expect(res.text()).toBe('base response');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should perform a post request for given url if options include a method',
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
backend.connections.subscribe(c => {
|
||||
expect(c.request.method).toEqual(RequestMethods.Post);
|
||||
c.mockRespond(baseResponse);
|
||||
});
|
||||
let requestOptions = {method: RequestMethods.Post};
|
||||
http.request('http://basic.connection', requestOptions)
|
||||
.subscribe(res => {
|
||||
expect(res.text()).toBe('base response');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should perform a get request and complete the response',
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
backend.connections.subscribe(c => c.mockRespond(baseResponse));
|
||||
|
@ -180,18 +221,6 @@ export function main() {
|
|||
.subscribe(res => { expect(res.text()).toBe('base response'); }, null,
|
||||
() => { async.done(); });
|
||||
}));
|
||||
// TODO: make dart not complain about "argument type 'Map' cannot be assigned to the
|
||||
// parameter type 'IRequestOptions'"
|
||||
// xit('should perform a get request for given url if passed a dictionary',
|
||||
// inject([AsyncTestCompleter], async => {
|
||||
// ObservableWrapper.subscribe(backend.connections, c => c.mockRespond(baseResponse));
|
||||
// ObservableWrapper.subscribe(http.request(url, {method: RequestMethods.GET}), res =>
|
||||
// {
|
||||
// expect(res.text()).toBe('base response');
|
||||
// async.done();
|
||||
// });
|
||||
// }));
|
||||
|
||||
|
||||
it('should throw if url is not a string or Request', () => {
|
||||
var req = <Request>{};
|
||||
|
|
Loading…
Reference in New Issue