quickbase-js 0.1.0-beta.8 → 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 (132) hide show
  1. package/README.md +252 -126
  2. package/dist/esm/quickbase.d.ts +2725 -2689
  3. package/dist/esm/quickbase.js +1763 -3524
  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 +1762 -3706
  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 +27 -12
  12. package/CHANGELOG.md +0 -155
  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 -256
  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/infer-schema.ts +0 -40
  37. package/open-api/utils/naming.ts +0 -10
  38. package/playwright.config.ts +0 -37
  39. package/rollup.config.js +0 -114
  40. package/specs/QuickBase_RESTful_API_2025-03-04T06_22_39.725Z.json +0 -46878
  41. package/specs/split/apps.json +0 -1315
  42. package/specs/split/auth.json +0 -191
  43. package/specs/split/fields.json +0 -3869
  44. package/specs/split/records.json +0 -754
  45. package/specs/split/reports.json +0 -619
  46. package/specs/split/tables.json +0 -1605
  47. package/src/RateLimitError.ts +0 -12
  48. package/src/ThrottleBucket.ts +0 -36
  49. package/src/generated-unified/QuickbaseClient.ts +0 -359
  50. package/src/generated-unified/missing-types-report.json +0 -3
  51. package/src/index.ts +0 -1
  52. package/src/invokeMethod.ts +0 -357
  53. package/src/quickbaseClient.ts +0 -244
  54. package/src/tokenCache.ts +0 -51
  55. package/src/utils.ts +0 -7
  56. package/test-esm.js +0 -1
  57. package/test-results.json +0 -2050
  58. package/test-umd.js +0 -1
  59. package/test.ts +0 -1
  60. package/tests/playwright/qb/auth/cacheSwitching.test.ts +0 -159
  61. package/tests/playwright/qb/auth/fetchTempToken401.test.ts +0 -219
  62. package/tests/playwright/qb/auth/getAppWithTempToken.test.ts +0 -162
  63. package/tests/playwright/qb/auth/getAppWithUserToken.test.ts +0 -153
  64. package/tests/playwright/qb/auth/getTempToken.test.ts +0 -152
  65. package/tests/playwright/qb/auth/tempTokenPrefetch.test.ts +0 -179
  66. package/tests/playwright/qb/auth/tempTokenRenewal.test.ts +0 -133
  67. package/tests/setup.ts +0 -53
  68. package/tests/vitest/qb/apps/copyApp.test.ts +0 -76
  69. package/tests/vitest/qb/apps/createApp.test.ts +0 -64
  70. package/tests/vitest/qb/apps/deleteApp.test.ts +0 -76
  71. package/tests/vitest/qb/apps/getApp.test.ts +0 -44
  72. package/tests/vitest/qb/apps/getAppEvents.test.ts +0 -67
  73. package/tests/vitest/qb/apps/updateApp.test.ts +0 -58
  74. package/tests/vitest/qb/auth/retryUserToken401.test.ts +0 -56
  75. package/tests/vitest/qb/fields/createField.test.ts +0 -77
  76. package/tests/vitest/qb/fields/deleteFields.test.ts +0 -83
  77. package/tests/vitest/qb/fields/getField.test.ts +0 -85
  78. package/tests/vitest/qb/fields/getFieldUsage.test.ts +0 -174
  79. package/tests/vitest/qb/fields/getFields.test.ts +0 -232
  80. package/tests/vitest/qb/fields/getFieldsUsage.test.ts +0 -77
  81. package/tests/vitest/qb/fields/updateField.test.ts +0 -93
  82. package/tests/vitest/qb/index.ts +0 -29
  83. package/tests/vitest/qb/records/deleteRecords.test.ts +0 -110
  84. package/tests/vitest/qb/records/runQuery.test.ts +0 -146
  85. package/tests/vitest/qb/records/upsert.test.ts +0 -102
  86. package/tests/vitest/qb/tables/createTable.test.ts +0 -55
  87. package/tests/vitest/qb/tables/deleteTable.test.ts +0 -50
  88. package/tests/vitest/qb/tables/getAppTables.test.ts +0 -46
  89. package/tests/vitest/qb/tables/getRelationships.test.ts +0 -80
  90. package/tests/vitest/qb/tables/getTable.test.ts +0 -26
  91. package/tests/vitest/qb/tables/updateRelationship.test.ts +0 -277
  92. package/tests/vitest/qb/tables/updateTable.test.ts +0 -48
  93. package/tests/vitest/unit/apps/copyApp.test.ts +0 -488
  94. package/tests/vitest/unit/apps/createApp.test.ts +0 -186
  95. package/tests/vitest/unit/apps/deleteApp.test.ts +0 -216
  96. package/tests/vitest/unit/apps/getApp.test.ts +0 -128
  97. package/tests/vitest/unit/apps/getAppEvents.test.ts +0 -193
  98. package/tests/vitest/unit/apps/updateApp.test.ts +0 -381
  99. package/tests/vitest/unit/auth/fetchTempToken401.test.ts +0 -62
  100. package/tests/vitest/unit/auth/getTempToken.test.ts +0 -95
  101. package/tests/vitest/unit/auth/retryTempToken401.test.ts +0 -113
  102. package/tests/vitest/unit/auth/retryTempTokenTwo401.test.ts +0 -81
  103. package/tests/vitest/unit/auth/retryUserToken401.test.ts +0 -56
  104. package/tests/vitest/unit/fields/createField.test.ts +0 -387
  105. package/tests/vitest/unit/fields/deleteFields.test.ts +0 -141
  106. package/tests/vitest/unit/fields/getField.test.ts +0 -189
  107. package/tests/vitest/unit/fields/getFieldUsage.test.ts +0 -166
  108. package/tests/vitest/unit/fields/getFields.test.ts +0 -122
  109. package/tests/vitest/unit/fields/getFieldsUsage.test.ts +0 -160
  110. package/tests/vitest/unit/fields/updateField.test.ts +0 -280
  111. package/tests/vitest/unit/index.ts +0 -33
  112. package/tests/vitest/unit/rateLimit.test.ts +0 -189
  113. package/tests/vitest/unit/records/deleteRecords.test.ts +0 -112
  114. package/tests/vitest/unit/records/runQuery.test.ts +0 -102
  115. package/tests/vitest/unit/records/upsert.test.ts +0 -234
  116. package/tests/vitest/unit/tables/createTable.test.ts +0 -70
  117. package/tests/vitest/unit/tables/deleteTable.test.ts +0 -77
  118. package/tests/vitest/unit/tables/getAppTables.test.ts +0 -85
  119. package/tests/vitest/unit/tables/getRelationships.test.ts +0 -259
  120. package/tests/vitest/unit/tables/getTable.test.ts +0 -233
  121. package/tests/vitest/unit/tables/updateRelationship.test.ts +0 -305
  122. package/tests/vitest/unit/tables/updateTable.test.ts +0 -80
  123. package/tests/vitest/unit/tokenLifespan.test.ts +0 -138
  124. package/tests/vitest/unit/umd.test.ts +0 -8
  125. package/text.txt +0 -104
  126. package/tools/log-gen.ts +0 -235
  127. package/tools/log-gen.yaml +0 -4982
  128. package/tools/openapi-jars/openapi-generator-cli-7.12.0.jar +0 -0
  129. package/tsconfig.build.json +0 -17
  130. package/tsconfig.json +0 -32
  131. package/versionrc.json +0 -9
  132. package/vitest.config.ts +0 -27
