-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement fetch album collection statuses when user enter album detai…
…l page #112
- Loading branch information
Showing
9 changed files
with
184 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import 'package:vocadb_app/models.dart'; | ||
|
||
class AlbumCollectionStatusModel { | ||
AlbumModel album; | ||
String mediaType; | ||
String purchaseStatus; | ||
int rating; | ||
|
||
AlbumCollectionStatusModel( | ||
{this.album, this.mediaType, this.purchaseStatus, this.rating}); | ||
|
||
AlbumCollectionStatusModel.fromJson(Map<String, dynamic> json) | ||
: album = (json.containsKey('album')) | ||
? AlbumModel.fromJson(json['album']) | ||
: null, | ||
mediaType = json['mediaType'], | ||
purchaseStatus = json['purchaseStatus'], | ||
rating = json['rating']; | ||
|
||
get label => (purchaseStatus != null) ? purchaseStatus : 'Add'; | ||
|
||
get isCollected => (purchaseStatus != null && purchaseStatus != 'Nothing'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:get/get.dart'; | ||
import 'package:mockito/mockito.dart'; | ||
import 'package:vocadb_app/controllers.dart'; | ||
import 'package:vocadb_app/models.dart'; | ||
import 'package:vocadb_app/repositories.dart'; | ||
import 'package:vocadb_app/services.dart'; | ||
|
||
class MockAlbumRepository extends Mock implements AlbumRepository {} | ||
|
||
class MockUserRepository extends Mock implements UserRepository {} | ||
|
||
class MockAuthService extends Mock implements AuthService {} | ||
|
||
void main() { | ||
final MockAlbumRepository mockAlbumRepository = MockAlbumRepository(); | ||
final MockUserRepository mockUserRepository = MockUserRepository(); | ||
final MockAuthService mockAuthService = MockAuthService(); | ||
|
||
test('should get album collection status success', () async { | ||
final AlbumCollectionStatusModel mockCollectionStatus = | ||
AlbumCollectionStatusModel(purchaseStatus: 'Wishlisted'); | ||
|
||
final mockUserModel = Rx<UserModel>(); | ||
mockUserModel(UserModel(id: 1)); | ||
|
||
when(mockAuthService.currentUser).thenReturn(mockUserModel); | ||
|
||
when(mockUserRepository.getCurrentUserAlbumCollection(1)) | ||
.thenAnswer((_) => Future.value(mockCollectionStatus)); | ||
|
||
final AlbumDetailController controller = AlbumDetailController( | ||
userRepository: mockUserRepository, | ||
albumRepository: mockAlbumRepository, | ||
authService: mockAuthService); | ||
|
||
controller.album(AlbumModel(id: 1)); | ||
|
||
await controller.checkAlbumCollectionStatus(); | ||
|
||
expect(controller.collectionStatus.value.purchaseStatus, "Wishlisted"); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:vocadb_app/models.dart'; | ||
|
||
void main() { | ||
group('Album collection status model', () { | ||
test('should parse from json correctly', () { | ||
const mockJson = { | ||
"album": { | ||
"artistString": "Harry, Teruaki Tanahashi, ELS feat. Hatsune Miku", | ||
"id": 23848, | ||
"name": "A HUNDRED MILLION LIGHTS", | ||
}, | ||
"mediaType": "Other", | ||
"purchaseStatus": "Wishlisted", | ||
"rating": 5 | ||
}; | ||
|
||
AlbumCollectionStatusModel result = | ||
AlbumCollectionStatusModel.fromJson(mockJson); | ||
expect(result.album.id, 23848); | ||
expect(result.mediaType, 'Other'); | ||
expect(result.purchaseStatus, 'Wishlisted'); | ||
expect(result.rating, 5); | ||
}); | ||
|
||
test('should not thrown exception when input empty json', () { | ||
AlbumCollectionStatusModel result = | ||
AlbumCollectionStatusModel.fromJson({}); | ||
expect(result, isNotNull); | ||
expect(result.album, isNull); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:mockito/mockito.dart'; | ||
import 'package:vocadb_app/models.dart'; | ||
import 'package:vocadb_app/repositories.dart'; | ||
import 'package:vocadb_app/services.dart'; | ||
|
||
class MockHttpService extends Mock implements HttpService {} | ||
|
||
void main() { | ||
test('should return AlbumCollectionStatusModel', () async { | ||
final Map<String, dynamic> mockResponse = { | ||
"album": { | ||
"artistString": "Harry, Teruaki Tanahashi, ELS feat. Hatsune Miku", | ||
"id": 23848, | ||
"name": "A HUNDRED MILLION LIGHTS", | ||
}, | ||
"mediaType": "Other", | ||
"purchaseStatus": "Wishlisted", | ||
"rating": 5 | ||
}; | ||
final MockHttpService mockHttpService = MockHttpService(); | ||
final UserRepository userRepository = | ||
UserRepository(httpService: mockHttpService); | ||
final AlbumCollectionStatusModel expectModel = | ||
AlbumCollectionStatusModel.fromJson(mockResponse); | ||
final String url = '/api/users/current/album-collection-statuses/1'; | ||
|
||
when(mockHttpService.get(url, null)) | ||
.thenAnswer((_) => Future.value(mockResponse)); | ||
|
||
final AlbumCollectionStatusModel actualModel = | ||
await userRepository.getCurrentUserAlbumCollection(1); | ||
|
||
expect(actualModel.album.id, expectModel.album.id); | ||
expect(actualModel.mediaType, expectModel.mediaType); | ||
expect(actualModel.purchaseStatus, expectModel.purchaseStatus); | ||
expect(actualModel.rating, expectModel.rating); | ||
}); | ||
} |