quickbase-js 1.1.0-beta.0 → 1.1.0-beta.2

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 (31) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/quickbase.d.ts +356 -6
  3. package/dist/quickbase.js +363 -20
  4. package/dist/quickbase.js.map +1 -1
  5. package/examples/react.js +42 -16
  6. package/examples/vanillajs.html +32 -8
  7. package/log-gen.yaml +146 -198
  8. package/package.json +4 -4
  9. package/src/code-generation/fix-spec-definitions.ts +99 -41
  10. package/src/code-generation/fix-spec-paths.ts +6 -19
  11. package/src/code-generation/generate-unified-interface.ts +1 -8
  12. package/src/code-generation/output/quickbase-fixed.json +142 -21
  13. package/src/generated-unified/QuickbaseClient.ts +3 -3
  14. package/tests/playwright/qb/auth/cacheSwitching.test.ts +2 -2
  15. package/tests/setup.ts +29 -9
  16. package/tests/vitest/qb/fields/getFields.test.ts +3 -5
  17. package/tests/vitest/qb/records/runQuery.test.ts +82 -0
  18. package/tests/vitest/unit/apps/getApp.test.ts +17 -12
  19. package/tests/vitest/unit/auth/fetchTempToken401.test.ts +29 -4
  20. package/tests/vitest/unit/auth/getTempToken.test.ts +30 -17
  21. package/tests/vitest/unit/auth/retryOn401.test.ts +39 -5
  22. package/tests/vitest/unit/fields/getFields.test.ts +14 -7
  23. package/tests/vitest/unit/records/deleteRecords.test.ts +28 -34
  24. package/tests/vitest/unit/records/runQuery.test.ts +102 -0
  25. package/tests/vitest/unit/records/upsert.test.ts +31 -41
  26. package/tests/vitest/unit/tables/createTable.test.ts +18 -10
  27. package/tests/vitest/unit/tables/deleteTable.test.ts +28 -19
  28. package/tests/vitest/unit/tables/getAppTables.test.ts +41 -28
  29. package/tests/vitest/unit/tables/getTable.test.ts +53 -32
  30. package/tests/vitest/unit/tables/updateTable.test.ts +17 -11
  31. package/vitest.config.ts +5 -0
@@ -1,21 +1,23 @@
1
1
  // tests/vitest/unit/records/upsert.test.ts
2
2
  import { describe, expect, test, beforeEach } from "vitest";
3
- import { createClient, mockFetch } from "@tests/setup.ts";
3
+ import {
4
+ createClient,
5
+ mockFetch,
6
+ QB_REALM,
7
+ QB_USER_TOKEN,
8
+ QB_TABLE_ID_1,
9
+ } from "@tests/setup.ts";
4
10
  import { vi } from "vitest";
5
11
 
6
12
  // Note: Type augmentation moved to src/types.d.ts
