From 0838038fad10dcbea9b4c729f892c9096ef12498 Mon Sep 17 00:00:00 2001 From: shafi54 <108669266+shafi-aviz@users.noreply.github.com> Date: Tue, 13 Oct 2026 19:10:27 +0530 Subject: [PATCH] enh --- apps/backend/README.md | 36 ++++ apps/backend/dumps/latest.sql | 59 ++++-- apps/backend/package.json | 1 + apps/backend/scripts/create-user.ts | 174 ++++++++++++++++++ apps/user-ui/src/components/AddressForm.tsx | 31 ++-- apps/user-ui/test-case-info.md | 63 +++++-- .../tests/components/address-form.test.tsx | 98 ++++++++-- .../components/cart-address-gate.test.tsx | 62 +++++++ .../components/location-wrapper.test.tsx | 72 ++++++-- .../user-ui/tests/lib/pending-address.test.ts | 50 +++++ apps/user-ui/tests/mocks/api.ts | 36 ++++ .../tests/screens/cart-screen.test.tsx | 43 +++++ .../user-ui/tests/stores/region-store.test.ts | 53 ++++++ apps/web-ui/src/components/AddressForm.tsx | 22 ++- apps/web-ui/src/routes/location-selector.tsx | 34 +++- change-log.txt | 59 ++++++ docs/e2e-sanity-test-plan.md | 8 +- docs/maestro-mcp-agent-guidelines.md | 6 +- docs/test-cases/README.md | 7 +- docs/test-cases/addresses.md | 18 +- docs/test-cases/bounds.md | 2 +- docs/test-cases/cart.md | 5 +- docs/test-cases/checkout.md | 5 +- docs/test-cases/location-region-switching.md | 20 +- .../recovery-platform-accessibility.md | 2 +- docs/test-cases/regions.md | 2 +- 26 files changed, 861 insertions(+), 107 deletions(-) create mode 100644 apps/backend/scripts/create-user.ts create mode 100644 apps/user-ui/tests/components/cart-address-gate.test.tsx create mode 100644 apps/user-ui/tests/lib/pending-address.test.ts create mode 100644 apps/user-ui/tests/stores/region-store.test.ts diff --git a/apps/backend/README.md b/apps/backend/README.md index f032dc0..573ea47 100755 --- a/apps/backend/README.md +++ b/apps/backend/README.md @@ -32,6 +32,42 @@ The database schema includes the following tables: - `npm run db:seed` - Seed the database with mock data - `npm run docker:build` - Build Docker image for the backend +## Create a user (script) + +`scripts/create-user.ts` creates a user with a password directly in D1 — without going through the app. It hashes the password with `bcryptjs` (12 rounds, same as the signup flow) and writes through `wrangler d1 execute`, so it targets the same database as `wrangler dev`. + +```bash +cd apps/backend + +bun run create-user -- \ + --mobile 9990001111 \ + --password "secret123" \ + --name "Test User" \ + --email test@freshyo.in +``` + +Log in with either the email or the mobile as the `identifier` (`trpc.user.auth.login`), plus the password. + +Flags: + +| Flag | Description | +| --- | --- | +| `--name ` | Display name (optional) | +| `--email ` / `--mobile ` | Login identifier — at least one is required | +| `--password ` | Plaintext password (required) | +| `--update` | If the user already exists, reset its password (otherwise it refuses) | +| `--remote` | Write to the remote D1 instead of the local one | +| `--show-sql` | Print the SQL and exit (no write) | +| `--help` | Show usage | + +Env overrides: `D1_CONFIG` (default `wrangler.dev.toml`; `wrangler.prod.toml` when `--remote`) and `D1_DB_NAME` (default `freshyo-dev`). + +It writes two tables: `users` (identity: name/email/mobile) and `user_creds` (bcrypt password hash). Dry run to preview the SQL: + +```bash +bun run create-user -- --mobile 9990001111 --password "secret123" --show-sql +``` + ## Getting Started 1. First, install dependencies: diff --git a/apps/backend/dumps/latest.sql b/apps/backend/dumps/latest.sql index e54f04b..61107fb 100644 --- a/apps/backend/dumps/latest.sql +++ b/apps/backend/dumps/latest.sql @@ -858,6 +858,7 @@ INSERT INTO "addresses" ("id","user_id","is_default","name","phone","address_lin INSERT INTO "addresses" ("id","user_id","is_default","name","phone","address_line1","address_line2","city","state","pincode","latitude","longitude","created_at","zone_id","admin_latitude","admin_longitude","google_maps_url") VALUES(880,1160,0,'SHANKAR','9505751237','8-5-42/A Dhanalaxmi Colony ','Abhaya Anjaneya Swamy temple,Teachers colony Mettugadda ','Mahabubnagar','Telangana','509001',16.7489837,78.0153721,'2026-10-11 08:48:07',NULL,NULL,NULL,NULL); INSERT INTO "addresses" ("id","user_id","is_default","name","phone","address_line1","address_line2","city","state","pincode","latitude","longitude","created_at","zone_id","admin_latitude","admin_longitude","google_maps_url") VALUES(881,679,0,'Priyanka ','8919926863','Sarika township ','','Mahabubnagar','Telangana','509001',16.7112532,78.0250534,'2026-10-12 04:15:13',NULL,NULL,NULL,NULL); INSERT INTO "addresses" ("id","user_id","is_default","name","phone","address_line1","address_line2","city","state","pincode","latitude","longitude","created_at","zone_id","admin_latitude","admin_longitude","google_maps_url") VALUES(882,1207,1,'Vijay','7989347494','1-6-9/3 palsab gutta','Opp lane to sri ramulu hospital','Mahabubnagar','Telangana','509001',NULL,NULL,'2026-10-12 05:03:14',NULL,NULL,NULL,NULL); +INSERT INTO "addresses" ("id","user_id","is_default","name","phone","address_line1","address_line2","city","state","pincode","latitude","longitude","created_at","zone_id","admin_latitude","admin_longitude","google_maps_url") VALUES(883,1322,0,'Mohammed Hussain ','9966770420','Bhageratha colony pragati nagar ','','Mahabubnagar','Telangana','509001',NULL,NULL,'2026-10-13 11:39:34',NULL,NULL,NULL,NULL); CREATE TABLE IF NOT EXISTS "complaints" ("id" INTEGER PRIMARY KEY, "user_id" INTEGER NOT NULL, "order_id" INTEGER, "complaint_body" TEXT NOT NULL, "is_resolved" INTEGER NOT NULL DEFAULT false, "created_at" TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP, "response" TEXT, "images" TEXT); INSERT INTO "complaints" ("id","user_id","order_id","complaint_body","is_resolved","created_at","response","images") VALUES(4,17,NULL,'Hello',1,'2025-12-19T08:34:32.924Z','Hi',NULL); INSERT INTO "complaints" ("id","user_id","order_id","complaint_body","is_resolved","created_at","response","images") VALUES(5,17,NULL,'Hello',1,'2025-12-19T09:32:59.187Z','','["complaint-images/1766136777180-0"]'); @@ -956,6 +957,7 @@ INSERT INTO "complaints" ("id","user_id","order_id","complaint_body","is_resolve INSERT INTO "complaints" ("id","user_id","order_id","complaint_body","is_resolved","created_at","response","images") VALUES(102,701,NULL,'Not delivered',1,'2026-10-04 06:04:32','Delivered Successfully',NULL); INSERT INTO "complaints" ("id","user_id","order_id","complaint_body","is_resolved","created_at","response","images") VALUES(103,538,NULL,'Not delivered',0,'2026-10-10 02:43:37',NULL,NULL); INSERT INTO "complaints" ("id","user_id","order_id","complaint_body","is_resolved","created_at","response","images") VALUES(104,538,NULL,'Not delivered',0,'2026-10-10 02:45:03',NULL,NULL); +INSERT INTO "complaints" ("id","user_id","order_id","complaint_body","is_resolved","created_at","response","images") VALUES(105,1262,NULL,replace('Booked slot 11 to 12 between \nCame after 12\nWe left for work\nNo option of rescheduling time','\n',char(10)),0,'2026-10-13 08:32:09',NULL,NULL); CREATE TABLE IF NOT EXISTS "coupon_applicable_users" ("id" INTEGER PRIMARY KEY, "coupon_id" INTEGER NOT NULL, "user_id" INTEGER NOT NULL); INSERT INTO "coupon_applicable_users" ("id","coupon_id","user_id") VALUES(2,11,4); INSERT INTO "coupon_applicable_users" ("id","coupon_id","user_id") VALUES(6,18,145); @@ -2768,6 +2770,14 @@ INSERT INTO "delivery_slot_info" ("id","delivery_time","freeze_time","is_active" INSERT INTO "delivery_slot_info" ("id","delivery_time","freeze_time","is_active","delivery_sequence","is_flash","group_ids","is_capacity_full","sku_ids") VALUES(2056,'2026-10-13T13:30:00.000Z','2026-10-13T13:20:00.000Z',1,'{}',0,'[12,11,10,9,5]',0,'[129,130,131,132,133,134,135,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,148,6,7,8,11,13,25,26,38,39,43,44,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,73,96,100,125,126,9,22,81,82,102,2,3,10,21,23,24,36,40,41,42,80,137,141]'); INSERT INTO "delivery_slot_info" ("id","delivery_time","freeze_time","is_active","delivery_sequence","is_flash","group_ids","is_capacity_full","sku_ids") VALUES(2057,'2026-10-14T01:30:00.000Z','2026-10-14T01:20:00.000Z',1,'{}',0,'[9,8,7,5]',0,'[9,22,81,82,102,5,6,13,16,17,18,19,27,28,29,30,31,32,33,37,45,64,65,66,67,68,69,70,71,72,74,76,77,78,79,88,89,90,91,92,94,95,97,101,103,127,144,145,146,4,14,35,86,98,99,2,3,10,21,23,24,36,40,41,42,80,137,149,147,140,139,138,136]'); INSERT INTO "delivery_slot_info" ("id","delivery_time","freeze_time","is_active","delivery_sequence","is_flash","group_ids","is_capacity_full","sku_ids") VALUES(2058,'2026-10-14T02:30:00.000Z','2026-10-14T02:20:00.000Z',1,'{}',0,'[12,11,10,9,8,7,5]',0,'[129,130,131,132,133,134,135,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,148,6,7,8,11,13,25,26,38,39,43,44,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,73,96,100,125,126,9,22,81,82,102,5,16,17,18,19,27,28,29,30,31,32,33,37,45,64,65,66,67,68,69,70,71,72,74,76,77,78,79,88,89,90,91,92,94,95,97,101,103,127,144,145,146,4,14,35,86,98,99,2,3,10,21,23,24,36,40,41,42,80,137,149,147,141,140,139,138,136]'); +INSERT INTO "delivery_slot_info" ("id","delivery_time","freeze_time","is_active","delivery_sequence","is_flash","group_ids","is_capacity_full","sku_ids") VALUES(2059,'2026-10-14T05:30:00.000Z','2026-10-14T05:20:00.000Z',1,'{}',0,'[12,11,10,9,8,7,5]',0,'[129,130,131,132,133,134,135,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,148,6,7,8,11,13,25,26,38,39,43,44,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,73,96,100,125,126,9,22,81,82,102,5,16,17,18,19,27,28,29,30,31,32,33,37,45,64,65,66,67,68,69,70,71,72,74,76,77,78,79,88,89,90,91,92,94,95,97,101,103,127,144,145,146,4,14,35,86,98,99,2,3,10,21,23,24,36,40,41,42,80,137,149,147,141,140,139,138,136]'); +INSERT INTO "delivery_slot_info" ("id","delivery_time","freeze_time","is_active","delivery_sequence","is_flash","group_ids","is_capacity_full","sku_ids") VALUES(2060,'2026-10-14T06:30:00.000Z','2026-10-14T06:20:00.000Z',1,'{}',0,'[12,11,10,9,8,7,5]',0,'[129,130,131,132,133,134,135,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,148,7,8,11,25,26,38,39,43,44,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,73,96,100,125,126,9,22,81,82,102,5,6,13,16,17,18,19,27,28,29,30,31,32,33,37,45,64,65,66,67,68,69,70,71,72,74,76,77,78,79,88,89,90,91,92,94,95,97,101,103,127,144,145,146,4,14,35,86,98,99,2,3,10,21,23,24,36,40,41,42,80,137,149,147,141,140,139,138,136]'); +INSERT INTO "delivery_slot_info" ("id","delivery_time","freeze_time","is_active","delivery_sequence","is_flash","group_ids","is_capacity_full","sku_ids") VALUES(2061,'2026-10-14T09:30:00.000Z','2026-10-14T09:20:00.000Z',1,'{}',0,'[12,11,10,9,8,5]',0,'[129,130,131,132,133,134,135,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,148,7,8,11,13,25,26,38,39,43,44,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,73,96,100,125,126,9,22,81,82,102,5,16,17,18,19,27,28,29,30,31,32,33,37,45,64,65,66,67,68,69,70,71,72,74,76,77,78,79,88,89,90,91,92,94,95,97,101,103,127,144,145,146,2,3,10,21,23,24,36,40,41,42,80,137,149,147,141,140,139,138,136]'); +INSERT INTO "delivery_slot_info" ("id","delivery_time","freeze_time","is_active","delivery_sequence","is_flash","group_ids","is_capacity_full","sku_ids") VALUES(2062,'2026-10-14T10:30:00.000Z','2026-10-14T10:20:00.000Z',1,'{}',0,'[12,11,10,9,8,5]',0,'[129,130,131,132,133,134,135,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,148,6,7,8,11,13,25,26,38,39,43,44,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,73,96,100,125,126,9,22,81,82,102,5,16,17,18,19,27,28,29,30,31,32,33,37,45,64,65,66,67,68,69,70,71,72,74,76,77,78,79,88,89,90,91,92,94,95,97,101,103,127,144,145,146,2,3,10,21,23,24,36,40,41,42,80,137,149,147,141,140,139,138,136]'); +INSERT INTO "delivery_slot_info" ("id","delivery_time","freeze_time","is_active","delivery_sequence","is_flash","group_ids","is_capacity_full","sku_ids") VALUES(2063,'2026-10-14T12:30:00.000Z','2026-10-14T12:20:00.000Z',1,'{}',0,'[12,11,10,9,5]',0,'[129,130,131,132,133,134,135,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,148,6,7,8,11,13,25,26,38,39,43,44,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,73,96,100,125,126,9,22,81,82,102,2,3,10,21,23,24,36,40,41,42,80,137,141]'); +INSERT INTO "delivery_slot_info" ("id","delivery_time","freeze_time","is_active","delivery_sequence","is_flash","group_ids","is_capacity_full","sku_ids") VALUES(2064,'2026-10-14T13:30:00.000Z','2026-10-14T13:20:00.000Z',1,'{}',0,'[12,11,10,5]',0,'[129,130,131,132,133,134,135,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,148,6,7,8,11,13,25,26,38,39,43,44,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,73,96,100,125,126,2,3,10,21,23,24,36,40,41,42,80,137,141]'); +INSERT INTO "delivery_slot_info" ("id","delivery_time","freeze_time","is_active","delivery_sequence","is_flash","group_ids","is_capacity_full","sku_ids") VALUES(2065,'2026-10-15T01:30:00.000Z','2026-10-15T01:20:00.000Z',1,'{}',0,'[9,8,7,5]',0,'[9,22,81,82,102,5,6,13,16,17,18,19,27,28,29,30,31,32,33,37,45,64,65,66,67,68,69,70,71,72,74,76,77,78,79,88,89,90,91,92,94,95,97,101,103,127,144,145,146,4,14,35,86,98,99,2,3,10,21,23,24,36,40,41,42,80,137,149,147,140,139,138,136]'); +INSERT INTO "delivery_slot_info" ("id","delivery_time","freeze_time","is_active","delivery_sequence","is_flash","group_ids","is_capacity_full","sku_ids") VALUES(2066,'2026-10-15T02:30:00.000Z','2026-10-15T02:20:00.000Z',1,'{}',0,'[12,11,10,9,8,7,5]',0,'[129,130,131,132,133,134,135,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,148,6,7,8,11,13,25,26,38,39,43,44,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,73,96,100,125,126,9,22,81,82,102,5,16,17,18,19,27,28,29,30,31,32,33,37,45,64,65,66,67,68,69,70,71,72,74,76,77,78,79,88,89,90,91,92,94,95,97,101,103,127,144,145,146,4,14,35,86,98,99,2,3,10,21,23,24,36,40,41,42,80,137,149,147,141,140,139,138,136]'); CREATE TABLE IF NOT EXISTS "home_banners" ("id" INTEGER PRIMARY KEY, "name" TEXT NOT NULL, "image_url" TEXT NOT NULL, "description" TEXT, "redirect_url" TEXT, "serial_num" INTEGER, "is_active" INTEGER NOT NULL DEFAULT false, "created_at" TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP, "last_updated" TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP, "sku_ids" TEXT); INSERT INTO "home_banners" ("id","name","image_url","description","redirect_url","serial_num","is_active","created_at","last_updated","sku_ids") VALUES(9,'10%off ','1770281046297.jpg',NULL,NULL,NULL,0,'2026-02-05T08:44:06.996Z','2026-09-04T15:04:56.030Z','[1,2,3,4,5,6,8,7,9,11,13,12,10]'); INSERT INTO "home_banners" ("id","name","image_url","description","redirect_url","serial_num","is_active","created_at","last_updated","sku_ids") VALUES(11,'Daily veggies ','store-images/1770429593455.jpg','Under 19 ',NULL,3,0,'2026-02-07T01:59:57.566Z','2026-08-19T04:14:07.794Z','[45,72,76,97,70,32,74,77,33]'); @@ -2790,7 +2800,7 @@ INSERT INTO "key_val_store" ("key","value") VALUES('supportMobile','9000885620') INSERT INTO "key_val_store" ("key","value") VALUES('tester','value41'); INSERT INTO "key_val_store" ("key","value") VALUES('versionNum','1.2.0'); INSERT INTO "key_val_store" ("key","value") VALUES('cache_version','769'); -INSERT INTO "key_val_store" ("key","value") VALUES('slots_version_num','666'); +INSERT INTO "key_val_store" ("key","value") VALUES('slots_version_num','674'); INSERT INTO "key_val_store" ("key","value") VALUES('availability_version_num','110'); INSERT INTO "key_val_store" ("key","value") VALUES('tagsOrder','9,1,2,4,5,8,3,7,6'); CREATE TABLE IF NOT EXISTS "notif_creds" ("id" INTEGER PRIMARY KEY, "token" TEXT NOT NULL, "added_at" TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP, "user_id" INTEGER NOT NULL, "last_verified" TEXT); @@ -2815,7 +2825,7 @@ INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VA INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(24,'ExponentPushToken[B2zWnHNaumIgbeFFKO-15D]','2026-02-09T19:53:37.594Z',113,'2026-02-10T07:43:48.632Z'); INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(25,'ExponentPushToken[wIhrdlAmwj0Eytvz3W3TTZ]','2026-02-10T11:09:24.848Z',127,'2026-04-18T06:53:49.329Z'); INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(26,'ExponentPushToken[hFUlPFOKMdAUgtDP7EtSzM]','2026-02-10T11:33:43.821Z',3,'2026-02-24T11:16:46.799Z'); -INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(27,'ExponentPushToken[NymZTEED3G7YCyDg7ihgBA]','2026-02-11T03:16:04.540Z',2,'2026-10-13T01:59:56.710Z'); +INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(27,'ExponentPushToken[NymZTEED3G7YCyDg7ihgBA]','2026-02-11T03:16:04.540Z',2,'2026-10-13T12:24:40.011Z'); INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(28,'ExponentPushToken[ARCT4KD7CJ_pFF_GkywepP]','2026-02-11T11:34:32.238Z',115,'2026-10-11T08:16:00.995Z'); INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(29,'ExponentPushToken[NN4v16BFslBX8ryVXDwQIg]','2026-02-12T08:46:42.421Z',128,'2026-02-17T19:04:12.936Z'); INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(30,'ExponentPushToken[qbteKBC1wbLMCe1ltpul7u]','2026-02-12T13:28:00.376Z',129,'2026-02-12T13:28:00.375Z'); @@ -2826,7 +2836,7 @@ INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VA INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(35,'ExponentPushToken[pIQ2waNDjjSHjQYJbXKD8m]','2026-02-15T07:14:10.912Z',9,'2026-02-15T07:14:10.910Z'); INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(37,'ExponentPushToken[kq0I8ADfcQ4VcsZ0yK0Mlc]','2026-02-16T04:01:56.375Z',102,'2026-07-05T14:39:51.366Z'); INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(38,'ExponentPushToken[8wH85rFtQRMk7ciFszmirX]','2026-02-16T09:30:32.930Z',134,'2026-09-08T07:22:34.339Z'); -INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(39,'ExponentPushToken[YJRSQmMUEUbaI2VCZLaoN_]','2026-02-16T09:49:56.439Z',6,'2026-10-13T05:14:17.480Z'); +INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(39,'ExponentPushToken[YJRSQmMUEUbaI2VCZLaoN_]','2026-02-16T09:49:56.439Z',6,'2026-10-13T10:28:55.609Z'); INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(40,'ExponentPushToken[QoWbURL2N8-3jRhQwfnRP_]','2026-02-17T08:59:14.561Z',135,'2026-02-17T08:59:14.561Z'); INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(41,'ExponentPushToken[sz_g75Il_CNAG6KpEAxYUH]','2026-02-17T12:56:33.589Z',136,'2026-02-21T08:42:45.220Z'); INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(42,'ExponentPushToken[JMEvkUHKT0n34hcs-MiJAJ]','2026-02-17T14:22:02.805Z',137,'2026-02-17T18:35:14.821Z'); @@ -3236,7 +3246,7 @@ INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VA INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(477,'ExponentPushToken[xW60lBF5T8QZhcukLKWiLT]','2026-06-13 06:50:53',539,'2026-06-13T06:50:53.542Z'); INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(478,'ExponentPushToken[OcXxPHN4S6jSOcfUst66iz]','2026-06-13 13:05:48',541,'2026-06-13T13:05:47.880Z'); INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(479,'ExponentPushToken[MDMAekEhhWndpo2uBAD9Aa]','2026-06-14 08:02:34',542,'2026-06-14T08:02:34.279Z'); -INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(480,'ExponentPushToken[-mWZEMNqDOXZj9ESRGhRuA]','2026-06-15 12:02:30',414,'2026-10-04T02:10:22.798Z'); +INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(480,'ExponentPushToken[-mWZEMNqDOXZj9ESRGhRuA]','2026-06-15 12:02:30',414,'2026-10-13T09:43:39.306Z'); INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(481,'ExponentPushToken[C36i1zA_O5lmgPSe0H6GCS]','2026-06-17 06:17:53',544,'2026-09-06T15:30:50.969Z'); INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(482,'ExponentPushToken[Kl7RrWOFizANCgLbHBZDTO]','2026-06-17 11:56:17',545,'2026-06-21T08:01:57.256Z'); INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(483,'ExponentPushToken[3R26bUHCHaUtIoOnHLVbTX]','2026-06-17 13:50:26',121,'2026-06-17T13:53:22.079Z'); @@ -3418,7 +3428,7 @@ INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VA INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(659,'ExponentPushToken[CKtkvdKBhOyLcBcL2cirQF]','2026-08-05 09:57:06',550,'2026-08-05T09:57:06.501Z'); INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(660,'ExponentPushToken[f91-T-JDGUhwQxHIj5b_cW]','2026-08-05 10:28:22',729,'2026-10-10T18:16:58.575Z'); INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(661,'ExponentPushToken[KCYAC4D-lqlRlC6oQ4ZVYE]','2026-08-06 09:57:33',730,'2026-09-19T00:12:29.753Z'); -INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(662,'ExponentPushToken[rM3yhvCX0lpGJB0O4XqqFe]','2026-08-07 06:25:39',731,'2026-10-07T15:12:32.160Z'); +INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(662,'ExponentPushToken[rM3yhvCX0lpGJB0O4XqqFe]','2026-08-07 06:25:39',731,'2026-10-13T11:51:10.164Z'); INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(663,'ExponentPushToken[gSzp_jDq77T-9KZT11iVSe]','2026-08-08 16:11:30',733,'2026-10-03T17:27:29.407Z'); INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(664,'ExponentPushToken[dO0jbBGkwwOKOL4RrYQTdY]','2026-08-08 16:18:27',734,'2026-08-08T16:18:27.828Z'); INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(665,'ExponentPushToken[WUxRgbKGbklj81GLodwWfv]','2026-08-08 16:31:58',735,'2026-08-09T05:35:15.218Z'); @@ -3475,7 +3485,7 @@ INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VA INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(716,'ExponentPushToken[x6SwyVAH1qfqZLVbCVQkex]','2026-08-28 04:02:04',753,'2026-08-28T04:02:04.916Z'); INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(717,'ExponentPushToken[n7SxWSMs2W7ui6TYUgAEbK]','2026-08-28 13:47:11',779,'2026-09-22T13:05:37.131Z'); INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(718,'ExponentPushToken[iNGyPfJ6JQ_EB8KSrSdPdQ]','2026-08-29 08:08:28',780,'2026-08-29T08:08:28.659Z'); -INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(719,'ExponentPushToken[Q7owrkPKnQ6h19Y7YhXNV6]','2026-08-29 13:35:29',782,'2026-10-05T02:16:25.849Z'); +INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(719,'ExponentPushToken[Q7owrkPKnQ6h19Y7YhXNV6]','2026-08-29 13:35:29',782,'2026-10-13T10:35:46.937Z'); INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(720,'ExponentPushToken[xrdiTHAyODb8MC2Ods51zE]','2026-08-29 13:42:13',783,'2026-08-29T13:42:13.252Z'); INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(721,'ExponentPushToken[MngcWzOVupG2jCP92aFAHU]','2026-08-29 15:28:31',784,'2026-09-27T03:02:00.567Z'); INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(722,'ExponentPushToken[An3bpDJv4ViVBBpzCzM44a]','2026-08-30 01:19:31',29,'2026-08-30T01:19:31.979Z'); @@ -3494,7 +3504,7 @@ INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VA INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(735,'ExponentPushToken[nj9TulMsXJU-aG2pHsqt1o]','2026-09-11 12:43:01',797,'2026-09-11T12:43:01.082Z'); INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(736,'ExponentPushToken[qAbg0rLfxL99I5uv71-5qT]','2026-09-11 12:43:20',798,'2026-09-11T15:18:39.200Z'); INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(737,'ExponentPushToken[0I2V3xDelvp5wwt4ejR-K8]','2026-09-11 12:44:58',799,'2026-09-12T11:53:25.343Z'); -INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(738,'ExponentPushToken[0IQ4rkHYo6JCZrJ1hwsdRC]','2026-09-11 12:46:06',800,'2026-09-27T04:41:25.841Z'); +INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(738,'ExponentPushToken[0IQ4rkHYo6JCZrJ1hwsdRC]','2026-09-11 12:46:06',800,'2026-10-13T11:17:27.386Z'); INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(739,'ExponentPushToken[K8FRzQAibdrucolbdDSgxF]','2026-09-11 12:47:04',801,'2026-09-11T12:47:04.367Z'); INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(740,'ExponentPushToken[xRteO-Cmw6N_Cw-Gp2VD3t]','2026-09-11 12:48:17',802,'2026-09-11T12:51:35.225Z'); INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(741,'ExponentPushToken[PwSeN-FT1Dy_NWAqI0OUfV]','2026-09-11 12:48:43',803,'2026-09-12T13:45:11.111Z'); @@ -3766,7 +3776,7 @@ INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VA INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(1009,'ExponentPushToken[8m6Kv8KIalWElZ49DTF9OF]','2026-09-13 10:39:45',1109,'2026-09-14T07:46:41.905Z'); INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(1010,'ExponentPushToken[ZUIRJwCnvAmbke66Sf9Znx]','2026-09-13 10:58:37',1110,'2026-09-13T10:59:58.376Z'); INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(1011,'ExponentPushToken[eL08_GAHcvVR21FuPDPy_U]','2026-09-13 11:17:47',1111,'2026-09-14T12:02:27.418Z'); -INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(1012,'ExponentPushToken[fTmN-PMifvn5P-4fQZA92R]','2026-09-13 11:31:30',816,'2026-10-07T10:12:44.609Z'); +INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(1012,'ExponentPushToken[fTmN-PMifvn5P-4fQZA92R]','2026-09-13 11:31:30',816,'2026-10-13T09:55:34.355Z'); INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(1013,'ExponentPushToken[L3yKDYPdb6ywdzKh5zTxQ2]','2026-09-13 11:33:05',1112,'2026-09-13T11:42:09.330Z'); INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(1014,'ExponentPushToken[N5P1BlNaIgCZuRyw0mttc-]','2026-09-13 11:42:04',1113,'2026-09-30T01:27:07.123Z'); INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(1015,'ExponentPushToken[V6phOrD8N5laDCKsOKkJSw]','2026-09-13 12:01:26',1114,'2026-10-04T05:21:51.585Z'); @@ -3971,6 +3981,8 @@ INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VA INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(1215,'ExponentPushToken[m60i1MPwY_u8XMTFEHSQSm]','2026-10-11 17:14:19',1319,'2026-10-11T17:14:19.431Z'); INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(1216,'ExponentPushToken[dQOhbqI5Xa2oazaM-X-FcN]','2026-10-13 00:54:25',1215,'2026-10-13T00:54:25.140Z'); INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(1217,'ExponentPushToken[_DdgjbH_6x9XoI59oucbpZ]','2026-10-13 04:12:36',1262,'2026-10-13T06:21:42.193Z'); +INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(1218,'ExponentPushToken[yS7eULOnCceMkCw8zIMKNP]','2026-10-13 11:37:57',1322,'2026-10-13T11:43:19.742Z'); +INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(1219,'ExponentPushToken[cADwQ4JvLmXE02gVoxhvlS]','2026-10-13 12:39:59',1320,'2026-10-13T12:39:59.028Z'); CREATE TABLE IF NOT EXISTS "notifications" ("id" INTEGER PRIMARY KEY, "user_id" INTEGER NOT NULL, "title" TEXT NOT NULL, "body" TEXT NOT NULL, "type" TEXT, "is_read" INTEGER NOT NULL DEFAULT false, "created_at" TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP); CREATE TABLE IF NOT EXISTS "order_status" ("id" INTEGER PRIMARY KEY, "order_time" TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP, "user_id" INTEGER NOT NULL, "order_id" INTEGER NOT NULL, "is_packaged" INTEGER NOT NULL DEFAULT false, "is_delivered" INTEGER NOT NULL DEFAULT false, "is_cancelled" INTEGER NOT NULL DEFAULT false, "cancel_reason" TEXT, "payment_state" TEXT NOT NULL DEFAULT 'pending', "cancellation_user_notes" TEXT, "cancellation_admin_notes" TEXT, "cancellation_reviewed" INTEGER NOT NULL DEFAULT false, "cancellation_reviewed_at" TEXT, "refund_coupon_id" INTEGER, "is_cancelled_by_admin" INTEGER); INSERT INTO "order_status" ("id","order_time","user_id","order_id","is_packaged","is_delivered","is_cancelled","cancel_reason","payment_state","cancellation_user_notes","cancellation_admin_notes","cancellation_reviewed","cancellation_reviewed_at","refund_coupon_id","is_cancelled_by_admin") VALUES(105,'2025-12-24T02:50:33.284Z',22,105,0,0,1,'E','cod','E',NULL,0,NULL,NULL,NULL); @@ -6342,6 +6354,9 @@ INSERT INTO "order_status" ("id","order_time","user_id","order_id","is_packaged" INSERT INTO "order_status" ("id","order_time","user_id","order_id","is_packaged","is_delivered","is_cancelled","cancel_reason","payment_state","cancellation_user_notes","cancellation_admin_notes","cancellation_reviewed","cancellation_reviewed_at","refund_coupon_id","is_cancelled_by_admin") VALUES(2532,'2026-10-13 05:19:44',1009,2538,1,1,0,NULL,'cod',NULL,NULL,0,NULL,NULL,NULL); INSERT INTO "order_status" ("id","order_time","user_id","order_id","is_packaged","is_delivered","is_cancelled","cancel_reason","payment_state","cancellation_user_notes","cancellation_admin_notes","cancellation_reviewed","cancellation_reviewed_at","refund_coupon_id","is_cancelled_by_admin") VALUES(2533,'2026-10-13 05:28:23',444,2539,1,1,0,NULL,'cod',NULL,NULL,0,NULL,NULL,NULL); INSERT INTO "order_status" ("id","order_time","user_id","order_id","is_packaged","is_delivered","is_cancelled","cancel_reason","payment_state","cancellation_user_notes","cancellation_admin_notes","cancellation_reviewed","cancellation_reviewed_at","refund_coupon_id","is_cancelled_by_admin") VALUES(2534,'2026-10-13 05:33:33',1203,2540,1,1,0,NULL,'cod',NULL,NULL,0,NULL,NULL,NULL); +INSERT INTO "order_status" ("id","order_time","user_id","order_id","is_packaged","is_delivered","is_cancelled","cancel_reason","payment_state","cancellation_user_notes","cancellation_admin_notes","cancellation_reviewed","cancellation_reviewed_at","refund_coupon_id","is_cancelled_by_admin") VALUES(2535,'2026-10-13 10:01:36',414,2541,1,1,0,NULL,'cod',NULL,NULL,0,NULL,NULL,NULL); +INSERT INTO "order_status" ("id","order_time","user_id","order_id","is_packaged","is_delivered","is_cancelled","cancel_reason","payment_state","cancellation_user_notes","cancellation_admin_notes","cancellation_reviewed","cancellation_reviewed_at","refund_coupon_id","is_cancelled_by_admin") VALUES(2536,'2026-10-13 11:39:57',1322,2542,1,1,0,NULL,'cod',NULL,NULL,0,NULL,NULL,NULL); +INSERT INTO "order_status" ("id","order_time","user_id","order_id","is_packaged","is_delivered","is_cancelled","cancel_reason","payment_state","cancellation_user_notes","cancellation_admin_notes","cancellation_reviewed","cancellation_reviewed_at","refund_coupon_id","is_cancelled_by_admin") VALUES(2537,'2026-10-13 12:49:04',1063,2543,0,0,1,'Order by mistake ','cod','Order by mistake ',NULL,0,NULL,NULL,NULL); CREATE TABLE IF NOT EXISTS "orders" ("id" INTEGER PRIMARY KEY, "user_id" INTEGER NOT NULL, "address_id" INTEGER NOT NULL, "slot_id" INTEGER, "total_amount" REAL NOT NULL, "created_at" TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP, "is_cod" INTEGER NOT NULL DEFAULT false, "is_online_payment" INTEGER NOT NULL DEFAULT false, "payment_info_id" INTEGER, "readable_id" INTEGER NOT NULL, "admin_notes" TEXT, "user_notes" TEXT, "delivery_charge" REAL NOT NULL DEFAULT '0', "order_group_id" TEXT, "order_group_proportion" REAL, "is_flash_delivery" INTEGER NOT NULL DEFAULT false, `delivered_at` text); INSERT INTO "orders" ("id","user_id","address_id","slot_id","total_amount","created_at","is_cod","is_online_payment","payment_info_id","readable_id","admin_notes","user_notes","delivery_charge","order_group_id","order_group_proportion","is_flash_delivery","delivered_at") VALUES(105,22,31,9,7700,'2025-12-24T02:50:33.284Z',1,0,NULL,147,NULL,NULL,0,NULL,NULL,0,NULL); INSERT INTO "orders" ("id","user_id","address_id","slot_id","total_amount","created_at","is_cod","is_online_payment","payment_info_id","readable_id","admin_notes","user_notes","delivery_charge","order_group_id","order_group_proportion","is_flash_delivery","delivered_at") VALUES(106,15,24,8,92,'2025-12-24T10:32:01.957Z',1,0,NULL,149,NULL,NULL,20,NULL,NULL,0,NULL); @@ -8718,6 +8733,9 @@ INSERT INTO "orders" ("id","user_id","address_id","slot_id","total_amount","crea INSERT INTO "orders" ("id","user_id","address_id","slot_id","total_amount","created_at","is_cod","is_online_payment","payment_info_id","readable_id","admin_notes","user_notes","delivery_charge","order_group_id","order_group_proportion","is_flash_delivery","delivered_at") VALUES(2538,1009,686,2051,275,'2026-10-13 05:19:44',1,0,NULL,-1,NULL,NULL,0,'1791868783938-1009',1,0,NULL); INSERT INTO "orders" ("id","user_id","address_id","slot_id","total_amount","created_at","is_cod","is_online_payment","payment_info_id","readable_id","admin_notes","user_notes","delivery_charge","order_group_id","order_group_proportion","is_flash_delivery","delivered_at") VALUES(2539,444,335,2052,399,'2026-10-13 05:28:23',1,0,NULL,-1,NULL,NULL,0,'1791869303033-444',1,0,NULL); INSERT INTO "orders" ("id","user_id","address_id","slot_id","total_amount","created_at","is_cod","is_online_payment","payment_info_id","readable_id","admin_notes","user_notes","delivery_charge","order_group_id","order_group_proportion","is_flash_delivery","delivered_at") VALUES(2540,1203,787,NULL,456,'2026-10-13 05:33:32',1,0,NULL,-1,NULL,NULL,0,'1791869612764-1203',1,1,NULL); +INSERT INTO "orders" ("id","user_id","address_id","slot_id","total_amount","created_at","is_cod","is_online_payment","payment_info_id","readable_id","admin_notes","user_notes","delivery_charge","order_group_id","order_group_proportion","is_flash_delivery","delivered_at") VALUES(2541,414,308,2054,235,'2026-10-13 10:01:36',1,0,NULL,-1,NULL,NULL,15,'1791885696733-414',1,0,NULL); +INSERT INTO "orders" ("id","user_id","address_id","slot_id","total_amount","created_at","is_cod","is_online_payment","payment_info_id","readable_id","admin_notes","user_notes","delivery_charge","order_group_id","order_group_proportion","is_flash_delivery","delivered_at") VALUES(2542,1322,883,NULL,191,'2026-10-13 11:39:57',1,0,NULL,-1,NULL,NULL,39,'1791891597063-1322',1,1,NULL); +INSERT INTO "orders" ("id","user_id","address_id","slot_id","total_amount","created_at","is_cod","is_online_payment","payment_info_id","readable_id","admin_notes","user_notes","delivery_charge","order_group_id","order_group_proportion","is_flash_delivery","delivered_at") VALUES(2543,1063,701,2056,167,'2026-10-13 12:49:04',1,0,NULL,-1,NULL,NULL,15,'1791895744153-1063',1,0,NULL); CREATE TABLE IF NOT EXISTS "payment_info" ("id" INTEGER PRIMARY KEY, "status" TEXT NOT NULL, "gateway" TEXT NOT NULL, "order_id" TEXT, "token" TEXT, "merchant_order_id" TEXT NOT NULL, "payload" TEXT); INSERT INTO "payment_info" ("id","status","gateway","order_id","token","merchant_order_id","payload") VALUES(1,'pending','phonepe',NULL,NULL,'order_1763563896010',NULL); INSERT INTO "payment_info" ("id","status","gateway","order_id","token","merchant_order_id","payload") VALUES(2,'pending','phonepe',NULL,NULL,'order_1763564910006',NULL); @@ -9061,6 +9079,7 @@ INSERT INTO "refunds" ("id","order_id","refund_amount","refund_status","merchant INSERT INTO "refunds" ("id","order_id","refund_amount","refund_status","merchant_refund_id","refund_processed_at","created_at") VALUES(283,2477,NULL,'na',NULL,NULL,'2026-10-08 14:18:39'); INSERT INTO "refunds" ("id","order_id","refund_amount","refund_status","merchant_refund_id","refund_processed_at","created_at") VALUES(284,2479,NULL,'na',NULL,NULL,'2026-10-09 02:05:52'); INSERT INTO "refunds" ("id","order_id","refund_amount","refund_status","merchant_refund_id","refund_processed_at","created_at") VALUES(285,2536,NULL,'na',NULL,NULL,'2026-10-13 07:24:14'); +INSERT INTO "refunds" ("id","order_id","refund_amount","refund_status","merchant_refund_id","refund_processed_at","created_at") VALUES(286,2543,NULL,'na',NULL,NULL,'2026-10-13 12:49:41'); CREATE TABLE IF NOT EXISTS "reserved_coupons" ("id" INTEGER PRIMARY KEY, "secret_code" TEXT NOT NULL, "coupon_code" TEXT NOT NULL, "discount_percent" REAL, "flat_discount" REAL, "min_order" REAL, "sku_ids" TEXT, "max_value" REAL, "valid_till" TEXT, "max_limit_for_user" INTEGER, "exclusive_apply" INTEGER NOT NULL DEFAULT false, "is_redeemed" INTEGER NOT NULL DEFAULT false, "redeemed_by" INTEGER, "redeemed_at" TEXT, "created_by" INTEGER NOT NULL, "created_at" TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP, `is_first_order_only` integer DEFAULT false NOT NULL); INSERT INTO "reserved_coupons" ("id","secret_code","coupon_code","discount_percent","flat_discount","min_order","sku_ids","max_value","valid_till","max_limit_for_user","exclusive_apply","is_redeemed","redeemed_by","redeemed_at","created_by","created_at","is_first_order_only") VALUES(1,'RESERVE_TEST34','RESERVE_TEST34',25,NULL,1000,'[]',250,'2026-01-30T13:16:00.000Z',2,0,1,NULL,'2026-01-12T08:58:20.468Z',6,'2026-01-07T13:16:53.387Z',0); INSERT INTO "reserved_coupons" ("id","secret_code","coupon_code","discount_percent","flat_discount","min_order","sku_ids","max_value","valid_till","max_limit_for_user","exclusive_apply","is_redeemed","redeemed_by","redeemed_at","created_by","created_at","is_first_order_only") VALUES(2,'TEST50OFF','TEST50OFF',10,NULL,250,'[]',500,'2026-08-13T02:30:00.000Z',1,0,1,6,'2026-08-12T16:15:10.211Z',4,'2026-08-12 16:14:27',0); @@ -11160,7 +11179,7 @@ INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VAL INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(2017,'ExponentPushToken[6mQLFoJCWb6rJr4wNTqJx9]','2026-09-12 17:15:06','2026-09-12T17:15:06.739Z'); INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(2018,'ExponentPushToken[V2ZLfsO9E3eRrDrXwTIzjc]','2026-09-12 17:46:48','2026-09-12T17:46:48.844Z'); INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(2019,'ExponentPushToken[r096lxKzJqBfDnPaDsbzUH]','2026-09-12 18:08:31','2026-09-13T02:10:22.417Z'); -INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(2020,'ExponentPushToken[9_nT4-PA-3iihAYY7xW7SZ]','2026-09-12 18:30:10','2026-09-13T05:08:50.460Z'); +INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(2020,'ExponentPushToken[9_nT4-PA-3iihAYY7xW7SZ]','2026-09-12 18:30:10','2026-10-13T09:47:38.142Z'); INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(2021,'ExponentPushToken[cAMXwxMEnO1FVRPhcwm3il]','2026-09-12 21:13:18','2026-09-12T21:13:18.330Z'); INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(2022,'ExponentPushToken[Tv_b_iD62s7yV5bI4yvlHd]','2026-09-13 00:01:00','2026-09-13T00:01:00.398Z'); INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(2024,'ExponentPushToken[6bYAVRFRbNFKNjfUtjBX0f]','2026-09-13 02:10:21','2026-10-10T04:48:58.565Z'); @@ -11237,7 +11256,7 @@ INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VAL INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(2118,'ExponentPushToken[1qlferBDyhQj2ostekPFkQ]','2026-09-15 06:05:34','2026-10-04T09:13:56.131Z'); INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(2119,'ExponentPushToken[jqhBotGOiWOJvIrs1PxCUD]','2026-09-15 08:50:32','2026-09-15T08:50:32.555Z'); INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(2120,'ExponentPushToken[1hEwecF0KBaFVG9KRrxwSt]','2026-09-15 10:00:18','2026-09-15T10:00:18.331Z'); -INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(2121,'ExponentPushToken[pzcD2rJzTaF8LNcMrko3JO]','2026-09-15 10:27:30','2026-09-15T10:27:30.297Z'); +INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(2121,'ExponentPushToken[pzcD2rJzTaF8LNcMrko3JO]','2026-09-15 10:27:30','2026-10-13T09:35:17.574Z'); INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(2122,'ExponentPushToken[W9bpGVAlCCDnpc45rGETov]','2026-09-15 11:11:31','2026-09-27T07:36:34.338Z'); INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(2123,'ExponentPushToken[fx5tY_Oj1w7d29qTo4SAZw]','2026-09-15 11:22:50','2026-09-15T11:22:50.409Z'); INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(2125,'ExponentPushToken[uVX7-dBav9jQInx3edP4ai]','2026-09-15 11:24:11','2026-09-15T11:24:11.763Z'); @@ -11368,7 +11387,7 @@ INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VAL INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(2274,'ExponentPushToken[28Y-FYFnOozpYnM5Ajx51w]','2026-09-27 16:34:43','2026-09-27T16:34:43.303Z'); INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(2275,'ExponentPushToken[MlgWJeHfqX2OTAcBvqlOHa]','2026-09-28 02:29:13','2026-10-11T06:24:32.007Z'); INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(2276,'ExponentPushToken[uAGt07L_nhAKAN6EM1aWmR]','2026-09-28 09:28:29','2026-09-28T09:28:29.923Z'); -INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(2277,'ExponentPushToken[-YfZGcPDgLNSNjO42hMdwt]','2026-09-28 10:21:35','2026-10-04T14:27:21.835Z'); +INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(2277,'ExponentPushToken[-YfZGcPDgLNSNjO42hMdwt]','2026-09-28 10:21:35','2026-10-13T09:32:38.925Z'); INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(2278,'ExponentPushToken[hPyq0CL19X5a4o8hhUHTPj]','2026-09-28 14:45:59','2026-10-02T16:03:49.642Z'); INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(2279,'ExponentPushToken[P5wBXdJpnMy9Ajb1p4YAZQ]','2026-09-28 19:53:53','2026-09-28T19:53:53.663Z'); INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(2280,'ExponentPushToken[8Iu8HoNv0J0sQk8KwXtk7C]','2026-09-29 05:39:06','2026-09-29T05:39:06.438Z'); @@ -13122,6 +13141,8 @@ INSERT INTO "users" ("id","name","email","mobile","created_at") VALUES(1317,NULL INSERT INTO "users" ("id","name","email","mobile","created_at") VALUES(1318,NULL,NULL,'7893626601','2026-10-11 05:12:16'); INSERT INTO "users" ("id","name","email","mobile","created_at") VALUES(1319,NULL,NULL,'7402636363','2026-10-11 17:14:18'); INSERT INTO "users" ("id","name","email","mobile","created_at") VALUES(1320,NULL,NULL,'9177185837','2026-10-12 13:33:27'); +INSERT INTO "users" ("id","name","email","mobile","created_at") VALUES(1321,NULL,NULL,'9603864717','2026-10-13 10:03:55'); +INSERT INTO "users" ("id","name","email","mobile","created_at") VALUES(1322,NULL,NULL,'9966770420','2026-10-13 11:37:55'); CREATE TABLE IF NOT EXISTS "vendor_snippets" ("id" INTEGER PRIMARY KEY, "snippet_code" TEXT NOT NULL, "slot_id" INTEGER, "sku_ids" TEXT NOT NULL, "valid_till" TEXT, "created_at" TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP, "is_permanent" INTEGER NOT NULL DEFAULT false); INSERT INTO "vendor_snippets" ("id","snippet_code","slot_id","sku_ids","valid_till","created_at","is_permanent") VALUES(55,'Allvegetables1',NULL,'[88,66,70,64,91,19,71,27,79,32,5,65,45,77,74,17,16,72,33,13,89,29,78,30,69,31,76,90,18,68]','2027-01-27T17:56:00.000Z','2026-01-27T18:03:18.974Z',1); INSERT INTO "vendor_snippets" ("id","snippet_code","slot_id","sku_ids","valid_till","created_at","is_permanent") VALUES(56,'AllMuttonitems',NULL,'[34,85,14,87,35,84,28,86,4,12,99,98,20]','2027-03-31T02:51:00.000Z','2026-01-28T02:52:14.560Z',1); @@ -22103,6 +22124,16 @@ INSERT INTO "order_items" ("id","order_id","sku_id","quantity","price","discount INSERT INTO "order_items" ("id","order_id","sku_id","quantity","price","discounted_price","is_packaged","is_package_verified","packaged_at") VALUES(8552,2538,30,'1','17.0','17.0',1,0,NULL); INSERT INTO "order_items" ("id","order_id","sku_id","quantity","price","discounted_price","is_packaged","is_package_verified","packaged_at") VALUES(8553,2539,82,'1','399','399',1,0,NULL); INSERT INTO "order_items" ("id","order_id","sku_id","quantity","price","discounted_price","is_packaged","is_package_verified","packaged_at") VALUES(8554,2540,23,'3','152','152',1,0,NULL); +INSERT INTO "order_items" ("id","order_id","sku_id","quantity","price","discounted_price","is_packaged","is_package_verified","packaged_at") VALUES(8555,2541,77,'2','15.0','15.0',1,0,NULL); +INSERT INTO "order_items" ("id","order_id","sku_id","quantity","price","discounted_price","is_packaged","is_package_verified","packaged_at") VALUES(8556,2541,103,'1','29.0','29.0',1,0,NULL); +INSERT INTO "order_items" ("id","order_id","sku_id","quantity","price","discounted_price","is_packaged","is_package_verified","packaged_at") VALUES(8557,2541,72,'2','15.0','15.0',1,0,NULL); +INSERT INTO "order_items" ("id","order_id","sku_id","quantity","price","discounted_price","is_packaged","is_package_verified","packaged_at") VALUES(8558,2541,67,'1','35','35',1,0,NULL); +INSERT INTO "order_items" ("id","order_id","sku_id","quantity","price","discounted_price","is_packaged","is_package_verified","packaged_at") VALUES(8559,2541,69,'1','15.0','15.0',1,0,NULL); +INSERT INTO "order_items" ("id","order_id","sku_id","quantity","price","discounted_price","is_packaged","is_package_verified","packaged_at") VALUES(8560,2541,27,'2','13.0','13.0',1,0,NULL); +INSERT INTO "order_items" ("id","order_id","sku_id","quantity","price","discounted_price","is_packaged","is_package_verified","packaged_at") VALUES(8561,2541,31,'2','16','16',1,0,NULL); +INSERT INTO "order_items" ("id","order_id","sku_id","quantity","price","discounted_price","is_packaged","is_package_verified","packaged_at") VALUES(8562,2541,45,'1','23','23',1,0,NULL); +INSERT INTO "order_items" ("id","order_id","sku_id","quantity","price","discounted_price","is_packaged","is_package_verified","packaged_at") VALUES(8563,2542,23,'1','152','152',1,0,NULL); +INSERT INTO "order_items" ("id","order_id","sku_id","quantity","price","discounted_price","is_packaged","is_package_verified","packaged_at") VALUES(8564,2543,23,'1','152','152',0,0,NULL); CREATE TABLE IF NOT EXISTS "special_deals" ( `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, `sku_id` integer NOT NULL, @@ -22541,15 +22572,15 @@ CREATE TABLE `staff_notif_creds` ( FOREIGN KEY (`staff_user_id`) REFERENCES `staff_users`(`id`) ON UPDATE no action ON DELETE no action ); INSERT INTO "staff_notif_creds" ("id","token","added_at","staff_user_id","last_verified") VALUES(1,'ExponentPushToken[HyU1kPNunSJaasQweODhvH]','2026-10-02 10:49:17',6,'2026-10-04T07:19:37.555Z'); -INSERT INTO "staff_notif_creds" ("id","token","added_at","staff_user_id","last_verified") VALUES(2,'ExponentPushToken[QydqxGMsUfzHuiqxel0nA9]','2026-10-02 10:49:27',4,'2026-10-13T07:23:08.580Z'); -INSERT INTO "staff_notif_creds" ("id","token","added_at","staff_user_id","last_verified") VALUES(3,'ExponentPushToken[bqqW02IeK4XcC4iuzpkQIG]','2026-10-05 01:28:42',4,'2026-10-13T07:50:31.719Z'); +INSERT INTO "staff_notif_creds" ("id","token","added_at","staff_user_id","last_verified") VALUES(2,'ExponentPushToken[QydqxGMsUfzHuiqxel0nA9]','2026-10-02 10:49:27',4,'2026-10-13T11:41:10.722Z'); +INSERT INTO "staff_notif_creds" ("id","token","added_at","staff_user_id","last_verified") VALUES(3,'ExponentPushToken[bqqW02IeK4XcC4iuzpkQIG]','2026-10-05 01:28:42',4,'2026-10-13T11:08:49.256Z'); DELETE FROM sqlite_sequence; INSERT INTO "sqlite_sequence" ("name","seq") VALUES('product_skus',150); INSERT INTO "sqlite_sequence" ("name","seq") VALUES('sku_features',182); INSERT INTO "sqlite_sequence" ("name","seq") VALUES('product_market_stats',150); INSERT INTO "sqlite_sequence" ("name","seq") VALUES('product_info',150); INSERT INTO "sqlite_sequence" ("name","seq") VALUES('cart_items',128); -INSERT INTO "sqlite_sequence" ("name","seq") VALUES('order_items',8554); +INSERT INTO "sqlite_sequence" ("name","seq") VALUES('order_items',8564); INSERT INTO "sqlite_sequence" ("name","seq") VALUES('special_deals',12); INSERT INTO "sqlite_sequence" ("name","seq") VALUES('coupon_applicable_products',1); INSERT INTO "sqlite_sequence" ("name","seq") VALUES('product_tags',604); diff --git a/apps/backend/package.json b/apps/backend/package.json index 4b06ba4..26a1387 100755 --- a/apps/backend/package.json +++ b/apps/backend/package.json @@ -6,6 +6,7 @@ "build": "rimraf ./dist && tsc --project tsconfig.json && tsc-alias -p tsconfig.json", "build2": "rimraf ./dist && tsc", "db:seed": "tsx src/db/seed.ts", + "create-user": "bun run scripts/create-user.ts", "dev2": "tsx watch index.ts", "dev_node": "tsx watch index.ts", "dev_prev": "bun --watch index.ts", diff --git a/apps/backend/scripts/create-user.ts b/apps/backend/scripts/create-user.ts new file mode 100644 index 0000000..800032f --- /dev/null +++ b/apps/backend/scripts/create-user.ts @@ -0,0 +1,174 @@ +#!/usr/bin/env bun +/** + * create-user — create a Freshyo user (or reset its password). + * + * Writes to the D1 database through `wrangler d1 execute`, so the same script + * works against the local dev DB (default) and the remote DB (--remote). + * Passwords are bcrypt-hashed (12 rounds) exactly like the signup flow. + * + * Run from apps/backend: + * + * bun run create-user -- \ + * --mobile 9990001111 --password "secret123" \ + * --name "Test User" --email test@freshyo.in + * + * Flags: + * --name display name (optional) + * --email email; at least one of --email/--mobile is required + * --mobile mobile; at least one of --email/--mobile is required + * --password plaintext password (required) + * --update if the user already exists, (re)set its password + * --remote target the remote D1 instead of the local one + * --show-sql print the SQL and exit (no write) + * --help show this help + * + * Env overrides: + * D1_CONFIG wrangler config file (default: wrangler.dev.toml, or + * wrangler.prod.toml when --remote) + * D1_DB_NAME D1 database name (default: freshyo-dev) + */ +import bcrypt from 'bcryptjs' +import { resolve } from 'node:path' +import { existsSync } from 'node:fs' + +const USAGE = `create-user — create a Freshyo user (or reset its password) + +Usage: + bun run create-user -- --mobile --password

