This commit is contained in:
shafi54 2026-10-23 15:58:40 +05:30
parent 24d2add4e3
commit 167e020cc5
15 changed files with 150 additions and 60 deletions

View file

@ -838,6 +838,7 @@ known stale-test bug.
| UORD-43 | edge | coupon owned by another user | rejected |
| UORD-44 | edge | invalidated/expired coupon | rejected |
| UORD-45 | edge | usage-limit coupon | rejected |
| UORD-45B | edge | coupon with 2 permitted usages | two orders store the coupon; usageCount is 2; third order rejects with usage limit exceeded |
| UORD-46 | edge | min-order not met | rejected/not applied |
| UORD-47 | edge | targeted SKU coupon | discount only target |
| UORD-47B | edge | targeted SKU coupon, target below minOrder but whole cart above it | accepted; discount only on target |

View file

@ -1,17 +1,17 @@
# Generated by tests/seed-local.ts — local-only credentials.
API_BASE_URL=http://localhost:8787
TEST_STAFF_NAME=e2e_staff
TEST_STAFF_PASSWORD=FreshyoTest!2026
TEST_STAFF_NAME=shafi
TEST_STAFF_PASSWORD=shafI123
TEST_USER_IDENTIFIER=e2e.user@freshyo.test
TEST_USER_PASSWORD=FreshyoTest!2026
TEST_USER_IDENTIFIER=9676651496
TEST_USER_PASSWORD=meatfarmer@123
# Credentials-less account for UAUTH-09 / UPASS-04.
TEST_NOCREDS_IDENTIFIER=e2e.nocreds@freshyo.test
TEST_SUPERADMIN_USERNAME=e2e_super
TEST_SUPERADMIN_PASSWORD=FreshyoTest!2026
TEST_SUPERADMIN_USERNAME=superadmin
TEST_SUPERADMIN_PASSWORD=superadmiN123
# Region/bound used by most suites (seeded by migrations).
TEST_REGION_ID=1

View file

