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,102 +0,0 @@
1
- // tests/vitest/unit/records/runQuery.test.ts
2
- import { describe, test, 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 { RunQueryRequest, RunQueryResponse } from "@/generated";
11
-
12
- describe("QuickbaseClient Unit - runQuery", () => {
13
- let client: ReturnType<typeof createClient>;
14
-
15
- beforeEach(() => {
16
- mockFetch.mockClear();
17
- client = createClient(mockFetch, { debug: true });
18
- });
19
-
20
- test("sends correct POST request and handles successful query response", async () => {
21
- const queryRequest: RunQueryRequest = {
22
- from: QB_TABLE_ID_1,
23
- select: [3, 6, 7],
24
- where: "{6.EX.'Task 1'}",
25
- sortBy: [{ fieldId: 6, order: "ASC" }],
26
- groupBy: [{ fieldId: 7, grouping: "equal-values" }],
27
- options: { skip: 0, top: 100, compareWithAppLocalTime: false },
28
- };
29
-
30
- const mockResponse: RunQueryResponse = {
31
- data: [
32
- { "3": { value: 1 }, "6": { value: "Task 1" }, "7": { value: "High" } },
33
- ],
34
- fields: [
35
- { id: 3, label: "Record ID#", type: "recordid" },
36
- { id: 6, label: "Task Name", type: "text" },
37
- { id: 7, label: "Priority", type: "text" },
38
- ],
39
- metadata: {
40
- numFields: 3,
41
- numRecords: 1,
42
- skip: 0,
43
- top: 100,
44
- totalRecords: 1,
45
- },
46
- };
47
-
48
- mockFetch.mockResolvedValueOnce({
49
- ok: true,
50
- status: 200,
51
- json: () => Promise.resolve(mockResponse),
52
- });
53
-
54
- const result = await client.runQuery({ body: queryRequest });
55
-
56
- expect(mockFetch).toHaveBeenCalledWith(
57
- "https://api.quickbase.com/v1/records/query",
58
- expect.objectContaining({
59
- method: "POST",
60
- headers: expect.objectContaining({
61
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
62
- Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
63
- "Content-Type": "application/json",
64
- }),
65
- body: JSON.stringify(queryRequest),
66
- })
67
- );
68
-
69
- expect(result).toEqual(mockResponse);
70
- });
71
-
72
- test("handles API error with invalid query", async () => {
73
- const invalidQueryRequest: RunQueryRequest = {
74
- from: QB_TABLE_ID_1,
75
- select: [3],
76
- where: "{999.EX.'Invalid'}",
77
- };
78
-
79
- mockFetch.mockResolvedValueOnce({
80
- ok: false,
81
- status: 400,
82
- json: () => Promise.resolve({ message: "Invalid query" }),
83
- });
84
-
85
- await expect(
86
- client.runQuery({ body: invalidQueryRequest })
87
- ).rejects.toThrow("API Error: Invalid query (Status: 400)");
88
-
89
- expect(mockFetch).toHaveBeenCalledWith(
90
- "https://api.quickbase.com/v1/records/query",
91
- expect.objectContaining({
92
- method: "POST",
93
- headers: expect.objectContaining({
94
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
95
- Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
96
- "Content-Type": "application/json",
97
- }),
98
- body: JSON.stringify(invalidQueryRequest),
99
- })
100
- );
101
- });
102
- });
@@ -1,234 +0,0 @@
1
- // tests/vitest/unit/records/upsert.test.ts
2
- import { describe, expect, test, 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 { vi } from "vitest";
11
-
12
- // Note: Type augmentation moved to src/types.d.ts
13
- describe("QuickbaseClient Unit - upsert", () => {
14
- beforeEach(() => {
15
- vi.resetModules(); // Reset module cache
16
- mockFetch.mockClear();
17
- });
18
-
19
- test("sends correct POST request and handles successful upsert", async () => {
20
- const qb = createClient(mockFetch, { debug: true });
21
-
22
- mockFetch.mockResolvedValueOnce({
23
- ok: true,
24
- status: 200,
25
- json: () =>
26
- Promise.resolve({
27
- data: [{ id: 1, "6": { value: "value1" } }],
28
- metadata: {
29
- createdRecordIds: [1],
30
- updatedRecordIds: [],
31
- unchangedRecordIds: [],
32
- totalNumberOfRecordsProcessed: 1,
33
- },
34
- }),
35
- });
36
-
37
- console.log("[Test] Calling qb.upsert with:", {
38
- body: { to: QB_TABLE_ID_1, data: [{ "6": { value: "value1" } }] },
39
- });
40
- const result = await qb.upsert({
41
- body: { to: QB_TABLE_ID_1, data: [{ "6": { value: "value1" } }] },
42
- });
43
-
44
- console.log("[Test] mockFetch calls:", mockFetch.mock.calls);
45
- expect(mockFetch).toHaveBeenCalledWith(
46
- "https://api.quickbase.com/v1/records",
47
- expect.objectContaining({
48
- method: "POST",
49
- headers: expect.objectContaining({
50
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
51
- Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
52
- "Content-Type": "application/json",
53
- }),
54
- body: expect.any(String), // Allow any string, check content below
55
- credentials: "omit",
56
- })
57
- );
58
- const callArgs = mockFetch.mock.calls[0];
59
- const receivedBody = JSON.parse(callArgs[1].body as string);
60
- expect(receivedBody).toEqual({
61
- to: QB_TABLE_ID_1,
62
- data: [{ "6": { value: "value1" } }],
63
- });
64
-
65
- expect(result).toEqual({
66
- data: [{ id: 1, "6": { value: "value1" } }],
67
- metadata: {
68
- createdRecordIds: [1],
69
- updatedRecordIds: [],
70
- unchangedRecordIds: [],
71
- totalNumberOfRecordsProcessed: 1,
72
- },
73
- });
74
- });
75
-
76
- test("handles API error with invalid data", async () => {
77
- const qb = createClient(mockFetch, { debug: true });
78
-
79
- mockFetch.mockResolvedValueOnce({
80
- ok: false,
81
- status: 400,
82
- json: () => Promise.resolve({ message: "Invalid data format" }),
83
- });
84
-
85
- await expect(
86
- qb.upsert({
87
- body: { to: QB_TABLE_ID_1, data: [{ "999": { value: "invalid" } }] },
88
- })
89
- ).rejects.toThrow("API Error: Invalid data format (Status: 400)");
90
-
91
- expect(mockFetch).toHaveBeenCalledWith(
92
- "https://api.quickbase.com/v1/records",
93
- expect.objectContaining({
94
- method: "POST",
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: expect.any(String),
101
- credentials: "omit",
102
- })
103
- );
104
- const callArgs = mockFetch.mock.calls[0];
105
- const receivedBody = JSON.parse(callArgs[1].body as string);
106
- expect(receivedBody).toEqual({
107
- to: QB_TABLE_ID_1,
108
- data: [{ "999": { value: "invalid" } }],
109
- });
110
- });
111
-
112
- test("handles upsert with temp token", async () => {
113
- const qb = createClient(mockFetch, { useTempTokens: true, debug: true });
114
-
115
- mockFetch
116
- .mockResolvedValueOnce({
117
- ok: true,
118
- status: 200,
119
- json: () => Promise.resolve({ temporaryAuthorization: "temp-token" }),
120
- })
121
- .mockResolvedValueOnce({
122
- ok: true,
123
- status: 200,
124
- json: () =>
125
- Promise.resolve({
126
- data: [{ id: 2, "7": { value: "value2" } }],
127
- metadata: {
128
- createdRecordIds: [2],
129
- updatedRecordIds: [],
130
- unchangedRecordIds: [],
131
- totalNumberOfRecordsProcessed: 1,
132
- },
133
- }),
134
- });
135
-
136
- const result = await qb.upsert({
137
- body: { to: QB_TABLE_ID_1, data: [{ "7": { value: "value2" } }] },
138
- dbid: QB_TABLE_ID_1, // Use QB_TABLE_ID_1 as dbid for temp token
139
- } as any); // Temporary type assertion until types.d.ts is applied
140
-
141
- expect(mockFetch).toHaveBeenCalledTimes(2);
142
- expect(mockFetch).toHaveBeenNthCalledWith(
143
- 1,
144
- `https://api.quickbase.com/v1/auth/temporary/${QB_TABLE_ID_1}`,
145
- expect.objectContaining({
146
- method: "GET",
147
- headers: expect.objectContaining({
148
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
149
- "Content-Type": "application/json",
150
- }),
151
- credentials: "include",
152
- })
153
- );
154
- expect(mockFetch).toHaveBeenNthCalledWith(
155
- 2,
156
- "https://api.quickbase.com/v1/records",
157
- expect.objectContaining({
158
- method: "POST",
159
- headers: expect.objectContaining({
160
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
161
- Authorization: "QB-TEMP-TOKEN temp-token",
162
- "Content-Type": "application/json",
163
- }),
164
- body: expect.any(String),
165
- credentials: "omit",
166
- })
167
- );
168
- const callArgs = mockFetch.mock.calls[1];
169
- const receivedBody = JSON.parse(callArgs[1].body as string);
170
- expect(receivedBody).toEqual({
171
- to: QB_TABLE_ID_1,
172
- data: [{ "7": { value: "value2" } }],
173
- });
174
-
175
- expect(result).toEqual({
176
- data: [{ id: 2, "7": { value: "value2" } }],
177
- metadata: {
178
- createdRecordIds: [2],
179
- updatedRecordIds: [],
180
- unchangedRecordIds: [],
181
- totalNumberOfRecordsProcessed: 1,
182
- },
183
- });
184
- });
185
-
186
- test("sends correct POST request with data fields", async () => {
187
- const qb = createClient(mockFetch, { debug: true });
188
-
189
- mockFetch.mockResolvedValueOnce({
190
- ok: true,
191
- status: 200,
192
- json: () =>
193
- Promise.resolve({
194
- data: [{ id: 1, "6": { value: "value1" } }],
195
- metadata: {
196
- createdRecordIds: [1],
197
- updatedRecordIds: [],
198
- unchangedRecordIds: [],
199
- totalNumberOfRecordsProcessed: 1,
200
- },
201
- }),
202
- });
203
-
204
- const result = await qb.upsert({
205
- body: { to: QB_TABLE_ID_1, data: [{ "6": { value: "value1" } }] },
206
- });
207
-
208
- expect(mockFetch).toHaveBeenCalledWith(
209
- "https://api.quickbase.com/v1/records",
210
- expect.objectContaining({
211
- method: "POST",
212
- headers: expect.objectContaining({
213
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
214
- Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
215
- "Content-Type": "application/json",
216
- }),
217
- body: expect.any(String),
218
- credentials: "omit",
219
- })
220
- );
221
- const callArgs = mockFetch.mock.calls[0];
222
- const receivedBody = JSON.parse(callArgs[1].body as string);
223
- expect(receivedBody).toEqual({
224
- to: QB_TABLE_ID_1,
225
- data: [{ "6": { value: "value1" } }],
226
- });
227
-
228
- if (result.data && result.data.length > 0) {
229
- expect((result.data[0]["6"] as { value: any }).value).toBe("value1");
230
- } else {
231
- throw new Error("Expected data array to have at least one element");
232
- }
233
- });
234
- });
@@ -1,70 +0,0 @@
1
- // tests/vitest/unit/records/createTable.test.ts
2
- import { describe, it, expect, beforeEach } from "vitest";
3
- import {
4
- createClient,
5
- mockFetch,
6
- QB_APP_ID,
7
- QB_REALM,
8
- QB_USER_TOKEN,
9
- } from "@tests/setup.ts";
10
-
11
- describe("QuickbaseClient Unit - createTable", () => {
12
- let client: ReturnType<typeof createClient>;
13
-
14
- beforeEach(() => {
15
- mockFetch.mockClear();
16
- client = createClient(mockFetch, { debug: true });
17
- });
18
-
19
- it("calls createTable successfully with user token", async () => {
20
- const mockBody = {
21
- name: "TestTable",
22
- description: "Unit test table",
23
- singleRecordName: "Test",
24
- pluralRecordName: "Tests",
25
- };
26
- const mockResponse = {
27
- id: "newly-created-table-id-1234567890", // Changed from "buya8h9iz"
28
- name: "TestTable",
29
- alias: "_DBID_TESTTABLE",
30
- description: "Unit test table",
31
- created: new Date("2025-03-10T21:00:00.000Z"),
32
- updated: new Date("2025-03-10T21:00:00.000Z"),
33
- nextRecordId: 1,
34
- nextFieldId: 6,
35
- defaultSortFieldId: 2,
36
- defaultSortOrder: "DESC",
37
- keyFieldId: 3,
38
- singleRecordName: "Test",
39
- pluralRecordName: "Tests",
40
- sizeLimit: "500 MB",
41
- spaceUsed: "0 KB",
42
- spaceRemaining: "500 MB",
43
- };
44
-
45
- mockFetch.mockResolvedValueOnce({
46
- ok: true,
47
- status: 200,
48
- json: () => Promise.resolve(mockResponse),
49
- });
50
-
51
- const response = await client.createTable({
52
- appId: QB_APP_ID,
53
- body: mockBody,
54
- });
55
- expect(response).toEqual(mockResponse);
56
- expect(mockFetch).toHaveBeenCalledTimes(1);
57
- expect(mockFetch).toHaveBeenCalledWith(
58
- `https://api.quickbase.com/v1/tables?appId=${QB_APP_ID}`,
59
- expect.objectContaining({
60
- method: "POST",
61
- headers: expect.objectContaining({
62
- "Content-Type": "application/json",
63
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
64
- Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
65
- }),
66
- body: JSON.stringify(mockBody),
67
- })
68
- );
69
- });
70
- });
@@ -1,77 +0,0 @@
1
- // tests/vitest/unit/records/deleteTable.test.ts
2
- import { describe, it, expect, beforeEach } from "vitest";
3
- import {
4
- createClient,
5
- mockFetch,
6
- QB_APP_ID,
7
- QB_TABLE_ID_1,
8
- QB_REALM,
9
- QB_USER_TOKEN,
10
- } from "@tests/setup.ts";
11
-
12
- describe("QuickbaseClient Unit - deleteTable", () => {
13
- let client: ReturnType<typeof createClient>;
14
-
15
- beforeEach(() => {
16
- mockFetch.mockClear();
17
- client = createClient(mockFetch, { debug: true });
18
- });
19
-
20
- it("calls deleteTable successfully with user token", async () => {
21
- const mockResponse = {
22
- deletedTableId: QB_TABLE_ID_1,
23
- };
24
-
25
- mockFetch.mockResolvedValueOnce({
26
- ok: true,
27
- status: 200,
28
- json: () => Promise.resolve(mockResponse),
29
- });
30
-
31
- const response = await client.deleteTable({
32
- tableId: QB_TABLE_ID_1,
33
- appId: QB_APP_ID,
34
- });
35
- expect(response).toEqual(mockResponse);
36
- expect(mockFetch).toHaveBeenCalledTimes(1);
37
- expect(mockFetch).toHaveBeenCalledWith(
38
- `https://api.quickbase.com/v1/tables/${QB_TABLE_ID_1}?appId=${QB_APP_ID}`,
39
- expect.objectContaining({
40
- method: "DELETE",
41
- headers: expect.objectContaining({
42
- "Content-Type": "application/json",
43
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
44
- Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
45
- }),
46
- })
47
- );
48
- });
49
-
50
- it("handles 404 error for non-existent table", async () => {
51
- mockFetch.mockResolvedValueOnce({
52
- ok: false,
53
- status: 404,
54
- json: () =>
55
- Promise.resolve({
56
- message: "Invalid DBID",
57
- description: "Table not found in app.",
58
- }),
59
- });
60
-
61
- await expect(
62
- client.deleteTable({ tableId: QB_TABLE_ID_1, appId: QB_APP_ID })
63
- ).rejects.toThrow("API Error: Invalid DBID (Status: 404)");
64
- expect(mockFetch).toHaveBeenCalledTimes(1);
65
- expect(mockFetch).toHaveBeenCalledWith(
66
- `https://api.quickbase.com/v1/tables/${QB_TABLE_ID_1}?appId=${QB_APP_ID}`,
67
- expect.objectContaining({
68
- method: "DELETE",
69
- headers: expect.objectContaining({
70
- "Content-Type": "application/json",
71
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
72
- Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
73
- }),
74
- })
75
- );
76
- });
77
- });
@@ -1,85 +0,0 @@
1
- // tests/vitest/unit/tables/getAppTables.test.ts
2
- import { describe, it, expect, beforeEach } from "vitest";
3
- import {
4
- createClient,
5
- mockFetch,
6
- QB_APP_ID,
7
- QB_REALM,
8
- QB_USER_TOKEN,
9
- } from "@tests/setup.ts";
10
-
11
- describe("QuickbaseClient Unit - getAppTables", () => {
12
- let client: ReturnType<typeof createClient>;
13
-
14
- beforeEach(() => {
15
- mockFetch.mockClear();
16
- client = createClient(mockFetch, { debug: true }); // Add debug: true for consistency
17
- });
18
-
19
- it("calls getAppTables successfully", async () => {
20
- mockFetch.mockImplementation((url: string, options: any) => {
21
- console.log("Mock fetch for getAppTables:", url, options);
22
- return Promise.resolve({
23
- ok: true,
24
- status: 200,
25
- json: () =>
26
- Promise.resolve([
27
- {
28
- id: "buwai2zr4",
29
- name: "Root",
30
- alias: "_DBID_ROOT",
31
- description: "",
32
- created: new Date("2025-02-13T18:22:33.000Z"),
33
- updated: new Date("2025-02-13T18:22:34.000Z"),
34
- nextRecordId: 1,
35
- nextFieldId: 6,
36
- defaultSortFieldId: 2,
37
- defaultSortOrder: "DESC",
38
- keyFieldId: 3,
39
- singleRecordName: "Root",
40
- pluralRecordName: "Roots",
41
- sizeLimit: "500 MB",
42
- spaceUsed: "0 KB",
43
- spaceRemaining: "500 MB",
44
- },
45
- ]),
46
- } as Response);
47
- });
48
-
49
- const result = await client.getAppTables({ appId: QB_APP_ID });
50
- console.log("getAppTables response:", result);
51
- expect(result).toEqual(
52
- expect.arrayContaining([
53
- expect.objectContaining({
54
- id: "buwai2zr4",
55
- name: "Root",
56
- alias: "_DBID_ROOT",
57
- description: "",
58
- created: new Date("2025-02-13T18:22:33.000Z"),
59
- updated: new Date("2025-02-13T18:22:34.000Z"),
60
- nextRecordId: 1,
61
- nextFieldId: 6,
62
- defaultSortFieldId: 2,
63
- defaultSortOrder: "DESC",
64
- keyFieldId: 3,
65
- singleRecordName: "Root",
66
- pluralRecordName: "Roots",
67
- sizeLimit: "500 MB",
68
- spaceUsed: "0 KB",
69
- spaceRemaining: "500 MB",
70
- }),
71
- ])
72
- );
73
- expect(mockFetch).toHaveBeenCalledWith(
74
- `https://api.quickbase.com/v1/tables?appId=${QB_APP_ID}`,
75
- expect.objectContaining({
76
- method: "GET",
77
- headers: expect.objectContaining({
78
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
79
- Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
80
- "Content-Type": "application/json",
81
- }),
82
- })
83
- );
84
- });
85
- });