feat: add customer orders feature with management, forms, and PDF export
Build and Release FLUX (Multi-Platform) / build-web (push) Successful in 1m37s
Build and Release FLUX (Multi-Platform) / build-linux (push) Successful in 1m38s
Build and Release FLUX (Multi-Platform) / build-macos (push) Successful in 2m24s
Build and Release FLUX (Multi-Platform) / build-windows (push) Successful in 10m50s
Build and Release FLUX (Multi-Platform) / build-web (push) Successful in 1m37s
Build and Release FLUX (Multi-Platform) / build-linux (push) Successful in 1m38s
Build and Release FLUX (Multi-Platform) / build-macos (push) Successful in 2m24s
Build and Release FLUX (Multi-Platform) / build-windows (push) Successful in 10m50s
This commit is contained in:
1 parent
5fcc16fb9c
commit
6d2c563ce2
33 files changed
+4081
-22
No files matched your search
@@ -0,0 +1,142 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flux/core/enums_and_consts/contact_preference.dart';
|
||||
import 'package:flux/features/customer_orders/models/customer_order_model.dart';
|
||||
import 'package:flux/features/customer_orders/models/customer_order_status.dart';
|
||||
import 'package:flux/features/customers/models/customer_model.dart';
|
||||
|
||||
void main() {
|
||||
group('ContactPreference enum', () {
|
||||
test('fromString resolves values and falls back to whatsappPrimary', () {
|
||||
expect(
|
||||
ContactPreference.fromString('whatsapp_alternative'),
|
||||
ContactPreference.whatsappAlternative,
|
||||
);
|
||||
expect(
|
||||
ContactPreference.fromString('call_primary'),
|
||||
ContactPreference.callPrimary,
|
||||
);
|
||||
expect(
|
||||
ContactPreference.fromString('call_alternative'),
|
||||
ContactPreference.callAlternative,
|
||||
);
|
||||
expect(
|
||||
ContactPreference.fromString('email'),
|
||||
ContactPreference.email,
|
||||
);
|
||||
expect(
|
||||
ContactPreference.fromString(null),
|
||||
ContactPreference.whatsappPrimary,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('CustomerOrderStatus & CustomerOrderQuickFilter', () {
|
||||
test('active quick filter includes only to_order, ordered, arrived', () {
|
||||
expect(CustomerOrderQuickFilter.active.dbStatuses, [
|
||||
'to_order',
|
||||
'ordered',
|
||||
'arrived',
|
||||
]);
|
||||
expect(CustomerOrderQuickFilter.all.dbStatuses, isNull);
|
||||
});
|
||||
|
||||
test('fromString parses status values cleanly', () {
|
||||
expect(
|
||||
CustomerOrderStatus.fromString('arrived'),
|
||||
CustomerOrderStatus.arrived,
|
||||
);
|
||||
expect(
|
||||
CustomerOrderStatus.fromString('delivered'),
|
||||
CustomerOrderStatus.delivered,
|
||||
);
|
||||
expect(
|
||||
CustomerOrderStatus.fromString('unknown'),
|
||||
CustomerOrderStatus.toOrder,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('CustomerOrderModel', () {
|
||||
test('computes remainingAmount, deepLinkUrl, and effectiveContactDestination', () {
|
||||
const customer = CustomerModel(
|
||||
id: 'cust-1',
|
||||
name: 'Mario Rossi',
|
||||
phoneNumber: '3331112233',
|
||||
alternativePhoneNumber: '3479998877',
|
||||
email: 'mario@example.com',
|
||||
note: '',
|
||||
companyId: 'comp-1',
|
||||
);
|
||||
|
||||
final order = CustomerOrderModel(
|
||||
id: 'ord-123',
|
||||
orderDate: DateTime(2026, 12, 2, 10, 30),
|
||||
companyId: 'comp-1',
|
||||
customerId: 'cust-1',
|
||||
customer: customer,
|
||||
productDescription: 'Cover MagSafe iPhone 16 Pro',
|
||||
quantity: 2,
|
||||
price: 29.90,
|
||||
deposit: 10.00,
|
||||
externalCode: 'ART-8891',
|
||||
status: CustomerOrderStatus.arrived,
|
||||
tags: const ['Amazon', 'Urgente'],
|
||||
contactPreference: ContactPreference.whatsappAlternative,
|
||||
);
|
||||
|
||||
expect(order.remainingAmount, closeTo(19.90, 0.001));
|
||||
expect(
|
||||
order.deepLinkUrl,
|
||||
'https://flux.catelli.it/orders/form/ord-123',
|
||||
);
|
||||
expect(order.effectiveContactDestination, '3479998877');
|
||||
|
||||
final emailOrder = order.copyWith(
|
||||
contactPreference: ContactPreference.email,
|
||||
);
|
||||
expect(emailOrder.effectiveContactDestination, 'mario@example.com');
|
||||
});
|
||||
|
||||
test('fromMap and toMap round-trip fields accurately', () {
|
||||
final map = {
|
||||
'id': 'ord-99',
|
||||
'created_at': '2026-12-02T09:00:00.000Z',
|
||||
'updated_at': '2026-12-02T11:30:00.000Z',
|
||||
'order_date': '2026-12-02T09:00:00.000Z',
|
||||
'company_id': 'comp-1',
|
||||
'store_id': 'store-1',
|
||||
'customer_id': 'cust-1',
|
||||
'product_description': 'Vetro Temperato S24',
|
||||
'quantity': 0, // clamped to 1
|
||||
'notes': 'Con cornice nera',
|
||||
'price': 15,
|
||||
'deposit': 5.5,
|
||||
'external_code': 'VET-024',
|
||||
'status': 'ordered',
|
||||
'tags': ['FornitoreB', 'Display'],
|
||||
'contact_preference': 'call_alternative',
|
||||
'alternative_phone_number': '0299887766',
|
||||
'customer_notified': true,
|
||||
'customer_notified_at': '2026-12-02T11:29:00.000Z',
|
||||
};
|
||||
|
||||
final parsed = CustomerOrderModel.fromMap(map);
|
||||
expect(parsed.id, 'ord-99');
|
||||
expect(parsed.quantity, 1);
|
||||
expect(parsed.price, 15.0);
|
||||
expect(parsed.deposit, 5.5);
|
||||
expect(parsed.externalCode, 'VET-024');
|
||||
expect(parsed.status, CustomerOrderStatus.ordered);
|
||||
expect(parsed.tags, ['FornitoreB', 'Display']);
|
||||
expect(parsed.contactPreference, ContactPreference.callAlternative);
|
||||
expect(parsed.customerNotified, isTrue);
|
||||
expect(parsed.customerNotifiedAt, isNotNull);
|
||||
|
||||
final serialized = parsed.toMap();
|
||||
expect(serialized['external_code'], 'VET-024');
|
||||
expect(serialized['status'], 'ordered');
|
||||
expect(serialized['contact_preference'], 'call_alternative');
|
||||
expect(serialized['tags'], ['FornitoreB', 'Display']);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user