OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library handle_access_token_response_test; | 5 library handle_access_token_response_test; |
6 | 6 |
7 import 'dart:convert'; | 7 import 'dart:convert'; |
8 | 8 |
9 import 'package:http/http.dart' as http; | 9 import 'package:http/http.dart' as http; |
10 import 'package:oauth2/oauth2.dart' as oauth2; | 10 import 'package:oauth2/oauth2.dart' as oauth2; |
(...skipping 20 matching lines...) Expand all Loading... |
31 | 31 |
32 test('causes an AuthorizationException', () { | 32 test('causes an AuthorizationException', () { |
33 expect(() => handleError(), throwsAuthorizationException); | 33 expect(() => handleError(), throwsAuthorizationException); |
34 }); | 34 }); |
35 | 35 |
36 test('with a 401 code causes an AuthorizationException', () { | 36 test('with a 401 code causes an AuthorizationException', () { |
37 expect(() => handleError(statusCode: 401), throwsAuthorizationException); | 37 expect(() => handleError(statusCode: 401), throwsAuthorizationException); |
38 }); | 38 }); |
39 | 39 |
40 test('with an unexpected code causes a FormatException', () { | 40 test('with an unexpected code causes a FormatException', () { |
41 expect(() => handleError(statusCode: 500), | 41 expect(() => handleError(statusCode: 500), throwsFormatException); |
42 throwsFormatException); | |
43 }); | 42 }); |
44 | 43 |
45 test('with no content-type causes a FormatException', () { | 44 test('with no content-type causes a FormatException', () { |
46 expect(() => handleError(headers: {}), throwsFormatException); | 45 expect(() => handleError(headers: {}), throwsFormatException); |
47 }); | 46 }); |
48 | 47 |
49 test('with a non-JSON content-type causes a FormatException', () { | 48 test('with a non-JSON content-type causes a FormatException', () { |
50 expect(() => handleError(headers: { | 49 expect(() => handleError(headers: { |
51 'content-type': 'text/plain' | 50 'content-type': 'text/plain' |
52 }), throwsFormatException); | 51 }), throwsFormatException); |
53 }); | 52 }); |
54 | 53 |
55 test('with a JSON content-type and charset causes an ' | 54 test('with a JSON content-type and charset causes an ' |
56 'AuthorizationException', () { | 55 'AuthorizationException', () { |
57 expect(() => handleError(headers: { | 56 expect(() => handleError(headers: { |
58 'content-type': 'application/json; charset=UTF-8' | 57 'content-type': 'application/json; charset=UTF-8' |
59 }), throwsAuthorizationException); | 58 }), throwsAuthorizationException); |
60 }); | 59 }); |
61 | 60 |
62 test('with invalid JSON causes a FormatException', () { | 61 test('with invalid JSON causes a FormatException', () { |
63 expect(() => handleError(body: 'not json'), | 62 expect(() => handleError(body: 'not json'), throwsFormatException); |
64 throwsFormatException); | |
65 }); | 63 }); |
66 | 64 |
67 test('with a non-string error causes a FormatException', () { | 65 test('with a non-string error causes a FormatException', () { |
68 expect(() => handleError(body: '{"error": 12}'), | 66 expect(() => handleError(body: '{"error": 12}'), throwsFormatException); |
69 throwsFormatException); | |
70 }); | 67 }); |
71 | 68 |
72 test('with a non-string error_description causes a FormatException', () { | 69 test('with a non-string error_description causes a FormatException', () { |
73 expect(() => handleError(body: JSON.encode({ | 70 expect(() => handleError(body: JSON.encode({ |
74 "error": "invalid_request", | 71 "error": "invalid_request", |
75 "error_description": 12 | 72 "error_description": 12 |
76 })), throwsFormatException); | 73 })), throwsFormatException); |
77 }); | 74 }); |
78 | 75 |
79 test('with a non-string error_uri causes a FormatException', () { | 76 test('with a non-string error_uri causes a FormatException', () { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 test('with a non-string scope throws a FormatException', () { | 183 test('with a non-string scope throws a FormatException', () { |
187 expect(() => handleSuccess(scope: 12), throwsFormatException); | 184 expect(() => handleSuccess(scope: 12), throwsFormatException); |
188 }); | 185 }); |
189 | 186 |
190 test('with a scope sets the scopes', () { | 187 test('with a scope sets the scopes', () { |
191 var credentials = handleSuccess(scope: "scope1 scope2"); | 188 var credentials = handleSuccess(scope: "scope1 scope2"); |
192 expect(credentials.scopes, equals(["scope1", "scope2"])); | 189 expect(credentials.scopes, equals(["scope1", "scope2"])); |
193 }); | 190 }); |
194 }); | 191 }); |
195 } | 192 } |
OLD | NEW |