import 'package:flutter_test/flutter_test.dart'; import 'package:miler/data/service_profile.dart'; import 'package:miler/data/stop_contact.dart'; /// ───────────────────────────────────────────────────────────────────────── /// THE LIVE STOP SCREEN'S CONTRACT /// /// One screen serves both legs — a kitchen counter and a customer's door — and /// almost everything on it changes meaning between them: the destination, the /// copy, the action, and the number under the Call button. /// /// That last one is the dangerous one, because it fails silently. A rider at a /// door taps Call, reaches the kitchen, and the screen looks correct /// throughout. These pin who is being rung, per leg, and who the app *says* is /// being rung — the two used to be decided in different places. /// ───────────────────────────────────────────────────────────────────────── void main() { tearDown(() => ServiceProfile.setActive(ServiceProfile.parcel)); group('the contact belongs to the leg', () { test('a delivery prefers the drop contact when one exists', () { final contact = StopContact.forLeg(const { 'pickupcontactno': '9000000001', 'dropcontactno': '9000000002', }, delivery: true); expect(contact.number, '9000000002'); expect(contact.who, 'the customer'); expect(contact.action, 'Call the customer'); }); test('a pickup prefers the pickup contact', () { final contact = StopContact.forLeg(const { 'pickupcontactno': '9000000001', 'dropcontactno': '9000000002', }, delivery: false); expect(contact.number, '9000000001'); expect(contact.who, 'the pickup'); expect(contact.action, 'Call the pickup'); }); test("today's payload carries one number, and both legs reach it", () { // Verified against production 21 Aug 2026: `GET /miler/bookings` returns // exactly one phone field, `customerphone`, which the adapter stores as // `pickupcontactno`. There is no drop contact in the contract at all. // // So the number is the same on both legs and dialling it is correct // either way — the defect was never the digits, it was the app calling // it "the customer" while the rider stood at a kitchen counter. const live = {'pickupcontactno': '9787698259'}; expect(StopContact.forLeg(live, delivery: true).number, '9787698259'); expect(StopContact.forLeg(live, delivery: false).number, '9787698259'); expect( StopContact.forLeg(live, delivery: true).who, isNot(StopContact.forLeg(live, delivery: false).who), reason: 'the label still has to tell the rider who answers', ); }); test('no number means no control, not a dead one', () { final contact = StopContact.forLeg(const { 'orderid': '1', }, delivery: true); expect(contact.isEmpty, isTrue); expect(contact.number, ''); }); test('a blank or placeholder number counts as none', () { for (final junk in const ['', ' ', '0', 'null']) { expect( StopContact.forLeg({ 'pickupcontactno': junk, }, delivery: false).isEmpty, isTrue, reason: '"$junk" must not reach a dialer', ); } }); test('the older spellings still resolve', () { expect( StopContact.forLeg(const { 'PickupContactNo': '9000000003', }, delivery: false).number, '9000000003', ); expect( StopContact.forLeg(const { 'customerphone': '9000000004', }, delivery: true).number, '9000000004', ); }); }); }