OLD | NEW |
| (Empty) |
1 library playback_http_spec; | |
2 | |
3 import '../_specs.dart'; | |
4 import 'package:angular/playback/playback_http.dart'; | |
5 | |
6 main() => describe('Playback HTTP', () { | |
7 MockHttpBackend backend; | |
8 beforeEach(module((Module m) { | |
9 backend = new MockHttpBackend(); | |
10 var wrapper = new HttpBackendWrapper(backend); | |
11 m | |
12 ..value(HttpBackendWrapper, wrapper) | |
13 ..type(PlaybackHttpBackendConfig); | |
14 })); | |
15 | |
16 afterEach(() { | |
17 backend.verifyNoOutstandingRequest(); | |
18 backend.verifyNoOutstandingExpectation(); | |
19 }); | |
20 | |
21 describe('RecordingHttpBackend', () { | |
22 beforeEach(module((Module m) { | |
23 m.type(HttpBackend, implementedBy: RecordingHttpBackend); | |
24 })); | |
25 | |
26 | |
27 it('should record a request', async(inject((Http http) { | |
28 backend.expectGET('request').respond(200, 'response'); | |
29 | |
30 var responseData; | |
31 | |
32 http(method: 'GET', url: 'request').then((HttpResponse r) { | |
33 responseData = r.data; | |
34 }); | |
35 | |
36 microLeap(); | |
37 backend.flush(); | |
38 backend | |
39 .expectPOST('/record', | |
40 r'{"key":"{\"url\":\"request\",\"method\":\"GET\",\"requestHeaders\"
:{\"Accept\":\"application/json, text/plain, */*\",\"X-XSRF-TOKEN\":\"secret\"},
\"data\":null}",' + | |
41 r'"data":"{\"status\":200,\"headers\":\"\",\"data\":\"response\"}"}'
) | |
42 .respond(200); | |
43 | |
44 microLeap(); | |
45 backend.flush(); | |
46 microLeap(); | |
47 | |
48 expect(responseData).toEqual('response'); | |
49 }))); | |
50 }); | |
51 | |
52 | |
53 describe('PlaybackHttpBackend', () { | |
54 beforeEach(module((Module m) { | |
55 m.type(HttpBackend, implementedBy: PlaybackHttpBackend); | |
56 })); | |
57 | |
58 it('should replay a request', async(inject((Http http, HttpBackend hb) { | |
59 (hb as PlaybackHttpBackend).data = { | |
60 r'{"url":"request","method":"GET","requestHeaders":{"Accept":"applicatio
n/json, text/plain, */*","X-XSRF-TOKEN":"secret"},"data":null}': {'status': 200,
'headers': '', 'data': 'playback data'} | |
61 }; | |
62 | |
63 var responseData; | |
64 | |
65 http(method: 'GET', url: 'request').then((HttpResponse r) { | |
66 responseData = r.data; | |
67 }); | |
68 | |
69 microLeap(); | |
70 | |
71 expect(responseData).toEqual('playback data'); | |
72 }))); | |
73 | |
74 }); | |
75 }); | |
OLD | NEW |