diff --git a/packages/app_center/lib/ratings/ratings_model.dart b/packages/app_center/lib/ratings/ratings_model.dart index 06df81017..edb10542c 100644 --- a/packages/app_center/lib/ratings/ratings_model.dart +++ b/packages/app_center/lib/ratings/ratings_model.dart @@ -31,7 +31,7 @@ class RatingsModel extends _$RatingsModel { } final results = await Future.wait([ - _ratings.getRating(snapId), + _ratings.getRating(snapName, snapId), _ratings.getSnapVotes(snapId), ]); diff --git a/packages/app_center/lib/ratings/ratings_service.dart b/packages/app_center/lib/ratings/ratings_service.dart index 9cd242be5..18e0cf88a 100644 --- a/packages/app_center/lib/ratings/ratings_service.dart +++ b/packages/app_center/lib/ratings/ratings_service.dart @@ -30,9 +30,13 @@ class RatingsService { } } - Future getRating(String snapId) async { + Future getRating( + String snapName, + // TODO: remove snapId once the server doesn't require it anymore + String snapId, + ) async { await _ensureValidToken(); - return client.getRating(snapId, _jwt!); + return client.getRating(snapName, snapId, _jwt!); } Future> getChart(SnapCategoryEnum category) async { @@ -46,7 +50,8 @@ class RatingsService { Future vote(ratings.Vote vote) async { await _ensureValidToken(); - await client.vote(vote.snapId, vote.snapRevision, vote.voteUp, _jwt!); + await client.vote( + vote.snapName, vote.snapId, vote.snapRevision, vote.voteUp, _jwt!); } Future delete() async { diff --git a/packages/app_center/test/ratings_service_test.dart b/packages/app_center/test/ratings_service_test.dart index 37dc57a01..2818866aa 100644 --- a/packages/app_center/test/ratings_service_test.dart +++ b/packages/app_center/test/ratings_service_test.dart @@ -19,7 +19,7 @@ void main() { ); final service = RatingsService(mockClient, id: 'myId'); - final rating = await service.getRating('firefox'); + final rating = await service.getRating('firefox', '1234'); verify(mockClient.authenticate('myId')).called(1); expect( rating, @@ -101,7 +101,7 @@ void main() { ), ); verify(mockClient.authenticate('myId')).called(1); - verify(mockClient.vote('7890', 42, true, 'jwt')).called(1); + verify(mockClient.vote('thunderbird', '7890', 42, true, 'jwt')).called(1); }); test('delete', () async { diff --git a/packages/app_center/test/test_utils.dart b/packages/app_center/test/test_utils.dart index 0c2c2e1f7..fa0fafd62 100644 --- a/packages/app_center/test/test_utils.dart +++ b/packages/app_center/test/test_utils.dart @@ -297,7 +297,7 @@ MockRatingsService registerMockRatingsService({ List? snapVotes, }) { final service = MockRatingsService(); - when(service.getRating(any)).thenAnswer( + when(service.getRating(any, any)).thenAnswer( (_) async => rating ?? const Rating( @@ -322,7 +322,7 @@ MockRatingsClient createMockRatingsClient({ }) { final client = MockRatingsClient(); when(client.authenticate(any)).thenAnswer((_) async => token ?? ''); - when(client.getRating(any, any)).thenAnswer( + when(client.getRating(any, any, any)).thenAnswer( (_) async => rating ?? const Rating( diff --git a/packages/app_center_ratings_client/lib/src/ratings_client.dart b/packages/app_center_ratings_client/lib/src/ratings_client.dart index 195969b57..b726770ca 100644 --- a/packages/app_center_ratings_client/lib/src/ratings_client.dart +++ b/packages/app_center_ratings_client/lib/src/ratings_client.dart @@ -70,10 +70,15 @@ class RatingsClient { } Future getRating( + String snapName, + // TODO: remove snapId once the server doesn't require it anymore String snapId, String token, ) async { - final request = app_pb.GetRatingRequest(snapId: snapId); + final request = app_pb.GetRatingRequest( + snapName: snapName, + snapId: snapId, + ); final callOptions = CallOptions(metadata: {'authorization': 'Bearer $token'}); final grpcResponse = await _appClient.getRating( @@ -95,12 +100,15 @@ class RatingsClient { } Future vote( + String snapName, + // TODO: remove snapId once the server doesn't require it anymore String snapId, int snapRevision, bool voteUp, String token, ) async { final request = user_pb.VoteRequest( + snapName: snapName, snapId: snapId, snapRevision: snapRevision, voteUp: voteUp, diff --git a/packages/app_center_ratings_client/test/ratings_client_test.dart b/packages/app_center_ratings_client/test/ratings_client_test.dart index 58cdc32f0..d1e7b84de 100644 --- a/packages/app_center_ratings_client/test/ratings_client_test.dart +++ b/packages/app_center_ratings_client/test/ratings_client_test.dart @@ -115,7 +115,7 @@ void main() { snapName: snapName, ); final mockResponse = pb.GetRatingResponse(rating: pbRating); - final request = pb.GetRatingRequest(snapId: snapId); + final request = pb.GetRatingRequest(snapName: snapName, snapId: snapId); when( mockAppClient.getRating( request, @@ -125,6 +125,7 @@ void main() { (_) => MockResponseFuture(mockResponse), ); final response = await ratingsClient.getRating( + snapName, snapId, token, ); @@ -166,10 +167,12 @@ void main() { test('user votes', () async { const snapId = 'foo'; + const snapName = 'fooName'; const snapRevision = 1; const voteUp = true; const token = 'bar'; final request = VoteRequest( + snapName: snapName, snapId: snapId, snapRevision: snapRevision, voteUp: voteUp, @@ -182,6 +185,7 @@ void main() { ), ).thenAnswer((_) => MockResponseFuture(Empty())); await ratingsClient.vote( + snapName, snapId, snapRevision, voteUp,