forked from eatvio/eatvio_app
feat(sbp_payments): added tests for new chosen_plan_state fixtures and new tests for chat repo and service
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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<String, String>.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<PaymentModel>());
|
||||
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(
|
||||
|
||||
Reference in New Issue
Block a user