diff --git a/lib/features/plans/enums/chosen_plan_state_enum.dart b/lib/features/plans/enums/chosen_plan_state_enum.dart index 2f37ec30..2e867f38 100644 --- a/lib/features/plans/enums/chosen_plan_state_enum.dart +++ b/lib/features/plans/enums/chosen_plan_state_enum.dart @@ -30,7 +30,9 @@ enum ChosenPlanStateEnum { @JsonValue('personal_diet_setted') personalDietSet, @JsonValue('charge_was_collected') - stateChargeWasCollected; + stateChargeWasCollected, + @JsonValue('payment_failed') + statePaymentFailed; static List getShowableChatBadgeStates() { return [ @@ -53,6 +55,7 @@ enum ChosenPlanStateEnum { case ChosenPlanStateEnum.stateInCoordination: case ChosenPlanStateEnum.stateStartDateHasBeenSet: case ChosenPlanStateEnum.statePendingPayment: + case ChosenPlanStateEnum.statePaymentFailed: return false; default: return true; @@ -68,7 +71,7 @@ enum ChosenPlanStateEnum { ChosenPlanStateEnum.stateLastDayFinished, ChosenPlanStateEnum.stateComplained, ChosenPlanStateEnum.stateDone, - ChosenPlanStateEnum.personalDietSet + ChosenPlanStateEnum.personalDietSet, ]; } } diff --git a/test/features/chat/models/payment_model_test.dart b/test/features/chat/models/payment_model_test.dart index 59675ab0..12019bff 100644 --- a/test/features/chat/models/payment_model_test.dart +++ b/test/features/chat/models/payment_model_test.dart @@ -33,5 +33,15 @@ void main() { expect(model.paymentProvider, 'alfa-bank'); }, ); + + test('fromJson парсит mock-ответ (checkout_url без order_id)', () { + final json = FixtureReader.readAsMap('chat/payments/payment_response.json'); + + final model = PaymentModel.fromJson(json); + + expect(model.paymentUrl, 'https://example.com/checkout/payment-123'); + expect(model.orderId, isNull); + expect(model.paymentProvider, isNull); + }); }); } diff --git a/test/features/chat/repositories/chat_repository_test.dart b/test/features/chat/repositories/chat_repository_test.dart index 12e75a64..247d1311 100644 --- a/test/features/chat/repositories/chat_repository_test.dart +++ b/test/features/chat/repositories/chat_repository_test.dart @@ -13,6 +13,7 @@ import 'package:eatvio_app/features/chat/models/payment_model.dart'; import 'package:eatvio_app/features/chat/models/plan_complain_model.dart'; import 'package:eatvio_app/features/chat/repositories/chat_repository.dart'; import 'package:eatvio_app/features/chat/services/chat_service.dart'; +import 'package:eatvio_app/features/plans/enums/chosen_plan_state_enum.dart'; import 'package:eatvio_app/features/plans/models/chosen_plan_model.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/annotations.dart'; @@ -401,6 +402,68 @@ void main() { verify(mockChatService.getChosenPlan(id: planId)).called(1); }); + group('getChosenPlan payment polling statuses', () { + test('getChosenPlan - возвращает план в статусе pending_payment', () async { + const planId = 1; + final fixture = FixtureReader.readAsMap( + 'chat/chosen_plan/chosen_plan_pending_payment_response.json', + ); + final expectedPlan = ChosenPlanModel.fromJson(fixture); + + when(mockChatService.getChosenPlan(id: planId)).thenAnswer((_) async => expectedPlan); + + final result = await chatRepository.getChosenPlan(id: planId); + + expect(result.chosenPlanState, ChosenPlanStateEnum.statePendingPayment); + verify(mockChatService.getChosenPlan(id: planId)).called(1); + }); + + test('getChosenPlan - возвращает план в статусе paid', () async { + const planId = 1; + final fixture = FixtureReader.readAsMap( + 'chat/chosen_plan/chosen_plan_paid_response.json', + ); + final expectedPlan = ChosenPlanModel.fromJson(fixture); + + when(mockChatService.getChosenPlan(id: planId)).thenAnswer((_) async => expectedPlan); + + final result = await chatRepository.getChosenPlan(id: planId); + + expect(result.chosenPlanState, ChosenPlanStateEnum.statePaid); + verify(mockChatService.getChosenPlan(id: planId)).called(1); + }); + + test('getChosenPlan - возвращает план в статусе payment_failed', () async { + const planId = 1; + final fixture = FixtureReader.readAsMap( + 'chat/chosen_plan/chosen_plan_payment_failed_response.json', + ); + final expectedPlan = ChosenPlanModel.fromJson(fixture); + + when(mockChatService.getChosenPlan(id: planId)).thenAnswer((_) async => expectedPlan); + + final result = await chatRepository.getChosenPlan(id: planId); + + expect(result.chosenPlanState, ChosenPlanStateEnum.statePaymentFailed); + verify(mockChatService.getChosenPlan(id: planId)).called(1); + }); + + test('getChosenPlan - возвращает план в статусе canceled_by_the_initiator', () async { + const planId = 1; + final fixture = FixtureReader.readAsMap( + 'chat/chosen_plan/chosen_plan_canceled_by_the_initiator_response.json', + ); + final expectedPlan = ChosenPlanModel.fromJson(fixture); + + when(mockChatService.getChosenPlan(id: planId)).thenAnswer((_) async => expectedPlan); + + final result = await chatRepository.getChosenPlan(id: planId); + + expect(result.chosenPlanState, ChosenPlanStateEnum.stateCanceledByTheInitiator); + verify(mockChatService.getChosenPlan(id: planId)).called(1); + }); + }); + test('finishChosenPlan - завершает выбранный план', () async { const planId = 123; diff --git a/test/features/chat/services/chat_service_test.dart b/test/features/chat/services/chat_service_test.dart index bf55d616..d544e6a2 100644 --- a/test/features/chat/services/chat_service_test.dart +++ b/test/features/chat/services/chat_service_test.dart @@ -235,6 +235,38 @@ void main() { verify(mockChatService.getPaymentLink(id: planId, body: {'payment_provider': 'mock'})).called(1); }); + test( + 'getPaymentLink - возвращает ссылку на оплату alfa-bank', + () async { + const planId = 123; + final requestFixture = FixtureReader.readAsMap( + 'chat/payments/payment_alfabank_request.json', + ); + final requestBody = Map.from(requestFixture); + final paymentFixture = FixtureReader.readAsMap( + 'chat/payments/payment_response_alfa_bank.json', + ); + final expectedPayment = PaymentModel.fromJson(paymentFixture); + + when( + mockChatService.getPaymentLink(id: planId, body: requestBody), + ).thenAnswer((_) async => expectedPayment); + + final result = await mockChatService.getPaymentLink( + id: planId, + body: requestBody, + ); + + expect(result, isA()); + expect(result.paymentUrl, 'https://qr.nspk.ru/ASDFASDFASDFASDF'); + expect(result.orderId, 'alfa_c29_k15138_t1712345678_r1234'); + expect(result.paymentProvider, 'alfa-bank'); + verify( + mockChatService.getPaymentLink(id: planId, body: requestBody), + ).called(1); + }, + ); + test('getChosenPlan - возвращает выбранный план', () async { const planId = 1; final chosenPlanFixture = FixtureReader.readAsMap( diff --git a/test/features/plans/enums/chosen_plan_state_enum_test.dart b/test/features/plans/enums/chosen_plan_state_enum_test.dart index 104bfa59..3c963836 100644 --- a/test/features/plans/enums/chosen_plan_state_enum_test.dart +++ b/test/features/plans/enums/chosen_plan_state_enum_test.dart @@ -4,7 +4,7 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('ChosenPlanStateEnum', () { test('has all expected values', () { - expect(ChosenPlanStateEnum.values.length, 15); + expect(ChosenPlanStateEnum.values.length, 16); expect(ChosenPlanStateEnum.values, contains(ChosenPlanStateEnum.stateInited)); expect(ChosenPlanStateEnum.values, contains(ChosenPlanStateEnum.stateStartDateHasBeenSet)); expect(ChosenPlanStateEnum.values, contains(ChosenPlanStateEnum.stateInCoordination)); @@ -20,6 +20,7 @@ void main() { expect(ChosenPlanStateEnum.values, contains(ChosenPlanStateEnum.stateDone)); expect(ChosenPlanStateEnum.values, contains(ChosenPlanStateEnum.personalDietSet)); expect(ChosenPlanStateEnum.values, contains(ChosenPlanStateEnum.stateChargeWasCollected)); + expect(ChosenPlanStateEnum.values, contains(ChosenPlanStateEnum.statePaymentFailed)); }); test('getShowableChatBadgeStates returns correct states', () { @@ -35,6 +36,7 @@ void main() { expect(states, contains(ChosenPlanStateEnum.stateDone)); expect(states, contains(ChosenPlanStateEnum.stateInProgress)); expect(states, contains(ChosenPlanStateEnum.personalDietSet)); + expect(states, isNot(contains(ChosenPlanStateEnum.statePaymentFailed))); }); test('isStateAfterPaidState returns false for states before paid', () { @@ -43,6 +45,7 @@ void main() { expect(ChosenPlanStateEnum.stateInCoordination.isStateAfterPaidState(), isFalse); expect(ChosenPlanStateEnum.stateStartDateHasBeenSet.isStateAfterPaidState(), isFalse); expect(ChosenPlanStateEnum.statePendingPayment.isStateAfterPaidState(), isFalse); + expect(ChosenPlanStateEnum.statePaymentFailed.isStateAfterPaidState(), isFalse); }); test('isStateAfterPaidState returns true for states after paid', () { @@ -70,6 +73,7 @@ void main() { expect(activeStates, contains(ChosenPlanStateEnum.stateComplained)); expect(activeStates, contains(ChosenPlanStateEnum.stateDone)); expect(activeStates, contains(ChosenPlanStateEnum.personalDietSet)); + expect(activeStates, isNot(contains(ChosenPlanStateEnum.statePaymentFailed))); }); }); } diff --git a/test/features/plans/models/chosen_plan_model_test.dart b/test/features/plans/models/chosen_plan_model_test.dart index c40dd0cc..a3100298 100644 --- a/test/features/plans/models/chosen_plan_model_test.dart +++ b/test/features/plans/models/chosen_plan_model_test.dart @@ -4,6 +4,8 @@ import 'package:eatvio_app/features/plans/enums/chosen_plan_state_enum.dart'; import 'package:eatvio_app/features/plans/models/chosen_plan_model.dart'; import 'package:flutter_test/flutter_test.dart'; +import '../../../fixtures/fixture_reader.dart'; + void main() { group('ChosenPlanModel', () { test('создает ChosenPlanModel с правильными значениями', () { @@ -140,6 +142,60 @@ void main() { expect(json['consultant_id'], 1); expect(json.containsKey('plan'), isTrue); }); + + group('fromJson payment polling statuses', () { + test('fromJson парсит pending_payment из фикстуры', () { + final json = FixtureReader.readAsMap( + 'chat/chosen_plan/chosen_plan_pending_payment_response.json', + ); + + final model = ChosenPlanModel.fromJson(json); + + expect(model.id, 1); + expect(model.optionType, '1'); + expect(model.chosenPlanState, ChosenPlanStateEnum.statePendingPayment); + expect(model.chatId, 'chat-1'); + }); + + test('fromJson парсит paid из фикстуры', () { + final json = FixtureReader.readAsMap( + 'chat/chosen_plan/chosen_plan_paid_response.json', + ); + + final model = ChosenPlanModel.fromJson(json); + + expect(model.id, 1); + expect(model.optionType, '1'); + expect(model.chosenPlanState, ChosenPlanStateEnum.statePaid); + expect(model.chatId, 'chat-1'); + }); + + test('fromJson парсит payment_failed из фикстуры', () { + final json = FixtureReader.readAsMap( + 'chat/chosen_plan/chosen_plan_payment_failed_response.json', + ); + + final model = ChosenPlanModel.fromJson(json); + + expect(model.id, 1); + expect(model.optionType, '1'); + expect(model.chosenPlanState, ChosenPlanStateEnum.statePaymentFailed); + expect(model.chatId, 'chat-1'); + }); + + test('fromJson парсит canceled_by_the_initiator из фикстуры', () { + final json = FixtureReader.readAsMap( + 'chat/chosen_plan/chosen_plan_canceled_by_the_initiator_response.json', + ); + + final model = ChosenPlanModel.fromJson(json); + + expect(model.id, 1); + expect(model.optionType, '1'); + expect(model.chosenPlanState, ChosenPlanStateEnum.stateCanceledByTheInitiator); + expect(model.chatId, 'chat-1'); + }); + }); }); group('parseChosenPlan', () { diff --git a/test/fixtures/chat/payments/alfa_status_failed_response.json b/test/fixtures/chat/payments/alfa_status_failed_response.json deleted file mode 100644 index 934b0487..00000000 --- a/test/fixtures/chat/payments/alfa_status_failed_response.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "order_id": "alfa_c29_k15138_t1712345678_r1234", - "status": "failed", - "is_paid": false, - "is_expired": false -} diff --git a/test/fixtures/chat/payments/alfa_status_pending_response.json b/test/fixtures/chat/payments/alfa_status_pending_response.json deleted file mode 100644 index d928665f..00000000 --- a/test/fixtures/chat/payments/alfa_status_pending_response.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "order_id": "alfa_c29_k15138_t1712345678_r1234", - "status": "pending", - "is_paid": false, - "is_expired": false -} diff --git a/test/fixtures/chat/payments/alfa_status_processing_response.json b/test/fixtures/chat/payments/alfa_status_processing_response.json deleted file mode 100644 index 08cb35c3..00000000 --- a/test/fixtures/chat/payments/alfa_status_processing_response.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "order_id": "alfa_c29_k15138_t1712345678_r1234", - "status": "processing", - "is_paid": false, - "is_expired": false -} diff --git a/test/fixtures/chat/payments/alfa_status_success_response.json b/test/fixtures/chat/payments/alfa_status_success_response.json deleted file mode 100644 index 53be4cae..00000000 --- a/test/fixtures/chat/payments/alfa_status_success_response.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "order_id": "alfa_c29_k15138_t1712345678_r1234", - "status": "success", - "is_paid": true, - "is_expired": false -}