@object-ui/data-objectstack 17.5.0 → 17.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2311 -0
- package/README.md +557 -11
- package/dist/index.cjs +1663 -463
- package/dist/index.d.cts +1780 -518
- package/dist/index.d.ts +1780 -518
- package/dist/index.js +1648 -457
- package/package.json +9 -9
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/src/aggregate-capability.test.ts +0 -177
- package/src/apiAccessDenied.test.ts +0 -233
- package/src/appAccessProbe.test.ts +0 -147
- package/src/bulkDelete.test.ts +0 -75
- package/src/bulkUpdate.test.ts +0 -93
- package/src/cache/MetadataCache.test.ts +0 -477
- package/src/cache/MetadataCache.ts +0 -289
- package/src/cloud-surface-retired-4152.pin.test.ts +0 -171
- package/src/connection.test.ts +0 -188
- package/src/contracts.ts +0 -115
- package/src/deleteView.homes.test.ts +0 -389
- package/src/deleteViewContract.types.test.ts +0 -246
- package/src/errors.test.ts +0 -426
- package/src/errors.ts +0 -293
- package/src/exportDownload.test.ts +0 -141
- package/src/filter-entry-translation.test.ts +0 -360
- package/src/filter-operator-ast-parity.test.ts +0 -135
- package/src/getObjectSchema.test.ts +0 -145
- package/src/httpFailureLogging.test.ts +0 -109
- package/src/importJob.test.ts +0 -71
- package/src/index.ts +0 -4442
- package/src/integration.ts +0 -200
- package/src/listViewOverrides.test.ts +0 -241
- package/src/listViews.test.ts +0 -175
- package/src/metadata-client.get-envelope.test.ts +0 -171
- package/src/metadata-client.saveAdvisories.test.ts +0 -226
- package/src/metadata-client.test.ts +0 -303
- package/src/metadata-client.ts +0 -1046
- package/src/occ.test.ts +0 -101
- package/src/onMutation.test.ts +0 -589
- package/src/onSaveAdvisory.test.ts +0 -311
- package/src/onWriteWarning.test.ts +0 -273
- package/src/orderby-serialization.test.ts +0 -115
- package/src/queryDataset.test.ts +0 -543
- package/src/searchAll.test.ts +0 -120
- package/src/security.ts +0 -243
- package/src/spec-symbol-batch6.test.ts +0 -326
- package/src/studio.ts +0 -152
- package/src/updateView.draft.test.ts +0 -242
- package/src/userState.test.ts +0 -315
- package/src/userState.ts +0 -238
- package/src/v3-compat.test.ts +0 -229
- package/src/validation-error.test.ts +0 -94
- package/src/viewCacheInvalidation.pin.test.ts +0 -260
- package/src/viewInvalidationSeam.pin.test.ts +0 -162
package/src/errors.ts
DELETED
|
@@ -1,293 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ObjectUI
|
|
3
|
-
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the MIT license found in the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Base error class for all ObjectStack adapter errors
|
|
11
|
-
*/
|
|
12
|
-
export class ObjectStackError extends Error {
|
|
13
|
-
/**
|
|
14
|
-
* Create a new ObjectStackError
|
|
15
|
-
*
|
|
16
|
-
* @param message - Human-readable error message
|
|
17
|
-
* @param code - Unique error code for programmatic handling
|
|
18
|
-
* @param statusCode - Optional HTTP status code
|
|
19
|
-
* @param details - Optional additional error details for debugging
|
|
20
|
-
*/
|
|
21
|
-
constructor(
|
|
22
|
-
message: string,
|
|
23
|
-
public code: string,
|
|
24
|
-
public statusCode?: number,
|
|
25
|
-
public details?: Record<string, unknown>
|
|
26
|
-
) {
|
|
27
|
-
super(message);
|
|
28
|
-
this.name = 'ObjectStackError';
|
|
29
|
-
|
|
30
|
-
// Maintains proper stack trace for where error was thrown (only in V8)
|
|
31
|
-
if ((Error as any).captureStackTrace) {
|
|
32
|
-
(Error as any).captureStackTrace(this, this.constructor);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Convert error to JSON for logging/debugging
|
|
38
|
-
*/
|
|
39
|
-
toJSON() {
|
|
40
|
-
return {
|
|
41
|
-
name: this.name,
|
|
42
|
-
message: this.message,
|
|
43
|
-
code: this.code,
|
|
44
|
-
statusCode: this.statusCode,
|
|
45
|
-
details: this.details,
|
|
46
|
-
stack: this.stack,
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Error thrown when requested metadata/schema is not found
|
|
53
|
-
*/
|
|
54
|
-
export class MetadataNotFoundError extends ObjectStackError {
|
|
55
|
-
constructor(
|
|
56
|
-
objectName: string,
|
|
57
|
-
details?: Record<string, unknown>
|
|
58
|
-
) {
|
|
59
|
-
super(
|
|
60
|
-
`Metadata not found for object: ${objectName}`,
|
|
61
|
-
'METADATA_NOT_FOUND',
|
|
62
|
-
404,
|
|
63
|
-
{ objectName, ...details }
|
|
64
|
-
);
|
|
65
|
-
this.name = 'MetadataNotFoundError';
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Error thrown when a bulk operation fails
|
|
71
|
-
*/
|
|
72
|
-
export class BulkOperationError extends ObjectStackError {
|
|
73
|
-
/**
|
|
74
|
-
* Create a new BulkOperationError
|
|
75
|
-
*
|
|
76
|
-
* @param operation - The bulk operation that failed (create, update, delete)
|
|
77
|
-
* @param successCount - Number of successful operations
|
|
78
|
-
* @param failureCount - Number of failed operations
|
|
79
|
-
* @param errors - Array of individual errors
|
|
80
|
-
* @param details - Additional error details
|
|
81
|
-
*/
|
|
82
|
-
constructor(
|
|
83
|
-
operation: 'create' | 'update' | 'delete',
|
|
84
|
-
public successCount: number,
|
|
85
|
-
public failureCount: number,
|
|
86
|
-
public errors: Array<{ index: number; error: unknown }>,
|
|
87
|
-
details?: Record<string, unknown>
|
|
88
|
-
) {
|
|
89
|
-
super(
|
|
90
|
-
`Bulk ${operation} operation failed: ${successCount} succeeded, ${failureCount} failed`,
|
|
91
|
-
'BULK_OPERATION_ERROR',
|
|
92
|
-
500,
|
|
93
|
-
{
|
|
94
|
-
operation,
|
|
95
|
-
successCount,
|
|
96
|
-
failureCount,
|
|
97
|
-
errors,
|
|
98
|
-
...details,
|
|
99
|
-
}
|
|
100
|
-
);
|
|
101
|
-
this.name = 'BulkOperationError';
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Get a summary of the bulk operation failure
|
|
106
|
-
*/
|
|
107
|
-
getSummary() {
|
|
108
|
-
const total = this.successCount + this.failureCount;
|
|
109
|
-
const failureRate = total > 0 ? this.failureCount / total : 0;
|
|
110
|
-
|
|
111
|
-
return {
|
|
112
|
-
operation: this.details?.operation as string,
|
|
113
|
-
total: total,
|
|
114
|
-
successful: this.successCount,
|
|
115
|
-
failed: this.failureCount,
|
|
116
|
-
failureRate: failureRate,
|
|
117
|
-
errors: this.errors,
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Error thrown when connection to ObjectStack server fails
|
|
124
|
-
*/
|
|
125
|
-
export class ConnectionError extends ObjectStackError {
|
|
126
|
-
constructor(
|
|
127
|
-
message: string,
|
|
128
|
-
public url?: string,
|
|
129
|
-
details?: Record<string, unknown>,
|
|
130
|
-
statusCode?: number
|
|
131
|
-
) {
|
|
132
|
-
super(
|
|
133
|
-
`Connection error: ${message}`,
|
|
134
|
-
'CONNECTION_ERROR',
|
|
135
|
-
statusCode || 503,
|
|
136
|
-
{ url, ...details }
|
|
137
|
-
);
|
|
138
|
-
this.name = 'ConnectionError';
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Error thrown when authentication fails
|
|
144
|
-
*/
|
|
145
|
-
export class AuthenticationError extends ObjectStackError {
|
|
146
|
-
constructor(
|
|
147
|
-
message: string = 'Authentication failed',
|
|
148
|
-
details?: Record<string, unknown>,
|
|
149
|
-
statusCode?: number
|
|
150
|
-
) {
|
|
151
|
-
super(
|
|
152
|
-
message,
|
|
153
|
-
'AUTHENTICATION_ERROR',
|
|
154
|
-
statusCode || 401,
|
|
155
|
-
details
|
|
156
|
-
);
|
|
157
|
-
this.name = 'AuthenticationError';
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Error thrown when the ObjectStack data API rejects a write as invalid.
|
|
163
|
-
*
|
|
164
|
-
* NOT the spec's `ValidationError` (`@objectstack/spec/kernel`), whose name this
|
|
165
|
-
* class wore until objectui#3160 (objectstack#4115 ledger batch 6). That one is
|
|
166
|
-
* a plain DATA SHAPE — `{ field, message, code? }`, one entry in a plugin
|
|
167
|
-
* manifest's validation report — and `@object-ui/types` re-exports it under that
|
|
168
|
-
* name. This is a runtime `Error` subclass carrying an HTTP status plus a list
|
|
169
|
-
* of such entries, so the two are not even the same KIND of thing.
|
|
170
|
-
*
|
|
171
|
-
* The name follows the convention registered on objectstack#4115 for this
|
|
172
|
-
* family — `<what was validated>Validation<Error|Result>`. `@object-ui/core`
|
|
173
|
-
* took `SchemaNodeValidationError` for its SDUI-tree walk; this one belongs to
|
|
174
|
-
* the data API.
|
|
175
|
-
*/
|
|
176
|
-
export class DataApiValidationError extends ObjectStackError {
|
|
177
|
-
/**
|
|
178
|
-
* Create a new DataApiValidationError
|
|
179
|
-
*
|
|
180
|
-
* @param message - Human-readable error message
|
|
181
|
-
* @param field - The field that failed validation (optional)
|
|
182
|
-
* @param validationErrors - Array of validation error details
|
|
183
|
-
* @param details - Additional error details
|
|
184
|
-
*/
|
|
185
|
-
constructor(
|
|
186
|
-
message: string,
|
|
187
|
-
public field?: string,
|
|
188
|
-
public validationErrors?: Array<{ field: string; message: string }>,
|
|
189
|
-
details?: Record<string, unknown>
|
|
190
|
-
) {
|
|
191
|
-
super(
|
|
192
|
-
message,
|
|
193
|
-
'VALIDATION_ERROR',
|
|
194
|
-
400,
|
|
195
|
-
{
|
|
196
|
-
field,
|
|
197
|
-
validationErrors,
|
|
198
|
-
...details,
|
|
199
|
-
}
|
|
200
|
-
);
|
|
201
|
-
// The RUNTIME name stays `'ValidationError'` on purpose — it is the wire
|
|
202
|
-
// discriminator this adapter shares with `@objectstack/client` and with
|
|
203
|
-
// consumers that sniff `err.name` rather than `instanceof`
|
|
204
|
-
// (`normaliseClientError` here, `@object-ui/react`'s `error-message`).
|
|
205
|
-
// Renaming the TypeScript symbol is a source-level rename; renaming this
|
|
206
|
-
// string would be a behaviour change nobody asked for.
|
|
207
|
-
this.name = 'ValidationError';
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Get all validation errors as a formatted list
|
|
212
|
-
*/
|
|
213
|
-
getValidationErrors() {
|
|
214
|
-
return this.validationErrors || [];
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Helper function to create an error from an HTTP response
|
|
220
|
-
*
|
|
221
|
-
* @param response - Response object or error from fetch/axios
|
|
222
|
-
* @param context - Additional context for debugging
|
|
223
|
-
* @returns Appropriate error instance
|
|
224
|
-
*/
|
|
225
|
-
export function createErrorFromResponse(response: Record<string, unknown>, context?: string): ObjectStackError {
|
|
226
|
-
const status = (response?.status as number) || (response?.statusCode as number) || 500;
|
|
227
|
-
const message = (response?.message as string) || (response?.statusText as string) || 'Unknown error';
|
|
228
|
-
const details = {
|
|
229
|
-
context,
|
|
230
|
-
response: {
|
|
231
|
-
status,
|
|
232
|
-
data: response?.data,
|
|
233
|
-
headers: response?.headers,
|
|
234
|
-
},
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
switch (status) {
|
|
238
|
-
case 401:
|
|
239
|
-
return new AuthenticationError(message, details, 401);
|
|
240
|
-
|
|
241
|
-
case 403:
|
|
242
|
-
return new AuthenticationError(message, details, 403);
|
|
243
|
-
|
|
244
|
-
case 404:
|
|
245
|
-
// Check if it's a metadata request based on context
|
|
246
|
-
if (context?.includes('metadata') || context?.includes('schema') || context?.includes('getObjectSchema')) {
|
|
247
|
-
const objectName = extractObjectName(context);
|
|
248
|
-
return new MetadataNotFoundError(objectName, details);
|
|
249
|
-
}
|
|
250
|
-
return new ObjectStackError(message, 'NOT_FOUND', 404, details);
|
|
251
|
-
|
|
252
|
-
case 400:
|
|
253
|
-
return new DataApiValidationError(message, undefined, (response?.data as Record<string, unknown>)?.errors as Array<{ field: string; message: string }>, details);
|
|
254
|
-
|
|
255
|
-
case 503:
|
|
256
|
-
return new ConnectionError(message, (response?.config as Record<string, unknown>)?.url as string, details, 503);
|
|
257
|
-
|
|
258
|
-
case 504:
|
|
259
|
-
return new ConnectionError(message, (response?.config as Record<string, unknown>)?.url as string, details, 504);
|
|
260
|
-
|
|
261
|
-
default:
|
|
262
|
-
return new ObjectStackError(message, 'UNKNOWN_ERROR', status, details);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Helper to extract object name from context string
|
|
268
|
-
*/
|
|
269
|
-
function extractObjectName(context?: string): string {
|
|
270
|
-
if (!context) return 'unknown';
|
|
271
|
-
|
|
272
|
-
// Try to extract object name from patterns like "getObjectSchema(users)"
|
|
273
|
-
const match = context.match(/\(([^)]+)\)/);
|
|
274
|
-
return match ? match[1] : 'unknown';
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* Type guard to check if an error is an ObjectStackError
|
|
279
|
-
*/
|
|
280
|
-
export function isObjectStackError(error: unknown): error is ObjectStackError {
|
|
281
|
-
return error instanceof ObjectStackError;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
* Type guard to check if an error is a specific ObjectStack error type
|
|
286
|
-
*/
|
|
287
|
-
export function isErrorType<T extends ObjectStackError>(
|
|
288
|
-
error: unknown,
|
|
289
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
290
|
-
errorClass: new (...args: any[]) => T
|
|
291
|
-
): error is T {
|
|
292
|
-
return error instanceof errorClass;
|
|
293
|
-
}
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ObjectUI
|
|
3
|
-
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the MIT license found in the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { describe, it, expect, vi } from 'vitest';
|
|
10
|
-
import { ObjectStackAdapter } from './index';
|
|
11
|
-
|
|
12
|
-
/** Build an adapter whose fetch is a spy returning the given Response. */
|
|
13
|
-
function makeDS(fetchImpl: any) {
|
|
14
|
-
const ds: any = new ObjectStackAdapter({ baseUrl: 'http://test.local', fetch: fetchImpl });
|
|
15
|
-
ds.connected = true;
|
|
16
|
-
ds.connectionState = 'connected';
|
|
17
|
-
return ds;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function csvResponse(body = 'ID,Name\n1,Acme') {
|
|
21
|
-
return new Response(body, { status: 200, headers: { 'Content-Type': 'text/csv' } });
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
describe('ObjectStackAdapter.exportDownload', () => {
|
|
25
|
-
it('GETs the /export route with format, fields, orderby, header and limit', async () => {
|
|
26
|
-
// Typed like `fetch` so `fetchImpl.mock.calls[0]` is `[url, init]` rather
|
|
27
|
-
// than an empty tuple (the zero-arg impl would otherwise infer `never`).
|
|
28
|
-
const fetchImpl = vi.fn(async (_url: string, _init: RequestInit) => csvResponse());
|
|
29
|
-
const ds = makeDS(fetchImpl);
|
|
30
|
-
|
|
31
|
-
const blob = await ds.exportDownload('task', {
|
|
32
|
-
format: 'xlsx',
|
|
33
|
-
fields: ['title', 'owner'],
|
|
34
|
-
sort: [{ field: 'title', direction: 'desc' }, { field: 'owner' }],
|
|
35
|
-
includeHeaders: false,
|
|
36
|
-
limit: 5000,
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
expect(blob).toBeInstanceOf(Blob);
|
|
40
|
-
expect(fetchImpl).toHaveBeenCalledTimes(1);
|
|
41
|
-
const [url, init] = fetchImpl.mock.calls[0];
|
|
42
|
-
const parsed = new URL(url);
|
|
43
|
-
expect(parsed.pathname).toBe('/api/v1/data/task/export');
|
|
44
|
-
expect(parsed.searchParams.get('format')).toBe('xlsx');
|
|
45
|
-
expect(parsed.searchParams.get('fields')).toBe('title,owner');
|
|
46
|
-
// direction defaults to asc when omitted.
|
|
47
|
-
expect(parsed.searchParams.get('orderby')).toBe('title:desc,owner:asc');
|
|
48
|
-
expect(parsed.searchParams.get('header')).toBe('false');
|
|
49
|
-
expect(parsed.searchParams.get('limit')).toBe('5000');
|
|
50
|
-
expect(init.method).toBe('GET');
|
|
51
|
-
expect(init.credentials).toBe('include');
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('defaults to csv and omits optional params when not provided', async () => {
|
|
55
|
-
// Typed like `fetch` so `fetchImpl.mock.calls[0]` is `[url, init]` rather
|
|
56
|
-
// than an empty tuple (the zero-arg impl would otherwise infer `never`).
|
|
57
|
-
const fetchImpl = vi.fn(async (_url: string, _init: RequestInit) => csvResponse());
|
|
58
|
-
const ds = makeDS(fetchImpl);
|
|
59
|
-
|
|
60
|
-
await ds.exportDownload('task', {});
|
|
61
|
-
|
|
62
|
-
const [url] = fetchImpl.mock.calls[0];
|
|
63
|
-
const parsed = new URL(url);
|
|
64
|
-
expect(parsed.searchParams.get('format')).toBe('csv');
|
|
65
|
-
expect(parsed.searchParams.get('fields')).toBeNull();
|
|
66
|
-
expect(parsed.searchParams.get('orderby')).toBeNull();
|
|
67
|
-
expect(parsed.searchParams.get('header')).toBeNull();
|
|
68
|
-
expect(parsed.searchParams.get('limit')).toBeNull();
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('serializes the filter to a JSON AST query param', async () => {
|
|
72
|
-
// Typed like `fetch` so `fetchImpl.mock.calls[0]` is `[url, init]` rather
|
|
73
|
-
// than an empty tuple (the zero-arg impl would otherwise infer `never`).
|
|
74
|
-
const fetchImpl = vi.fn(async (_url: string, _init: RequestInit) => csvResponse());
|
|
75
|
-
const ds = makeDS(fetchImpl);
|
|
76
|
-
|
|
77
|
-
await ds.exportDownload('task', { filter: [['status', '=', 'open']] });
|
|
78
|
-
|
|
79
|
-
const [url] = fetchImpl.mock.calls[0];
|
|
80
|
-
const raw = new URL(url).searchParams.get('filter');
|
|
81
|
-
expect(raw).toBeTruthy();
|
|
82
|
-
expect(JSON.parse(raw!)).toEqual([['status', '=', 'open']]);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('throws an error carrying the server message and status on failure', async () => {
|
|
86
|
-
const fetchImpl = vi.fn(async () =>
|
|
87
|
-
new Response(JSON.stringify({ error: { message: 'Permission denied' } }), {
|
|
88
|
-
status: 403,
|
|
89
|
-
headers: { 'Content-Type': 'application/json' },
|
|
90
|
-
}),
|
|
91
|
-
);
|
|
92
|
-
const ds = makeDS(fetchImpl);
|
|
93
|
-
|
|
94
|
-
await expect(ds.exportDownload('task', { format: 'csv' })).rejects.toMatchObject({
|
|
95
|
-
message: 'Permission denied',
|
|
96
|
-
status: 403,
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* `search` — the half of a list this request could not carry.
|
|
103
|
-
*
|
|
104
|
-
* The route mirrored `filter` and `orderby` only, so an export taken while a
|
|
105
|
-
* search was active downloaded the UNSEARCHED superset: more rows than the
|
|
106
|
-
* screen showed, in a file that looks authoritative. Server half:
|
|
107
|
-
* objectstack#4230.
|
|
108
|
-
*/
|
|
109
|
-
describe('ObjectStackAdapter.exportDownload — search', () => {
|
|
110
|
-
const paramsFor = async (request: Record<string, unknown>) => {
|
|
111
|
-
const fetchImpl = vi.fn(async (_url: string, _init: RequestInit) => csvResponse());
|
|
112
|
-
await makeDS(fetchImpl).exportDownload('task', request);
|
|
113
|
-
return new URL(fetchImpl.mock.calls[0][0]).searchParams;
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
it('sends the term as `search`', async () => {
|
|
117
|
-
expect((await paramsFor({ search: 'acme' })).get('search')).toBe('acme');
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it('sends `searchFields` as a comma list alongside the term', async () => {
|
|
121
|
-
const p = await paramsFor({ search: 'acme', searchFields: ['name', 'stage'] });
|
|
122
|
-
expect(p.get('searchFields')).toBe('name,stage');
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it('omits both when no term is given — `searchFields` alone means nothing', async () => {
|
|
126
|
-
const p = await paramsFor({ searchFields: ['name'] });
|
|
127
|
-
expect(p.get('search')).toBeNull();
|
|
128
|
-
expect(p.get('searchFields')).toBeNull();
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it('treats a whitespace-only term as absent, and trims a real one', async () => {
|
|
132
|
-
expect((await paramsFor({ search: ' ' })).get('search')).toBeNull();
|
|
133
|
-
expect((await paramsFor({ search: ' acme ' })).get('search')).toBe('acme');
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it('carries search and filter together — neither replaces the other', async () => {
|
|
137
|
-
const p = await paramsFor({ search: 'acme', filter: [['status', '=', 'open']] });
|
|
138
|
-
expect(p.get('search')).toBe('acme');
|
|
139
|
-
expect(JSON.parse(p.get('filter')!)).toEqual([['status', '=', 'open']]);
|
|
140
|
-
});
|
|
141
|
-
});
|