quickbase-js 0.1.0-beta.9 → 1.0.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.
Files changed (146) hide show
  1. package/README.md +270 -60
  2. package/dist/esm/quickbase.d.ts +2553 -3220
  3. package/dist/esm/quickbase.js +1545 -3443
  4. package/dist/esm/quickbase.js.map +1 -1
  5. package/dist/esm/quickbase.min.js +1 -1
  6. package/dist/esm/quickbase.min.js.map +1 -1
  7. package/dist/umd/quickbase.umd.js +1544 -3625
  8. package/dist/umd/quickbase.umd.js.map +1 -1
  9. package/dist/umd/quickbase.umd.min.js +1 -1
  10. package/dist/umd/quickbase.umd.min.js.map +1 -1
  11. package/package.json +25 -12
  12. package/CHANGELOG.md +0 -184
  13. package/build-common.js +0 -131
  14. package/build-esm.js +0 -71
  15. package/build-umd.js +0 -69
  16. package/examples/quicbase-jsCDN.html +0 -36
  17. package/examples/react.js +0 -48
  18. package/examples/vanillajs.html +0 -47
  19. package/open-api/fix-spec-main.ts +0 -97
  20. package/open-api/generate-override-report.ts +0 -214
  21. package/open-api/generate-unified-interface.ts +0 -336
  22. package/open-api/output/override-report.html +0 -11
  23. package/open-api/output/override-report.json +0 -14395
  24. package/open-api/output/quickbase-fixed.json +0 -11191
  25. package/open-api/regenerate-client.ts +0 -116
  26. package/open-api/schema/enhance-general.ts +0 -100
  27. package/open-api/schema/fix-arrays.ts +0 -69
  28. package/open-api/schema/tags/apps.ts +0 -90
  29. package/open-api/schema/tags/fields.ts +0 -471
  30. package/open-api/schema/tags/groups.ts +0 -51
  31. package/open-api/schema/tags/index.ts +0 -66
  32. package/open-api/schema/tags/records.ts +0 -115
  33. package/open-api/schema/tags/tables.ts +0 -211
  34. package/open-api/schema/tags/users.ts +0 -47
  35. package/open-api/types/spec.ts +0 -42
  36. package/open-api/utils/generateJsDoc.ts +0 -96
  37. package/open-api/utils/infer-schema.ts +0 -40
  38. package/open-api/utils/naming.ts +0 -10
  39. package/playwright.config.ts +0 -37
  40. package/rollup.config.js +0 -114
  41. package/specs/QuickBase_RESTful_API_2025-03-04T06_22_39.725Z.json +0 -46878
  42. package/specs/split/apps.json +0 -1315
  43. package/specs/split/auth.json +0 -191
  44. package/specs/split/fields.json +0 -3869
  45. package/specs/split/records.json +0 -754
  46. package/specs/split/reports.json +0 -619
  47. package/specs/split/tables.json +0 -1605
  48. package/src/RateLimitError.ts +0 -12
  49. package/src/ThrottleBucket.ts +0 -41
  50. package/src/authorizationStrategy.ts +0 -246
  51. package/src/generated-unified/QuickbaseClient.ts +0 -1049
  52. package/src/generated-unified/missing-types-report.json +0 -3
  53. package/src/index.ts +0 -1
  54. package/src/invokeMethod.ts +0 -242
  55. package/src/quickbaseClient.ts +0 -271
  56. package/src/rateLimiter.ts +0 -25
  57. package/src/tokenCache.ts +0 -35
  58. package/src/utils.ts +0 -7
  59. package/test-esm.js +0 -1
  60. package/test-results.json +0 -2050
  61. package/test-umd.js +0 -1
  62. package/test.ts +0 -1
  63. package/tests/playwright/qb/auth/cacheSwitching.test.ts +0 -159
  64. package/tests/playwright/qb/auth/fetchTempToken401.test.ts +0 -219
  65. package/tests/playwright/qb/auth/getAppWithTempToken.test.ts +0 -162
  66. package/tests/playwright/qb/auth/getAppWithUserToken.test.ts +0 -153
  67. package/tests/playwright/qb/auth/getTempToken.test.ts +0 -152
  68. package/tests/playwright/qb/auth/tempTokenPrefetch.test.ts +0 -179
  69. package/tests/playwright/qb/auth/tempTokenRenewal.test.ts +0 -133
  70. package/tests/setup.ts +0 -53
  71. package/tests/vitest/qb/apps/copyApp.test.ts +0 -76
  72. package/tests/vitest/qb/apps/createApp.test.ts +0 -64
  73. package/tests/vitest/qb/apps/deleteApp.test.ts +0 -76
  74. package/tests/vitest/qb/apps/getApp.test.ts +0 -44
  75. package/tests/vitest/qb/apps/getAppEvents.test.ts +0 -67
  76. package/tests/vitest/qb/apps/updateApp.test.ts +0 -58
  77. package/tests/vitest/qb/auth/mockQuickbaseServer.ts +0 -60
  78. package/tests/vitest/qb/auth/retryUserToken401.test.ts +0 -73
  79. package/tests/vitest/qb/auth/ssoTokenIntegrationWithServer.test.ts +0 -65
  80. package/tests/vitest/qb/fields/createField.test.ts +0 -77
  81. package/tests/vitest/qb/fields/deleteFields.test.ts +0 -83
  82. package/tests/vitest/qb/fields/getField.test.ts +0 -85
  83. package/tests/vitest/qb/fields/getFieldUsage.test.ts +0 -82
  84. package/tests/vitest/qb/fields/getFields.test.ts +0 -232
  85. package/tests/vitest/qb/fields/getFieldsUsage.test.ts +0 -77
  86. package/tests/vitest/qb/fields/updateField.test.ts +0 -93
  87. package/tests/vitest/qb/formulas/runFormula.test.ts +0 -96
  88. package/tests/vitest/qb/index.ts +0 -29
  89. package/tests/vitest/qb/records/deleteRecords.test.ts +0 -110
  90. package/tests/vitest/qb/records/runQuery.test.ts +0 -146
  91. package/tests/vitest/qb/records/upsert.test.ts +0 -102
  92. package/tests/vitest/qb/tables/createRelationship.test.ts +0 -102
  93. package/tests/vitest/qb/tables/createTable.test.ts +0 -55
  94. package/tests/vitest/qb/tables/deleteRelationship.test.ts +0 -143
  95. package/tests/vitest/qb/tables/deleteTable.test.ts +0 -50
  96. package/tests/vitest/qb/tables/getAppTables.test.ts +0 -46
  97. package/tests/vitest/qb/tables/getRelationships.test.ts +0 -80
  98. package/tests/vitest/qb/tables/getTable.test.ts +0 -26
  99. package/tests/vitest/qb/tables/updateRelationship.test.ts +0 -250
  100. package/tests/vitest/qb/tables/updateTable.test.ts +0 -48
  101. package/tests/vitest/unit/ThrottleBucket.test.ts +0 -95
  102. package/tests/vitest/unit/apps/copyApp.test.ts +0 -581
  103. package/tests/vitest/unit/apps/createApp.test.ts +0 -186
  104. package/tests/vitest/unit/apps/deleteApp.test.ts +0 -216
  105. package/tests/vitest/unit/apps/getApp.test.ts +0 -128
  106. package/tests/vitest/unit/apps/getAppEvents.test.ts +0 -193
  107. package/tests/vitest/unit/apps/updateApp.test.ts +0 -412
  108. package/tests/vitest/unit/auth/fetchTempToken401.test.ts +0 -63
  109. package/tests/vitest/unit/auth/getTempToken.test.ts +0 -119
  110. package/tests/vitest/unit/auth/retryTempToken401.test.ts +0 -95
  111. package/tests/vitest/unit/auth/retryTempTokenMaxRetries.test.ts +0 -235
  112. package/tests/vitest/unit/auth/retryUserToken401.test.ts +0 -69
  113. package/tests/vitest/unit/auth/ssoTokenRefresh.test.ts +0 -325
  114. package/tests/vitest/unit/fields/createField.test.ts +0 -451
  115. package/tests/vitest/unit/fields/deleteFields.test.ts +0 -141
  116. package/tests/vitest/unit/fields/getField.test.ts +0 -189
  117. package/tests/vitest/unit/fields/getFieldUsage.test.ts +0 -180
  118. package/tests/vitest/unit/fields/getFields.test.ts +0 -122
  119. package/tests/vitest/unit/fields/getFieldsUsage.test.ts +0 -160
  120. package/tests/vitest/unit/fields/updateField.test.ts +0 -285
  121. package/tests/vitest/unit/formulas/runFormula.test.ts +0 -205
  122. package/tests/vitest/unit/index.ts +0 -34
  123. package/tests/vitest/unit/inferHttpMethod.test.ts +0 -131
  124. package/tests/vitest/unit/rateLimit.test.ts +0 -191
  125. package/tests/vitest/unit/records/deleteRecords.test.ts +0 -112
  126. package/tests/vitest/unit/records/runQuery.test.ts +0 -102
  127. package/tests/vitest/unit/records/upsert.test.ts +0 -234
  128. package/tests/vitest/unit/tables/createRelationship.test.ts +0 -212
  129. package/tests/vitest/unit/tables/createTable.test.ts +0 -70
  130. package/tests/vitest/unit/tables/deleteRelationship.test.ts +0 -97
  131. package/tests/vitest/unit/tables/deleteTable.test.ts +0 -77
  132. package/tests/vitest/unit/tables/getAppTables.test.ts +0 -85
  133. package/tests/vitest/unit/tables/getRelationships.test.ts +0 -259
  134. package/tests/vitest/unit/tables/getTable.test.ts +0 -233
  135. package/tests/vitest/unit/tables/updateRelationship.test.ts +0 -307
  136. package/tests/vitest/unit/tables/updateTable.test.ts +0 -80
  137. package/tests/vitest/unit/tokenLifespan.test.ts +0 -204
  138. package/tests/vitest/unit/umd.test.ts +0 -8
  139. package/text.txt +0 -104
  140. package/tools/log-gen.ts +0 -244
  141. package/tools/log-gen.yaml +0 -5424
  142. package/tools/openapi-jars/openapi-generator-cli-7.12.0.jar +0 -0
  143. package/tsconfig.build.json +0 -17
  144. package/tsconfig.json +0 -32
  145. package/versionrc.json +0 -9
  146. package/vitest.config.ts +0 -27
