Files
lab-app/test/pricing_workflow_test.dart
2026-10-10 14:52:05 +03:00

104 lines
3.2 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:dls_app/core/services/pricing_service.dart';
import 'package:dls_app/models/job.dart';
import 'package:dls_app/models/prosthetic_product.dart';
void main() {
final upper = [
for (var tooth = 11; tooth <= 18; tooth++) tooth,
for (var tooth = 21; tooth <= 28; tooth++) tooth,
];
final lower = [
for (var tooth = 31; tooth <= 38; tooth++) tooth,
for (var tooth = 41; tooth <= 48; tooth++) tooth,
];
test('Each selected jaw costs one unit, including legacy removable types',
() {
for (final type in [
ProstheticType.hareketli,
ProstheticType.tamProtez,
ProstheticType.parsiyel,
ProstheticType.sabit,
]) {
for (final teeth in [
upper,
lower,
[...upper, ...lower]
]) {
final result = PricingService.instance.calculate(
product: const ProstheticProduct(
id: 'product',
labTenantId: 'lab',
name: 'Protez',
prostheticType: 'hareketli',
unitPrice: 5000,
),
prostheticType: type,
memberCount: teeth.length,
teeth: teeth,
clinicTenantId: 'clinic',
discounts: [],
);
expect(result.finalAmount, teeth.length == 32 ? 10000 : 5000);
}
}
});
test('Partial removable jaws count separately; fixed teeth stay per tooth',
() {
expect(
PricingService.instance
.billableUnitsForTeeth(ProstheticType.hareketli, [11, 12, 31]),
2);
expect(
PricingService.instance
.billableUnitsForTeeth(ProstheticType.sabit, [11, 12, 31]),
3);
});
Job job({bool provaRequired = true}) => Job(
id: 'job',
clinicTenantId: 'clinic',
labTenantId: 'lab',
patientCode: 'patient',
prostheticType: ProstheticType.sabit,
memberCount: 1,
status: JobStatus.inProgress,
dateCreated: DateTime(2026),
currentStep: JobStep.olcuKontrol,
location: JobLocation.atLab,
provaRequired: provaRequired,
);
test('Trials can repeat without automatically advancing to finishing', () {
final initial = job();
final trial = initial.labDispatchStep(finish: false);
expect(trial, isNot(JobStep.olcuKontrol));
expect(trial, isNot(JobStep.cilaBitim));
final returned = initial.copyWith(currentStep: trial);
expect(returned.labDispatchStep(finish: false), trial);
expect(returned.labDispatchStep(finish: true), JobStep.cilaBitim);
});
test('No-trial jobs can finish but cannot be sent to trial', () {
expect(() => job(provaRequired: false).labDispatchStep(finish: false),
throwsStateError);
expect(job(provaRequired: false).labDispatchStep(finish: true),
JobStep.cilaBitim);
});
test('Jobs at clinic or already sent cannot be dispatched again', () {
expect(
() => job()
.copyWith(location: JobLocation.atClinic)
.labDispatchStep(finish: false),
throwsStateError);
expect(
() => job()
.copyWith(status: JobStatus.sent)
.labDispatchStep(finish: true),
throwsStateError);
});
}