e2e testing
This commit is contained in:
@@ -125,6 +125,46 @@ export interface FiestaOrderSummary {
|
||||
tenantname?: string;
|
||||
}
|
||||
|
||||
export interface FiestaLocationRevenue {
|
||||
locationid: number;
|
||||
locationname: string;
|
||||
revenue: number;
|
||||
}
|
||||
|
||||
export interface FiestaRevenueSummary {
|
||||
tenantid: number;
|
||||
tenantname: string;
|
||||
overallrevenue: number;
|
||||
locationrevenue: FiestaLocationRevenue[];
|
||||
}
|
||||
|
||||
/** /orders/getrevenuesummary?tenantid=&locationid=&fromdate=&todate= — tenant revenue and location breakdown. */
|
||||
export async function getRevenueSummary(opts: {
|
||||
tenantid: number;
|
||||
fromdate: string;
|
||||
todate: string;
|
||||
locationid?: number;
|
||||
}) {
|
||||
const res = await fiestaGet('orders/getrevenuesummary', opts);
|
||||
return firstRow<{
|
||||
tenantid: number;
|
||||
locationid: number | null;
|
||||
grossrevenue: number;
|
||||
netrevenue: number;
|
||||
profit: number;
|
||||
marginpct: number;
|
||||
ordercount: number;
|
||||
deliveredcount: number;
|
||||
cancelledcount: number;
|
||||
otifpct: number;
|
||||
avgordervalue: number;
|
||||
prev_grossrevenue: number;
|
||||
prev_ordercount: number;
|
||||
}>(res);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** /orders/getordersummary?tenantid=&locationid=&fromdate=&todate= — flat order counts. */
|
||||
export async function getOrderSummary(
|
||||
tenantid: number,
|
||||
@@ -203,6 +243,25 @@ export async function getOrders(opts: {
|
||||
);
|
||||
}
|
||||
|
||||
/** /orders/gettimeseries?tenantid=&locationid=&granularity=&fromdate=&todate= — time-series chart data */
|
||||
export async function getTimeSeries(opts: {
|
||||
tenantid: number;
|
||||
granularity: 'day' | 'month' | 'year';
|
||||
fromdate: string;
|
||||
todate: string;
|
||||
locationid?: number;
|
||||
}) {
|
||||
const res = await fiestaGet('orders/gettimeseries', opts);
|
||||
return toRows<{
|
||||
label: string;
|
||||
orders: number;
|
||||
revenue: number;
|
||||
delivered: number;
|
||||
cancelled: number;
|
||||
activeskus: number;
|
||||
}>(res);
|
||||
}
|
||||
|
||||
/** /orders/getorderdetails?orderheaderid= — line items for a single order. */
|
||||
export async function getOrderDetails(orderheaderid: number | string): Promise<Row[]> {
|
||||
let cleanId = String(orderheaderid).trim();
|
||||
|
||||
@@ -20,6 +20,8 @@ import {
|
||||
FIESTA_APPLOCATION_ID,
|
||||
FIESTA_PRIMARY_LOCATION_ID,
|
||||
getOrderSummary,
|
||||
getRevenueSummary,
|
||||
getTimeSeries,
|
||||
getLocationSummary,
|
||||
getOrderInsight,
|
||||
getOrders,
|
||||
@@ -62,6 +64,8 @@ import {
|
||||
export const fiestaKeys = {
|
||||
orderSummary: (tenantid: number, fromdate: string, todate: string, locationid?: number) =>
|
||||
['fiesta', 'orderSummary', tenantid, fromdate, todate, locationid ?? 0] as const,
|
||||
revenueSummary: (params: Record<string, unknown>) => ['fiesta', 'revenueSummary', params] as const,
|
||||
timeSeries: (params: Record<string, unknown>) => ['fiesta', 'timeSeries', params] as const,
|
||||
locationSummary: (tenantid: number) => ['fiesta', 'locationSummary', tenantid] as const,
|
||||
orderInsight: (tenantid: number) => ['fiesta', 'orderInsight', tenantid] as const,
|
||||
orders: (params: Record<string, unknown>) => ['fiesta', 'orders', params] as const,
|
||||
@@ -102,6 +106,33 @@ export function useFiestaOrderSummary(tenantid: number = FIESTA_TENANT_ID, fromd
|
||||
});
|
||||
}
|
||||
|
||||
export function useFiestaRevenueSummary(opts: {
|
||||
tenantid: number;
|
||||
fromdate: string;
|
||||
todate: string;
|
||||
locationid?: number;
|
||||
}) {
|
||||
return useQuery({
|
||||
queryKey: fiestaKeys.revenueSummary(opts as Record<string, unknown>),
|
||||
queryFn: () => getRevenueSummary(opts),
|
||||
enabled: Boolean(opts.tenantid && opts.fromdate && opts.todate),
|
||||
});
|
||||
}
|
||||
|
||||
export function useFiestaTimeSeries(opts: {
|
||||
tenantid: number;
|
||||
granularity: 'day' | 'month' | 'year';
|
||||
fromdate: string;
|
||||
todate: string;
|
||||
locationid?: number;
|
||||
}) {
|
||||
return useQuery({
|
||||
queryKey: fiestaKeys.timeSeries(opts as Record<string, unknown>),
|
||||
queryFn: () => getTimeSeries(opts),
|
||||
enabled: Boolean(opts.tenantid && opts.fromdate && opts.todate),
|
||||
});
|
||||
}
|
||||
|
||||
export function useFiestaLocationSummary(tenantid: number = FIESTA_TENANT_ID) {
|
||||
return useQuery({
|
||||
queryKey: fiestaKeys.locationSummary(tenantid),
|
||||
@@ -153,10 +184,16 @@ export function useFiestaAllOrders(opts: {
|
||||
return useQuery({
|
||||
queryKey: ['fiesta', 'allOrders', opts],
|
||||
queryFn: async () => {
|
||||
const statuses = ['created', 'pending', 'processing', 'delivered', 'cancelled'];
|
||||
const results = await Promise.all(
|
||||
statuses.map(status =>
|
||||
getOrders({
|
||||
// Include all known statuses from ORDER_STATUS_MAP to ensure we don't miss orders
|
||||
const statuses = [
|
||||
'created', 'pending', 'processing', 'delivered', 'cancelled',
|
||||
'accepted', 'assigned', 'ready', 'picked', 'active', 'arrived'
|
||||
];
|
||||
// Fetch sequentially to avoid rate-limiting or proxy dropping parallel requests
|
||||
const results: Row[][] = [];
|
||||
for (const status of statuses) {
|
||||
try {
|
||||
const res = await getOrders({
|
||||
tenantid: opts.tenantid,
|
||||
status,
|
||||
fromdate: opts.fromdate,
|
||||
@@ -164,10 +201,13 @@ export function useFiestaAllOrders(opts: {
|
||||
locationid: opts.locationid,
|
||||
applocationid: opts.applocationid,
|
||||
keyword: opts.keyword,
|
||||
pagesize: 100,
|
||||
}).catch(() => [] as Row[])
|
||||
)
|
||||
);
|
||||
pagesize: 500,
|
||||
});
|
||||
results.push(res);
|
||||
} catch (e) {
|
||||
results.push([]);
|
||||
}
|
||||
}
|
||||
// Merge and deduplicate by orderid/orderheaderid
|
||||
const merged: Row[] = [];
|
||||
const seen = new Set<string>();
|
||||
|
||||
Reference in New Issue
Block a user