@@ -1,451 +0,0 @@
1
- import { describe, it, expect, beforeEach, vi } from "vitest";
2
- import {
3
- createClient,
4
- mockFetch,
5
- QB_TABLE_ID_1,
6
- QB_REALM,
7
- QB_USER_TOKEN,
8
- } from "@tests/setup.ts";
9
- import { CreateFieldRequest } from "@/generated/models";
10
-
11
- describe("QuickbaseClient Unit - createField", () => {
12
- let client: ReturnType<typeof createClient>;
13
-
14
- beforeEach(() => {
15
- mockFetch.mockClear();
16
- });
17
-
18
- it("initializes without errors and has createField method", () => {
19
- client = createClient(mockFetch, { debug: true });
20
- expect(client).toBeDefined();
21
- expect(typeof client.createField).toBe("function");
22
- });
23
-
24
- it("creates field successfully with user token", async () => {
25
- client = createClient(mockFetch, { debug: true });
26
-
27
- const request: CreateFieldRequest = {
28
- label: "NewField",
29
- fieldType: "text",
30
- };
31
-
32
- const mockResponse = {
33
- id: 101,
34
- label: "NewField",
35
- fieldType: "text",
36
- appearsByDefault: true,
37
- audited: false,
38
- bold: false,
39
- doesDataCopy: false,
40
- fieldHelp: "",
41
- findEnabled: true,
42
- mode: "",
43
- noWrap: false,
44
- permissions: [],
45
- properties: {
46
- allowHTML: false,
47
- allowMentions: false,
48
- allowNewChoices: false,
49
- appendOnly: false,
50
- carryChoices: true,
51
- defaultValue: "",
52
- foreignKey: false,
53
- formula: "",
54
- maxLength: 0,
55
- numLines: 1,
56
- primaryKey: false,
57
- sortAsGiven: false,
58
- },
59
- required: false,
60
- unique: false,
61
- };
62
-
63
- mockFetch.mockResolvedValueOnce({
64
- ok: true,
65
- status: 200,
66
- json: () => Promise.resolve(mockResponse),
67
- });
68
-
69
- const result = await client.createField({
70
- tableId: QB_TABLE_ID_1,
71
- body: request,
72
- });
73
-
74
- expect(result).toEqual(mockResponse);
75
- expect(mockFetch).toHaveBeenCalledWith(
76
- `https://api.quickbase.com/v1/fields?tableId=${QB_TABLE_ID_1}`,
77
- {
78
- method: "POST",
79
- body: JSON.stringify(request),
80
- headers: {
81
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
82
- Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
83
- "Content-Type": "application/json",
84
- },
85
- credentials: "omit",
86
- }
87
- );
88
- });
89
-
90
- it("creates field successfully with temp token", async () => {
91
- client = createClient(mockFetch, { useTempTokens: true, debug: true });
92
-
93
- const request: CreateFieldRequest = {
94
- label: "TempField",
95
- fieldType: "numeric",
96
- addToForms: false,
97
- };
98
-
99
- const mockResponse = {
100
- id: 102,
101
- label: "TempField",
102
- fieldType: "numeric",
103
- appearsByDefault: false,
104
- audited: false,
105
- bold: false,
106
- doesDataCopy: false,
107
- fieldHelp: "",
108
- findEnabled: true,
109
- mode: "",
110
- noWrap: false,
111
- permissions: [],
112
- properties: {
113
- allowHTML: false,
114
- allowMentions: false,
115
- allowNewChoices: false,
116
- appendOnly: false,
117
- carryChoices: true,
118
- defaultValue: "",
119
- foreignKey: false,
120
- formula: "",
121
- maxLength: 0,
122
- numLines: 1,
123
- primaryKey: false,
124
- sortAsGiven: false,
125
- },
126
- required: false,
127
- unique: false,
128
- };
129
-
130
- mockFetch
131
- .mockResolvedValueOnce({
132
- ok: true,
133
- status: 200,
134
- json: () => Promise.resolve({ temporaryAuthorization: "temp_token" }),
135
- })
136
- .mockResolvedValueOnce({
137
- ok: true,
138
- status: 200,
139
- json: () => Promise.resolve(mockResponse),
140
- });
141
-
142
- const result = await client.createField({
143
- tableId: QB_TABLE_ID_1,
144
- body: request,
145
- });
146
-
147
- expect(result).toEqual(mockResponse);
148
- expect(mockFetch).toHaveBeenCalledTimes(2);
149
- expect(mockFetch).toHaveBeenNthCalledWith(
150
- 1,
151
- `https://api.quickbase.com/v1/auth/temporary/${QB_TABLE_ID_1}`,
152
- expect.any(Object)
153
- );
154
- expect(mockFetch).toHaveBeenNthCalledWith(
155
- 2,
156
- `https://api.quickbase.com/v1/fields?tableId=${QB_TABLE_ID_1}`,
157
- {
158
- method: "POST",
159
- body: JSON.stringify(request),
160
- headers: {
161
- Authorization: "QB-TEMP-TOKEN temp_token",
162
- "Content-Type": "application/json",
163
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
164
- },
165
- credentials: "omit",
166
- }
167
- );
168
- });
169
-
170
- it("retries successfully after 401 with temp token", async () => {
171
- client = createClient(mockFetch, { useTempTokens: true, debug: true });
172
-
173
- const request: CreateFieldRequest = {
174
- label: "RetryField",
175
- fieldType: "checkbox",
176
- };
177
-
178
- const mockResponse = {
179
- id: 102,
180
- label: "RetryField",
181
- fieldType: "checkbox",
182
- appearsByDefault: true,
183
- audited: false,
184
- bold: false,
185
- doesDataCopy: false,
186
- fieldHelp: "",
187
- findEnabled: true,
188
- mode: "",
189
- noWrap: false,
190
- permissions: [],
191
- properties: {
192
- allowHTML: false,
193
- allowMentions: false,
194
- allowNewChoices: false,
195
- appendOnly: false,
196
- carryChoices: true,
197
- defaultValue: "",
198
- foreignKey: false,
199
- formula: "",
200
- maxLength: 0,
201
- numLines: 1,
202
- primaryKey: false,
203
- sortAsGiven: false,
204
- },
205
- required: false,
206
- unique: false,
207
- };
208
-
209
- mockFetch
210
- .mockResolvedValueOnce({
211
- ok: true,
212
- status: 200,
213
- json: () =>
214
- Promise.resolve({ temporaryAuthorization: "initial_token" }),
215
- })
216
- .mockResolvedValueOnce({
217
- ok: false,
218
- status: 401,
219
- json: () => Promise.resolve({ message: "Unauthorized" }),
220
- text: () => Promise.resolve("Unauthorized"),
221
- })
222
- .mockResolvedValueOnce({
223
- ok: true,
224
- status: 200,
225
- json: () => Promise.resolve({ temporaryAuthorization: "new_token" }),
226
- })
227
- .mockResolvedValueOnce({
228
- ok: true,
229
- status: 200,
230
- json: () => Promise.resolve(mockResponse),
231
- });
232
-
233
- const consoleSpy = vi.spyOn(console, "log");
234
- const result = await client.createField({
235
- tableId: QB_TABLE_ID_1,
236
- body: request,
237
- });
238
-
239
- expect(result).toEqual(mockResponse);
240
- expect(mockFetch).toHaveBeenCalledTimes(4);
241
- expect(mockFetch).toHaveBeenNthCalledWith(
242
- 1,
243
- `https://api.quickbase.com/v1/auth/temporary/${QB_TABLE_ID_1}`,
244
- expect.any(Object)
245
- );
246
- expect(mockFetch).toHaveBeenNthCalledWith(
247
- 2,
248
- `https://api.quickbase.com/v1/fields?tableId=${QB_TABLE_ID_1}`,
249
- {
250
- method: "POST",
251
- body: JSON.stringify(request),
252
- headers: {
253
- Authorization: "QB-TEMP-TOKEN initial_token",
254
- "Content-Type": "application/json",
255
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
256
- },
257
- credentials: "omit",
258
- }
259
- );
260
- expect(mockFetch).toHaveBeenNthCalledWith(
261
- 3,
262
- `https://api.quickbase.com/v1/auth/temporary/${QB_TABLE_ID_1}`,
263
- expect.any(Object)
264
- );
265
- expect(mockFetch).toHaveBeenNthCalledWith(
266
- 4,
267
- `https://api.quickbase.com/v1/fields?tableId=${QB_TABLE_ID_1}`,
268
- {
269
- method: "POST",
270
- body: JSON.stringify(request),
271
- headers: {
272
- Authorization: "QB-TEMP-TOKEN new_token",
273
- "Content-Type": "application/json",
274
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
275
- },
276
- credentials: "omit",
277
- }
278
- );
279
- expect(consoleSpy).toHaveBeenCalledWith(
280
- "Authorization error for createField (temp token), refreshing token:"
281
- );
282
- expect(consoleSpy).toHaveBeenCalledWith(
283
- "[createField] Retrying with token: new_token..."
284
- );
285
- consoleSpy.mockRestore();
286
- });
287
-
288
- it("handles 400 error for invalid request", async () => {
289
- client = createClient(mockFetch, { debug: true });
290
-
291
- const request: CreateFieldRequest = {
292
- label: "", // Invalid: empty label
293
- fieldType: "text",
294
- };
295
-
296
- mockFetch.mockResolvedValueOnce({
297
- ok: false,
298
- status: 400,
299
- json: () => Promise.resolve({ message: "Label is required" }),
300
- text: () => Promise.resolve("Label is required"),
301
- });
302
-
303
- await expect(
304
- client.createField({ tableId: QB_TABLE_ID_1, body: request })
305
- ).rejects.toThrow("API Error: Label is required (Status: 400)");
306
-
307
- expect(mockFetch).toHaveBeenCalledWith(
308
- `https://api.quickbase.com/v1/fields?tableId=${QB_TABLE_ID_1}`,
309
- {
310
- method: "POST",
311
- body: JSON.stringify(request),
312
- headers: {
313
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
314
- Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
315
- "Content-Type": "application/json",
316
- },
317
- credentials: "omit",
318
- }
319
- );
320
- });
321
-
322
- it("handles 401 with failed temp token retry", async () => {
323
- client = createClient(mockFetch, { useTempTokens: true, debug: true });
324
-
325
- const request: CreateFieldRequest = {
326
- label: "FailField",
327
- fieldType: "text",
328
- };
329
-
330
- mockFetch
331
- .mockResolvedValueOnce({
332
- ok: true,
333
- status: 200,
334
- json: () =>
335
- Promise.resolve({ temporaryAuthorization: "initial_token" }),
336
- })
337
- .mockResolvedValueOnce({
338
- ok: false,
339
- status: 401,
340
- json: () => Promise.resolve({ message: "Unauthorized" }),
341
- text: () => Promise.resolve("Unauthorized"),
342
- })
343
- .mockResolvedValueOnce({
344
- ok: true,
345
- status: 200,
346
- json: () => Promise.resolve({ temporaryAuthorization: "token_2" }),
347
- })
348
- .mockResolvedValueOnce({
349
- ok: false,
350
- status: 401,
351
- json: () => Promise.resolve({ message: "Unauthorized again" }),
352
- text: () => Promise.resolve("Unauthorized again"),
353
- })
354
- .mockResolvedValueOnce({
355
- ok: true,
356
- status: 200,
357
- json: () => Promise.resolve({ temporaryAuthorization: "token_3" }),
358
- })
359
- .mockResolvedValueOnce({
360
- ok: false,
361
- status: 401,
362
- json: () => Promise.resolve({ message: "Unauthorized again" }),
363
- text: () => Promise.resolve("Unauthorized again"),
364
- })
365
- .mockResolvedValueOnce({
366
- ok: true,
367
- status: 200,
368
- json: () => Promise.resolve({ temporaryAuthorization: "token_4" }),
369
- })
370
- .mockResolvedValueOnce({
371
- ok: false,
372
- status: 401,
373
- json: () => Promise.resolve({ message: "Unauthorized again" }),
374
- text: () => Promise.resolve("Unauthorized again"),
375
- });
376
-
377
- const consoleSpy = vi.spyOn(console, "log");
378
-
379
- await expect(
380
- client.createField({ tableId: QB_TABLE_ID_1, body: request })
381
- ).rejects.toThrow("API Error: Unauthorized again (Status: 401)");
382
-
383
- expect(mockFetch).toHaveBeenCalledTimes(8);
384
- expect(mockFetch).toHaveBeenNthCalledWith(
385
- 1,
386
- `https://api.quickbase.com/v1/auth/temporary/${QB_TABLE_ID_1}`,
387
- expect.any(Object)
388
- );
389
- expect(mockFetch).toHaveBeenNthCalledWith(
390
- 2,
391
- `https://api.quickbase.com/v1/fields?tableId=${QB_TABLE_ID_1}`,
392
- expect.objectContaining({
393
- method: "POST",
394
- headers: expect.objectContaining({
395
- Authorization: "QB-TEMP-TOKEN initial_token",
396
- }),
397
- })
398
- );
399
- expect(mockFetch).toHaveBeenNthCalledWith(
400
- 3,
401
- `https://api.quickbase.com/v1/auth/temporary/${QB_TABLE_ID_1}`,
402
- expect.any(Object)
403
- );
404
- expect(mockFetch).toHaveBeenNthCalledWith(
405
- 4,
406
- `https://api.quickbase.com/v1/fields?tableId=${QB_TABLE_ID_1}`,
407
- expect.objectContaining({
408
- method: "POST",
409
- headers: expect.objectContaining({
410
- Authorization: "QB-TEMP-TOKEN token_2",
411
- }),
412
- })
413
- );
414
- expect(mockFetch).toHaveBeenNthCalledWith(
415
- 5,
416
- `https://api.quickbase.com/v1/auth/temporary/${QB_TABLE_ID_1}`,
417
- expect.any(Object)
418
- );
419
- expect(mockFetch).toHaveBeenNthCalledWith(
420
- 6,
421
- `https://api.quickbase.com/v1/fields?tableId=${QB_TABLE_ID_1}`,
422
- expect.objectContaining({
423
- method: "POST",
424
- headers: expect.objectContaining({
425
- Authorization: "QB-TEMP-TOKEN token_3",
426
- }),
427
- })
428
- );
429
- expect(mockFetch).toHaveBeenNthCalledWith(
430
- 7,
431
- `https://api.quickbase.com/v1/auth/temporary/${QB_TABLE_ID_1}`,
432
- expect.any(Object)
433
- );
434
- expect(mockFetch).toHaveBeenNthCalledWith(
435
- 8,
436
- `https://api.quickbase.com/v1/fields?tableId=${QB_TABLE_ID_1}`,
437
- expect.objectContaining({
438
- method: "POST",
439
- headers: expect.objectContaining({
440
- Authorization: "QB-TEMP-TOKEN token_4",
441
- }),
442
- })
443
- );
444
-
445
- expect(consoleSpy).toHaveBeenCalledWith(
446
- "Authorization error for createField (temp token), refreshing token:"
447
- );
448
-
449
- consoleSpy.mockRestore();
450
- });
451
- });
@@ -1,141 +0,0 @@
1
- // tests/vitest/unit/fields/deleteFields.test.ts
2
- import { describe, it, expect, beforeEach } from "vitest";
3
- import {
4
- createClient,
5
- mockFetch,
6
- QB_REALM,
7
- QB_USER_TOKEN,
8
- QB_TABLE_ID_1,
9
- } from "@tests/setup.ts";
10
- import {
11
- DeleteFieldsRequest,
12
- DeleteFields200Response,
13
- } from "@/generated/models";
14
-
15
- describe("QuickbaseClient Unit - deleteFields", () => {
16
- let client: ReturnType<typeof createClient>;
17
-
18
- beforeEach(() => {
19
- mockFetch.mockClear();
20
- });
21
-
22
- it("initializes without errors and has deleteFields method", () => {
23
- client = createClient(mockFetch, { debug: true });
24
- expect(client).toBeDefined();
25
- expect(typeof client.deleteFields).toBe("function");
26
- });
27
-
28
- it("deletes fields successfully with user token", async () => {
29
- client = createClient(mockFetch, { debug: true });
30
-
31
- const request: DeleteFieldsRequest = {
32
- fieldIds: [6, 7, 8],
33
- };
34
-
35
- const mockResponse: DeleteFields200Response = {
36
- deletedFieldIds: [6, 7, 8],
37
- errors: [],
38
- };
39
-
40
- mockFetch.mockResolvedValueOnce({
41
- ok: true,
42
- status: 200,
43
- json: () => Promise.resolve(mockResponse),
44
- });
45
-
46
- const result = await client.deleteFields({
47
- tableId: QB_TABLE_ID_1,
48
- body: request,
49
- });
50
-
51
- expect(result).toEqual(mockResponse);
52
- expect(mockFetch).toHaveBeenCalledWith(
53
- `https://api.quickbase.com/v1/fields?tableId=${QB_TABLE_ID_1}`,
54
- expect.objectContaining({
55
- method: "DELETE",
56
- headers: expect.objectContaining({
57
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
58
- Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
59
- "Content-Type": "application/json",
60
- }),
61
- body: JSON.stringify(request),
62
- credentials: "omit",
63
- })
64
- );
65
- });
66
-
67
- it("handles partial success with errors", async () => {
68
- client = createClient(mockFetch, { debug: true });
69
-
70
- const request: DeleteFieldsRequest = {
71
- fieldIds: [6, 7, 8],
72
- };
73
-
74
- const mockResponse: DeleteFields200Response = {
75
- deletedFieldIds: [6, 8],
76
- errors: ["Error found with fid: 7"],
77
- };
78
-
79
- mockFetch.mockResolvedValueOnce({
80
- ok: true,
81
- status: 200,
82
- json: () => Promise.resolve(mockResponse),
83
- });
84
-
85
- const result = await client.deleteFields({
86
- tableId: QB_TABLE_ID_1,
87
- body: request,
88
- });
89
-
90
- expect(result).toEqual(mockResponse);
91
- expect(mockFetch).toHaveBeenCalledWith(
92
- `https://api.quickbase.com/v1/fields?tableId=${QB_TABLE_ID_1}`,
93
- expect.objectContaining({
94
- method: "DELETE",
95
- headers: expect.objectContaining({
96
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
97
- Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
98
- "Content-Type": "application/json",
99
- }),
100
- body: JSON.stringify(request),
101
- credentials: "omit",
102
- })
103
- );
104
- });
105
-
106
- it("handles 400 error for invalid request", async () => {
107
- client = createClient(mockFetch, { debug: true });
108
-
109
- const request: DeleteFieldsRequest = {
110
- fieldIds: [], // Invalid: empty fieldIds array
111
- };
112
-
113
- mockFetch.mockResolvedValueOnce({
114
- ok: false,
115
- status: 400,
116
- json: () =>
117
- Promise.resolve({
118
- message: "Invalid input",
119
- description: "Field IDs list cannot be empty.",
120
- }),
121
- });
122
-
123
- await expect(
124
- client.deleteFields({ tableId: QB_TABLE_ID_1, body: request })
125
- ).rejects.toThrow("API Error: Invalid input (Status: 400)");
126
-
127
- expect(mockFetch).toHaveBeenCalledWith(
128
- `https://api.quickbase.com/v1/fields?tableId=${QB_TABLE_ID_1}`,
129
- expect.objectContaining({
130
- method: "DELETE",
131
- headers: expect.objectContaining({
132
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
133
- Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
134
- "Content-Type": "application/json",
135
- }),
136
- body: JSON.stringify(request),
137
- credentials: "omit",
138
- })
139
- );
140
- });
141
- });