Skip to content

Commit

Permalink
chore(code_push_client): remove getUsage (#1346)
Browse files Browse the repository at this point in the history
  • Loading branch information
felangel authored Oct 3, 2023
1 parent 09f41a4 commit 8080446
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 279 deletions.
13 changes: 0 additions & 13 deletions packages/shorebird_code_push_client/lib/src/code_push_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -482,19 +482,6 @@ class CodePushClient {
return decoded.artifacts;
}

/// Get all usage information for the associated account.
Future<GetUsageResponse> getUsage() async {
final response = await _httpClient.get(Uri.parse('$_v1/usage'));

if (response.statusCode != HttpStatus.ok) {
throw _parseErrorResponse(response.statusCode, response.body);
}

return GetUsageResponse.fromJson(
json.decode(response.body) as Map<String, dynamic>,
);
}

/// Promote the [patchId] to the [channelId].
Future<void> promotePatch({
required String appId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1981,91 +1981,6 @@ void main() {
});
});

group('getUsage', () {
test('makes the correct request', () async {
codePushClient.getUsage().ignore();
final request = verify(() => httpClient.send(captureAny()))
.captured
.single as http.BaseRequest;
expect(request.method, equals('GET'));
expect(request.url, equals(v1('usage')));
expect(request.hasStandardHeaders, isTrue);
});

test('throws an exception if the http request fails (unknown)', () async {
when(() => httpClient.send(any())).thenAnswer(
(_) async => http.StreamedResponse(
const Stream.empty(),
HttpStatus.failedDependency,
),
);

expect(
codePushClient.getUsage(),
throwsA(
isA<CodePushException>().having(
(e) => e.message,
'message',
CodePushClient.unknownErrorMessage,
),
),
);
});

test('throws an exception if the http request fails', () async {
when(() => httpClient.send(any())).thenAnswer(
(_) async => http.StreamedResponse(
Stream.value(utf8.encode(json.encode(errorResponse.toJson()))),
HttpStatus.failedDependency,
),
);

expect(
codePushClient.getUsage(),
throwsA(
isA<CodePushException>().having(
(e) => e.message,
'message',
errorResponse.message,
),
),
);
});

test('completes when request succeeds', () async {
final expected = GetUsageResponse(
plan: ShorebirdPlan(
name: 'Hobby',
monthlyCost: Money.fromIntWithCurrency(0, usd),
currency: 'USD',
patchInstallLimit: 1000,
maxTeamSize: 1,
),
apps: [
AppUsage(
id: 'test-app-id',
name: 'Test App',
patchInstallCount: 42,
),
],
currentPeriodCost: Money.fromIntWithCurrency(0, usd),
currentPeriodStart: DateTime(2023),
currentPeriodEnd: DateTime(2023, 2),
cancelAtPeriodEnd: false,
);

when(() => httpClient.send(any())).thenAnswer(
(_) async => http.StreamedResponse(
Stream.value(utf8.encode(json.encode(expected))),
HttpStatus.ok,
),
);

final actual = await codePushClient.getUsage();
expect(json.encode(actual), equals(json.encode(expected)));
});
});

group('promotePatch', () {
const patchId = 0;
const channelId = 0;
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export 'get_apps/get_apps.dart';
export 'get_overages/get_overages.dart';
export 'get_release_artifacts/get_release_artifacts.dart';
export 'get_releases/get_releases.dart';
export 'get_usage/get_usage.dart';
export 'promote_patch/promote_patch.dart';
export 'update_overages/update_overages.dart';
export 'update_release/update_release.dart';

This file was deleted.

0 comments on commit 8080446

Please sign in to comment.