Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
refactor(terminal: naming error
Browse files Browse the repository at this point in the history
Correct json key name

Linked #42
  • Loading branch information
MansourWolou committed Dec 19, 2023
1 parent 92b90c6 commit c50612e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class GetProduct implements UseCase<List<Product>, void> {
//return product list
return result.data;
} else {
//Todo: Implement error handling
throw Exception("Didn't get products ; result.errorMessage");
}
} catch (err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:terminal/features/transaction/domain/entity/check.dart';
import 'package:flutter_zxing/flutter_zxing.dart';

class GetCheckData implements UseCase<DataState, Code> {
// test Qr code scnaning with https://fr.qr-code-generator.com/
@override
Future<DataState> call({Code? params}) {
late DataState result;
Expand All @@ -18,38 +19,19 @@ class GetCheckData implements UseCase<DataState, Code> {
throw Exception("The scan result is not a string or empty");
}

//* valild json : {"checkNumer":468516,"amount":85}
//* valild json : {"checkNumber":468516,"amount":85}
data = jsonDecode(params.text!);

if (data["amount"] is! int || data["checkNumber"] is! int) {
throw Exception("json data not valid");
}

result = Success(
Check(amount: data["amount"], checkNumber: data["checkNumer"]));
Check(amount: data["amount"], checkNumber: data["checkNumber"]));
} catch (e) {
result = Error(e);
}

return Future(() => result);
}
}
// if (params!.text != null) {
// if (params.text!.isNotEmpty && params.text is String) {
// //* valild json : {"checkNumer":468516,"amount":85}

// data = jsonDecode(params.text!);

// if (data["amount"].runtimeType is int ||
// data["checkNumer"].runtimeType is int) {
// result = Success(
// Check(amount: data["amount"], checkNumber: data["checkNumer"]));
// } else {
// result = Error("json data not valid");
// }
// } else {
// result = Error("The scan result is not a string or empty");
// }
// } else {
// result = Error("params is null");
// }
6 changes: 3 additions & 3 deletions terminal/test/domain/usecase/get_check_data_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ void main() {
test('GetCheckData call method with valid JSON data', () async {
// Arrange
final useCase = GetCheckData();
final code = Code(text: '{"checkNumer":468516,"amount":85}');
final code = Code(text: '{"checkNumber":468516,"amount":85}');

// Act
final result = await useCase.call(params: code);
Expand All @@ -22,7 +22,7 @@ void main() {
test('should throw exception for invalid JSON data', () async {
// Arrange
final useCase = GetCheckData();
final code = Code(text: '{"checkNumer":468516,"amount":"85"}');
final code = Code(text: '{"checkNumber":468516,"amount":"85"}');

// Act
final result = await useCase.call(params: code);
Expand Down Expand Up @@ -60,7 +60,7 @@ void main() {
});
test("Should return Error for unvalid check data ", () async {
final useCase = GetCheckData();
final code = Code(text: '{"Checknumer":468516,"amount":HACKER}');
final code = Code(text: '{"checkNumber":468516,"amount":HACKER}');

final result = await useCase(params: code);

Expand Down

0 comments on commit c50612e

Please sign in to comment.