From 8936669f94c6b7fbc9a0015f07efa07d2067cf89 Mon Sep 17 00:00:00 2001 From: dharaneesh-r Date: Thu, 3 Sep 2026 13:04:13 +0530 Subject: [PATCH] updates on the builded changes --- config-overrides.js | 21 +++++++++++++++++++++ src/pages/nearle/api/api.js | 1 + src/pages/nearle/api/api.test.js | 20 ++++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/config-overrides.js b/config-overrides.js index 1e07a2f..bac080c 100644 --- a/config-overrides.js +++ b/config-overrides.js @@ -1,7 +1,28 @@ const webpack = require('webpack'); const WorkBoxPlugin = require('workbox-webpack-plugin'); +// Fail the build loudly when an API base is missing, instead of emitting a +// bundle in which every request URL is the string "undefined/orders/..." — +// a relative path that silently resolves against whatever host the console is +// served from. That produced a deploy where the API base appeared to be the +// front-end's own origin. Only enforced for production builds; `npm start` +// is left alone. +const REQUIRED_PROD_ENV = ['REACT_APP_URL', 'REACT_APP_URL2']; + +function assertRequiredEnv() { + if (process.env.NODE_ENV !== 'production') return; + const missing = REQUIRED_PROD_ENV.filter((k) => !process.env[k]); + if (!missing.length) return; + throw new Error( + `\n\nBuild aborted — missing required environment variable(s): ${missing.join(', ')}.\n` + + 'Define them in .env (loaded by every build) or build via `npm run build:staging` / `build:dev`,\n' + + 'which load .env.staging / .env.development through env-cmd.\n' + ); +} + module.exports = function override(config) { + assertRequiredEnv(); + config.resolve.fallback = { process: require.resolve('process/browser'), // zlib: require.resolve('browserify-zlib'), diff --git a/src/pages/nearle/api/api.js b/src/pages/nearle/api/api.js index 51a4870..cbd11f9 100644 --- a/src/pages/nearle/api/api.js +++ b/src/pages/nearle/api/api.js @@ -1,4 +1,5 @@ import axios from 'axios'; +import dayjs from 'dayjs'; import { OpenToast } from 'components/nearle_components/OpenToast'; const tenid = localStorage.getItem('tenantid'); diff --git a/src/pages/nearle/api/api.test.js b/src/pages/nearle/api/api.test.js index 819303c..51bfb73 100644 --- a/src/pages/nearle/api/api.test.js +++ b/src/pages/nearle/api/api.test.js @@ -438,3 +438,23 @@ describe('orders.js empty-batch guard contract', () => { expect(guardFires(normaliseAssignResponse(zoned))).toBe(false); }); }); + +// ========================================================================== +// Regression: cancelMultipleOrder referenced dayjs without importing it, +// throwing a ReferenceError on the multi-cancel confirm button. +// ========================================================================== +describe('cancelMultipleOrder', () => { + it('builds a cancelled timestamp without throwing a ReferenceError', async () => { + const { cancelMultipleOrder } = require('./api'); + axios.put.mockResolvedValue({ data: { status: true } }); + await cancelMultipleOrder([{ orderheaderid: 1 }, { orderheaderid: 2 }]); + + const [, body] = axios.put.mock.calls[0]; + expect(body).toHaveLength(2); + body.forEach((row) => { + expect(row.orderstatus).toBe('cancelled'); + // Real formatted timestamp, not "Invalid Date" or undefined. + expect(row.cancelled).toMatch(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/); + }); + }); +});