Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 635440d

Browse files
committed
dart format
1 parent 2aee116 commit 635440d

File tree

8 files changed

+162
-105
lines changed

8 files changed

+162
-105
lines changed

packages/google_sign_in/google_sign_in_web/example/integration_test/google_sign_in_web_test.dart

Lines changed: 56 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,21 @@ void main() {
2828

2929
testWidgets('Loads clientId when set in a meta', (_) async {
3030
final GoogleSignInPlugin plugin = GoogleSignInPlugin(
31-
debugOverrideLoader: true
31+
debugOverrideLoader: true,
3232
);
3333

3434
expect(plugin.autoDetectedClientId, isNull);
3535

3636
// Add it to the test page now, and try again
37-
final DomHtmlMetaElement meta = document.createElement('meta') as DomHtmlMetaElement
38-
..name = clientIdMetaName
39-
..content = expectedClientId;
37+
final DomHtmlMetaElement meta =
38+
document.createElement('meta') as DomHtmlMetaElement
39+
..name = clientIdMetaName
40+
..content = expectedClientId;
4041

4142
document.head.appendChild(meta);
4243

4344
final GoogleSignInPlugin another = GoogleSignInPlugin(
44-
debugOverrideLoader: true
45+
debugOverrideLoader: true,
4546
);
4647

4748
expect(another.autoDetectedClientId, expectedClientId);
@@ -57,22 +58,11 @@ void main() {
5758

5859
setUp(() {
5960
plugin = GoogleSignInPlugin(
60-
debugOverrideLoader: true
61+
debugOverrideLoader: true,
6162
);
6263
mockGis = MockGisSdkClient();
6364
});
6465

65-
testWidgets('must be called for most of the API to work', (_) async {
66-
expect(() async { await plugin.signInSilently(); }, throwsA(isA<StateError>()));
67-
expect(() async { await plugin.signIn(); }, throwsA(isA<StateError>()));
68-
expect(() async { await plugin.getTokens(email: ''); }, throwsA(isA<StateError>()));
69-
expect(() async { await plugin.signOut(); }, throwsA(isA<StateError>()));
70-
expect(() async { await plugin.disconnect(); }, throwsA(isA<StateError>()));
71-
expect(() async { await plugin.isSignedIn(); }, throwsA(isA<StateError>()));
72-
expect(() async { await plugin.clearAuthCache(token: ''); }, throwsA(isA<StateError>()));
73-
expect(() async { await plugin.requestScopes(<String>[]); }, throwsA(isA<StateError>()));
74-
});
75-
7666
testWidgets('initializes if all is OK', (_) async {
7767
await plugin.initWithParams(
7868
const SignInInitParameters(
@@ -117,6 +107,40 @@ void main() {
117107
);
118108
}, throwsAssertionError);
119109
});
110+
111+
testWidgets('must be called for most of the API to work', (_) async {
112+
expect(() async {
113+
await plugin.signInSilently();
114+
}, throwsStateError);
115+
116+
expect(() async {
117+
await plugin.signIn();
118+
}, throwsStateError);
119+
120+
expect(() async {
121+
await plugin.getTokens(email: '');
122+
}, throwsStateError);
123+
124+
expect(() async {
125+
await plugin.signOut();
126+
}, throwsStateError);
127+
128+
expect(() async {
129+
await plugin.disconnect();
130+
}, throwsStateError);
131+
132+
expect(() async {
133+
await plugin.isSignedIn();
134+
}, throwsStateError);
135+
136+
expect(() async {
137+
await plugin.clearAuthCache(token: '');
138+
}, throwsStateError);
139+
140+
expect(() async {
141+
await plugin.requestScopes(<String>[]);
142+
}, throwsStateError);
143+
});
120144
});
121145

122146
group('(with mocked GIS)', () {
@@ -129,7 +153,7 @@ void main() {
129153

130154
setUp(() {
131155
plugin = GoogleSignInPlugin(
132-
debugOverrideLoader: true
156+
debugOverrideLoader: true,
133157
);
134158
mockGis = MockGisSdkClient();
135159
});
@@ -142,15 +166,15 @@ void main() {
142166
testWidgets('always returns null, regardless of GIS response', (_) async {
143167
final GoogleSignInUserData someUser = extractUserData(person)!;
144168

145-
mockito.when(mockGis.signInSilently()).thenAnswer(
146-
(_) => Future<GoogleSignInUserData>.value(someUser),
147-
);
169+
mockito
170+
.when(mockGis.signInSilently())
171+
.thenAnswer((_) => Future<GoogleSignInUserData>.value(someUser));
148172

149173
expect(plugin.signInSilently(), completion(isNull));
150174

151-
mockito.when(mockGis.signInSilently()).thenAnswer(
152-
(_) => Future<GoogleSignInUserData?>.value(),
153-
);
175+
mockito
176+
.when(mockGis.signInSilently())
177+
.thenAnswer((_) => Future<GoogleSignInUserData?>.value());
154178

155179
expect(plugin.signInSilently(), completion(isNull));
156180
});
@@ -164,28 +188,28 @@ void main() {
164188
testWidgets('returns the signed-in user', (_) async {
165189
final GoogleSignInUserData someUser = extractUserData(person)!;
166190

167-
mockito.when(mockGis.signIn()).thenAnswer(
168-
(_) => Future<GoogleSignInUserData>.value(someUser),
169-
);
191+
mockito
192+
.when(mockGis.signIn())
193+
.thenAnswer((_) => Future<GoogleSignInUserData>.value(someUser));
170194

171195
expect(await plugin.signIn(), someUser);
172196
});
173197

174198
testWidgets('returns null if no user is signed in', (_) async {
175-
mockito.when(mockGis.signIn()).thenAnswer(
176-
(_) => Future<GoogleSignInUserData?>.value(),
177-
);
199+
mockito
200+
.when(mockGis.signIn())
201+
.thenAnswer((_) => Future<GoogleSignInUserData?>.value());
178202

179203
expect(await plugin.signIn(), isNull);
180204
});
181205

182-
testWidgets('converts inner errors.toString to PlatformException', (_) async {
206+
testWidgets('converts inner errors to PlatformException', (_) async {
183207
mockito.when(mockGis.signIn()).thenThrow('popup_closed');
184208

185209
try {
186210
await plugin.signIn();
187211
fail('signIn should have thrown an exception');
188-
} catch(exception) {
212+
} catch (exception) {
189213
expect(exception, isA<PlatformException>());
190214
expect((exception as PlatformException).code, 'popup_closed');
191215
}

packages/google_sign_in/google_sign_in_web/example/integration_test/people_test.dart

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ void main() {
2222
group('requestUserData', () {
2323
const String expectedAccessToken = '3xp3c73d_4cc355_70k3n';
2424

25-
final TokenResponse fakeToken = jsifyAs(<String, Object?> {
25+
final TokenResponse fakeToken = jsifyAs(<String, Object?>{
2626
'token_type': 'Bearer',
2727
'access_token': expectedAccessToken,
2828
});
@@ -31,16 +31,16 @@ void main() {
3131
final Completer<String> accessTokenCompleter = Completer<String>();
3232

3333
final http.Client mockClient = http_test.MockClient(
34-
(http.Request request) async {
35-
36-
accessTokenCompleter.complete(request.headers['Authorization']);
37-
38-
return http.Response(
39-
jsonEncode(person),
40-
200,
41-
headers: <String, String>{'content-type': 'application/json'},
42-
);
43-
});
34+
(http.Request request) async {
35+
accessTokenCompleter.complete(request.headers['Authorization']);
36+
37+
return http.Response(
38+
jsonEncode(person),
39+
200,
40+
headers: <String, String>{'content-type': 'application/json'},
41+
);
42+
},
43+
);
4444

4545
final GoogleSignInUserData? user = await requestUserData(
4646
fakeToken,
@@ -53,17 +53,21 @@ void main() {
5353
expect(user.displayName, expectedPersonName);
5454
expect(user.photoUrl, expectedPersonPhoto);
5555
expect(user.idToken, isNull);
56-
expect(accessTokenCompleter.future, completion('Bearer $expectedAccessToken'));
56+
expect(
57+
accessTokenCompleter.future,
58+
completion('Bearer $expectedAccessToken'),
59+
);
5760
});
5861

5962
testWidgets('Unauthorized request - throws exception', (_) async {
6063
final http.Client mockClient = http_test.MockClient(
61-
(http.Request request) async {
62-
return http.Response(
63-
'Unauthorized',
64-
403,
65-
);
66-
});
64+
(http.Request request) async {
65+
return http.Response(
66+
'Unauthorized',
67+
403,
68+
);
69+
},
70+
);
6771

6872
expect(() async {
6973
await requestUserData(
@@ -87,7 +91,8 @@ void main() {
8791
});
8892

8993
testWidgets('no name/photo - keeps going', (_) async {
90-
final Map<String, Object?> personWithoutSomeData = mapWithoutKeys(person, <String>{
94+
final Map<String, Object?> personWithoutSomeData =
95+
mapWithoutKeys(person, <String>{
9196
'names',
9297
'photos',
9398
});
@@ -103,7 +108,8 @@ void main() {
103108
});
104109

105110
testWidgets('no userId - throws assertion error', (_) async {
106-
final Map<String, Object?> personWithoutId = mapWithoutKeys(person, <String>{
111+
final Map<String, Object?> personWithoutId =
112+
mapWithoutKeys(person, <String>{
107113
'resourceName',
108114
});
109115

@@ -113,7 +119,8 @@ void main() {
113119
});
114120

115121
testWidgets('no email - throws assertion error', (_) async {
116-
final Map<String, Object?> personWithoutEmail = mapWithoutKeys(person, <String>{
122+
final Map<String, Object?> personWithoutEmail =
123+
mapWithoutKeys(person, <String>{
117124
'emailAddresses',
118125
});
119126

packages/google_sign_in/google_sign_in_web/example/integration_test/src/dom.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ abstract class DomHtmlDocument {}
2121
extension DomHtmlDocumentExtension on DomHtmlDocument {
2222
/// document.head
2323
external DomHtmlElement get head;
24+
2425
/// document.createElement
2526
external DomHtmlElement createElement(String tagName);
2627
}
@@ -34,6 +35,7 @@ abstract class DomHtmlElement {}
3435
extension DomHtmlElementExtension on DomHtmlElement {
3536
/// Node.appendChild
3637
external DomHtmlElement appendChild(DomHtmlElement child);
38+
3739
/// Element.remove
3840
external void remove();
3941
}

packages/google_sign_in/google_sign_in_web/example/integration_test/src/person.dart

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,55 +5,62 @@
55
const String expectedPersonId = '1234567890';
66
const String expectedPersonName = 'Test McTestFace True';
77
const String expectedPersonEmail = '[email protected]';
8-
const String expectedPersonPhoto = 'https://thispersondoesnotexist.com/image?x=.jpg';
8+
const String expectedPersonPhoto =
9+
'https://thispersondoesnotexist.com/image?x=.jpg';
910

10-
/// A subset of https://developers.google.com/people/api/rest/v1/people#Person
11-
final Map<String, Object?> person = <String, Object?> {
11+
/// A subset of https://developers.google.com/people/api/rest/v1/people#Person.
12+
final Map<String, Object?> person = <String, Object?>{
1213
'resourceName': 'people/$expectedPersonId',
13-
'emailAddresses': <Object ?>[
14-
<String, Object?> {
15-
'metadata': <String, Object?> {
14+
'emailAddresses': <Object?>[
15+
<String, Object?>{
16+
'metadata': <String, Object?>{
1617
'primary': false,
1718
},
1819
'value': '[email protected]',
1920
},
20-
<String, Object?> {
21-
'metadata': <String, Object?> {},
21+
<String, Object?>{
22+
'metadata': <String, Object?>{},
2223
'value': '[email protected]',
2324
},
24-
<String, Object?> {
25-
'metadata': <String, Object?> {
25+
<String, Object?>{
26+
'metadata': <String, Object?>{
2627
'primary': true,
2728
},
2829
'value': expectedPersonEmail,
2930
},
3031
],
31-
'names': <Object ?>[
32-
<String, Object?> {
33-
'metadata': <String, Object?> {
32+
'names': <Object?>[
33+
<String, Object?>{
34+
'metadata': <String, Object?>{
3435
'primary': true,
3536
},
3637
'displayName': expectedPersonName,
3738
},
38-
<String, Object?> {
39-
'metadata': <String, Object?> {
39+
<String, Object?>{
40+
'metadata': <String, Object?>{
4041
'primary': false,
4142
},
4243
'displayName': 'Fakey McFakeface',
4344
},
4445
],
45-
'photos': <Object ?>[
46-
<String, Object?> {
47-
'metadata': <String, Object?> {
46+
'photos': <Object?>[
47+
<String, Object?>{
48+
'metadata': <String, Object?>{
4849
'primary': true,
4950
},
5051
'url': expectedPersonPhoto,
5152
},
5253
],
5354
};
5455

55-
T mapWithoutKeys<T extends Map<String, Object?>>(T map, Set<String> keysToRemove) {
56+
/// Returns a copy of [map] without the [keysToRemove].
57+
T mapWithoutKeys<T extends Map<String, Object?>>(
58+
T map,
59+
Set<String> keysToRemove,
60+
) {
5661
return Map<String, Object?>.fromEntries(
57-
map.entries.where((MapEntry<String, Object?> entry) => !keysToRemove.contains(entry.key))
62+
map.entries.where((MapEntry<String, Object?> entry) {
63+
return !keysToRemove.contains(entry.key);
64+
}),
5865
) as T;
5966
}

packages/google_sign_in/google_sign_in_web/example/integration_test/utils_test.dart

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ void main() {
2929
const String expectedIdToken = 'some-value-for-testing';
3030
const String expectedAccessToken = 'another-value-for-testing';
3131

32-
final CredentialResponse credential = jsifyAs<CredentialResponse>(<String, Object?>{
32+
final CredentialResponse credential =
33+
jsifyAs<CredentialResponse>(<String, Object?>{
3334
'credential': expectedIdToken,
3435
});
35-
final TokenResponse token = jsifyAs<TokenResponse>(<String, Object?> {
36+
final TokenResponse token = jsifyAs<TokenResponse>(<String, Object?>{
3637
'access_token': expectedAccessToken,
3738
});
38-
final GoogleSignInTokenData tokens = gisResponsesToTokenData(credential, token);
39+
final GoogleSignInTokenData tokens =
40+
gisResponsesToTokenData(credential, token);
3941
expect(tokens.accessToken, expectedAccessToken);
4042
expect(tokens.idToken, expectedIdToken);
4143
expect(tokens.serverAuthCode, isNull);
@@ -70,7 +72,8 @@ void main() {
7072
});
7173

7274
testWidgets('invalid payload -> null', (_) async {
73-
final CredentialResponse response = jsifyAs<CredentialResponse>(<String, Object?>{
75+
final CredentialResponse response =
76+
jsifyAs<CredentialResponse>(<String, Object?>{
7477
'credential': 'some-bogus.thing-that-is-not.valid-jwt',
7578
});
7679
expect(gisResponsesToUserData(response), isNull);
@@ -84,10 +87,12 @@ CredentialResponse createJwt(Map<String, Object?>? claims) {
8487
final JsonWebTokenClaims token = JsonWebTokenClaims.fromJson(claims);
8588
final JsonWebSignatureBuilder builder = JsonWebSignatureBuilder();
8689
builder.jsonContent = token.toJson();
87-
builder.addRecipient(JsonWebKey.fromJson(<String, Object?>{
88-
'kty': 'oct',
89-
'k': base64.encode('symmetric-encryption-is-weak'.codeUnits),
90-
}), algorithm: 'HS256'); // bogus crypto, don't use this for prod!
90+
builder.addRecipient(
91+
JsonWebKey.fromJson(<String, Object?>{
92+
'kty': 'oct',
93+
'k': base64.encode('symmetric-encryption-is-weak'.codeUnits),
94+
}),
95+
algorithm: 'HS256'); // bogus crypto, don't use this for prod!
9196
builder.setProtectedHeader('typ', 'JWT');
9297
credential = builder.build().toCompactSerialization();
9398
// ignore:avoid_print

0 commit comments

Comments
 (0)