Skip to content

Commit

Permalink
feat(shorebird_code_push_client): add deleteRelease (#430)
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanoltman authored May 3, 2023
1 parent 1cb8154 commit 9ae64e9
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
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

0 comments on commit 9ae64e9

Please sign in to comment.