File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -131,22 +131,25 @@ class CimaRepository {
131131 params: params,
132132 );
133133 log ('statusCode: ${response .statusCode }' );
134- if (response.statusCode != 200 ) {
135- return Left (ServerFailure ());
136- }
137-
138- try {
139- final cimaPaginado = CimaPaginado .fromJson (jsonDecode (response.body));
140- if (cimaPaginado.resultados? .isEmpty ?? true ) {
141- return Right ([]);
134+ if (response.statusCode == 200 ) {
135+ try {
136+ final cimaPaginado =
137+ CimaPaginado .fromJson (jsonDecode (response.body));
138+ if (cimaPaginado.resultados? .isEmpty ?? true ) {
139+ return Right ([]);
140+ }
141+ final problemasSuministro = cimaPaginado.resultados!
142+ .map ((e) => SupplyProblems .fromJson (e))
143+ .toList ();
144+ return Right (problemasSuministro);
145+ } catch (e) {
146+ log ('error: $e ' );
147+ return Left (FormatFailure ());
142148 }
143- final problemasSuministro = cimaPaginado.resultados!
144- .map ((e) => SupplyProblems .fromJson (e))
145- .toList ();
146- return Right (problemasSuministro);
147- } catch (e) {
148- log ('error: $e ' );
149- return Left (FormatFailure ());
149+ } else if (response.statusCode == 204 ) {
150+ return Left (NoDataFailure ());
151+ } else {
152+ return Left (ServerFailure ());
150153 }
151154 } catch (e) {
152155 return Left (ServerFailure ());
Original file line number Diff line number Diff line change @@ -150,6 +150,15 @@ void main() {
150150 expect (result.fold ((_) => null , (r) => r), problemasSuministro);
151151 });
152152
153+ test ('find problemas suministro without data' , () async {
154+ when (() => apiClient.getProblemasSuministro (params: {}))
155+ .thenAnswer ((_) async => Response ('' , 204 ));
156+
157+ final repository = CimaRepository (remoteDataSource: apiClient);
158+ final result = await repository.findProblemasSuministro (params: {});
159+ expect (result, Left (NoDataFailure ()));
160+ });
161+
153162 test ('find with params' , () async {
154163 final params = {'nombre' : 'aspirina' };
155164 final problemasSuministroRaw =
You can’t perform that action at this time.
0 commit comments