quickbase-js 1.1.0-beta.0 → 1.1.0-beta.1
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.
- package/CHANGELOG.md +14 -0
- package/examples/react.js +42 -16
- package/examples/vanillajs.html +32 -8
- package/log-gen.yaml +146 -198
- package/package.json +4 -4
- package/src/code-generation/fix-spec-definitions.ts +99 -41
- package/src/code-generation/fix-spec-paths.ts +6 -19
- package/src/code-generation/generate-unified-interface.ts +1 -8
- package/src/code-generation/output/quickbase-fixed.json +142 -21
- package/src/generated-unified/QuickbaseClient.ts +3 -3
- package/tests/playwright/qb/auth/cacheSwitching.test.ts +2 -2
- package/tests/setup.ts +29 -9
- package/tests/vitest/qb/fields/getFields.test.ts +3 -5
- package/tests/vitest/qb/records/runQuery.test.ts +82 -0
- package/tests/vitest/unit/apps/getApp.test.ts +17 -12
- package/tests/vitest/unit/auth/fetchTempToken401.test.ts +29 -4
- package/tests/vitest/unit/auth/getTempToken.test.ts +30 -17
- package/tests/vitest/unit/auth/retryOn401.test.ts +39 -5
- package/tests/vitest/unit/fields/getFields.test.ts +14 -7
- package/tests/vitest/unit/records/deleteRecords.test.ts +28 -34
- package/tests/vitest/unit/records/runQuery.test.ts +102 -0
- package/tests/vitest/unit/records/upsert.test.ts +31 -41
- package/tests/vitest/unit/tables/createTable.test.ts +18 -10
- package/tests/vitest/unit/tables/deleteTable.test.ts +28 -19
- package/tests/vitest/unit/tables/getAppTables.test.ts +41 -28
- package/tests/vitest/unit/tables/getTable.test.ts +53 -32
- package/tests/vitest/unit/tables/updateTable.test.ts +17 -11
- 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 {
|
|
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
|
|
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:
|
|
38
|
+
body: { to: QB_TABLE_ID_1, data: [{ "6": { value: "value1" } }] },
|
|
37
39
|
});
|
|
38
40
|
const result = await qb.upsert({
|
|
39
|
-
body: { to:
|
|
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":
|
|
49
|
-
Authorization:
|
|
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:
|
|
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:
|
|
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":
|
|
95
|
-
Authorization:
|
|
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:
|
|
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:
|
|
136
|
-
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
|
-
|
|
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":
|
|
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":
|
|
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:
|
|
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:
|
|
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":
|
|
212
|
-
Authorization:
|
|
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:
|
|
206
|
+
to: QB_TABLE_ID_1,
|
|
217
207
|
data: [{ "6": { value: "value1" } }],
|
|
218
208
|
}),
|
|
219
209
|
})
|
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
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
|
|
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({
|
|
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=${
|
|
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":
|
|
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
|
-
|
|
2
|
-
import {
|
|
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
|
|
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:
|
|
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({
|
|
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/${
|
|
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":
|
|
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(
|
|
57
|
-
|
|
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/${
|
|
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.
|
|
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
|
-
|
|
2
|
-
import {
|
|
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
|
-
|
|
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
|
-
|
|
43
|
+
spaceRemaining: "500 MB",
|
|
30
44
|
},
|
|
31
45
|
]),
|
|
32
46
|
} as Response);
|
|
33
47
|
});
|
|
34
48
|
|
|
35
|
-
const
|
|
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
|
-
|
|
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
|
-
|
|
69
|
+
spaceRemaining: "500 MB",
|
|
59
70
|
}),
|
|
60
71
|
])
|
|
61
72
|
);
|
|
62
73
|
expect(mockFetch).toHaveBeenCalledWith(
|
|
63
|
-
`https://api.quickbase.com/v1/tables?appId=${
|
|
74
|
+
`https://api.quickbase.com/v1/tables?appId=${QB_APP_ID}`,
|
|
64
75
|
expect.objectContaining({
|
|
76
|
+
method: "GET",
|
|
65
77
|
headers: expect.objectContaining({
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
14
|
-
|
|
20
|
+
client = createClient(mockFetch, { debug: true });
|
|
21
|
+
|
|
15
22
|
const mockResponse = {
|
|
16
|
-
id:
|
|
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:
|
|
42
|
-
appId:
|
|
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/${
|
|
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
|
-
|
|
51
|
-
|
|
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
|
-
|
|
60
|
-
const mockTableId = "buwai2zr4";
|
|
66
|
+
|
|
61
67
|
const mockResponse = {
|
|
62
|
-
id:
|
|
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:
|
|
94
|
-
appId:
|
|
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/${
|
|
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/${
|
|
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
|
-
|
|
115
|
-
const mockTableId = "buwai2zr4";
|
|
121
|
+
|
|
116
122
|
const mockResponse = {
|
|
117
|
-
id:
|
|
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:
|
|
160
|
-
appId:
|
|
165
|
+
tableId: QB_TABLE_ID_1,
|
|
166
|
+
appId: QB_APP_ID,
|
|
161
167
|
});
|
|
162
168
|
expect(response).toEqual(mockResponse);
|
|
163
|
-
expect(mockFetch).toHaveBeenCalledTimes(4);
|
|
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:
|
|
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
|
-
|
|
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:
|
|
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
|
});
|