[--name ] [--email ] [--update] [--remote] + +Options: + --name display name (optional) + --email email (one of --email/--mobile required) + --mobile mobile (one of --email/--mobile required) + --password plaintext password (required) + --update if the user already exists, (re)set its password + --remote use the remote D1 (default: local) + --show-sql print the SQL instead of running it + --help show this help +` + +const argv = process.argv.slice(2) +const flag = (n: string) => argv.includes(`--${n}`) +const opt = (n: string): string | undefined => { + const eq = argv.find((a) => a.startsWith(`--${n}=`)) + if (eq) return eq.slice(n.length + 3) + const i = argv.indexOf(`--${n}`) + if (i !== -1 && argv[i + 1] !== undefined && !argv[i + 1].startsWith('--')) return argv[i + 1] + return undefined +} + +function die(msg: string): never { + console.error(`\n error: ${msg}\n`) + console.error(USAGE) + process.exit(1) +} + +if (flag('help') || flag('h') || argv.length === 0) { + console.log(USAGE) + process.exit(0) +} + +const name = opt('name')?.trim() ?? null +const email = opt('email')?.trim() ?? null +const mobile = opt('mobile')?.trim() ?? null +const password = opt('password') +const update = flag('update') +const remote = flag('remote') +const showSql = flag('show-sql') + +if (!password) die('--password is required') +if (!email && !mobile) die('at least one of --email / --mobile is required') + +const BACKEND_DIR = resolve(import.meta.dir, '..') +const config = process.env.D1_CONFIG ?? (remote ? 'wrangler.prod.toml' : 'wrangler.dev.toml') +const dbName = process.env.D1_DB_NAME ?? 'freshyo-dev' +const WRANGLER = resolve(BACKEND_DIR, 'node_modules/.bin/wrangler') + +function run(args: string[]): { out: string; err: string; code: number } { + const p = Bun.spawnSync([existsSync(WRANGLER) ? WRANGLER : 'wrangler', ...args], { + cwd: BACKEND_DIR, + stdout: 'pipe', + stderr: 'pipe', + }) + return { out: p.stdout.toString(), err: p.stderr.toString(), code: p.exitCode } +} + +function parseJson(out: string): any[] | null { + const s = out.indexOf('[') + const e = out.lastIndexOf(']') + if (s === -1 || e === -1) return null + try { + return JSON.parse(out.slice(s, e + 1)) + } catch { + return null + } +} + +const q = (s: string) => `'${s.replace(/'/g, "''")}'` +const lit = (s: string | null) => (s === null ? 'NULL' : q(s)) + +// Match clause: find the user by mobile and/or (case-insensitive) email. +const matchParts: string[] = [] +if (mobile) matchParts.push(`mobile = ${q(mobile)}`) +if (email) matchParts.push(`lower(email) = lower(${q(email)})`) +const match = matchParts.join(' OR ') + +const targetArgs = ['d1', 'execute', dbName, '--config', resolve(BACKEND_DIR, config), remote ? '--remote' : '--local'] + +const main = async () => { + // 1) Look up an existing user. + const checkSql = `SELECT id, name, email, mobile FROM users WHERE ${match} ORDER BY id LIMIT 1;` + const check = run([...targetArgs, '--json', '--command', checkSql]) + if (check.code !== 0) { + die(`lookup failed:\n${check.err || check.out}`) + } + const parsed = parseJson(check.out) + const existing = parsed?.[0]?.results?.[0] as { id: number } | undefined + + if (existing && !update) { + die(`a user with that email/mobile already exists (id=${existing.id}). Pass --update to reset its password.`) + } + + // 2) Hash the password (bcrypt, same cost as signup). + const hash = await bcrypt.hash(password!, 12) + + // 3) Build the write. + let sql: string + if (existing) { + sql = [ + `UPDATE users SET name = ${name === null ? 'name' : `COALESCE(${lit(name)}, name)`}, email = ${email === null ? 'email' : `COALESCE(${lit(email)}, email)`}, mobile = ${mobile === null ? 'mobile' : `COALESCE(${lit(mobile)}, mobile)`} WHERE id = ${existing.id};`, + `UPDATE user_creds SET user_password = ${q(hash)} WHERE user_id = ${existing.id};`, + `INSERT INTO user_creds (user_id, user_password) SELECT ${existing.id}, ${q(hash)} WHERE NOT EXISTS (SELECT 1 FROM user_creds WHERE user_id = ${existing.id});`, + ].join('\n') + } else { + sql = [ + `INSERT INTO users (name, email, mobile) VALUES (${lit(name)}, ${lit(email)}, ${lit(mobile)});`, + `INSERT INTO user_creds (user_id, user_password) VALUES (last_insert_rowid(), ${q(hash)});`, + ].join('\n') + } + + if (showSql) { + console.log(`-- target: ${dbName} (${remote ? 'remote' : 'local'}) via ${config}\n`) + console.log(sql) + return + } + + // 4) Write. + const write = run([...targetArgs, '--command', sql]) + if (write.code !== 0) { + die(`write failed:\n${write.err || write.out}`) + } + + // 5) Report. + const after = run([...targetArgs, '--json', '--command', checkSql]) + const row = parseJson(after.out)?.[0]?.results?.[0] + console.log( + `\n ${existing ? 'Updated password for' : 'Created'} user ${row?.id != null ? `#${row.id}` : ''}` + + `\n name: ${row?.name ?? name ?? '-'}` + + `\n email: ${row?.email ?? email ?? '-'}` + + `\n mobile: ${row?.mobile ?? mobile ?? '-'}` + + `\n target: ${dbName} (${remote ? 'remote' : 'local'})\n`, + ) +} + +await main() diff --git a/apps/user-ui/src/components/AddressForm.tsx b/apps/user-ui/src/components/AddressForm.tsx index f6c3b18..1eb9d93 100644 --- a/apps/user-ui/src/components/AddressForm.tsx +++ b/apps/user-ui/src/components/AddressForm.tsx @@ -1,5 +1,5 @@ import React, { useCallback, useEffect, useState } from 'react'; -import { View, Modal, ScrollView, KeyboardAvoidingView, Platform } from 'react-native'; +import { View, Modal, ScrollView, KeyboardAvoidingView, Platform, Keyboard } from 'react-native'; import { Formik } from 'formik'; import * as Yup from 'yup'; import { tw, MyText, MyTouchableOpacity , Checkbox , MyTextInput , LoadingDialog } from 'common-ui'; @@ -13,6 +13,8 @@ import { useLocationStore } from '@/src/store/locationStore'; type Coords = { latitude: number; longitude: number }; type ResolvedRegion = { regionId: number; boundId: number | null }; +// Where the delivery coordinates came from, so the heading can say so. +type LocationSource = 'device' | 'map'; const AddressForm: React.FC = ({ onSuccess, @@ -37,6 +39,9 @@ const AddressForm: React.FC = ({ browsingRegionId != null ? { regionId: browsingRegionId, boundId: browsingBoundId } : null ); const [locationError, setLocationError] = useState(null); + const [locationSource, setLocationSource] = useState( + initialValues?.latitude != null && initialValues?.longitude != null ? 'device' : null + ); const utils = trpc.useUtils(); @@ -49,8 +54,9 @@ const AddressForm: React.FC = ({ // Resolve coordinates -> region + bound. Used for whichever source the user // picks (attach current location or the map). Out-of-area points are refused. const resolveLocation = useCallback( - async (coords: Coords) => { + async (coords: Coords, source: LocationSource = 'device') => { setCurrentLocation(coords); + setLocationSource(source); setLocationError(null); try { const resolved = await utils.common.resolveRegionByLocation.fetch({ @@ -178,16 +184,6 @@ const AddressForm: React.FC = ({ > {isEdit ? 'Edit Address' : 'Add Address'} - {/* Service Area Notice */} - - - ℹ️ - - We currently serve only in the towns listed below - - - - {/* Submit Error Message */} {submitError && ( @@ -300,7 +296,10 @@ const AddressForm: React.FC = ({ City * setCityOpen((prev) => !prev)} + onPress={() => { + Keyboard.dismiss(); + setCityOpen((prev) => !prev); + }} style={tw`border border-gray-200 rounded-lg p-3 flex-row items-center justify-between bg-gray-50`} > @@ -355,7 +354,9 @@ const AddressForm: React.FC = ({ - Current Location Attached + {locationSource === 'map' + ? 'Location Attached from Map' + : 'Current Location Attached'} @@ -429,7 +430,7 @@ const AddressForm: React.FC = ({ { setMapOpen(false); - void resolveLocation(coords); + void resolveLocation(coords, 'map'); }} onCancel={() => setMapOpen(false)} /> diff --git a/apps/user-ui/test-case-info.md b/apps/user-ui/test-case-info.md index f0e71c0..f4a41bc 100644 --- a/apps/user-ui/test-case-info.md +++ b/apps/user-ui/test-case-info.md @@ -5,7 +5,7 @@ each one locks in. Companion to `tests/home-page/README.md` (long-form home-page detail). - **Runner**: `jest-expo` + `@testing-library/react-native` -- **Total**: **63 suites / 329 tests** — all green (`NODE_ENV=test bun run test`, ~45 s) +- **Total**: **66 suites / 347 tests** (counted from the files after the region-test sync; not re-run in that pass) - Per-group counts below are counted from the files (`it`/`test` lines); jest expands `it.each` cases, so a run reports a few more than the sum of these tables. - Network is mocked at the layer (`tests/mocks/api.ts`); components, stores, hooks and the router stay real. @@ -122,7 +122,7 @@ bun run test:typecheck # tsc over app + tests --- -# screens (`tests/screens/`) — 130 +# screens (`tests/screens/`) — 133 ### `auth.test.tsx` — 9 | # | Test | Asserts | @@ -198,14 +198,22 @@ bun run test:typecheck # tsc over app + tests | 7 | filters products by the search box | no-results copy | | 8 | shows the empty message when there are no products | "No 1 Hr Delivery products available." | -### `cart-screen.test.tsx` — 5 +### `cart-screen.test.tsx` — 11 +Signed in by default (login wall when signed out; first-address gate when there are no addresses). + | # | Test | Asserts | | --- | --- | --- | | 1 | shows the empty state and Start Shopping navigates home | push `…/home` | | 2 | renders the seeded line, the bill and queries the cart slots | bill ₹230 + `user.cart.getCartSlots` input `{productIds:[2]}` | | 3 | queries eligible coupons only when authenticated | `user.coupon.getEligible` + Offers & Coupons | | 4 | navigates to checkout with the selected slot | push `…/home/checkout` | -| 5 | renders the flash cart variant without slot selection | "1 Hr Delivery Cart" | +| 5 | shows an enabled merge row when every item can use the majority slot | `delivery-slot-merge` → apply → hidden | +| 6 | hides the merge row when one item cannot use the majority slot | no merge row | +| 7 | hides the merge row when only one slot is selected | no merge row | +| 8 | renders the flash cart variant without slot selection | "1 Hr Delivery Cart" | +| 9 | shows the login wall when signed out | "Please log in" + "Log In"; no cart line | +| 10 | shows the add-address gate before the cart when the user has no addresses | "Where should we deliver?" + `cart-address-other`; cart line hidden | +| 11 | shows the add-address gate even when the cart is empty | gate, not "Your cart is empty" | ### `cart-coupons.test.tsx` — 12 (coupon application + discount calculation) Cart: 2 x product 2 @ 215 = 430. Consts: freeDeliveryThreshold 249, deliveryCharge 15. @@ -323,7 +331,7 @@ Cart: 2 x product 2 @ 215 = 430. Consts: freeDeliveryThreshold 249, deliveryChar --- -# components (`tests/components/`) — 63 +# components (`tests/components/`) — 70 ### `product-card.test.tsx` — 5 | # | Test | Asserts | @@ -376,13 +384,17 @@ Cart: 2 x product 2 @ 215 = 430. Consts: freeDeliveryThreshold 249, deliveryChar | 4 | submits the normalised register payload | trimmed/lowercased payload | | 5 | updates the password in edit mode via user.auth.updatePassword | `{password}` | -### `address-form.test.tsx` — 4 +### `address-form.test.tsx` — 6 +Coordinates are mandatory, so most cases seed the device location (`useLocationStore`) before rendering. + | # | Test | Asserts | | --- | --- | --- | -| 1 | renders the add-address form | title + name field + service notice | -| 2 | validates the required fields | name/phone/line1 errors | -| 3 | creates an address via user.address.createAddress | payload | -| 4 | updates an address in edit mode via user.address.updateAddress | `{id, name}` | +| 1 | renders the add-address form without a service-area notice | title + name field; no "We currently serve" | +| 2 | keeps Add Address disabled until a location is attached | disabled CTA + "Attach a location to add address" after the first field is touched | +| 3 | shows the device-source heading once a location is attached | "Current Location Attached" + "Choose Another Location in Map" | +| 4 | validates the required fields | name/phone/line1 errors | +| 5 | creates an address with the region and coordinates derived from the location | `createAddress` payload carries `regionId`, `latitude`/`longitude` and the City name | +| 6 | updates an address in edit mode via user.address.updateAddress | `{id, regionId}` | ### `address-selectors.test.tsx` — 6 | # | Test | Asserts | @@ -401,10 +413,19 @@ Cart: 2 x product 2 @ 215 = 430. Consts: freeDeliveryThreshold 249, deliveryChar | 2 | shows an error when permission is denied | error copy, no callback | | 3 | does nothing while disabled | no permission request | -### `location-wrapper.test.tsx` — 1 +### `location-wrapper.test.tsx` — 3 | # | Test | Asserts | | --- | --- | --- | -| 1 | renders its children on an emulator | passthrough | +| 1 | renders its children once a region is selected | passthrough | +| 2 | shows a spinner while the region is still resolving | "Finding your region..." | +| 3 | asks for an address with a location notice when the location is denied | chooser + "Location access is not granted..." + `open-location-settings` | + +### `cart-address-gate.test.tsx` — 3 +| # | Test | Asserts | +| --- | --- | --- | +| 1 | offers the current-location and map options | both option cards; current enabled with a device fix | +| 2 | disables the current-location option without a device fix | disabled card + "Turn on location to use this option" | +| 3 | opens the address form from the map option | `address-name` visible | ### `slot-layout.test.tsx` — 2 | # | Test | Asserts | @@ -441,7 +462,7 @@ Cart: 2 x product 2 @ 215 = 430. Consts: freeDeliveryThreshold 249, deliveryChar --- -# hooks / stores / lib / contexts — 82 (hooks 40, stores 19, contexts 14, lib 9) +# hooks / stores / lib / contexts — 90 (hooks 40, stores 23, contexts 14, lib 13) ### `hooks/cart-query-hooks.test.tsx` — 6 | # | Test | Asserts | @@ -519,6 +540,14 @@ Cart: 2 x product 2 @ 215 = 430. Consts: freeDeliveryThreshold 249, deliveryChar | 10 | centralProductStore indexes products by id | productsById | | 11 | centralSlotStore builds productSlotsMap from slots + availability | map + flags | +### `stores/region-store.test.ts` — 4 +| # | Test | Asserts | +| --- | --- | --- | +| 1 | stores the selected region and bound and bumps the generation | id/region/bound + generation 1 | +| 2 | does not bump the generation for an identical selection | generation stays 1 | +| 3 | clears the region and bumps the generation | nulls + generation 2 | +| 4 | is memory-only (no persist middleware) | `persist` undefined | + ### `lib/string-manipulators.test.ts` — 3 | # | Test | Asserts | | --- | --- | --- | @@ -526,6 +555,14 @@ Cart: 2 x product 2 @ 215 = 430. Consts: freeDeliveryThreshold 249, deliveryChar | 2 | is case-insensitive | PENDING/Pending | | 3 | passes every other status through unchanged | packaged/success/cancelled/'' | +### `lib/pending-address.test.ts` — 4 +| # | Test | Asserts | +| --- | --- | --- | +| 1 | round-trips a signed-out draft | save → get equals the draft | +| 2 | returns null when there is no draft | null | +| 3 | clears the draft | null after clear | +| 4 | returns null for corrupt stored JSON | null | + ### `lib/trpc-client.test.ts` — 2 | # | Test | Asserts | | --- | --- | --- | diff --git a/apps/user-ui/tests/components/address-form.test.tsx b/apps/user-ui/tests/components/address-form.test.tsx index 02c4248..05a1edf 100644 --- a/apps/user-ui/tests/components/address-form.test.tsx +++ b/apps/user-ui/tests/components/address-form.test.tsx @@ -1,5 +1,10 @@ /** * AddressForm (src/components/AddressForm.tsx) — create/update + validation. + * + * The City (region) and bound are derived from the attached location, so these + * cases seed the device location via useLocationStore before rendering. + * Coordinates are mandatory: Add Address stays disabled until a location is + * attached. */ jest.mock('expo-router', () => require('../mocks/router').expoRouterMock()) @@ -8,28 +13,91 @@ import React from 'react' import { fireEvent, screen, waitFor } from '@testing-library/react-native' import AddressForm from '@/src/components/AddressForm' +import { useLocationStore } from '@/src/store/locationStore' +import { useRegionStore } from '@/src/store/regionStore' import { resetStorage, setupApiMocks } from '../mocks/api' import { expectProcedureCalled, lastProcedureInput } from '../mocks/procedures' import { renderWithProviders } from '../helpers/render' +const LOCATION = { latitude: 16.7488, longitude: 77.9851 } + +/** Pretend the launch fix already produced coordinates (or was denied). */ +function seedLocation(coords: typeof LOCATION | null) { + useLocationStore.setState({ + coords, + status: coords ? 'granted' : 'denied', + error: null, + }) +} + describe('AddressForm', () => { beforeEach(async () => { + const Location = require('expo-location') + Location.requestForegroundPermissionsAsync.mockResolvedValue({ + status: 'granted', + granted: true, + }) + Location.hasServicesEnabledAsync.mockResolvedValue(true) + Location.getCurrentPositionAsync.mockResolvedValue({ + coords: { ...LOCATION, accuracy: 5 }, + timestamp: Date.now(), + }) + await resetStorage() + // zustand stores are module singletons. + useLocationStore.getState().stop() + useRegionStore.setState({ + selectedRegionId: null, + selectedRegion: null, + selectedBoundId: null, + regionGeneration: 0, + }) }) - it('renders the add-address form', () => { + it('renders the add-address form without a service-area notice', () => { setupApiMocks() renderWithProviders(, { centralStores: false }) expect(screen.getAllByText('Add Address').length).toBeGreaterThan(0) expect(screen.getByTestId('address-name')).toBeVisible() - expect(screen.getByText(/Mahabubnagar town/)).toBeVisible() + expect(screen.queryByText(/currently serve/)).toBeNull() }) - it('validates the required fields', async () => { + it('keeps Add Address disabled until a location is attached', () => { + const Location = require('expo-location') + Location.requestForegroundPermissionsAsync.mockResolvedValue({ + status: 'denied', + granted: false, + }) + useLocationStore.getState().stop() + setupApiMocks() + + renderWithProviders(, { centralStores: false }) + + expect(screen.getByTestId('address-attach-location')).toBeVisible() + expect(screen.getByTestId('address-submit')).toBeDisabled() + + // The hint only appears once the first field has been touched. + fireEvent.changeText(screen.getByTestId('address-name'), 'Home') + fireEvent(screen.getByTestId('address-name'), 'blur') + expect(screen.getByText('Attach a location to add address')).toBeVisible() + }) + + it('shows the device-source heading once a location is attached', async () => { + seedLocation(LOCATION) setupApiMocks() renderWithProviders(, { centralStores: false }) + await waitFor(() => expect(screen.getByText('Current Location Attached')).toBeVisible()) + expect(screen.getByText('Choose Another Location in Map')).toBeVisible() + }) + + it('validates the required fields', async () => { + seedLocation(LOCATION) + setupApiMocks() + renderWithProviders(, { centralStores: false }) + + await waitFor(() => expect(screen.getByTestId('address-submit')).not.toBeDisabled()) fireEvent.press(screen.getByTestId('address-submit')) await waitFor(() => expect(screen.getByText('Name is required')).toBeVisible()) @@ -37,24 +105,30 @@ describe('AddressForm', () => { expect(screen.getByText('Address Line 1 is required')).toBeVisible() }) - it('creates an address via user.address.createAddress', async () => { + it('creates an address with the region and coordinates derived from the location', async () => { + seedLocation(LOCATION) const api = setupApiMocks({ procedures: { 'user.address.createAddress': { data: { id: 7 } } }, }) renderWithProviders(, { centralStores: false }) + // The City shows the region resolved from the attached location. + await waitFor(() => expect(screen.getByText('Mahabubnagar')).toBeVisible()) + fireEvent.changeText(screen.getByTestId('address-name'), 'Home') fireEvent.changeText(screen.getByTestId('address-phone'), '9876543210') fireEvent.changeText(screen.getByTestId('address-line1'), '12 Main Road') fireEvent.press(screen.getByTestId('address-submit')) - await waitFor(() => - expectProcedureCalled(api.fetchMock, 'user.address.createAddress') - ) + await waitFor(() => expectProcedureCalled(api.fetchMock, 'user.address.createAddress')) expect(lastProcedureInput(api.fetchMock, 'user.address.createAddress')).toMatchObject({ name: 'Home', phone: '9876543210', addressLine1: '12 Main Road', + city: 'Mahabubnagar', + regionId: 1, + latitude: LOCATION.latitude, + longitude: LOCATION.longitude, }) }) @@ -72,9 +146,11 @@ describe('AddressForm', () => { name: 'Work', phone: '9876543211', addressLine1: '9 Office St', - city: 'Hyderabad', + city: 'Mahabubnagar', state: 'Telangana', isDefault: false, + latitude: LOCATION.latitude, + longitude: LOCATION.longitude, } as never } />, @@ -82,14 +158,14 @@ describe('AddressForm', () => { ) expect(screen.getByText('Edit Address')).toBeVisible() + await waitFor(() => expect(screen.getByTestId('address-submit')).not.toBeDisabled()) fireEvent.press(screen.getByTestId('address-submit')) - await waitFor(() => - expectProcedureCalled(api.fetchMock, 'user.address.updateAddress') - ) + await waitFor(() => expectProcedureCalled(api.fetchMock, 'user.address.updateAddress')) expect(lastProcedureInput(api.fetchMock, 'user.address.updateAddress')).toMatchObject({ id: 3, name: 'Work', + regionId: 1, }) }) }) diff --git a/apps/user-ui/tests/components/cart-address-gate.test.tsx b/apps/user-ui/tests/components/cart-address-gate.test.tsx new file mode 100644 index 0000000..642406f --- /dev/null +++ b/apps/user-ui/tests/components/cart-address-gate.test.tsx @@ -0,0 +1,62 @@ +/** + * CartAddressGate (components/CartAddressGate.tsx). + * + * The cart's first-address gate: shown before the cart when a signed-in user + * has no delivery address. Offers "Address of current Location" (needs a device + * fix) or "Choose another location" (opens the address form). + */ + +jest.mock('expo-router', () => require('../mocks/router').expoRouterMock()) + +import React from 'react' +import { fireEvent, screen, waitFor } from '@testing-library/react-native' + +import CartAddressGate from '@/components/CartAddressGate' +import { useLocationStore } from '@/src/store/locationStore' +import { resetStorage, setupApiMocks } from '../mocks/api' +import { renderWithProviders } from '../helpers/render' + +const LOCATION = { latitude: 16.7488, longitude: 77.9851 } + +describe('CartAddressGate', () => { + beforeEach(async () => { + await resetStorage() + useLocationStore.getState().stop() + }) + + it('offers the current-location and map options', () => { + useLocationStore.setState({ coords: LOCATION, status: 'granted', error: null }) + setupApiMocks() + + renderWithProviders(, { + centralStores: false, + }) + + expect(screen.getByText('Where should we deliver?')).toBeVisible() + expect(screen.getByTestId('cart-address-current')).toBeEnabled() + expect(screen.getByTestId('cart-address-other')).toBeVisible() + }) + + it('disables the current-location option without a device fix', () => { + setupApiMocks() + + renderWithProviders(, { + centralStores: false, + }) + + expect(screen.getByTestId('cart-address-current')).toBeDisabled() + expect(screen.getByText('Turn on location to use this option')).toBeVisible() + }) + + it('opens the address form from the map option', async () => { + setupApiMocks() + + renderWithProviders(, { + centralStores: false, + }) + + fireEvent.press(screen.getByTestId('cart-address-other')) + + await waitFor(() => expect(screen.getByTestId('address-name')).toBeVisible()) + }) +}) diff --git a/apps/user-ui/tests/components/location-wrapper.test.tsx b/apps/user-ui/tests/components/location-wrapper.test.tsx index b62f47a..751aa6c 100644 --- a/apps/user-ui/tests/components/location-wrapper.test.tsx +++ b/apps/user-ui/tests/components/location-wrapper.test.tsx @@ -1,37 +1,85 @@ /** * LocationTestWrapper (components/LocationTestWrapper.tsx). * - * It is now the region gate: once a region is selected it is a passthrough, - * otherwise it derives the region from location and falls back to the chooser. - * Under jest the platform constants read as a simulator, so with no region the - * chooser would show; this locks in the passthrough path with a region set. + * It is the region gate: once a region is selected it is a passthrough, + * otherwise it derives the region from the location/default address and falls + * back to the address chooser with a notice explaining why. */ import React from 'react' import { Text } from 'react-native' -import { screen } from '@testing-library/react-native' +import { screen, waitFor } from '@testing-library/react-native' import LocationTestWrapper from '@/components/LocationTestWrapper' +import { useLocationStore } from '@/src/store/locationStore' import { useRegionStore } from '@/src/store/regionStore' import { resetStorage, setupApiMocks } from '../mocks/api' import { renderWithProviders } from '../helpers/render' +function renderGate() { + return renderWithProviders( + + app content + , + { centralStores: false } + ) +} + describe('LocationTestWrapper', () => { + beforeEach(async () => { + const Location = require('expo-location') + Location.requestForegroundPermissionsAsync.mockResolvedValue({ + status: 'granted', + granted: true, + }) + Location.hasServicesEnabledAsync.mockResolvedValue(true) + Location.getCurrentPositionAsync.mockResolvedValue({ + coords: { latitude: 17.385, longitude: 78.4867, accuracy: 5 }, + timestamp: Date.now(), + }) + + await resetStorage() + useLocationStore.getState().stop() + useRegionStore.setState({ + selectedRegionId: null, + selectedRegion: null, + selectedBoundId: null, + regionGeneration: 0, + }) + }) + it('renders its children once a region is selected', async () => { setupApiMocks() - await resetStorage() useRegionStore .getState() .setRegion({ id: 1, name: 'Test Region', description: null }) - renderWithProviders( - - app content - , - { centralStores: false } - ) + renderGate() expect(screen.getByText('app content')).toBeVisible() }) + + it('shows a spinner while the region is still resolving', () => { + setupApiMocks() + + renderGate() + + expect(screen.getByText('Finding your region...')).toBeVisible() + }) + + it('asks for an address with a location notice when the location is denied', async () => { + const Location = require('expo-location') + Location.requestForegroundPermissionsAsync.mockResolvedValue({ + status: 'denied', + granted: false, + }) + setupApiMocks() + + renderGate() + + await waitFor(() => expect(screen.getByText('Delivery Address')).toBeVisible()) + expect(screen.getByText(/Location access is not granted/)).toBeVisible() + expect(screen.getByTestId('open-location-settings')).toBeVisible() + }) }) diff --git a/apps/user-ui/tests/lib/pending-address.test.ts b/apps/user-ui/tests/lib/pending-address.test.ts new file mode 100644 index 0000000..d849076 --- /dev/null +++ b/apps/user-ui/tests/lib/pending-address.test.ts @@ -0,0 +1,50 @@ +/** + * pending-address (src/lib/pending-address.ts). + * + * A delivery address a signed-out user filled in is kept in casual storage and + * posted after authentication (see PendingAddressSync). + */ + +import { + clearPendingAddress, + getPendingAddress, + savePendingAddress, +} from '@/src/lib/pending-address' + +const ADDRESS = { + regionId: 1, + name: 'Home', + phone: '9876543210', + addressLine1: '12 Main Road', + city: 'Mahabubnagar', + state: 'Telangana', + latitude: 16.7488, + longitude: 77.9851, +} + +describe('pending address', () => { + beforeEach(async () => { + await clearPendingAddress() + }) + + it('round-trips a signed-out draft', async () => { + await savePendingAddress(ADDRESS) + expect(await getPendingAddress()).toEqual(ADDRESS) + }) + + it('returns null when there is no draft', async () => { + expect(await getPendingAddress()).toBeNull() + }) + + it('clears the draft', async () => { + await savePendingAddress(ADDRESS) + await clearPendingAddress() + expect(await getPendingAddress()).toBeNull() + }) + + it('returns null for corrupt stored JSON', async () => { + const { StorageServiceCasual } = require('common-ui/src/services/StorageServiceCasual') + await StorageServiceCasual.setItem('freshyo_pending_address', '{not json') + expect(await getPendingAddress()).toBeNull() + }) +}) diff --git a/apps/user-ui/tests/mocks/api.ts b/apps/user-ui/tests/mocks/api.ts index 058a811..d166977 100644 --- a/apps/user-ui/tests/mocks/api.ts +++ b/apps/user-ui/tests/mocks/api.ts @@ -43,6 +43,31 @@ export const FLASH_ENABLED_CONSTS = { /** products.json with no tags and no products (empty-state tests). */ export const EMPTY_PRODUCTS = { products: [], tags: [] } +/** Region fixtures returned by common.listRegions (region 1 / Mahabubnagar). */ +export const MOCK_REGIONS = [ + { id: 1, name: 'Mahabubnagar', description: null, effectiveBoundId: 1 }, +] + +/** + * Default address fixture. Coordinates are mandatory now and the region/bound + * are derived from them; returned by user.address.getDefaultAddress and (as a + * one-item list) user.address.getUserAddresses when a test doesn't override. + */ +export const MOCK_ADDRESS = { + id: 1, + regionId: 1, + boundId: 1, + name: 'Home', + phone: '9876543210', + addressLine1: '12 Main Road', + addressLine2: null, + city: 'Mahabubnagar', + state: 'Telangana', + isDefault: true, + latitude: 16.7488, + longitude: 77.9851, +} + /** A dashboard tag that points at no products (empty-tag-grid test). */ export const EMPTY_TAG = { id: 9999, @@ -294,6 +319,17 @@ export function setupApiMocks(opts: ApiMockOptions = {}) { return { data: orders } } + // Region/location plumbing used by useRegion, the region gate and the + // address form. Tests can still override any of these via `procedures`. + if (name === 'common.listRegions') return MOCK_REGIONS + if (name === 'common.activeBound') return { boundId: 1 } + if (name === 'common.resolveRegionByLocation') { + return { region: MOCK_REGIONS[0], bound: { id: 1 } } + } + if (name === 'common.resolveBound') return { boundId: 1 } + if (name === 'user.address.getDefaultAddress') return { data: MOCK_ADDRESS } + if (name === 'user.address.getUserAddresses') return { data: [MOCK_ADDRESS] } + throw new Error( `[tests] unmocked trpc procedure: ${name} (add it to setupApiMocks({ procedures }))` ) diff --git a/apps/user-ui/tests/screens/cart-screen.test.tsx b/apps/user-ui/tests/screens/cart-screen.test.tsx index ab562a6..11a7836 100644 --- a/apps/user-ui/tests/screens/cart-screen.test.tsx +++ b/apps/user-ui/tests/screens/cart-screen.test.tsx @@ -53,6 +53,10 @@ const cartItem = (over: Record = {}) => ({ describe('Cart screen', () => { beforeEach(async () => { resetAuthMock() + // Signed in by default: the cart screen shows a login wall when signed out, + // and the first-address gate when the user has zero addresses. Individual + // cases flip `authMock.user` / `getUserAddresses` to exercise those. + authMock.user = { id: 1 } await resetStorage() jest.spyOn(Alert, 'alert').mockImplementation(() => {}) }) @@ -199,4 +203,43 @@ describe('Cart screen', () => { await waitFor(() => expect(screen.getByText('1 Hr Delivery Cart')).toBeVisible()) expect(screen.queryByText('Scheduled Delivery Cart')).toBeNull() }) + + it('shows the login wall when signed out', async () => { + authMock.user = null + setupApiMocks() + await seedCart([cartItem()]) + + renderWithProviders() + + await waitFor(() => expect(screen.getByText('Please log in')).toBeVisible()) + expect(screen.getByText('Log In')).toBeVisible() + expect(screen.queryByText('Chicken Breast 500 g')).toBeNull() + }) + + it('shows the add-address gate before the cart when the user has no addresses', async () => { + setupApiMocks({ + procedures: { + 'user.cart.getCartSlots': { [PRODUCT_ID]: [futureSlot()] }, + 'user.address.getUserAddresses': { data: [] }, + }, + }) + await seedCart([cartItem()]) + + renderWithProviders() + + await waitFor(() => expect(screen.getByText('Where should we deliver?')).toBeVisible()) + expect(screen.getByTestId('cart-address-other')).toBeVisible() + expect(screen.queryByText('Chicken Breast 500 g')).toBeNull() + }) + + it('shows the add-address gate even when the cart is empty', async () => { + setupApiMocks({ + procedures: { 'user.address.getUserAddresses': { data: [] } }, + }) + + renderWithProviders() + + await waitFor(() => expect(screen.getByText('Where should we deliver?')).toBeVisible()) + expect(screen.queryByText('Your cart is empty')).toBeNull() + }) }) diff --git a/apps/user-ui/tests/stores/region-store.test.ts b/apps/user-ui/tests/stores/region-store.test.ts new file mode 100644 index 0000000..30d4e30 --- /dev/null +++ b/apps/user-ui/tests/stores/region-store.test.ts @@ -0,0 +1,53 @@ +/** + * regionStore (src/store/regionStore.ts). + * + * The browsing region is deliberately NOT persisted — it is re-derived on every + * launch — so this pins the in-memory contract and the generation bump. + */ + +import { useRegionStore } from '@/src/store/regionStore' + +const REGION = { id: 2, name: 'Region B', description: null, effectiveBoundId: 7 } + +describe('regionStore', () => { + beforeEach(() => { + useRegionStore.setState({ + selectedRegionId: null, + selectedRegion: null, + selectedBoundId: null, + regionGeneration: 0, + }) + }) + + it('stores the selected region and bound and bumps the generation', () => { + useRegionStore.getState().setRegion(REGION, 7) + + const state = useRegionStore.getState() + expect(state.selectedRegionId).toBe(2) + expect(state.selectedRegion).toMatchObject({ id: 2, name: 'Region B' }) + expect(state.selectedBoundId).toBe(7) + expect(state.regionGeneration).toBe(1) + }) + + it('does not bump the generation for an identical selection', () => { + useRegionStore.getState().setRegion(REGION, 7) + useRegionStore.getState().setRegion(REGION, 7) + + expect(useRegionStore.getState().regionGeneration).toBe(1) + }) + + it('clears the region and bumps the generation', () => { + useRegionStore.getState().setRegion(REGION, 7) + useRegionStore.getState().clearRegion() + + const state = useRegionStore.getState() + expect(state.selectedRegionId).toBeNull() + expect(state.selectedRegion).toBeNull() + expect(state.selectedBoundId).toBeNull() + expect(state.regionGeneration).toBe(2) + }) + + it('is memory-only (no persist middleware)', () => { + expect((useRegionStore as unknown as { persist?: unknown }).persist).toBeUndefined() + }) +}) diff --git a/apps/web-ui/src/components/AddressForm.tsx b/apps/web-ui/src/components/AddressForm.tsx index b21cf2d..dec8ec9 100644 --- a/apps/web-ui/src/components/AddressForm.tsx +++ b/apps/web-ui/src/components/AddressForm.tsx @@ -8,6 +8,8 @@ import type { AddressFormProps } from '@packages/shared' type Coords = { latitude: number; longitude: number } type ResolvedRegion = { regionId: number; boundId: number | null } +// Where the delivery coordinates came from, so the heading can say so. +type LocationSource = 'device' | 'map' const validationSchema = Yup.object({ name: Yup.string().required('Name is required'), @@ -24,6 +26,9 @@ export function AddressForm({ onSuccess, initialValues, isEdit = false, onResolv const [mapOpen, setMapOpen] = useState(false) const [locating, setLocating] = useState(false) const [locationError, setLocationError] = useState(null) + const [locationSource, setLocationSource] = useState( + initialValues?.latitude != null && initialValues?.longitude != null ? 'device' : null + ) const [currentLocation, setCurrentLocation] = useState( initialValues?.latitude != null && initialValues?.longitude != null ? { latitude: initialValues.latitude, longitude: initialValues.longitude } @@ -85,8 +90,9 @@ export function AddressForm({ onSuccess, initialValues, isEdit = false, onResolv const [errors, setErrors] = useState>({}) const resolveLocation = useCallback( - async (coords: Coords) => { + async (coords: Coords, source: LocationSource = 'device') => { setCurrentLocation(coords) + setLocationSource(source) setLocationError(null) try { const resolved = await utils.common.resolveRegionByLocation.fetch({ @@ -143,7 +149,7 @@ export function AddressForm({ onSuccess, initialValues, isEdit = false, onResolv typeof data.longitude === 'number' ) { setMapOpen(false) - void resolveLocation({ latitude: data.latitude, longitude: data.longitude }) + void resolveLocation({ latitude: data.latitude, longitude: data.longitude }, 'map') } } window.addEventListener('message', handler) @@ -244,13 +250,6 @@ export function AddressForm({ onSuccess, initialValues, isEdit = false, onResolv

{isEdit ? 'Edit Address' : 'Add Address'}

-
-
- ℹ️ -

We currently serve only in the towns listed below

-
-
- {submitError && (

{submitError}

@@ -324,7 +323,10 @@ export function AddressForm({ onSuccess, initialValues, isEdit = false, onResolv {currentLocation ? (

- Current Location Attached + {' '} + {locationSource === 'map' + ? 'Location Attached from Map' + : 'Current Location Attached'}

📍 {currentLocation.latitude.toFixed(5)}, {currentLocation.longitude.toFixed(5)} diff --git a/apps/web-ui/src/routes/location-selector.tsx b/apps/web-ui/src/routes/location-selector.tsx index e859a9a..e142ae7 100644 --- a/apps/web-ui/src/routes/location-selector.tsx +++ b/apps/web-ui/src/routes/location-selector.tsx @@ -1,6 +1,6 @@ import { createFileRoute } from '@tanstack/react-router' import { useCallback, useEffect, useRef, useState } from 'react' -import { AlertCircle, Loader2 } from 'lucide-react' +import { AlertCircle, Loader2, Minus, Plus } from 'lucide-react' import { BottomDialog } from 'web-components' import { Dialog } from '../components/Dialog' @@ -31,6 +31,8 @@ interface GoogleMapClickEvent { } interface GoogleMap { addListener: (event: string, handler: (event: GoogleMapClickEvent) => void) => void + setZoom: (zoom: number) => void + getZoom: () => number | undefined } interface GoogleMarker { setMap: (map: GoogleMap | null) => void @@ -228,6 +230,7 @@ function LocationSelectorPage() { mapTypeControl: false, streetViewControl: false, fullscreenControl: false, + zoomControl: false, clickableIcons: false, }) mapRef.current = map @@ -283,10 +286,39 @@ function LocationSelectorPage() { setPendingCoords(null) }, []) + const handleZoom = useCallback((delta: number) => { + const map = mapRef.current + if (!map) return + const current = map.getZoom() ?? DEFAULT_ZOOM + map.setZoom(Math.min(21, Math.max(1, current + delta))) + }, []) + return (

+ {!isLoading && !loadError && ( +
+ +
+ +
+ )} + {isLoading && !loadError && (
diff --git a/change-log.txt b/change-log.txt index fd338fb..00c9008 100644 --- a/change-log.txt +++ b/change-log.txt @@ -3993,3 +3993,62 @@ user-ui + below the Add Address button, when !currentLocation and the first field (Name) has been touched, show a red "Attach a location to add address" No dependency added. No migration. No tests run. + +2026-10-13 18:12:52 web-ui location selector map: zoom in/out buttons at the top-left. + apps/web-ui/src/routes/location-selector.tsx: + + custom +/- zoom controls overlaid at the top-left (absolute, z-10), styled to match the app; + each calls map.setZoom(map.getZoom() +/- 1) + + GoogleMap structural type extended with setZoom/getZoom + No dependency added (lucide-react Plus/Minus already available). No migration. No tests run. + +2026-10-13 18:15:58 web-ui location selector map: move the zoom controls to the top-right. + apps/web-ui/src/routes/location-selector.tsx: + + zoom control overlay: left-4 -> right-4 (still top-4) + No dependency added. No migration. No tests run. + +2026-10-13 18:33:20 Address form: dismiss keyboard on the City dropdown + distinguish map-attached location. + 1/2 apps/user-ui/src/components/AddressForm.tsx: + + import Keyboard; on the City button press call Keyboard.dismiss() before toggling the dropdown + + track the location source ('device' | 'map'); resolveLocation(coords, source) + + the attached-location heading reads "Location Attached from Map" when the point came from the map, + otherwise "Current Location Attached" + 2/2 apps/web-ui/src/components/AddressForm.tsx: same source tracking + heading swap + No dependency added. No migration. No tests run. + +2026-10-13 18:36:43 Address form: remove the "We currently serve only in the towns listed below" notice. + 1/2 apps/user-ui/src/components/AddressForm.tsx: dropped the amber service-area notice block + 2/2 apps/web-ui/src/components/AddressForm.tsx: dropped the equivalent amber notice block + No dependency added. No migration. No tests run. + +2026-10-13 18:53:37 Tests: sync the region-space test cases with the address/location/region rework. + (Catalog .md edits — no log needed — in docs/test-cases/{addresses,location-region-switching,cart, + checkout,bounds,regions,recovery-platform-accessibility,README}.md, docs/e2e-sanity-test-plan.md, + docs/maestro-mcp-agent-guidelines.md. New catalog cases: LOC-19..LOC-22, CART-23, ADDR-24, + ADDR-25, CHECK-21.) + 1/7 apps/user-ui/tests/mocks/api.ts: exported MOCK_REGIONS/MOCK_ADDRESS fixtures; default tRPC + resolvers for common.listRegions, common.activeBound, common.resolveRegionByLocation, + common.resolveBound, user.address.getDefaultAddress (region-1 address) and + user.address.getUserAddresses (1 address) so the new hooks no longer throw unmocked. + 2/7 apps/user-ui/tests/components/address-form.test.tsx: rewritten. Now seeds the device location + (useLocationStore) + resets the region store; cases: renders (no service notice); disabled Add + Address + "Attach a location to add address" hint until a location is attached; map/device + source heading; required-field validation; create payload with regionId + coords + City; + edit-mode update. + 3/7 apps/user-ui/tests/screens/cart-screen.test.tsx: authenticated coupon case now asserts the + cart (address fixture); added a case that a signed-in user with zero addresses sees the + CartAddressGate before the cart. + 4/7 apps/user-ui/tests/components/location-wrapper.test.tsx: added "spinner while resolving" and + "denied -> chooser notice + Open location settings" cases. + 5/7 apps/user-ui/tests/components/cart-address-gate.test.tsx: NEW — options, disabled current- + location option without a device fix, and opening the address form. + 6/7 apps/user-ui/tests/lib/pending-address.test.ts: NEW — save/get/clear round-trip + corrupt JSON. + 7/7 apps/user-ui/tests/stores/region-store.test.ts: NEW — setRegion/clearRegion/generation bump + + asserts the store has no persist middleware (memory-only). + apps/user-ui/test-case-info.md: updated the address-form / cart-screen / location-wrapper entries + and added the new suites. + No dependency added. No migration. No tests run (typecheck only). + - Added apps/backend/scripts/create-user.ts: creates/updates a user + bcrypt password. + Hashes with bcryptjs (12 rounds, matches signup) and writes via `wrangler d1 execute` + (--local default, --remote optional). Auto-detects existing user by mobile/email; + refuses to clobber unless --update. Supports --show-sql. No tests run. + - apps/backend/package.json: added "create-user" script -> bun run scripts/create-user.ts. diff --git a/docs/e2e-sanity-test-plan.md b/docs/e2e-sanity-test-plan.md index 58616ad..086887f 100644 --- a/docs/e2e-sanity-test-plan.md +++ b/docs/e2e-sanity-test-plan.md @@ -123,11 +123,11 @@ be a release gate. High-risk financial cases deserve priority even if slower. | RG-01 | Superadmin creates region A with a valid bound → assigns an admin → customer opens region selector and selects A. | A is discoverable; configuration/cache loads without undefined amounts or broken asset requests. An empty catalog has an intentional empty state. | | RG-02 | Try creating a region without bounds; add malformed GeoJSON or duplicate bound priorities. | Validation explains the error; no half-created region/configuration remains. | | RG-03 | Fresh customer launch with GPS inside A, first signed out and then signed in. | A resolves once; catalog and delivery threshold load without needing login. | -| RG-04 | Deny GPS, return an outside-service point, or make resolution time out; repeat with/without a saved region. | Saved region survives when location is unusable; otherwise a usable manual chooser appears, not an endless spinner. | +| RG-04 | Deny GPS, return an outside-service point, or make resolution time out; repeat with/without a default address. | Default address is used when the location is unusable; otherwise a usable manual chooser appears, not an endless spinner. Nothing is persisted between launches. | | RG-05 | Delay GPS resolution → manually select B before the response → let A's GPS response arrive. | Late startup response does not undo the customer's manual choice. | | RG-06 | Create distinct products/stores/slots/tags/banners in A/B → browse A, then B, then A. | Each region shows only its own content; no cached content/prices from the previous region leak. | | RG-07 | Add regular and flash items in A → request switch to B → cancel, then repeat and confirm. | Cancel preserves A and both carts; confirm clears both carts and address/slot selections and loads B. | -| RG-08 | Keep the app open → move GPS from A to B → later cold-launch from B. | No continuous automatic switching while open; cold launch performs the one-shot resolution and resets regional state if changing region. | +| RG-08 | Keep the app open → move GPS from A to B → later cold-launch from B. | No continuous automatic switching while open; cold launch performs the one-shot resolution, and adoption does not clear the local cart; no region is persisted between launches. | | RG-09 | Give U1 addresses in A1/A2 → sign in/browse A; remove an eligible nondefault address and refresh; repeat with no A addresses. | Active browsing bound is lowest numeric priority among U1's A address bounds, else A's effective bound. B addresses do not participate. | | RG-10 | Superadmin changes A1/A2 priorities, then edits A1 charge; separately edit A's support/welcome/flash settings and global app version. | Effective bound changes as specified; bound edit affects that bound, region edit affects A's bounds, global edit affects all regions; B's regional settings stay unchanged. | | RG-11 | Resolve GPS in overlapping bounds and on a polygon edge → compare with active-bound selection from addresses. | Geo-resolution follows numeric priority within a region; browsing prices follow address/effective-bound rules, not an accidental GPS-bound override. Define cross-region overlap policy separately. | @@ -213,8 +213,8 @@ be a release gate. High-risk financial cases deserve priority even if slower. |---|---|---| | AD-01 | Fresh customer adds first address while browsing A, without checking Default → inspect Me and Cart. | Address belongs to A and becomes default; Cart can select it and Checkout shows correct contact/address. | | AD-02 | Add second address → make it default → edit contact/address **without sending `isDefault`**, and with an explicit value → relaunch. | Exactly one default persists; an omitted `isDefault` must leave the flag untouched, an explicit `false` clears it and an explicit `true` moves the default; edits never leave the user with zero defaults or select an unrelated address. | -| AD-03 | Submit missing fields, bad phone/pincode and no region → correct and save. | Clear 4xx validation for each field — **phone = exactly 10 digits starting 6/7/8/9, pincode = exactly 6 digits** (rule 2026-10-10); no partial saved address; retry succeeds once. | -| AD-04 | Add address without coordinates → inspect “No Location is attached to address” → attach GPS location; repeat denying permission and using a supported Maps link. | Missing-location notice is accurate; successful attachment persists; denied/invalid-link path is recoverable without overwriting address data. Define whether missing coordinates block ordering. | +| AD-03 | Submit missing fields, bad phone, and no attached location → correct and save. | Clear 4xx/UI validation — **phone = exactly 10 digits starting 6/7/8/9**; Add Address stays disabled until a location is attached; no partial saved address; retry succeeds once. | +| AD-04 | Add address with no location → the form shows "Attach Location in map" → attach on the map (then "Location Attached from Map") or the device location ("Current Location Attached"); repeat denying permission and with an out-of-area point. | Coordinates are mandatory; the heading reflects the source; out-of-area points are refused; denied path is recoverable without overwriting address data. | | AD-05 | U1 has A1/A2 addresses → select A2 on Cart → compare fee before/after selection → place order. | Selected address's bound overrides browsing active bound; catalog remains A; saved order total agrees with A2 config. | | AD-06 | While browsing A, explicitly choose B as a new address's region; separately edit an existing B address while browsing A. | Address region and bound are coherent; editing preserves/derives the correct bound, never borrowing A's current browsing bound for B. | | AD-07 | A cart populated, default address in B → load address selector → explicitly tap B address → cancel, then confirm. | No automatic foreign-default selection; cancel retains A/cart; confirm switches B, clears both carts and returns Home. | diff --git a/docs/maestro-mcp-agent-guidelines.md b/docs/maestro-mcp-agent-guidelines.md index 84abc43..4ea1c97 100644 --- a/docs/maestro-mcp-agent-guidelines.md +++ b/docs/maestro-mcp-agent-guidelines.md @@ -207,7 +207,7 @@ Notes: - **Persistence:** the setting survives app relaunch, so it must be set *before* the app's startup region resolution. `clear` restores "no location" — do this after a location-dependent test so later runs are not biased. -- A location outside all bounds keeps the saved region (no hang) — good for RG-04. +- A location outside all bounds does not hang; with no default address the chooser appears (the region is never persisted) — good for RG-04. - There is no continuous region tracking while the app is open; resolution is a one-shot startup check, so change location then **relaunch** to re-resolve. @@ -314,6 +314,10 @@ row → "Add to Cart" → "Go to Cart". **Cart login wall:** signed out, open cart → "Please log in … view your cart" with "Log In" + "Go Back". Login returns to the cart with items intact. +**Cart first-address gate:** signed in with zero addresses, open cart → the +add-address gate shows *before* the cart (even when the cart is empty); the first +saved address becomes the default, then the cart renders. + **Logout:** Me tab → gear → scroll down → "Logout". **Flash:** enable flash in the region (`superadmin.regions.updateRegionConstants`), diff --git a/docs/test-cases/README.md b/docs/test-cases/README.md index e9b049e..0df5824 100644 --- a/docs/test-cases/README.md +++ b/docs/test-cases/README.md @@ -6,7 +6,7 @@ This folder contains feature-by-feature acceptance and regression checklists for **All cases are proposed and NOT RUN.** A listed expected result is a requirement to verify, not a claim that the implementation currently satisfies it. Known review defects are intentionally covered. Documentation creation does not authorize running tests, sending notifications, charging payments, deleting data, or applying migrations. -Inventory: **45 feature checklists and 804 uniquely identified cases**, plus this index. Features are grouped by business responsibility; closely related operations share a checklist (for example stock, offer flags and suspension). Reuse the shared boundary/security matrix rather than assuming a finite list can cover every possible input. +Inventory: **45 feature checklists and 812 uniquely identified cases**, plus this index. Features are grouped by business responsibility; closely related operations share a checklist (for example stock, offer flags and suspension). Reuse the shared boundary/security matrix rather than assuming a finite list can cover every possible input. Sources: current routers/screens/helpers, existing API tests, [sanity plan](../e2e-sanity-test-plan.md), and [branch review](../multi-region-i2-review.md). Older sanity-plan statements that coupons ignore regions/SKUs are superseded here by the newer coupon requirements. Vendor snippets and reviews remain conditional/legacy coverage; online gateway cases are readiness coverage until implementation is enabled. @@ -33,7 +33,7 @@ Use isolated staging with dedicated DB/KV/assets/queues and sandbox recipients. | Products | A-only P with two SKUs, B-only Q, global G with independent A/B prices; regular-only R; flash F with a distinct price; combo C and combo-only component K. | | Availability | Available, OOS, globally suspended, regionally suspended, soft-deleted variants; preserve a historical order referencing one. | | Slots | Two valid A slots S1/S2, B slot, inactive/frozen/full/past slots, and midnight-boundary times. | -| Addresses | U1 in A1/A2/B1; U2-only address; boundless legacy address; default and sole-address fixtures; coordinate-free address. | +| Addresses | U1 in A1/A2/B1; U2-only address; default and sole-address fixtures; legacy address without a stored bound; a zero-address signed-in customer for the cart gate. Coordinates are mandatory. | | Coupons | Regional A/B and global; percentage/flat; targeted/whole-cart; capped, min-spend, exclusive, first-order, limited-use, user-only, expired/invalidated, reserved. | | Orders | Pending COD, packaged, verified, delivered, cancelled, multi-slot group; payment/refund fixtures only in approved sandbox. | | Money | T = free threshold, D = fee; test T−0.01, T, T+0.01. Example goods: ₹100 targeted + ₹900 unrelated. Separate regular/flash values. | @@ -64,6 +64,7 @@ Use unique run prefixes. Do not delete regions for cleanup: region deletion is u - Global coupon targeting regional products: confirm intended authoring restrictions; never permit a regional author to attach another region's private SKU. - Combo component availability, group-to-slot snapshot/live membership, global-name uniqueness/case normalization, and account-switch cart behavior need explicit decisions where not specified. - No general minimum order value is required by the current policy. Coupon `minOrder` is independent from free-delivery thresholds. +- The browsing region is never persisted: each launch re-derives it from the device location and/or the default address (see [location and switching](location-region-switching.md)). Do not assert a "saved region" survives relaunch. - UI duplicate-submit prevention is required. Server order-idempotency was previously deferred: record concurrent API behavior and ambiguous-retry exposure, not an assumed guaranteed deduplication. - Define concurrency guarantees for capacity, default-address updates, limited coupons, and reserved redemption. Financial/one-time invariants must not silently be weakened to match observed races. @@ -94,4 +95,4 @@ Screenshot/log links (redacted): Cleanup / retained evidence / linked defect: ``` -Recommended first pass: AUTH-01, CFG-01, LOC-06, GP-03, STOCK-03, STOCK-07, SLOT-01, CART-01, ADDR-01, CHECK-01, MONEY-01, CPA-01, CPA-07, CPA-14, ORDER-01, FUL-01, CANCEL-01, SEC-01, CACHE-01. Then execute all P0 cases before release and the remaining applicable cases in the full regression run. +Recommended first pass: AUTH-01, CFG-01, LOC-19, GP-03, STOCK-03, STOCK-07, SLOT-01, CART-01, ADDR-01, CHECK-01, MONEY-01, CPA-01, CPA-07, CPA-14, ORDER-01, FUL-01, CANCEL-01, SEC-01, CACHE-01. Then execute all P0 cases before release and the remaining applicable cases in the full regression run. diff --git a/docs/test-cases/addresses.md b/docs/test-cases/addresses.md index 1a62603..e1006cc 100644 --- a/docs/test-cases/addresses.md +++ b/docs/test-cases/addresses.md @@ -1,31 +1,33 @@ # Addresses, defaults and attached location -Scope: customer address CRUD, Me/Cart selectors, checkout summary, bound/region assignment and coordinates. Use disposable address fixtures and U1/U2. +Scope: customer address CRUD, Me/Cart selectors, checkout summary, region/bound derivation from coordinates. Use disposable address fixtures and U1/U2. Coordinates are mandatory; the region (City) and bound are derived from them, `pincode` no longer exists, and State is fixed to Telangana. | ID | Priority | Action / input | Expected result | |---|---|---|---| -| ADDR-01 | P0 | First address created in A without Default tick. | Correct region/bound; becomes default; selectable for checkout. | +| ADDR-01 | P0 | First address created in A without Default tick. | Region/bound derived from the address coordinates; becomes default; selectable for checkout. | | ADDR-02 | P1 | Add second address, switch default, relaunch. | Exactly one default consistent in every client. | | ADDR-03 | P1 | Edit contact fields with omitted `isDefault`. | Existing default flag retained; no incidental default loss. | | ADDR-04 | P1 | Explicit default true/false update. | Defined default policy, coherent flags and selected address. | | ADDR-05 | P0 | Select A2 while browsing A1, then order. | Selected address's bound supplies quote/server fee. | -| ADDR-06 | P1 | Create/edit B address while browsing A. | Region and bound derived coherently; no borrowed A bound. | +| ADDR-06 | P1 | Create/edit B address while browsing A. | Region and bound derived from the address coordinates, not the browsing region; no borrowed A bound. | | ADDR-07 | P1 | Missing required contact/address fields. | Specific validation; no partial address. | -| ADDR-08 | P1 | Phone length 9/10/11 and prefix 5/6/7/8/9; pincode 5/6/7 digits. | Current 10-digit 6–9 phone and 6-digit pincode rules consistent UI/API. | +| ADDR-08 | P1 | Phone length 9/10/11 and prefix 5/6/7/8/9. | Current 10-digit 6–9 phone rule consistent UI/API (no pincode field). | | ADDR-09 | P1 | Unicode/long address, spaces, punctuation, optional landmark. | Agreed limits; complete persisted display, no silent truncation. | -| ADDR-10 | P1 | No coordinates, then attach allowed GPS/Maps location. | Accurate warning; successful coordinates saved without overwriting text. | -| ADDR-11 | P1 | Deny location, invalid map link/coordinates or outside service. | Recoverable error; previous valid location remains intact. | +| ADDR-10 | P1 | Open the form with no location, then attach the device location or pick on the map. | Add Address stays disabled until a location is attached; the heading shows "Current Location Attached" vs "Location Attached from Map" by source; coordinates saved without overwriting text. | +| ADDR-11 | P1 | Deny location, invalid map link/coordinates or outside service. | Recoverable error; previous valid location remains intact; out-of-area points refused. | | ADDR-12 | P0 | U2 reads/updates/deletes/selects U1 address by ID. | Ownership rejected; U1 state unchanged. | | ADDR-13 | P0 | Only address/default/protected open-order address deletion. | Required protections and explanatory message; no detached ongoing order. | | ADDR-14 | P1 | Delete allowed nondefault unused address. | Removed persistently; selection/discovery recomputed safely. | | ADDR-15 | P1 | Delete referenced address after order cancelled/delivered. | Approved dependency rule applied; history remains readable. | | ADDR-16 | P0 | Foreign default address when browsing A. | Not auto-selected; explicit switch confirmation required. | | ADDR-17 | P1 | Cancel/confirm foreign-address region switch. | Cancel preserves cart/address; confirm clears incompatible checkout state. | -| ADDR-18 | P1 | Legacy null-bound address, nonexistent bound, mismatched region/bound. | Allowed null fallback; invalid/mismatched IDs rejected. | +| ADDR-18 | P1 | Legacy address with no stored bound; nonexistent bound; mismatched region/bound. | Bound re-derived from the address coordinates; invalid/mismatched IDs rejected. | | ADDR-19 | P1 | Two simultaneous default changes or first-address creations. | Consistent approved default invariant; no partial duplicate details. | | ADDR-20 | P1 | Address deleted/edited while checkout open. | Submit revalidates owner/serviceability; no stale foreign bound quote. | | ADDR-21 | P1 | Save timeout/background/retry after ambiguous response. | Inspect persisted outcome; no silent duplicates or endless spinner. | | ADDR-22 | P1 | Address change alters active browsing bound. | Bound discovery refetched; B addresses excluded from A choice. | | ADDR-23 | P2 | BottomDialog deletion error, keyboard/scroll, readonly checkout address. | Message visible; editing not hidden behind wrong sheet. | +| ADDR-24 | P1 | Open the add form: City dropdown, State field, Submit before/after attaching a location. | City lists the serviceable regions and pre-selects the current browsing region; State is fixed to Telangana and uneditable; coordinates must fall inside the chosen town (else rejected); Add Address disabled until a location is attached. | +| ADDR-25 | P1 | Signed-out user drafts an address, then logs in/registers. | The draft is posted exactly once after authentication (first saved address becomes default); a failed sync keeps the draft for retry. | -Policy checkpoint: whether missing coordinates blocks checkout, and default clearing versus the requirement to keep a default. Record ambiguity rather than assuming both contradictory behaviors. +Policy checkpoint: coordinates are mandatory and the bound is always derived from them; confirm whether any legacy coordinate-free address may still order, and record the default-clearing vs keep-a-default behaviour rather than assuming both contradictory behaviours. diff --git a/docs/test-cases/bounds.md b/docs/test-cases/bounds.md index f599eb0..d115ce6 100644 --- a/docs/test-cases/bounds.md +++ b/docs/test-cases/bounds.md @@ -19,7 +19,7 @@ Scope: region bound CRUD, geographic resolution, active-bound selection and boun | BOUND-13 | P1 | U1 addresses in A1/A2/B1, change A priorities. | Active A bound comes from eligible A addresses, then effective fallback. | | BOUND-14 | P1 | Remove/replace polygon while checkout already open. | Address serviceability policy enforced; no stale bound fee misuse. | | BOUND-15 | P1 | Concurrent delete/address attachment or priority edits. | Referential integrity and deterministic active selection preserved. | -| BOUND-16 | P1 | Bound constants removed/null; legacy address with no bound. | Defined fallback; never foreign region's bound. | +| BOUND-16 | P1 | Bound constants removed/null; legacy address with no stored bound. | Bound re-derived from the address coordinates; defined fallback; never a foreign region's bound. | | BOUND-17 | P2 | Pan/zoom/draw/cancel form/resize map. | Geometry only saved on confirmation; usable controls. | | BOUND-18 | P1 | Geo resolver timeout/no match. | Explicit no-service/retry response; no arbitrary region. | diff --git a/docs/test-cases/cart.md b/docs/test-cases/cart.md index 28d8d13..4ec8eb8 100644 --- a/docs/test-cases/cart.md +++ b/docs/test-cases/cart.md @@ -14,7 +14,7 @@ Scope: local cart storage, query hooks, quantity/slot reconciliation, floating/e | CART-08 | P0 | One line becomes OOS/suspended/deleted; all lines invalid. | Clearly excluded from pricing/submit; all-invalid checkout blocked. | | CART-09 | P1 | Notes entered, navigate checkout/back, edit again. | Latest notes survive and are submitted; readonly checkout agrees. | | CART-10 | P1 | Apply/remove several coupons, quantity changes. | Eligibility/discount recomputed; no stale invalid selected discount. | -| CART-11 | P0 | Confirm A→B switch; cancel switch. | Confirm clears regional state/both carts; cancel preserves everything. | +| CART-11 | P0 | Confirm A→B switch (from an already-set region); cancel switch. | Confirm clears regional state/both carts; cancel preserves everything. First region adoption at cold start is not this path and does not clear. | | CART-12 | P1 | Two rapid adds/different SKU writes and concurrent controls. | No lost storage update or duplicate local ID/negative quantity. | | CART-13 | P1 | Corrupt JSON/storage unavailable/full. | Recoverable state; never order corrupted/unknown quantity. | | CART-14 | P1 | Catalog ID missing after product deletion or region switch. | Useful missing-line state; no zero-priced purchasable phantom. | @@ -26,5 +26,6 @@ Scope: local cart storage, query hooks, quantity/slot reconciliation, floating/e | CART-20 | P1 | Back from checkout with malformed/stale slot/coupon params. | Existing cart unchanged; explicit reconciliation instead of wrong item ordered. | | CART-21 | P0 | Network unavailable; attempt submit from cached cart. | No false order success; recoverable offline state. | | CART-22 | P1 | Same global SKU across A/B switch. | Old A quote/slot does not survive because structural ID is shared. | +| CART-23 | P0 | Signed-in customer with zero addresses opens the cart, populated and empty. | Add-address gate shows before the cart, even when empty; the first saved address becomes the default, then the cart renders. | -Policy checkpoints: local cart behavior on account switch, slot persistence, fractional increment support, and retention of invalid lines after partial checkout. +Policy checkpoints: local cart behavior on account switch, first region adoption must preserve the cart (only an explicit switch clears it), slot persistence, fractional increment support, and retention of invalid lines after partial checkout. diff --git a/docs/test-cases/checkout.md b/docs/test-cases/checkout.md index b8546cf..938471b 100644 --- a/docs/test-cases/checkout.md +++ b/docs/test-cases/checkout.md @@ -8,7 +8,7 @@ Scope: regular/flash checkout, route params, selected address/slots/coupons/note | CHECK-02 | P1 | Items assigned to S1/S2, inspect grouped summary. | Correct group quantities/dates, chronologically ordered. | | CHECK-03 | P1 | Back to Cart, edit every selection, return. | Latest state shown/submitted; no obsolete cached route selection. | | CHECK-04 | P1 | Checkout readonly items/address/notes. | Cart is intentional edit path; back navigation usable. | -| CHECK-05 | P0 | Missing address/region/all-valid items. | Submission blocked with useful action; no empty group. | +| CHECK-05 | P0 | Missing address, missing/out-of-area coordinates or region, no valid items. | Submission blocked with useful action; no empty group. | | CHECK-06 | P1 | Empty cart vs items with no assigned slots. | Distinct meaningful empty states; hook order stable on async load. | | CHECK-07 | P0 | Malformed slot/coupon param, duplicate/nonfinite IDs, missing colon/groups. | Safe validation/reconciliation; cannot order unintended SKU/slot. | | CHECK-08 | P0 | Stale price/stock/freeze/capacity/address/coupon before submit. | Server revalidation; documented reprice/recovery, no false success. | @@ -20,9 +20,10 @@ Scope: regular/flash checkout, route params, selected address/slots/coupons/note | CHECK-14 | P1 | Fully discounted goods and free fee give server total zero. | Success shows authoritative zero, not stale fallback preview. | | CHECK-15 | P0 | UI selected coupons are now ineligible but IDs remain selected. | No silently misleading discounted preview; invalid selection removed or actionable rejection. | | CHECK-16 | P1 | Customer signs out/session expires mid-checkout. | Protected mutation denied; safe login return preserves allowed state. | -| CHECK-17 | P0 | Client bound differs from address bound. | Server ignores malicious/mistaken override where address bound exists. | +| CHECK-17 | P0 | Client-supplied regionId/bound differs from the order address coordinates. | Server derives region+bound from the address coordinates and ignores the client override. | | CHECK-18 | P1 | One cart item invalid, several valid; flash eligibility changed. | Summary and submitted item subset/charge agree. | | CHECK-19 | P2 | Android back/iOS swipe/browser refresh/deep link. | No stale cart, lost instruction or login-return loop. | | CHECK-20 | P1 | Online option in current build. | Clearly disabled until gateway feature enabled; COD invokes no gateway. | +| CHECK-21 | P0 | Place an order whose address coordinates are in B while the client browsing region is A. | Order is scoped to the address's region/bound (from coordinates); the browsing region is not corrupted. | Known policy: server order-idempotency is deferred; concurrent raw API submissions are characterization/risk cases, not an assumed deduplicated happy path. diff --git a/docs/test-cases/location-region-switching.md b/docs/test-cases/location-region-switching.md index c1c6b3f..5796be3 100644 --- a/docs/test-cases/location-region-switching.md +++ b/docs/test-cases/location-region-switching.md @@ -1,26 +1,30 @@ # Location resolution and region switching -Scope: native location store/useRegion, web region gate/store, manual selector, GPS attachment, persisted browsing context. +Scope: native location store/useRegion, web region gate/store, manual selector, GPS attachment. The browsing region is **in-memory only and never persisted**: every launch re-derives it from the device location and/or the default address. | ID | Priority | Action / input | Expected result | |---|---|---|---| | LOC-01 | P0 | Fresh signed-out/signed-in launch inside A. | One-shot resolution selects A; bound/catalog loads without mandatory login. | -| LOC-02 | P1 | Permission denied/permanently denied/GPS unavailable. | Manual choice available; saved valid region preserved. | +| LOC-02 | P1 | Permission denied/permanently denied/GPS unavailable. | A usable manual chooser (and, when a default address exists, that region); no silently "remembered" region, since none is persisted. | | LOC-03 | P1 | Coordinates outside all bounds; empty regions list. | Useful unavailable-service state, not endless spinner. | | LOC-04 | P0 | Delayed GPS A response after manual B selection. | Late automatic response cannot undo manual choice. | | LOC-05 | P1 | Location changes A→B while app remains open. | No unexpected continuous cart-clearing auto-switch. | | LOC-06 | P0 | Both A carts populated; request B switch, cancel then confirm. | Cancel preserves all; confirm clears regional carts/slots/coupons/address context and loads B. | | LOC-07 | P0 | Rapid A→B→A with delayed catalog responses. | Region-generation guard rejects stale B/A responses and mixed prices. | -| LOC-08 | P1 | Relaunch saved region with changed/removed service metadata. | Selection revalidated; appropriate fallback, no invalid cached context. | -| LOC-09 | P1 | Cold launch physically in B with A carts. | One-shot switch follows confirmation/reset policy; no silent mixed-region order. | +| LOC-08 | P1 | Relaunch after the region's service metadata changed/removed. | Region re-derived (nothing persisted); changed metadata revalidated; no stale cached context. | +| LOC-09 | P1 | Cold launch physically in B with A carts. | One-shot resolution follows the anchored startup decision; region adoption does not clear the local cart; no silent mixed-region order. | | LOC-10 | P1 | U1 A/B addresses; default B while browsing A. | No automatic foreign default override; A browsing choice retained. | | LOC-11 | P0 | Explicit foreign-address switch confirm/cancel. | Same safe region-switch behavior and cleared regional state. | -| LOC-12 | P1 | Missing coordinates but saved regional address. | Address-bound/effective-bound fallback works; warnings accurate. | +| LOC-12 | P1 | Saved address without a stored bound. | Bound is derived from the address coordinates; never a foreign region's bound; warnings accurate. | | LOC-13 | P1 | Shared location-store consumers mount/unmount repeatedly. | No duplicate listeners/resolutions or memory leaks affecting selection. | -| LOC-14 | P2 | Browser refresh/SSR/localStorage denied. | No hydration crash; usable manual region selector. | +| LOC-14 | P2 | Browser refresh/SSR/private-mode. | No hydration crash; usable manual region selector. | | LOC-15 | P1 | Force-quit during confirmed switch/state clearing. | Relaunch coherent region and carts; no half-reset checkout. | | LOC-16 | P1 | Resolve request offline/timeout, then restore network. | Bounded retry; manual selection remains usable. | | LOC-17 | P2 | Emulator/mock-location environment vs physical device. | Supported location path without production-only/emulator-only assumptions. | -| LOC-18 | P0 | Change region while submit request pending. | No duplicate order or new-region UI falsely representing old-region order. | +| LOC-18 | P0 | Change region while submit request is pending. | No duplicate order or new-region UI falsely representing old-region order. | +| LOC-19 | P0 | Cold launch (a) with a default address in the resolved region, (b) with the location resolving to another serviceable region, (c) with location off/out-of-area and a default address, (d) with no default address. | (a) use the default silently; (b) ask the user to choose; (c) use the default; (d) use the resolved region, else ask. | +| LOC-20 | P1 | Set a region → force-quit → relaunch with location unavailable. | Nothing is persisted: the region is re-derived (default address / location); when neither resolves a chooser appears — a previously set region does not silently survive. | +| LOC-21 | P0 | Cold start adopts the first region while a local cart has items. | Adoption uses the non-clearing path (local cart preserved). Only an explicit switch away from an already-set region confirms and clears regional state. | +| LOC-22 | P1 | Launch with location access denied, then with device location services off, then with permission granted but no fix. | Distinct messages ("access not granted" vs "services off" vs "couldn't get a fix") plus an "Open location settings" action, then an address-chooser fallback. | -Open policy: exact cold-start/manual-choice precedence after a populated saved cart. Do not label ambiguity PASS. +Open policy: exact cold-start/manual-choice precedence after a populated local cart. Do not label ambiguity PASS. diff --git a/docs/test-cases/recovery-platform-accessibility.md b/docs/test-cases/recovery-platform-accessibility.md index 1476422..829726e 100644 --- a/docs/test-cases/recovery-platform-accessibility.md +++ b/docs/test-cases/recovery-platform-accessibility.md @@ -4,7 +4,7 @@ Scope: common user/admin/superadmin journeys on Android/iOS/Chromium, errors/loa | ID | Priority | Action / input | Expected result | |---|---|---|---| -| UX-01 | P1 | Slow/offline startup with persisted cart/session/region. | Bounded clear loading/error; no silent cart reset or private-data flash. | +| UX-01 | P1 | Slow/offline startup with persisted cart/session. | Bounded clear loading/error; no silent cart reset or private-data flash. | | UX-02 | P1 | Catalog endpoint accepts request but never responds. | Deadline/abort/retry surfaced, not permanent spinner; baseline request cap verified where configured. | | UX-03 | P1 | Asset/discovery/auth request returns 400/401/403/404/409/500. | Appropriate recovery/messages; no success toast on rejected write. | | UX-04 | P0 | Disconnect before vs after order/save commit. | Outcome checked authoritatively; no blind duplicate/false rollback claim. | diff --git a/docs/test-cases/regions.md b/docs/test-cases/regions.md index 1fbf50d..62a8ea2 100644 --- a/docs/test-cases/regions.md +++ b/docs/test-cases/regions.md @@ -16,7 +16,7 @@ Scope: `superadmin.regions`, public region listing and region summary selectors. | REGION-10 | P1 | Double create, concurrent same-name creation. | One complete region or documented conflict; no orphan rows. | | REGION-11 | P1 | Update region while users browse/order. | Existing IDs/order region labels remain coherent; no data moves accidentally. | | REGION-12 | P1 | Attempt deletion through UI/direct API. | Unsupported action clearly unavailable; no destructive side effects. | -| REGION-13 | P2 | Large list and renamed region in saved selection. | Selected region resolves by ID; stale labels refresh. | +| REGION-13 | P2 | Large list and a region renamed during the session. | Selected region resolves by ID; stale labels refresh. | | REGION-14 | P0 | Inspect public list payload. | Only intended region/bound discovery metadata, no private staff/account data. | | REGION-15 | P1 | Newly created region publication to fresh/existing customers. | Discoverable within bounded deadline; B unchanged. |