Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(shorebird_code_push_client): add deleteRelease #430

Merged
merged 1 commit into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/shorebird_code_push_client/lib/src/code_push_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,17 @@ class CodePushClient {
return Release.fromJson(body);
}

/// Delete the release with the provided [releaseId].
Future<void> deleteRelease({required int releaseId}) async {
final response = await _httpClient.delete(
Uri.parse('$hostedUri/api/v1/releases/$releaseId'),
);

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

/// Create a new Shorebird user with the provided [name].
///
/// The email associated with the user's JWT will be used as the user's email.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,76 @@ void main() {
});
});

group('deleteRelease', () {
const releaseId = 42;

test('throws an exception if the http request fails (unknown)', () async {
when(
() => httpClient.delete(any(), headers: any(named: 'headers')),
).thenAnswer(
(_) async => http.Response('', HttpStatus.failedDependency),
);

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

test('throws an exception if the http request fails', () async {
when(
() => httpClient.delete(any(), headers: any(named: 'headers')),
).thenAnswer(
(_) async => http.Response(
json.encode(errorResponse.toJson()),
HttpStatus.failedDependency,
),
);

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

test('completes when request succeeds', () async {
when(
() => httpClient.delete(
any(),
headers: any(named: 'headers'),
),
).thenAnswer((_) async => http.Response('', HttpStatus.noContent));

await codePushClient.deleteRelease(releaseId: releaseId);

final uri = verify(
() => httpClient.delete(
captureAny(),
headers: any(named: 'headers'),
),
).captured.single as Uri;

expect(
uri,
codePushClient.hostedUri.replace(
path: '/api/v1/releases/$releaseId',
),
);
});
});

group('createUser', () {
const userName = 'Jane Doe';
final user = User(
Expand Down