@@ -1,488 +0,0 @@
1
- // tests/vitest/unit/apps/copyApp.test.ts
2
-
3
- import { describe, it, expect, beforeEach } from "vitest";
4
- import {
5
- createClient,
6
- mockFetch,
7
- QB_APP_ID,
8
- QB_REALM,
9
- QB_USER_TOKEN,
10
- } from "@tests/setup.ts";
11
- import { CopyAppRequest, CopyApp200Response } from "@/generated/models";
12
-
13
- describe("QuickbaseClient Unit - copyApp", () => {
14
- let client: ReturnType<typeof createClient>;
15
-
16
- beforeEach(() => {
17
- mockFetch.mockClear();
18
- });
19
-
20
- it("initializes without errors", () => {
21
- client = createClient(mockFetch, { debug: true });
22
- expect(client).toBeDefined();
23
- });
24
-
25
- it("has copyApp method", () => {
26
- client = createClient(mockFetch, { debug: true });
27
- expect(typeof client.copyApp).toBe("function");
28
- });
29
-
30
- it("calls copyApp successfully with user token and dates as Date objects", async () => {
31
- client = createClient(mockFetch, { debug: true }); // convertDates defaults to true
32
-
33
- const request: CopyAppRequest = {
34
- name: "Copied App",
35
- description: "A copy of the original app",
36
- properties: {
37
- keepData: false,
38
- excludeFiles: true,
39
- usersAndRoles: false,
40
- assignUserToken: true,
41
- },
42
- };
43
-
44
- const mockResponse: CopyApp200Response = {
45
- id: "bpqe82s1",
46
- name: "Copied App",
47
- description: "A copy of the original app",
48
- created: new Date("2025-03-11T10:00:00Z"), // Expect Date object
49
- updated: new Date("2025-03-11T10:00:00Z"), // Expect Date object
50
- dateFormat: "MM-DD-YYYY",
51
- timeZone: "(UTC-08:00) Pacific Time (US & Canada)",
52
- hasEveryoneOnTheInternet: false,
53
- ancestorId: "buwai2zpe",
54
- dataClassification: "None",
55
- variables: [],
56
- };
57
-
58
- mockFetch.mockResolvedValueOnce({
59
- ok: true,
60
- status: 200,
61
- json: () => Promise.resolve(mockResponse),
62
- });
63
-
64
- const result = await client.copyApp({ appId: QB_APP_ID, body: request });
65
-
66
- expect(result).toEqual(mockResponse);
67
- expect(mockFetch).toHaveBeenCalledWith(
68
- `https://api.quickbase.com/v1/apps/${QB_APP_ID}/copy`,
69
- expect.objectContaining({
70
- method: "POST",
71
- headers: expect.objectContaining({
72
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
73
- Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
74
- "Content-Type": "application/json",
75
- }),
76
- credentials: "omit",
77
- body: JSON.stringify(request),
78
- })
79
- );
80
- });
81
-
82
- it("calls copyApp successfully with user token and dates as strings", async () => {
83
- client = createClient(mockFetch, { debug: true, convertDates: false });
84
-
85
- const request: CopyAppRequest = {
86
- name: "Copied App",
87
- description: "A copy of the original app",
88
- properties: {
89
- keepData: false,
90
- excludeFiles: true,
91
- usersAndRoles: false,
92
- assignUserToken: true,
93
- },
94
- };
95
-
96
- const mockResponse = {
97
- id: "bpqe82s1",
98
- name: "Copied App",
99
- description: "A copy of the original app",
100
- created: "2025-03-11T10:00:00Z", // Expect string
101
- updated: "2025-03-11T10:00:00Z", // Expect string
102
- dateFormat: "MM-DD-YYYY",
103
- timeZone: "(UTC-08:00) Pacific Time (US & Canada)",
104
- hasEveryoneOnTheInternet: false,
105
- ancestorId: "buwai2zpe",
106
- dataClassification: "None",
107
- variables: [],
108
- };
109
-
110
- mockFetch.mockResolvedValueOnce({
111
- ok: true,
112
- status: 200,
113
- json: () => Promise.resolve(mockResponse),
114
- });
115
-
116
- const result = await client.copyApp({ appId: QB_APP_ID, body: request });
117
-
118
- expect(result).toEqual(mockResponse);
119
- expect(mockFetch).toHaveBeenCalledWith(
120
- `https://api.quickbase.com/v1/apps/${QB_APP_ID}/copy`,
121
- expect.objectContaining({
122
- method: "POST",
123
- headers: expect.objectContaining({
124
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
125
- Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
126
- "Content-Type": "application/json",
127
- }),
128
- credentials: "omit",
129
- body: JSON.stringify(request),
130
- })
131
- );
132
- });
133
-
134
- it("calls copyApp successfully with temp token and dates as Date objects", async () => {
135
- client = createClient(mockFetch, { useTempTokens: true, debug: true });
136
-
137
- const request: CopyAppRequest = {
138
- name: "Copied App with Temp Token",
139
- description: "A copy using temp token",
140
- properties: {
141
- keepData: true,
142
- excludeFiles: false,
143
- usersAndRoles: true,
144
- assignUserToken: false,
145
- },
146
- };
147
-
148
- const mockResponse: CopyApp200Response = {
149
- id: "bpqe82s2",
150
- name: "Copied App with Temp Token",
151
- description: "A copy using temp token",
152
- created: new Date("2025-03-11T11:00:00Z"), // Expect Date object
153
- updated: new Date("2025-03-11T11:00:00Z"), // Expect Date object
154
- dateFormat: "MM-DD-YYYY",
155
- timeZone: "(UTC-08:00) Pacific Time (US & Canada)",
156
- hasEveryoneOnTheInternet: true,
157
- ancestorId: QB_APP_ID,
158
- dataClassification: "None",
159
- variables: [],
160
- };
161
-
162
- mockFetch
163
- .mockResolvedValueOnce({
164
- ok: true,
165
- status: 200,
166
- json: () => Promise.resolve({ temporaryAuthorization: "temp_token" }),
167
- })
168
- .mockResolvedValueOnce({
169
- ok: true,
170
- status: 200,
171
- json: () => Promise.resolve(mockResponse),
172
- });
173
-
174
- const result = await client.copyApp({ appId: QB_APP_ID, body: request });
175
-
176
- expect(result).toEqual(mockResponse);
177
- expect(mockFetch).toHaveBeenCalledTimes(2);
178
- expect(mockFetch).toHaveBeenNthCalledWith(
179
- 1,
180
- `https://api.quickbase.com/v1/auth/temporary/${QB_APP_ID}`,
181
- expect.objectContaining({
182
- method: "GET",
183
- headers: expect.objectContaining({
184
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
185
- "Content-Type": "application/json",
186
- }),
187
- credentials: "include",
188
- })
189
- );
190
- expect(mockFetch).toHaveBeenNthCalledWith(
191
- 2,
192
- `https://api.quickbase.com/v1/apps/${QB_APP_ID}/copy`,
193
- expect.objectContaining({
194
- method: "POST",
195
- headers: expect.objectContaining({
196
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
197
- Authorization: "QB-TEMP-TOKEN temp_token",
198
- "Content-Type": "application/json",
199
- }),
200
- credentials: "omit",
201
- body: JSON.stringify(request),
202
- })
203
- );
204
- });
205
-
206
- it("calls copyApp successfully with temp token and dates as strings", async () => {
207
- client = createClient(mockFetch, {
208
- useTempTokens: true,
209
- debug: true,
210
- convertDates: false,
211
- });
212
-
213
- const request: CopyAppRequest = {
214
- name: "Copied App with Temp Token",
215
- description: "A copy using temp token",
216
- properties: {
217
- keepData: true,
218
- excludeFiles: false,
219
- usersAndRoles: true,
220
- assignUserToken: false,
221
- },
222
- };
223
-
224
- const mockResponse = {
225
- id: "bpqe82s2",
226
- name: "Copied App with Temp Token",
227
- description: "A copy using temp token",
228
- created: "2025-03-11T11:00:00Z", // Expect string
229
- updated: "2025-03-11T11:00:00Z", // Expect string
230
- dateFormat: "MM-DD-YYYY",
231
- timeZone: "(UTC-08:00) Pacific Time (US & Canada)",
232
- hasEveryoneOnTheInternet: true,
233
- ancestorId: QB_APP_ID,
234
- dataClassification: "None",
235
- variables: [],
236
- };
237
-
238
- mockFetch
239
- .mockResolvedValueOnce({
240
- ok: true,
241
- status: 200,
242
- json: () => Promise.resolve({ temporaryAuthorization: "temp_token" }),
243
- })
244
- .mockResolvedValueOnce({
245
- ok: true,
246
- status: 200,
247
- json: () => Promise.resolve(mockResponse),
248
- });
249
-
250
- const result = await client.copyApp({ appId: QB_APP_ID, body: request });
251
-
252
- expect(result).toEqual(mockResponse);
253
- expect(mockFetch).toHaveBeenCalledTimes(2);
254
- expect(mockFetch).toHaveBeenNthCalledWith(
255
- 1,
256
- `https://api.quickbase.com/v1/auth/temporary/${QB_APP_ID}`,
257
- expect.objectContaining({
258
- method: "GET",
259
- headers: expect.objectContaining({
260
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
261
- "Content-Type": "application/json",
262
- }),
263
- credentials: "include",
264
- })
265
- );
266
- expect(mockFetch).toHaveBeenNthCalledWith(
267
- 2,
268
- `https://api.quickbase.com/v1/apps/${QB_APP_ID}/copy`,
269
- expect.objectContaining({
270
- method: "POST",
271
- headers: expect.objectContaining({
272
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
273
- Authorization: "QB-TEMP-TOKEN temp_token",
274
- "Content-Type": "application/json",
275
- }),
276
- credentials: "omit",
277
- body: JSON.stringify(request),
278
- })
279
- );
280
- });
281
-
282
- it("retries successfully after 401 with temp token and dates as Date objects", async () => {
283
- client = createClient(mockFetch, { useTempTokens: true, debug: true });
284
-
285
- const request: CopyAppRequest = {
286
- name: "Retry Copied App",
287
- description: "Retry after 401",
288
- properties: {
289
- keepData: false,
290
- excludeFiles: true,
291
- usersAndRoles: false,
292
- assignUserToken: true,
293
- },
294
- };
295
-
296
- const mockResponse: CopyApp200Response = {
297
- id: "bpqe82s3",
298
- name: "Retry Copied App",
299
- description: "Retry after 401",
300
- created: new Date("2025-03-11T12:00:00Z"), // Expect Date object
301
- updated: new Date("2025-03-11T12:00:00Z"), // Expect Date object
302
- dateFormat: "MM-DD-YYYY",
303
- timeZone: "(UTC-08:00) Pacific Time (US & Canada)",
304
- hasEveryoneOnTheInternet: false,
305
- ancestorId: QB_APP_ID,
306
- dataClassification: "None",
307
- variables: [],
308
- };
309
-
310
- mockFetch
311
- .mockResolvedValueOnce({
312
- ok: true,
313
- status: 200,
314
- json: () =>
315
- Promise.resolve({ temporaryAuthorization: "initial_token" }),
316
- })
317
- .mockResolvedValueOnce({
318
- ok: false,
319
- status: 401,
320
- json: () => Promise.resolve({ message: "Unauthorized" }),
321
- })
322
- .mockResolvedValueOnce({
323
- ok: true,
324
- status: 200,
325
- json: () => Promise.resolve({ temporaryAuthorization: "new_token" }),
326
- })
327
- .mockResolvedValueOnce({
328
- ok: true,
329
- status: 200,
330
- json: () => Promise.resolve(mockResponse),
331
- });
332
-
333
- const result = await client.copyApp({ appId: QB_APP_ID, body: request });
334
-
335
- expect(result).toEqual(mockResponse);
336
- expect(mockFetch).toHaveBeenCalledTimes(4);
337
- expect(mockFetch).toHaveBeenNthCalledWith(
338
- 1,
339
- `https://api.quickbase.com/v1/auth/temporary/${QB_APP_ID}`,
340
- expect.any(Object)
341
- );
342
- expect(mockFetch).toHaveBeenNthCalledWith(
343
- 2,
344
- `https://api.quickbase.com/v1/apps/${QB_APP_ID}/copy`,
345
- expect.objectContaining({
346
- headers: expect.objectContaining({
347
- Authorization: "QB-TEMP-TOKEN initial_token",
348
- }),
349
- })
350
- );
351
- expect(mockFetch).toHaveBeenNthCalledWith(
352
- 3,
353
- `https://api.quickbase.com/v1/auth/temporary/${QB_APP_ID}`,
354
- expect.any(Object)
355
- );
356
- expect(mockFetch).toHaveBeenNthCalledWith(
357
- 4,
358
- `https://api.quickbase.com/v1/apps/${QB_APP_ID}/copy`,
359
- expect.objectContaining({
360
- headers: expect.objectContaining({
361
- Authorization: "QB-TEMP-TOKEN new_token",
362
- }),
363
- })
364
- );
365
- });
366
-
367
- it("retries successfully after 401 with temp token and dates as strings", async () => {
368
- client = createClient(mockFetch, {
369
- useTempTokens: true,
370
- debug: true,
371
- convertDates: false,
372
- });
373
-
374
- const request: CopyAppRequest = {
375
- name: "Retry Copied App",
376
- description: "Retry after 401",
377
- properties: {
378
- keepData: false,
379
- excludeFiles: true,
380
- usersAndRoles: false,
381
- assignUserToken: true,
382
- },
383
- };
384
-
385
- const mockResponse = {
386
- id: "bpqe82s3",
387
- name: "Retry Copied App",
388
- description: "Retry after 401",
389
- created: "2025-03-11T12:00:00Z", // Expect string
390
- updated: "2025-03-11T12:00:00Z", // Expect string
391
- dateFormat: "MM-DD-YYYY",
392
- timeZone: "(UTC-08:00) Pacific Time (US & Canada)",
393
- hasEveryoneOnTheInternet: false,
394
- ancestorId: QB_APP_ID,
395
- dataClassification: "None",
396
- variables: [],
397
- };
398
-
399
- mockFetch
400
- .mockResolvedValueOnce({
401
- ok: true,
402
- status: 200,
403
- json: () =>
404
- Promise.resolve({ temporaryAuthorization: "initial_token" }),
405
- })
406
- .mockResolvedValueOnce({
407
- ok: false,
408
- status: 401,
409
- json: () => Promise.resolve({ message: "Unauthorized" }),
410
- })
411
- .mockResolvedValueOnce({
412
- ok: true,
413
- status: 200,
414
- json: () => Promise.resolve({ temporaryAuthorization: "new_token" }),
415
- })
416
- .mockResolvedValueOnce({
417
- ok: true,
418
- status: 200,
419
- json: () => Promise.resolve(mockResponse),
420
- });
421
-
422
- const result = await client.copyApp({ appId: QB_APP_ID, body: request });
423
-
424
- expect(result).toEqual(mockResponse);
425
- expect(mockFetch).toHaveBeenCalledTimes(4);
426
- expect(mockFetch).toHaveBeenNthCalledWith(
427
- 1,
428
- `https://api.quickbase.com/v1/auth/temporary/${QB_APP_ID}`,
429
- expect.any(Object)
430
- );
431
- expect(mockFetch).toHaveBeenNthCalledWith(
432
- 2,
433
- `https://api.quickbase.com/v1/apps/${QB_APP_ID}/copy`,
434
- expect.objectContaining({
435
- headers: expect.objectContaining({
436
- Authorization: "QB-TEMP-TOKEN initial_token",
437
- }),
438
- })
439
- );
440
- expect(mockFetch).toHaveBeenNthCalledWith(
441
- 3,
442
- `https://api.quickbase.com/v1/auth/temporary/${QB_APP_ID}`,
443
- expect.any(Object)
444
- );
445
- expect(mockFetch).toHaveBeenNthCalledWith(
446
- 4,
447
- `https://api.quickbase.com/v1/apps/${QB_APP_ID}/copy`,
448
- expect.objectContaining({
449
- headers: expect.objectContaining({
450
- Authorization: "QB-TEMP-TOKEN new_token",
451
- }),
452
- })
453
- );
454
- });
455
-
456
- it("handles 400 error for invalid request", async () => {
457
- client = createClient(mockFetch, { debug: true });
458
-
459
- const request: CopyAppRequest = {
460
- name: "",
461
- description: "Invalid request",
462
- };
463
-
464
- mockFetch.mockResolvedValueOnce({
465
- ok: false,
466
- status: 400,
467
- json: () => Promise.resolve({ message: "Name is required" }),
468
- });
469
-
470
- await expect(
471
- client.copyApp({ appId: QB_APP_ID, body: request })
472
- ).rejects.toThrow("API Error: Name is required (Status: 400)");
473
-
474
- expect(mockFetch).toHaveBeenCalledWith(
475
- `https://api.quickbase.com/v1/apps/${QB_APP_ID}/copy`,
476
- expect.objectContaining({
477
- method: "POST",
478
- headers: expect.objectContaining({
479
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
480
- Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
481
- "Content-Type": "application/json",
482
- }),
483
- credentials: "omit",
484
- body: JSON.stringify(request),
485
- })
486
- );
487
- });
488
- });
@@ -1,186 +0,0 @@
1
- // tests/vitest/unit/apps/createApp.test.ts
2
-
3
- import { describe, it, expect, beforeEach } from "vitest";
4
- import {
5
- createClient,
6
- mockFetch,
7
- QB_REALM,
8
- QB_USER_TOKEN,
9
- } from "@tests/setup.ts";
10
- import { CreateAppRequest, CreateApp200Response } from "@/generated/models";
11
-
12
- describe("QuickbaseClient Unit - createApp", () => {
13
- console.log(
14
- "Running updated createApp.test.ts - Version with full request expectation"
15
- );
16
-
17
- let client: ReturnType<typeof createClient>;
18
-
19
- beforeEach(() => {
20
- mockFetch.mockClear();
21
- });
22
-
23
- it("initializes without errors", () => {
24
- client = createClient(mockFetch, { debug: true });
25
- expect(client).toBeDefined();
26
- });
27
-
28
- it("has createApp method", () => {
29
- client = createClient(mockFetch, { debug: true });
30
- expect(typeof client.createApp).toBe("function");
31
- });
32
-
33
- it("calls createApp successfully with user token and dates as Date objects", async () => {
34
- client = createClient(mockFetch, { debug: true });
35
-
36
- const request: CreateAppRequest = {
37
- name: "New App",
38
- description: "A new app for testing",
39
- assignToken: true,
40
- };
41
-
42
- const mockResponse: CreateApp200Response = {
43
- id: "new-app-id",
44
- name: "New App",
45
- description: "A new app for testing",
46
- created: new Date("2025-03-11T10:00:00Z"),
47
- updated: new Date("2025-03-11T10:00:00Z"),
48
- dateFormat: "MM-DD-YYYY",
49
- timeZone: "(UTC-08:00) Pacific Time (US & Canada)",
50
- hasEveryoneOnTheInternet: false,
51
- variables: [],
52
- dataClassification: "None",
53
- memoryInfo: { estMemory: 0, estMemoryInclDependentApps: 0 },
54
- securityProperties: {
55
- allowClone: false,
56
- allowExport: true,
57
- enableAppTokens: true,
58
- hideFromPublic: false,
59
- mustBeRealmApproved: false,
60
- useIPFilter: false,
61
- },
62
- };
63
-
64
- mockFetch.mockResolvedValueOnce({
65
- ok: true,
66
- status: 200,
67
- json: () => Promise.resolve(mockResponse),
68
- });
69
-
70
- const result = await client.createApp({ body: request });
71
-
72
- expect(result).toEqual(mockResponse);
73
- const callArgs = mockFetch.mock.calls[0];
74
- const body = JSON.parse(callArgs[1].body as string);
75
- console.log("Date objects test - Expected request:", request);
76
- console.log("Date objects test - Actual body:", body);
77
- expect(mockFetch).toHaveBeenCalledWith(
78
- `https://api.quickbase.com/v1/apps`,
79
- expect.objectContaining({
80
- method: "POST",
81
- headers: expect.objectContaining({
82
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
83
- Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
84
- "Content-Type": "application/json",
85
- }),
86
- body: expect.any(String), // Ensure it’s a string, we’ll check content below
87
- credentials: "omit",
88
- })
89
- );
90
- expect(body).toEqual(request); // Moved outside toHaveBeenCalledWith
91
- });
92
-
93
- it("calls createApp successfully with user token and dates as strings", async () => {
94
- client = createClient(mockFetch, { debug: true, convertDates: false });
95
-
96
- const request: CreateAppRequest = {
97
- name: "New App",
98
- description: "A new app for testing",
99
- assignToken: true,
100
- };
101
-
102
- const mockResponse = {
103
- id: "new-app-id",
104
- name: "New App",
105
- description: "A new app for testing",
106
- created: "2025-03-11T10:00:00Z",
107
- updated: "2025-03-11T10:00:00Z",
108
- dateFormat: "MM-DD-YYYY",
109
- timeZone: "(UTC-08:00) Pacific Time (US & Canada)",
110
- hasEveryoneOnTheInternet: false,
111
- variables: [],
112
- dataClassification: "None",
113
- memoryInfo: { estMemory: 0, estMemoryInclDependentApps: 0 },
114
- securityProperties: {
115
- allowClone: false,
116
- allowExport: true,
117
- enableAppTokens: true,
118
- hideFromPublic: false,
119
- mustBeRealmApproved: false,
120
- useIPFilter: false,
121
- },
122
- };
123
-
124
- mockFetch.mockResolvedValueOnce({
125
- ok: true,
126
- status: 200,
127
- json: () => Promise.resolve(mockResponse),
128
- });
129
-
130
- const result = await client.createApp({ body: request });
131
-
132
- expect(result).toEqual(mockResponse);
133
- const callArgs = mockFetch.mock.calls[0];
134
- const body = JSON.parse(callArgs[1].body as string);
135
- console.log("Strings test - Expected request:", request);
136
- console.log("Strings test - Actual body:", body);
137
- expect(mockFetch).toHaveBeenCalledWith(
138
- `https://api.quickbase.com/v1/apps`,
139
- expect.objectContaining({
140
- method: "POST",
141
- headers: expect.objectContaining({
142
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
143
- Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
144
- "Content-Type": "application/json",
145
- }),
146
- body: expect.any(String), // Ensure it’s a string, we’ll check content below
147
- credentials: "omit",
148
- })
149
- );
150
- expect(body).toEqual(request); // Moved outside toHaveBeenCalledWith
151
- });
152
-
153
- it("handles 400 error for invalid request", async () => {
154
- client = createClient(mockFetch, { debug: true });
155
-
156
- const request: CreateAppRequest = {
157
- name: "",
158
- };
159
-
160
- mockFetch.mockImplementationOnce(() =>
161
- Promise.resolve({
162
- ok: false,
163
- status: 400,
164
- json: () => Promise.resolve({ message: "Name is required" }),
165
- })
166
- );
167
-
168
- await expect(client.createApp({ body: request })).rejects.toThrow(
169
- "API Error: Name is required (Status: 400)"
170
- );
171
-
172
- expect(mockFetch).toHaveBeenCalledWith(
173
- `https://api.quickbase.com/v1/apps`,
174
- expect.objectContaining({
175
- method: "POST",
176
- headers: expect.objectContaining({
177
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
178
- Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
179
- "Content-Type": "application/json",
180
- }),
181
- body: JSON.stringify(request),
182
- credentials: "omit",
183
- })
184
- );
185
- });
186
- });