quickbase-js 0.1.0-beta.7

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 (123) hide show
  1. package/CHANGELOG.md +129 -0
  2. package/LICENSE +21 -0
  3. package/README.md +204 -0
  4. package/build-common.js +131 -0
  5. package/build-esm.js +71 -0
  6. package/build-umd.js +69 -0
  7. package/dist/esm/quickbase.d.ts +7594 -0
  8. package/dist/esm/quickbase.js +9752 -0
  9. package/dist/esm/quickbase.js.map +1 -0
  10. package/dist/esm/quickbase.min.js +2 -0
  11. package/dist/esm/quickbase.min.js.map +1 -0
  12. package/dist/umd/quickbase.umd.js +10502 -0
  13. package/dist/umd/quickbase.umd.js.map +1 -0
  14. package/dist/umd/quickbase.umd.min.js +2 -0
  15. package/dist/umd/quickbase.umd.min.js.map +1 -0
  16. package/examples/quicbase-jsCDN.html +36 -0
  17. package/examples/react.js +48 -0
  18. package/examples/vanillajs.html +47 -0
  19. package/notes.txt +158 -0
  20. package/open-api/fix-spec-main.ts +96 -0
  21. package/open-api/generate-unified-interface.ts +277 -0
  22. package/open-api/output/override-report.json +58 -0
  23. package/open-api/output/quickbase-fixed.json +10610 -0
  24. package/open-api/regenerate-client.ts +116 -0
  25. package/open-api/schema/enhance-general.ts +100 -0
  26. package/open-api/schema/fix-arrays.ts +69 -0
  27. package/open-api/schema/tags/apps.ts +90 -0
  28. package/open-api/schema/tags/fields.ts +156 -0
  29. package/open-api/schema/tags/groups.ts +51 -0
  30. package/open-api/schema/tags/index.ts +68 -0
  31. package/open-api/schema/tags/records.ts +115 -0
  32. package/open-api/schema/tags/tables.ts +211 -0
  33. package/open-api/schema/tags/users.ts +47 -0
  34. package/open-api/types/spec.ts +41 -0
  35. package/open-api/utils/infer-schema.ts +40 -0
  36. package/open-api/utils/naming.ts +10 -0
  37. package/package.json +91 -0
  38. package/playwright.config.ts +37 -0
  39. package/rollup.config.js +114 -0
  40. package/specs/QuickBase_RESTful_API_2025-03-04T06_22_39.725Z.json +46878 -0
  41. package/specs/split/apps.json +1315 -0
  42. package/specs/split/auth.json +191 -0
  43. package/specs/split/fields.json +3869 -0
  44. package/specs/split/records.json +754 -0
  45. package/specs/split/reports.json +619 -0
  46. package/specs/split/tables.json +1605 -0
  47. package/src/generated-unified/QuickbaseClient.ts +359 -0
  48. package/src/generated-unified/missing-types-report.json +3 -0
  49. package/src/index.ts +1 -0
  50. package/src/quickbaseClient.ts +402 -0
  51. package/src/tokenCache.ts +51 -0
  52. package/src/utils.ts +7 -0
  53. package/test-esm.js +1 -0
  54. package/test-results.json +2050 -0
  55. package/test-umd.js +1 -0
  56. package/test.ts +1 -0
  57. package/tests/playwright/qb/auth/cacheSwitching.test.ts +159 -0
  58. package/tests/playwright/qb/auth/fetchTempToken401.test.ts +219 -0
  59. package/tests/playwright/qb/auth/getAppWithTempToken.test.ts +162 -0
  60. package/tests/playwright/qb/auth/getAppWithUserToken.test.ts +153 -0
  61. package/tests/playwright/qb/auth/getTempToken.test.ts +152 -0
  62. package/tests/playwright/qb/auth/tokenPrefetch.test.ts +179 -0
  63. package/tests/playwright/qb/auth/tokenRenewal.test.ts +133 -0
  64. package/tests/setup.ts +51 -0
  65. package/tests/vitest/qb/apps/copyApp.test.ts +76 -0
  66. package/tests/vitest/qb/apps/createApp.test.ts +64 -0
  67. package/tests/vitest/qb/apps/deleteApp.test.ts +76 -0
  68. package/tests/vitest/qb/apps/getApp.test.ts +40 -0
  69. package/tests/vitest/qb/fields/createField.test.ts +78 -0
  70. package/tests/vitest/qb/fields/deleteFields.test.ts +89 -0
  71. package/tests/vitest/qb/fields/getField.test.ts +85 -0
  72. package/tests/vitest/qb/fields/getFieldUsage.test.ts +174 -0
  73. package/tests/vitest/qb/fields/getFields.test.ts +232 -0
  74. package/tests/vitest/qb/fields/getFieldsUsage.test.ts +77 -0
  75. package/tests/vitest/qb/index.ts +28 -0
  76. package/tests/vitest/qb/records/deleteRecords.test.ts +110 -0
  77. package/tests/vitest/qb/records/runQuery.test.ts +146 -0
  78. package/tests/vitest/qb/records/upsert.test.ts +102 -0
  79. package/tests/vitest/qb/tables/createTable.test.ts +55 -0
  80. package/tests/vitest/qb/tables/deleteTable.test.ts +50 -0
  81. package/tests/vitest/qb/tables/getAppTables.test.ts +46 -0
  82. package/tests/vitest/qb/tables/getRelationships.test.ts +80 -0
  83. package/tests/vitest/qb/tables/getTable.test.ts +26 -0
  84. package/tests/vitest/qb/tables/updateTable.test.ts +48 -0
  85. package/tests/vitest/unit/apps/copyApp.test.ts +488 -0
  86. package/tests/vitest/unit/apps/createApp.test.ts +186 -0
  87. package/tests/vitest/unit/apps/deleteApp.test.ts +216 -0
  88. package/tests/vitest/unit/apps/getApp.test.ts +128 -0
  89. package/tests/vitest/unit/auth/fetchTempToken401.test.ts +82 -0
  90. package/tests/vitest/unit/auth/getTempToken.test.ts +95 -0
  91. package/tests/vitest/unit/auth/retryOn401.test.ts +116 -0
  92. package/tests/vitest/unit/auth/two401s.test.ts +86 -0
  93. package/tests/vitest/unit/fields/createField.test.ts +391 -0
  94. package/tests/vitest/unit/fields/deleteFields.test.ts +141 -0
  95. package/tests/vitest/unit/fields/getField.test.ts +189 -0
  96. package/tests/vitest/unit/fields/getFieldUsage.test.ts +147 -0
  97. package/tests/vitest/unit/fields/getFields.test.ts +122 -0
  98. package/tests/vitest/unit/fields/getFieldsUsage.test.ts +160 -0
  99. package/tests/vitest/unit/index.ts +33 -0
  100. package/tests/vitest/unit/records/deleteRecords.test.ts +112 -0
  101. package/tests/vitest/unit/records/runQuery.test.ts +102 -0
  102. package/tests/vitest/unit/records/upsert.test.ts +234 -0
  103. package/tests/vitest/unit/tables/createTable.test.ts +70 -0
  104. package/tests/vitest/unit/tables/deleteTable.test.ts +77 -0
  105. package/tests/vitest/unit/tables/getAppTables.test.ts +85 -0
  106. package/tests/vitest/unit/tables/getRelationships.test.ts +259 -0
  107. package/tests/vitest/unit/tables/getTable.test.ts +233 -0
  108. package/tests/vitest/unit/tables/updateTable.test.ts +80 -0
  109. package/tests/vitest/unit/umd.test.ts +8 -0
  110. package/text.txt +104 -0
  111. package/tools/generate-types.ts +29 -0
  112. package/tools/log-gen.ts +231 -0
  113. package/tools/log-gen.yaml +3826 -0
  114. package/tools/openapi-jars/openapi-generator-cli-7.12.0.jar +0 -0
  115. package/tools/openapi-schema-validator.ts +38 -0
  116. package/tools/spec-analyzer.ts +163 -0
  117. package/tools/split-spec.ts +148 -0
  118. package/tools/test-import.ts +3 -0
  119. package/tools/validate-spec.ts +40 -0
  120. package/tsconfig.build.json +17 -0
  121. package/tsconfig.json +29 -0
  122. package/versionrc.json +9 -0
  123. package/vitest.config.ts +27 -0
@@ -0,0 +1,488 @@
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
+ });
@@ -0,0 +1,186 @@
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
+ });