Skip to content

Commit 8cd535f

Browse files
committed
Refactor proposal: use unnamed callback function in with*HttpPubApiClient methods.
1 parent fd5eda7 commit 8cd535f

14 files changed

+89
-91
lines changed

app/lib/fake/backend/fake_auth_provider.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,10 +419,10 @@ Future<String> _acquireCsrfToken({
419419
///
420420
/// The [email] is used to create an HTTP session and the related CSRF token is
421421
/// extracted from the session, both are sent alongside the requests.
422-
Future<R> withFakeAuthHttpPubApiClient<R>({
422+
Future<R> withFakeAuthHttpPubApiClient<R>(
423+
Future<R> Function(PubApiClient client) fn, {
423424
required String email,
424425
List<String>? scopes,
425-
required Future<R> Function(PubApiClient client) fn,
426426
String? pubHostedUrl,
427427
Set<String>? experimental,
428428
}) async {
@@ -440,8 +440,8 @@ Future<R> withFakeAuthHttpPubApiClient<R>({
440440
sessionId: sessionId,
441441
csrfToken: csrfToken,
442442
pubHostedUrl: pubHostedUrl,
443-
fn: fn,
444443
experimental: experimental,
444+
fn,
445445
);
446446
}
447447

app/lib/tool/test_profile/importer.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Future<void> importProfile({
4949
email: firstMemberEmail,
5050
scopes: [webmasterScope],
5151
pubHostedUrl: pubHostedUrl,
52-
fn: (client) async {
52+
(client) async {
5353
try {
5454
await client.createPublisher(p.name);
5555
} on RequestException catch (e) {
@@ -98,7 +98,7 @@ Future<void> importProfile({
9898
bearerToken: createFakeAuthTokenForEmail(uploaderEmail,
9999
audience: activeConfiguration.pubClientAudience),
100100
pubHostedUrl: pubHostedUrl,
101-
fn: (client) => client.uploadPackageBytes(bytes),
101+
(client) => client.uploadPackageBytes(bytes),
102102
);
103103
published = true;
104104
} catch (e, st) {
@@ -123,7 +123,7 @@ Future<void> importProfile({
123123
await withFakeAuthHttpPubApiClient(
124124
email: activeEmail!,
125125
pubHostedUrl: pubHostedUrl,
126-
fn: (client) async {
126+
(client) async {
127127
// update publisher
128128
if (testPackage.publisher != null) {
129129
await client.setPackagePublisher(
@@ -155,7 +155,7 @@ Future<void> importProfile({
155155
bearerToken:
156156
createFakeServiceAccountToken(email: adminUserEmail ?? activeEmail),
157157
pubHostedUrl: pubHostedUrl,
158-
fn: (client) async {
158+
(client) async {
159159
await client.adminPostAssignedTags(
160160
packageName,
161161
PatchAssignedTags(
@@ -173,7 +173,7 @@ Future<void> importProfile({
173173
await withFakeAuthHttpPubApiClient(
174174
email: u.email,
175175
pubHostedUrl: pubHostedUrl,
176-
fn: (client) async {
176+
(client) async {
177177
// creates user (regardless of likes being specified)
178178
await client.listPackageLikes();
179179

@@ -197,7 +197,7 @@ Future<void> importProfile({
197197
await withFakeAuthHttpPubApiClient(
198198
email: userEmail,
199199
pubHostedUrl: pubHostedUrl,
200-
fn: (client) async {
200+
(client) async {
201201
await client.likePackage(p.name);
202202
},
203203
);

app/lib/tool/utils/pub_api_client.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ class _FakeTimeClient implements http.Client {
9898
///
9999
/// If [bearerToken], [sessionId] or [csrfToken] is specified, the corresponding
100100
/// HTTP header will be sent alongside the request.
101-
Future<R> withHttpPubApiClient<R>({
101+
Future<R> withHttpPubApiClient<R>(
102+
Future<R> Function(PubApiClient client) fn, {
102103
String? bearerToken,
103104
String? sessionId,
104105
String? csrfToken,
105106
String? pubHostedUrl,
106107
Set<String>? experimental,
107-
required Future<R> Function(PubApiClient client) fn,
108108
}) async {
109109
final httpClient = httpClientWithAuthorization(
110110
tokenProvider: () async => bearerToken,

app/test/account/consent_backend_test.dart

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void main() {
2828
await withFakeAuthHttpPubApiClient(
2929
email: adminEmail,
3030
pubHostedUrl: activeConfiguration.primarySiteUri.toString(),
31-
fn: (client) async {
31+
(client) async {
3232
await client.invitePackageUploader(
3333
'oxygen', InviteUploaderRequest(email: userAtPubDevEmail));
3434
},
@@ -309,15 +309,13 @@ void main() {
309309

310310
group('Sanity check', () {
311311
testWithProfile('consent parameter length', fn: () async {
312-
await withFakeAuthHttpPubApiClient(
313-
email: adminAtPubDevEmail,
314-
fn: (c) async {
315-
await expectApiException(
316-
c.consentInfo('abcd' * 500),
317-
status: 400,
318-
code: 'InvalidInput',
319-
);
320-
});
312+
await withFakeAuthHttpPubApiClient(email: adminAtPubDevEmail, (c) async {
313+
await expectApiException(
314+
c.consentInfo('abcd' * 500),
315+
status: 400,
316+
code: 'InvalidInput',
317+
);
318+
});
321319
});
322320
});
323321
}

app/test/admin/exported_api_sync_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void main() {
2121
}) async {
2222
await withHttpPubApiClient(
2323
bearerToken: siteAdminToken,
24-
fn: (api) async {
24+
(api) async {
2525
await api.adminInvokeAction(
2626
'exported-api-sync',
2727
AdminInvokeActionArguments(arguments: {

app/test/admin/moderate_package_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void main() {
3434
group('Moderate package', () {
3535
Future<ModerationCase> _report(String package) async {
3636
await withHttpPubApiClient(
37-
fn: (client) async {
37+
(client) async {
3838
await client.postReport(ReportForm(
3939
4040
subject: 'package:$package',

app/test/admin/moderate_package_version_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void main() {
3434
group('Moderate package version', () {
3535
Future<ModerationCase> _report(String package, String version) async {
3636
await withHttpPubApiClient(
37-
fn: (client) async {
37+
(client) async {
3838
await client.postReport(ReportForm(
3939
4040
subject: 'package-version:$package/$version',

app/test/admin/moderate_publisher_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void main() {
2525
group('Moderate Publisher', () {
2626
Future<ModerationCase> _report(String publisherId) async {
2727
await withHttpPubApiClient(
28-
fn: (client) async {
28+
(client) async {
2929
await client.postReport(ReportForm(
3030
3131
subject: 'publisher:$publisherId',

app/test/admin/moderate_user_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void main() {
2929
group('Moderate User', () {
3030
Future<ModerationCase> _report(String package) async {
3131
await withHttpPubApiClient(
32-
fn: (client) async {
32+
(client) async {
3333
await client.postReport(account_api.ReportForm(
3434
3535
subject: 'package:$package',

app/test/admin/moderation_case_resolve_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ void main() {
1919
required bool? apply,
2020
}) async {
2121
await withHttpPubApiClient(
22-
fn: (client) async {
22+
(client) async {
2323
await client.postReport(ReportForm(
2424
2525
caseId: appealCaseId,

0 commit comments

Comments
 (0)