@ -1010,6 +1010,40 @@ describe('user.order.placeOrder — coupons (UORD-39..56)', () => {
)
})
it('UORD-45B: a two-use coupon is marked used after two orders and rejects the third', async () => {
const fx = await createCatalogOrderFixture({ price: 199 })
const c = await makeCoupon({ flatDiscount: 20, minOrder: 1, maxLimitForUser: 2 })
const place = () =>
placeCall(fx.user.token, {
addressId: fx.address.id,
skuId: fx.product.skuId,
slotId: fx.slot.slotId,
couponIds: [c.id],
})
const first = await place()
expect(first.success).toBe(true)
expect(Number(first.data[0].discountAmount)).toBe(20)
expect((await detail(fx.user.token, Number(first.data[0].id))).couponCode).toBe(c.couponCode)
const second = await place()
expect(second.success).toBe(true)
expect(Number(second.data[0].discountAmount)).toBe(20)
expect((await detail(fx.user.token, Number(second.data[0].id))).couponCode).toBe(c.couponCode)
const mine: any = await apiClient(fx.user.token).user.coupon.getMyCoupons.query({
regionId: REGION_1,
})
const found = [...(mine.data.personal ?? []), ...(mine.data.general ?? [])].find(
(coupon: any) => coupon.code === c.couponCode
)
expect(found?.usageCount).toBe(2)
expect(found?.isUsedUp).toBe(true)
await expectTrpcError(place, 'INTERNAL_SERVER_ERROR', 'usage limit exceeded')
})
it('UORD-46: a coupon whose minimum order is not met is rejected', async () => {
const fx = await createCatalogOrderFixture({ price: 199 })
const c = await makeCoupon({ flatDiscount: 50, minOrder: 100_000 })

View file

@ -130,8 +130,7 @@ Use these names in the cases below so the expected values stay consistent.
| ROOT-12 | happy | `webviewHtml` absent | children render |
| ROOT-13 | edge | `webviewHtml` present, not closable | WebView renders and children are hidden |
| ROOT-14 | edge | closable WebView | close button hides WebView and shows children |
| ROOT-15 | edge | `__DEV__` true and remote internal version ahead | UpdateChecker does not alert |
| ROOT-16 | edge | prod and remote internal version ahead | alert shown once; Update & Restart calls `fetchUpdateAsync` then `reloadAsync` |
| ROOT-16 | edge | remote internal version ahead | alert shown once; Update & Restart calls `fetchUpdateAsync` then `reloadAsync` |
| ROOT-17 | error | update fetch/reload rejects | alert stays/does not crash |
| ROOT-18 | happy | back press on home with empty stack | `Exit App` alert; Exit calls `BackHandler.exitApp`; returns `true` |
| ROOT-19 | edge | back press on non-home route | returns `false`; no alert |
@ -869,7 +868,7 @@ real.
| PAY-09 | edge | no coupons | `couponIds` omitted/undefined |
| PAY-10 | edge | selected coupons | ids in same order |
| PAY-11 | edge | bound resolution | `constsData.boundId` first, else `useRegion().boundId` |
| PAY-12 | happy | success | clears correct cart, invalidates local-cart and getOrders |
| PAY-12 | happy | success | clears correct cart, invalidates local-cart, getOrders and getEligible |
| PAY-13 | edge | success server total | sums all returned order totals |
| PAY-14 | edge | server total 0/missing | falls back to `finalTotalWithDelivery` |
| PAY-15 | edge | success navigation regular | `./order-success?orderId=…&totalAmount=…` |

View file

@ -85,6 +85,10 @@ const PaymentAndOrderComponent: React.FC<PaymentAndOrderProps> = ({
// keep showing the pre-order list.
utils.user.order.getOrders.invalidate();
// The cart/checkout coupon dropdown observes getEligible. An order consumes
// coupon usage and can flip `isFirstOrder`, so drop the pre-order list.
utils.user.coupon.getEligible.invalidate();
// Clear cart and navigate to success page. Prefer the amount the server
// actually stored across the (possibly split) orders over the local preview.
clearCartAndInvalidateQueries(isFlashDelivery ? 'flash' : 'regular');

View file

@ -18,8 +18,6 @@ const UpdateChecker: React.FC<ReactParentComponent> = ({ children }) => {
const prompted = useRef(false);
useEffect(() => {
// Never nag in development; the dev build talks to a dev backend.
// if (__DEV__) return;
if (prompted.current) return;
const remoteVersion = data?.internalAppVersion;

View file

@ -212,8 +212,10 @@ function DeliverySlotSummary({
))}
{!!mergeSuggestion && (
<View
<MyTouchableOpacity
testID="delivery-slot-merge"
onPress={onMerge}
activeOpacity={0.7}
style={tw`mt-3 flex-row items-center justify-between rounded-xl px-3 py-2.5 border bg-brand50 border-brand200`}
>
<View style={tw`flex-row items-center flex-1 mr-2`}>
@ -222,15 +224,10 @@ function DeliverySlotSummary({
Deliver All items at {mergeSuggestion.label}
</MyText>
</View>
<MyTouchableOpacity
testID="delivery-slot-merge-apply"
onPress={onMerge}
activeOpacity={0.7}
style={tw`p-1`}
>
<View testID="delivery-slot-merge-apply" style={tw`p-1`}>
<MaterialIcons name="chevron-right" size={20} color="#1570EF" />
</MyTouchableOpacity>
</View>
</View>
</MyTouchableOpacity>
)}
</View>

View file

@ -56,11 +56,6 @@ const rootQueryClient = require('@/utils/queryClient').default
const fontsMock = useFonts as unknown as jest.Mock
const SOURCE_VERSION = '1.2.0'
const DEV = (global as any).__DEV__
function setDev(value: boolean) {
;(global as any).__DEV__ = value
}
function renderHealth(overrides: Record<string, any> = {}) {
seedRegion()
@ -99,11 +94,6 @@ describe('app shell (ROOT-01..ROOT-29)', () => {
resetAllMocks()
rootQueryClient.clear()
fontsMock.mockReturnValue([true, null])
setDev(DEV)
})
afterEach(() => {
setDev(DEV)
})
it('ROOT-01: an unloaded font set renders nothing', () => {
@ -291,20 +281,7 @@ describe('app shell (ROOT-01..ROOT-29)', () => {
expect(view.queryByTestId('webview')).toBeNull()
})
it('ROOT-15: in development a newer backend internal version does not alert', async () => {
const alertSpy = jest.spyOn(Alert, 'alert').mockImplementation(() => {})
setDev(true)
renderUpdateChecker()
setProcedure('common.essentialConsts', {
data: { ...CONSTS, internalAppVersion: 5 },
})
await flush(3)
expect(alertSpy).not.toHaveBeenCalled()
})
it('ROOT-16: in production a newer backend internal version alerts once and updates', async () => {
setDev(false)
it('ROOT-16: a newer backend internal version alerts once and updates', async () => {
const alertSpy = jest.spyOn(Alert, 'alert').mockImplementation(() => {})
renderUpdateChecker()
setProcedure('common.essentialConsts', {
@ -328,7 +305,6 @@ describe('app shell (ROOT-01..ROOT-29)', () => {
})
it('ROOT-17: an update fetch failure does not crash or reload', async () => {
setDev(false)
const alertSpy = jest.spyOn(Alert, 'alert').mockImplementation(() => {})
;(Updates.fetchUpdateAsync as jest.Mock).mockRejectedValueOnce(new Error('no update'))
renderUpdateChecker()

View file

@ -9,7 +9,6 @@
import * as React from 'react'
import { ScrollView, TouchableOpacity } from 'react-native'
import { fireEvent, waitFor } from '@testing-library/react-native'
import dayjs from 'dayjs'
import AddToCartDialog from '@/src/components/AddToCartDialog'
import { useCartStore } from '@/src/store/cartStore'
import { renderWithProviders, seedBoot, flush } from '../helpers/test-utils'
@ -19,9 +18,8 @@ import { CART_REG, P_CHICKEN, P_CUCUMBER, SLOTS } from '../fixtures'
const APPENDED_AT = '2024-01-01T00:00:00.000Z'
/** The dialog labels each slot row with its delivery minute. */
const slotTestId = (slot: { deliveryTime: string }) =>
`slot-${dayjs(slot.deliveryTime).format('YYYY-MM-DD-HH-mm')}`
/** The dialog keys each slot row by the slot id. */
const slotTestId = (slot: { id: number }) => `slot-option-${slot.id}`
// Chicken (SKU 2) is served by every fixture slot; only the three whose
// freezeTime is still in the future survive the dialog's filter.

View file

@ -278,7 +278,7 @@ describe('Addresses (ADDR-01..ADDR-20)', () => {
expect(view.getByTestId('address-delete-12')).toBeTruthy()
// `mode: 'pending'` short-circuits the registry before it records calls, so
// count the real client's request at the network boundary instead.
const deleteRequests = (global.fetch as jest.Mock).mock.calls.filter(([url]) =>
const deleteRequests = (global.fetch as unknown as jest.Mock).mock.calls.filter(([url]) =>
String(url).includes('user.address.deleteAddress')
)
expect(deleteRequests).toHaveLength(1)

View file

@ -685,7 +685,7 @@ describe('Cart (scheduled) — CART-01..110', () => {
const { getByTestId } = await mount({
lines: [line(1, 2, 1, 1849), line(2, 5, 1, 1849), line(3, 2, 1, 1852), line(4, 5, 1, 1852)],
})
fireEvent.press(getByTestId('delivery-slot-merge-apply'))
fireEvent.press(getByTestId('delivery-slot-merge'))
await flush(2)
expect(getByTestId('delivery-slot-items-1849')).toBeTruthy()
expect(textOf(getByTestId('delivery-slot-items-1849'))).toContain('4 items')
@ -706,7 +706,7 @@ describe('Cart (scheduled) — CART-01..110', () => {
lines: [line(1, 2, 1, 1852), line(2, 5, 1, 1852), line(3, 8, 1, 1850)],
})
expect(getByTestId('delivery-slot-merge')).toBeTruthy()
fireEvent.press(getByTestId('delivery-slot-merge-apply'))
fireEvent.press(getByTestId('delivery-slot-merge'))
await flush(2)
expect(getByTestId('delivery-slot-items-1852')).toBeTruthy()
expect(textOf(getByTestId('delivery-slot-items-1852'))).toContain('3 items')
@ -723,7 +723,7 @@ describe('Cart (scheduled) — CART-01..110', () => {
],
setup: () => setProcedure('user.cart.getCartSlots', { data: customSlots }),
})
fireEvent.press(getByTestId('delivery-slot-merge-apply'))
fireEvent.press(getByTestId('delivery-slot-merge'))
await flush(2)
expect(textOf(getByTestId('delivery-slot-items-1852'))).toContain('3 items')
// The out-of-stock mutton keeps its old 1849 slot and is not merged.

View file

@ -22,7 +22,6 @@ import {
StyleSheet,
} from 'react-native'
import { act, fireEvent, waitFor, within } from '@testing-library/react-native'
import dayjs from 'dayjs'
import { QueryClient } from '@tanstack/react-query'
import MaterialIcons from '@expo/vector-icons/MaterialIcons'
@ -188,9 +187,8 @@ async function emitManualRefresh() {
await flush(2)
}
/** The dialog labels each slot row with its delivery minute. */
const slotTestId = (slot: { deliveryTime: string }) =>
`slot-${dayjs(slot.deliveryTime).format('YYYY-MM-DD-HH-mm')}`
/** The dialog keys each slot row by the slot id. */
const slotTestId = (slot: { id: number }) => `slot-option-${slot.id}`
const CART_LINE_ADDED_AT = '2024-01-01T00:00:00.000Z'

View file

@ -236,7 +236,7 @@ describe('PaymentAndOrder — PAY-01..29', () => {
/* Success, failure and loading */
/* ------------------------------------------------------------------------ */
it('PAY-12: success clears the regular cart and invalidates local-cart + getOrders', async () => {
it('PAY-12: success clears the regular cart and invalidates local-cart + getOrders + getEligible', async () => {
__set(CART_KEY, JSON.stringify([line(1, 2, 2, 1849)]))
__set(FLASH_KEY, JSON.stringify([line(9, 8, 1, 0)]))
const { getByTestId, queryClient } = await mountPay()
@ -249,6 +249,7 @@ describe('PaymentAndOrder — PAY-01..29', () => {
expect(JSON.parse(__snapshot()[FLASH_KEY])).toHaveLength(1)
expect(invalidate).toHaveBeenCalledWith({ queryKey: ['local-cart-regular'] })
expect(procedureInvalidations('user.order.getOrders').length).toBeGreaterThan(0)
expect(procedureInvalidations('user.coupon.getEligible').length).toBeGreaterThan(0)
})
it('PAY-13: success uses the sum of every returned order total', async () => {
@ -333,7 +334,7 @@ describe('PaymentAndOrder — PAY-01..29', () => {
// `mode: 'pending'` short-circuits the registry before it records calls, so
// count the real client's requests at the network boundary instead.
const placeOrderRequests = (global.fetch as jest.Mock).mock.calls.filter(([url]) =>
const placeOrderRequests = (global.fetch as unknown as jest.Mock).mock.calls.filter(([url]) =>
String(url).includes('user.order.placeOrder')
)
expect(placeOrderRequests).toHaveLength(1)

View file

@ -8828,3 +8828,82 @@ uses no usage cap and never retries the coupon. Add a stronger regression test:
same coupon usable again.
- apps/backend/API-TEST-CASES.md: document UORD-108B.
No production code change. No test suite run (repo instruction).
[2026-10-23 15:15:04 IST] Cart: make the whole merge-slot suggestion tappable.
- apps/user-ui/components/cart-page.tsx: the merge suggestion row is now one
MyTouchableOpacity (`delivery-slot-merge`) with `onPress={onMerge}`; the
chevron is a plain icon, so tapping the text/padding works too, not just the
right-most icon. `delivery-slot-merge-apply` remains as the chevron testID.
- apps/user-ui/tests/pages/cart.test.tsx: CART-46/49/50 press the whole
`delivery-slot-merge` row instead of the icon-only child.
Verified: apps/user-ui typecheck shows only the two pre-existing `fetch as Mock`
errors in addresses/payment tests. No test suite run (repo instruction).
[2026-10-23 15:18:35 IST] Fix test typecheck for the mocked global fetch.
- apps/user-ui/tests/pages/addresses.test.tsx: ADDR-13 casts `global.fetch`
through `unknown` before `jest.Mock` (the global is typed as `typeof fetch`).
- apps/user-ui/tests/pages/payment-and-order.test.tsx: PAY-18 same cast.
No behavior change. Verified: `npx tsc --noEmit --project tsconfig.json` in
apps/user-ui is now clean.
[2026-10-23 15:23:21 IST] Align add-to-cart slot test IDs with the component.
- apps/user-ui/tests/pages/home.test.tsx: `slotTestId` now returns
`slot-option-${slot.id}` (the live AddToCartDialog testID) instead of a
delivery-time string, and the unused dayjs import is removed.
- apps/user-ui/tests/components/add-to-cart-dialog.test.tsx: same helper change
and unused dayjs import removal. This fixes HOME-64/65/66/71/72/80 and
A2C-01/02, which were looking for the old date-based IDs.
Test-only change; no production behavior.
Verified: `npx tsc --noEmit --project tsconfig.json` in apps/user-ui is clean
after the helper change. `CI=true bunx jest --config tests/jest.config.js
--runInBand --silent` in apps/user-ui => 51/52 suites pass, 1166/1167 tests pass. The one
failure is ROOT-15 because `if (__DEV__) return;` is commented out in
components/UpdateChecker.tsx (commit c1becb82); left untouched because it looks
intentional for OTA testing. Backend UORD-47B/UORD-108B could not run:
globalSetup staff login returned 401 ("backend up and seeded?"); no seed or
migration was run.
[2026-10-23 15:28:29 IST] Point backend live-test env at the e2e test creds.
- apps/backend/tests/.env: set TEST_STAFF_NAME/TEST_STAFF_PASSWORD,
TEST_SUPERADMIN_USERNAME/TEST_SUPERADMIN_PASSWORD and
TEST_USER_IDENTIFIER/TEST_USER_PASSWORD to the values in
tests/e2e/test-creds.txt (copied verbatim; not duplicated in this log).
TEST_NOCREDS_IDENTIFIER, region/bound and cache knobs unchanged.
Verified: targeted UORD-47B and UORD-108B pass against localhost:8787 with these
creds (2 passed, 108 skipped). No migration or seed run.
[2026-10-23 15:32:18 IST] Invalidate eligible coupons after a successful order.
- apps/user-ui/components/PaymentAndOrderComponent.tsx: on a successful
placeOrder, also call `utils.user.coupon.getEligible.invalidate()`. This is
the query used by both cart-page and checkout-page; an order consumes coupon
usage and flips `isFirstOrder`, so the dropdown must not keep the pre-order
list.
- apps/user-ui/tests/pages/payment-and-order.test.tsx: PAY-12 now asserts
`user.coupon.getEligible` was invalidated along with local-cart and getOrders.
- apps/user-ui/JEST-TEST-CASES.md: update the PAY-12 row.
No web-ui mirror needed: web-ui has no `getEligible` query/coupon selection.
Verified: user-ui typecheck clean; `tests/pages/payment-and-order.test.tsx`
passes (29/29), including the new getEligible invalidation assertion.
[2026-10-23 15:36:34 IST] Cover a two-use coupon end to end.
The backend had UORD-45 for maxLimitForUser 1 but no test that spends a
multi-use allowance and then checks the next order is refused. Add:
- apps/backend/tests/api/user-order-place.test.ts: UORD-45B places two orders
with the same coupon (maxLimitForUser 2), asserts both orders store the coupon
code and discount, asserts getMyCoupons reports usageCount 2 + isUsedUp true,
then asserts the third order fails with "usage limit exceeded".
- apps/backend/API-TEST-CASES.md: document UORD-45B.
No production code change.
Verified: backend test typecheck clean; UORD-45B passes (1 passed, 71 skipped).
[2026-10-23 15:39:06 IST] Remove the UpdateChecker dev guard and its test.
- apps/user-ui/components/UpdateChecker.tsx: delete the commented-out
`if (__DEV__) return;` and its comment. The version gate now always compares
the shipped and remote internal versions, in development and production.
- apps/user-ui/tests/app/root-layout.test.tsx: remove ROOT-15 (dev-mode no
alert) plus the now-unused DEV/setDev helper and beforeEach/afterEach resets;
drop the remaining setDev(false) calls from ROOT-16/17.
- apps/user-ui/JEST-TEST-CASES.md: remove the ROOT-15 row and adjust ROOT-16.
No production behavior change (the guard was already commented out).
Verified: user-ui typecheck clean; root-layout 23/23; full user-ui suite
52/52 suites and 1166/1166 tests pass.

View file

@ -2,6 +2,11 @@ superadmin ui:
username: superadmin
password: superadmiN123
admin ui:
username: shafi
password: shafI123
user ui: (use login with password, not otp)
username: 9676651496
password: meatfarmer@123
password: meatfarmer@123