-
Notifications
You must be signed in to change notification settings - Fork 248
feat(Http): Http service can make cross-site requests (get, post, put, e... #1026
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…, etc.) which use credentials (such as cookies or authorization headers). Closes #945
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,6 +98,23 @@ void main() { | |
flush(); | ||
})); | ||
|
||
describe('backend', () { | ||
beforeEachModule((Module module) { | ||
FakeBackend fakeBackend = new FakeBackend(); | ||
module.bind(HttpBackend, toFactory: (i) => fakeBackend); | ||
module.bind(FakeBackend, toFactory: (i) => i.get(HttpBackend)); | ||
}); | ||
|
||
it('should pass on withCredentials to backend and use GET as default method', | ||
async((FakeBackend backend) { | ||
http(url: '/url', method: 'GET', withCredentials: true); | ||
microLeap(); | ||
expect(backend.url).toEqual('/url'); | ||
expect(backend.method).toEqual('GET'); | ||
expect(backend.withCredentials).toBeTruthy(); | ||
})); | ||
}); | ||
|
||
|
||
describe('params', () { | ||
it('should do basic request with params and encode', async(() { | ||
|
@@ -1356,3 +1373,40 @@ class FakeFile implements File { | |
Blob slice([int start, int end, String contentType]) => null; | ||
int get lastModified => new DateTime.now().millisecondsSinceEpoch; | ||
} | ||
|
||
class FakeBackend extends Mock implements HttpBackend { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use MockHttpBackend? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jbdeboer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you use something like https://github.com/angular/angular.dart/blob/a5d5c2b17a64acadb7935bf734da7e92d3a4cf74/test/core_dom/http_spec.dart#L72 It should be extended to support withCrdentials, ie There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 to @vicb's comment. You should extend the MockHttpBackend as well. |
||
|
||
String url; | ||
String method; | ||
bool withCredentials; | ||
String responseType; | ||
String mimeType; | ||
Map<String, String> requestHeaders; | ||
dynamic sendData; | ||
|
||
Future<HttpRequest> request(String url, { | ||
String method, | ||
bool withCredentials, | ||
String responseType, | ||
String mimeType, | ||
Map<String, String> requestHeaders, | ||
sendData, | ||
void onProgress(ProgressEvent e)}) { | ||
this.url = url; | ||
this.method = method; | ||
this.withCredentials = withCredentials; | ||
this.responseType = responseType; | ||
this.mimeType = mimeType; | ||
this.requestHeaders = requestHeaders; | ||
this.sendData = sendData; | ||
HttpRequest request = new HttpRequest(); | ||
return new Future.value(new HttpRequest()); | ||
} | ||
} | ||
|
||
class FakeHttpRequest extends Mock implements HttpRequest { | ||
FakeHttpRequest() { | ||
when(callsTo('get status')).thenReturn(200); | ||
when(callsTo('get responseText')).thenReturn('Fake Request'); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could it be
toValue: fackBackend
for both of them ?