feat(sbp_payments): added tests for new chosen_plan_state fixtures and new tests for chat repo and service

This commit is contained in:
misha
2026-07-08 15:07:36 +03:00
parent e10610d93c
commit 51397003b5
10 changed files with 171 additions and 27 deletions

View File

@@ -30,7 +30,9 @@ enum ChosenPlanStateEnum {
@JsonValue('personal_diet_setted')
personalDietSet,
@JsonValue('charge_was_collected')
stateChargeWasCollected;
stateChargeWasCollected,
@JsonValue('payment_failed')
statePaymentFailed;
static List<ChosenPlanStateEnum> 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,
];
}
}

View File

@@ -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);
});
});
}

View File

@@ -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;

View File

@@ -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(

View File

@@ -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)));
});
});
}

View File

@@ -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', () {

View File

@@ -1,6 +0,0 @@
{
"order_id": "alfa_c29_k15138_t1712345678_r1234",
"status": "failed",
"is_paid": false,
"is_expired": false
}

View File

@@ -1,6 +0,0 @@
{
"order_id": "alfa_c29_k15138_t1712345678_r1234",
"status": "pending",
"is_paid": false,
"is_expired": false
}

View File

@@ -1,6 +0,0 @@
{
"order_id": "alfa_c29_k15138_t1712345678_r1234",
"status": "processing",
"is_paid": false,
"is_expired": false
}

View File

@@ -1,6 +0,0 @@
{
"order_id": "alfa_c29_k15138_t1712345678_r1234",
"status": "success",
"is_paid": true,
"is_expired": false
}