7
- describe("QuickbaseClient - upsert (Unit)", () => {
13
+ describe("QuickbaseClient Unit - upsert", () => {
8
14
  beforeEach(() => {
9
15
  vi.resetModules(); // Reset module cache
10
16
  mockFetch.mockClear();
11
17
  });
12
18
 
13
19
  test("sends correct POST request and handles successful upsert", async () => {
14
- const qb = createClient(mockFetch, {
15
- realm: "test-realm",
16
- userToken: "test-token",
17
- debug: true,
18
- });
20
+ const qb = createClient(mockFetch, { debug: true });
19
21
 
20
22
  mockFetch.mockResolvedValueOnce({
21
23
  ok: true,
@@ -33,10 +35,10 @@ describe("QuickbaseClient - upsert (Unit)", () => {
33
35
  });
34
36
 
35
37
  console.log("[Test] Calling qb.upsert with:", {
36
- body: { to: "test-table-id", data: [{ "6": { value: "value1" } }] },
38
+ body: { to: QB_TABLE_ID_1, data: [{ "6": { value: "value1" } }] },
37
39
  });
38
40
  const result = await qb.upsert({
39
- body: { to: "test-table-id", data: [{ "6": { value: "value1" } }] },
41
+ body: { to: QB_TABLE_ID_1, data: [{ "6": { value: "value1" } }] },
40
42
  });
41
43
 
42
44
  console.log("[Test] mockFetch calls:", mockFetch.mock.calls);
@@ -45,12 +47,12 @@ describe("QuickbaseClient - upsert (Unit)", () => {
45
47
  expect.objectContaining({
46
48
  method: "POST",
47
49
  headers: expect.objectContaining({
48
- "QB-Realm-Hostname": "test-realm.quickbase.com",
49
- Authorization: "QB-USER-TOKEN test-token",
50
+ "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
51
+ Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
50
52
  "Content-Type": "application/json",
51
53
  }),
52
54
  body: JSON.stringify({
53
- to: "test-table-id",
55
+ to: QB_TABLE_ID_1,
54
56
  data: [{ "6": { value: "value1" } }],
55
57
  }),
56
58
  })
@@ -68,11 +70,7 @@ describe("QuickbaseClient - upsert (Unit)", () => {
68
70
  });
69
71
 
70
72
  test("handles API error with invalid data", async () => {
71
- const qb = createClient(mockFetch, {
72
- realm: "test-realm",
73
- userToken: "test-token",
74
- debug: true,
75
- });
73
+ const qb = createClient(mockFetch, { debug: true });
76
74
 
77
75
  mockFetch.mockResolvedValueOnce({
78
76
  ok: false,
@@ -82,7 +80,7 @@ describe("QuickbaseClient - upsert (Unit)", () => {
82
80
 
83
81
  await expect(
84
82
  qb.upsert({
85
- body: { to: "test-table-id", data: [{ "999": { value: "invalid" } }] },
83
+ body: { to: QB_TABLE_ID_1, data: [{ "999": { value: "invalid" } }] },
86
84
  })
87
85
  ).rejects.toThrow("API Error: Invalid data format (Status: 400)");
88
86
 
@@ -91,12 +89,12 @@ describe("QuickbaseClient - upsert (Unit)", () => {
91
89
  expect.objectContaining({
92
90
  method: "POST",
93
91
  headers: expect.objectContaining({
94
- "QB-Realm-Hostname": "test-realm.quickbase.com",
95
- Authorization: "QB-USER-TOKEN test-token",
92
+ "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
93
+ Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
96
94
  "Content-Type": "application/json",
97
95
  }),
98
96
  body: JSON.stringify({
99
- to: "test-table-id",
97
+ to: QB_TABLE_ID_1,
100
98
  data: [{ "999": { value: "invalid" } }],
101
99
  }),
102
100
  })
@@ -104,11 +102,7 @@ describe("QuickbaseClient - upsert (Unit)", () => {
104
102
  });
105
103
 
106
104
  test("handles upsert with temp token", async () => {
107
- const qb = createClient(mockFetch, {
108
- realm: "test-realm",
109
- useTempTokens: true,
110
- debug: true,
111
- });
105
+ const qb = createClient(mockFetch, { useTempTokens: true, debug: true });
112
106
 
113
107
  mockFetch
114
108
  .mockResolvedValueOnce({
@@ -132,18 +126,18 @@ describe("QuickbaseClient - upsert (Unit)", () => {
132
126
  });
133
127
 
134
128
  const result = await qb.upsert({
135
- body: { to: "test-table-id", data: [{ "7": { value: "value2" } }] },
136
- dbid: "test-dbid",
129
+ body: { to: QB_TABLE_ID_1, data: [{ "7": { value: "value2" } }] },
130
+ dbid: QB_TABLE_ID_1, // Use QB_TABLE_ID_1 as dbid for temp token
137
131
  } as any); // Temporary type assertion until types.d.ts is applied
138
132
 
139
133
  expect(mockFetch).toHaveBeenCalledTimes(2);
140
134
  expect(mockFetch).toHaveBeenNthCalledWith(
141
135
  1,
142
- "https://api.quickbase.com/v1/auth/temporary/test-dbid",
136
+ `https://api.quickbase.com/v1/auth/temporary/${QB_TABLE_ID_1}`,
143
137
  expect.objectContaining({
144
138
  method: "GET",
145
139
  headers: expect.objectContaining({
146
- "QB-Realm-Hostname": "test-realm.quickbase.com",
140
+ "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
147
141
  "Content-Type": "application/json",
148
142
  }),
149
143
  credentials: "include",
@@ -155,12 +149,12 @@ describe("QuickbaseClient - upsert (Unit)", () => {
155
149
  expect.objectContaining({
156
150
  method: "POST",
157
151
  headers: expect.objectContaining({
158
- "QB-Realm-Hostname": "test-realm.quickbase.com",
152
+ "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
159
153
  Authorization: "QB-TEMP-TOKEN temp-token",
160
154
  "Content-Type": "application/json",
161
155
  }),
162
156
  body: JSON.stringify({
163
- to: "test-table-id",
157
+ to: QB_TABLE_ID_1,
164
158
  data: [{ "7": { value: "value2" } }],
165
159
  }),
166
160
  })
@@ -178,11 +172,7 @@ describe("QuickbaseClient - upsert (Unit)", () => {
178
172
  });
179
173
 
180
174
  test("sends correct POST request with data fields", async () => {
181
- const qb = createClient(mockFetch, {
182
- realm: "test-realm",
183
- userToken: "test-token",
184
- debug: true,
185
- });
175
+ const qb = createClient(mockFetch, { debug: true });
186
176
 
187
177
  mockFetch.mockResolvedValueOnce({
188
178
  ok: true,
@@ -200,7 +190,7 @@ describe("QuickbaseClient - upsert (Unit)", () => {
200
190
  });
201
191
 
202
192
  const result = await qb.upsert({
203
- body: { to: "test-table-id", data: [{ "6": { value: "value1" } }] },
193
+ body: { to: QB_TABLE_ID_1, data: [{ "6": { value: "value1" } }] },
204
194
  });
205
195
 
206
196
  expect(mockFetch).toHaveBeenCalledWith(
@@ -208,12 +198,12 @@ describe("QuickbaseClient - upsert (Unit)", () => {
208
198
  expect.objectContaining({
209
199
  method: "POST",
210
200
  headers: expect.objectContaining({
211
- "QB-Realm-Hostname": "test-realm.quickbase.com",
212
- Authorization: "QB-USER-TOKEN test-token",
201
+ "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
202
+ Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
213
203
  "Content-Type": "application/json",
214
204
  }),
215
205
  body: JSON.stringify({
216
- to: "test-table-id",
206
+ to: QB_TABLE_ID_1,
217
207
  data: [{ "6": { value: "value1" } }],
218
208
  }),
219
209
  })
@@ -1,7 +1,14 @@
1
- import { describe, it, expect, beforeEach, vi } from "vitest";
2
- import { createClient, mockFetch } from "@tests/setup.ts";
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";
3
10
 
4
- describe("QuickbaseClient - createTable (Unit)", () => {
11
+ describe("QuickbaseClient Unit - createTable", () => {
5
12
  let client: ReturnType<typeof createClient>;
6
13
 
7
14
  beforeEach(() => {
@@ -10,7 +17,6 @@ describe("QuickbaseClient - createTable (Unit)", () => {
10
17
  });
11
18
 
12
19
  it("calls createTable successfully with user token", async () => {
13
- const appId = "buwai2zpe";
14
20
  const mockBody = {
15
21
  name: "TestTable",
16
22
  description: "Unit test table",
@@ -18,7 +24,7 @@ describe("QuickbaseClient - createTable (Unit)", () => {
18
24
  pluralRecordName: "Tests",
19
25
  };
20
26
  const mockResponse = {
21
- id: "buya8h9iz",
27
+ id: "newly-created-table-id-1234567890", // Changed from "buya8h9iz"
22
28
  name: "TestTable",
23
29
  alias: "_DBID_TESTTABLE",
24
30
  description: "Unit test table",
@@ -42,18 +48,20 @@ describe("QuickbaseClient - createTable (Unit)", () => {
42
48
  json: () => Promise.resolve(mockResponse),
43
49
  });
44
50
 
45
- const response = await client.createTable({ appId, body: mockBody });
51
+ const response = await client.createTable({
52
+ appId: QB_APP_ID,
53
+ body: mockBody,
54
+ });
46
55
  expect(response).toEqual(mockResponse);
47
56
  expect(mockFetch).toHaveBeenCalledTimes(1);
48
57
  expect(mockFetch).toHaveBeenCalledWith(
49
- `https://api.quickbase.com/v1/tables?appId=${appId}`,
58
+ `https://api.quickbase.com/v1/tables?appId=${QB_APP_ID}`,
50
59
  expect.objectContaining({
51
60
  method: "POST",
52
61
  headers: expect.objectContaining({
53
62
  "Content-Type": "application/json",
54
- "QB-Realm-Hostname": "builderprogram-dbradford6815.quickbase.com",
55
- Authorization:
56
- "QB-USER-TOKEN b9f3pk_q4jd_0_b4qu5eebyvuix3xs57ysd7zn3",
63
+ "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
64
+ Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
57
65
  }),
58
66
  body: JSON.stringify(mockBody),
59
67
  })
@@ -1,7 +1,15 @@
1
- import { describe, it, expect, beforeEach, vi } from "vitest";
2
- import { createClient, mockFetch } from "@tests/setup.ts";
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";
3
11
 
4
- describe("QuickbaseClient - deleteTable (Unit)", () => {
12
+ describe("QuickbaseClient Unit - deleteTable", () => {
5
13
  let client: ReturnType<typeof createClient>;
6
14
 
7
15
  beforeEach(() => {
@@ -10,10 +18,8 @@ describe("QuickbaseClient - deleteTable (Unit)", () => {
10
18
  });
11
19
 
12
20
  it("calls deleteTable successfully with user token", async () => {
13
- const appId = "buwai2zpe";
14
- const tableId = "buya8h9iz";
15
21
  const mockResponse = {
16
- deletedTableId: tableId,
22
+ deletedTableId: QB_TABLE_ID_1,
17
23
  };
18
24
 
19
25
  mockFetch.mockResolvedValueOnce({
@@ -22,27 +28,26 @@ describe("QuickbaseClient - deleteTable (Unit)", () => {
22
28
  json: () => Promise.resolve(mockResponse),
23
29
  });
24
30
 
25
- const response = await client.deleteTable({ tableId, appId });
31
+ const response = await client.deleteTable({
32
+ tableId: QB_TABLE_ID_1,
33
+ appId: QB_APP_ID,
34
+ });
26
35
  expect(response).toEqual(mockResponse);
27
36
  expect(mockFetch).toHaveBeenCalledTimes(1);
28
37
  expect(mockFetch).toHaveBeenCalledWith(
29
- `https://api.quickbase.com/v1/tables/${tableId}?appId=${appId}`,
38
+ `https://api.quickbase.com/v1/tables/${QB_TABLE_ID_1}?appId=${QB_APP_ID}`,
30
39
  expect.objectContaining({
31
40
  method: "DELETE",
32
41
  headers: expect.objectContaining({
33
42
  "Content-Type": "application/json",
34
- "QB-Realm-Hostname": "builderprogram-dbradford6815.quickbase.com",
35
- Authorization:
36
- "QB-USER-TOKEN b9f3pk_q4jd_0_b4qu5eebyvuix3xs57ysd7zn3",
43
+ "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
44
+ Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
37
45
  }),
38
46
  })
39
47
  );
40
48
  });
41
49
 
42
50
  it("handles 404 error for non-existent table", async () => {
43
- const appId = "buwai2zpe";
44
- const tableId = "nonexistent";
45
-
46
51
  mockFetch.mockResolvedValueOnce({
47
52
  ok: false,
48
53
  status: 404,
@@ -53,15 +58,19 @@ describe("QuickbaseClient - deleteTable (Unit)", () => {
53
58
  }),
54
59
  });
55
60
 
56
- await expect(client.deleteTable({ tableId, appId })).rejects.toThrow(
57
- "API Error: Invalid DBID (Status: 404)"
58
- );
61
+ await expect(
62
+ client.deleteTable({ tableId: QB_TABLE_ID_1, appId: QB_APP_ID })
63
+ ).rejects.toThrow("API Error: Invalid DBID (Status: 404)");
59
64
  expect(mockFetch).toHaveBeenCalledTimes(1);
60
65
  expect(mockFetch).toHaveBeenCalledWith(
61
- `https://api.quickbase.com/v1/tables/${tableId}?appId=${appId}`,
66
+ `https://api.quickbase.com/v1/tables/${QB_TABLE_ID_1}?appId=${QB_APP_ID}`,
62
67
  expect.objectContaining({
63
68
  method: "DELETE",
64
- headers: expect.any(Object),
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
+ }),
65
74
  })
66
75
  );
67
76
  });
@@ -1,7 +1,21 @@
1
- import { describe, it, expect } from "vitest";
2
- import { createClient, mockFetch } from "@tests/setup.ts";
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
+ });
3
18
 
4
- describe("QuickbaseClient - getAppTables (Unit)", () => {
5
19
  it("calls getAppTables successfully", async () => {
6
20
  mockFetch.mockImplementation((url: string, options: any) => {
7
21
  console.log("Mock fetch for getAppTables:", url, options);
@@ -11,60 +25,59 @@ describe("QuickbaseClient - getAppTables (Unit)", () => {
11
25
  json: () =>
12
26
  Promise.resolve([
13
27
  {
28
+ id: "buwai2zr4",
29
+ name: "Root",
14
30
  alias: "_DBID_ROOT",
15
- created: "2025-02-13T18:22:33Z",
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,
16
36
  defaultSortFieldId: 2,
17
37
  defaultSortOrder: "DESC",
18
- description: "",
19
- id: "buwai2zr4",
20
38
  keyFieldId: 3,
21
- name: "Root",
22
- nextFieldId: 6,
23
- nextRecordId: 1,
24
- pluralRecordName: "Roots",
25
39
  singleRecordName: "Root",
40
+ pluralRecordName: "Roots",
26
41
  sizeLimit: "500 MB",
27
- spaceRemaining: "500 MB",
28
42
  spaceUsed: "0 KB",
29
- updated: "2025-02-13T18:22:34Z",
43
+ spaceRemaining: "500 MB",
30
44
  },
31
45
  ]),
32
46
  } as Response);
33
47
  });
34
48
 
35
- const client = createClient(mockFetch);
36
- const tablesAppId = process.env.QB_APP_ID;
37
- if (!tablesAppId) throw new Error("QB_APP_ID is not defined in .env");
38
- const result = await client.getAppTables({ appId: tablesAppId });
49
+ const result = await client.getAppTables({ appId: QB_APP_ID });
39
50
  console.log("getAppTables response:", result);
40
51
  expect(result).toEqual(
41
52
  expect.arrayContaining([
42
53
  expect.objectContaining({
54
+ id: "buwai2zr4",
55
+ name: "Root",
43
56
  alias: "_DBID_ROOT",
44
- created: new Date("2025-02-13T18:22:33Z"),
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,
45
62
  defaultSortFieldId: 2,
46
63
  defaultSortOrder: "DESC",
47
- description: "",
48
- id: "buwai2zr4",
49
64
  keyFieldId: 3,
50
- name: "Root",
51
- nextFieldId: 6,
52
- nextRecordId: 1,
53
- pluralRecordName: "Roots",
54
65
  singleRecordName: "Root",
66
+ pluralRecordName: "Roots",
55
67
  sizeLimit: "500 MB",
56
- spaceRemaining: "500 MB",
57
68
  spaceUsed: "0 KB",
58
- updated: new Date("2025-02-13T18:22:34Z"),
69
+ spaceRemaining: "500 MB",
59
70
  }),
60
71
  ])
61
72
  );
62
73
  expect(mockFetch).toHaveBeenCalledWith(
63
- `https://api.quickbase.com/v1/tables?appId=${tablesAppId}`,
74
+ `https://api.quickbase.com/v1/tables?appId=${QB_APP_ID}`,
64
75
  expect.objectContaining({
76
+ method: "GET",
65
77
  headers: expect.objectContaining({
66
- Authorization: `QB-USER-TOKEN ${process.env.QB_USER_TOKEN}`,
67
- "QB-Realm-Hostname": `${process.env.QB_REALM}.quickbase.com`,
78
+ "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
79
+ Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
80
+ "Content-Type": "application/json",
68
81
  }),
69
82
  })
70
83
  );
@@ -1,19 +1,26 @@
1
- import { describe, it, expect, beforeEach, vi } from "vitest";
2
- import { createClient, mockFetch } from "@tests/setup.ts";
3
-
4
- describe("QuickbaseClient - getTable (Unit)", () => {
1
+ // tests/vitest/unit/tables/getTable.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 - getTable", () => {
5
13
  let client: ReturnType<typeof createClient>;
6
14
 
7
15
  beforeEach(() => {
8
16
  mockFetch.mockClear();
9
- client = createClient(mockFetch, { debug: true });
10
17
  });
11
18
 
12
19
  it("calls getTable successfully with user token", async () => {
13
- const mockAppId = "buwai2zpe";
14
- const mockTableId = "buwai2zr4";
20
+ client = createClient(mockFetch, { debug: true });
21
+
15
22
  const mockResponse = {
16
- id: mockTableId,
23
+ id: QB_TABLE_ID_1,
17
24
  name: "Root",
18
25
  alias: "_DBID_ROOT",
19
26
  description: "",
@@ -38,17 +45,17 @@ describe("QuickbaseClient - getTable (Unit)", () => {
38
45
  });
39
46
 
40
47
  const response = await client.getTable({
41
- tableId: mockTableId,
42
- appId: mockAppId,
48
+ tableId: QB_TABLE_ID_1,
49
+ appId: QB_APP_ID,
43
50
  });
44
51
  expect(response).toEqual(mockResponse);
45
52
  expect(mockFetch).toHaveBeenCalledWith(
46
- `https://api.quickbase.com/v1/tables/${mockTableId}?appId=${mockAppId}`,
53
+ `https://api.quickbase.com/v1/tables/${QB_TABLE_ID_1}?appId=${QB_APP_ID}`,
47
54
  expect.objectContaining({
48
55
  method: "GET",
49
56
  headers: expect.objectContaining({
50
- Authorization:
51
- "QB-USER-TOKEN b9f3pk_q4jd_0_b4qu5eebyvuix3xs57ysd7zn3",
57
+ "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
58
+ Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
52
59
  }),
53
60
  })
54
61
  );
@@ -56,10 +63,9 @@ describe("QuickbaseClient - getTable (Unit)", () => {
56
63
 
57
64
  it("calls getTable successfully with temp token", async () => {
58
65
  client = createClient(mockFetch, { debug: true, useTempTokens: true });
59
- const mockAppId = "buwai2zpe";
60
- const mockTableId = "buwai2zr4";
66
+
61
67
  const mockResponse = {
62
- id: mockTableId,
68
+ id: QB_TABLE_ID_1,
63
69
  name: "Root",
64
70
  alias: "_DBID_ROOT",
65
71
  description: "",
@@ -90,19 +96,20 @@ describe("QuickbaseClient - getTable (Unit)", () => {
90
96
  });
91
97
 
92
98
  const response = await client.getTable({
93
- tableId: mockTableId,
94
- appId: mockAppId,
99
+ tableId: QB_TABLE_ID_1,
100
+ appId: QB_APP_ID,
95
101
  });
96
102
  expect(response).toEqual(mockResponse);
97
103
  expect(mockFetch).toHaveBeenCalledTimes(2);
98
104
  expect(mockFetch).toHaveBeenCalledWith(
99
- `https://api.quickbase.com/v1/auth/temporary/${mockTableId}`,
105
+ `https://api.quickbase.com/v1/auth/temporary/${QB_TABLE_ID_1}`,
100
106
  expect.any(Object)
101
107
  );
102
108
  expect(mockFetch).toHaveBeenCalledWith(
103
- `https://api.quickbase.com/v1/tables/${mockTableId}?appId=${mockAppId}`,
109
+ `https://api.quickbase.com/v1/tables/${QB_TABLE_ID_1}?appId=${QB_APP_ID}`,
104
110
  expect.objectContaining({
105
111
  headers: expect.objectContaining({
112
+ "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
106
113
  Authorization: "QB-TEMP-TOKEN temp_token",
107
114
  }),
108
115
  })
@@ -111,10 +118,9 @@ describe("QuickbaseClient - getTable (Unit)", () => {
111
118
 
112
119
  it("retries successfully after 401 with temp token", async () => {
113
120
  client = createClient(mockFetch, { debug: true, useTempTokens: true });
114
- const mockAppId = "buwai2zpe";
115
- const mockTableId = "buwai2zr4";
121
+
116
122
  const mockResponse = {
117
- id: mockTableId,
123
+ id: QB_TABLE_ID_1,
118
124
  name: "Root",
119
125
  alias: "_DBID_ROOT",
120
126
  description: "",
@@ -156,17 +162,23 @@ describe("QuickbaseClient - getTable (Unit)", () => {
156
162
  });
157
163
 
158
164
  const response = await client.getTable({
159
- tableId: mockTableId,
160
- appId: mockAppId,
165
+ tableId: QB_TABLE_ID_1,
166
+ appId: QB_APP_ID,
161
167
  });
162
168
  expect(response).toEqual(mockResponse);
163
- expect(mockFetch).toHaveBeenCalledTimes(4); // Initial token, 401, retry token, success
169
+ expect(mockFetch).toHaveBeenCalledTimes(4);
170
+ expect(mockFetch).toHaveBeenCalledWith(
171
+ `https://api.quickbase.com/v1/tables/${QB_TABLE_ID_1}?appId=${QB_APP_ID}`,
172
+ expect.objectContaining({
173
+ headers: expect.objectContaining({
174
+ Authorization: "QB-TEMP-TOKEN new_token",
175
+ }),
176
+ })
177
+ );
164
178
  });
165
179
 
166
180
  it("handles 401 with failed temp token retry", async () => {
167
181
  client = createClient(mockFetch, { debug: true, useTempTokens: true });
168
- const mockAppId = "buwai2zpe";
169
- const mockTableId = "buwai2zr4";
170
182
 
171
183
  mockFetch
172
184
  .mockResolvedValueOnce({
@@ -188,7 +200,7 @@ describe("QuickbaseClient - getTable (Unit)", () => {
188
200
  });
189
201
 
190
202
  await expect(
191
- client.getTable({ tableId: mockTableId, appId: mockAppId })
203
+ client.getTable({ tableId: QB_TABLE_ID_1, appId: QB_APP_ID })
192
204
  ).rejects.toThrow(
193
205
  "API Error: Unauthorized in fetchTempToken (Status: 401)"
194
206
  );
@@ -196,8 +208,7 @@ describe("QuickbaseClient - getTable (Unit)", () => {
196
208
  });
197
209
 
198
210
  it("handles 404 Not Found", async () => {
199
- const mockAppId = "buwai2zpe";
200
- const mockTableId = "invalidTableId";
211
+ client = createClient(mockFetch, { debug: true });
201
212
 
202
213
  mockFetch.mockResolvedValueOnce({
203
214
  ok: false,
@@ -206,7 +217,17 @@ describe("QuickbaseClient - getTable (Unit)", () => {
206
217
  });
207
218
 
208
219
  await expect(
209
- client.getTable({ tableId: mockTableId, appId: mockAppId })
220
+ client.getTable({ tableId: QB_TABLE_ID_1, appId: QB_APP_ID })
210
221
  ).rejects.toThrow("API Error: Table not found (Status: 404)");
222
+ expect(mockFetch).toHaveBeenCalledWith(
223
+ `https://api.quickbase.com/v1/tables/${QB_TABLE_ID_1}?appId=${QB_APP_ID}`,
224
+ expect.objectContaining({
225
+ method: "GET",
226
+ headers: expect.objectContaining({
227
+ "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
228
+ Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
229
+ }),
230
+ })
231
+ );
211
232
  });
212
233
  });