quickbase-js 0.1.0-beta.10
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 +211 -0
- package/LICENSE +21 -0
- package/README.md +179 -0
- package/api-examples.md +49 -0
- package/build-common.js +131 -0
- package/build-esm.js +71 -0
- package/build-umd.js +69 -0
- package/dist/esm/quickbase.d.ts +8081 -0
- package/dist/esm/quickbase.js +7928 -0
- package/dist/esm/quickbase.js.map +1 -0
- package/dist/esm/quickbase.min.js +2 -0
- package/dist/esm/quickbase.min.js.map +1 -0
- package/dist/umd/quickbase.umd.js +8504 -0
- package/dist/umd/quickbase.umd.js.map +1 -0
- package/dist/umd/quickbase.umd.min.js +2 -0
- package/dist/umd/quickbase.umd.min.js.map +1 -0
- package/docs/.vitepress/cache/deps/@theme_index.js +275 -0
- package/docs/.vitepress/cache/deps/@theme_index.js.map +7 -0
- package/docs/.vitepress/cache/deps/_metadata.json +40 -0
- package/docs/.vitepress/cache/deps/chunk-5A67QEFC.js +12542 -0
- package/docs/.vitepress/cache/deps/chunk-5A67QEFC.js.map +7 -0
- package/docs/.vitepress/cache/deps/chunk-7D4P4MMP.js +9719 -0
- package/docs/.vitepress/cache/deps/chunk-7D4P4MMP.js.map +7 -0
- package/docs/.vitepress/cache/deps/package.json +3 -0
- package/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js +4504 -0
- package/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js.map +7 -0
- package/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js +583 -0
- package/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js.map +7 -0
- package/docs/.vitepress/cache/deps/vue.js +343 -0
- package/docs/.vitepress/cache/deps/vue.js.map +7 -0
- package/docs/.vitepress/config.mts +26 -0
- package/docs/api-examples.md +49 -0
- package/docs/index.md +59 -0
- package/docs/markdown-examples.md +85 -0
- package/docs-data/api-docs.json +4143 -0
- package/examples/quicbase-jsCDN.html +36 -0
- package/examples/react.js +48 -0
- package/examples/vanillajs.html +47 -0
- package/index.md +25 -0
- package/markdown-examples.md +85 -0
- package/open-api/fix-spec-main.ts +133 -0
- package/open-api/generate-unified-interface.ts +104 -0
- package/open-api/generateDocsJson.ts +24 -0
- package/open-api/output/quickbase-fixed.json +11191 -0
- package/open-api/post-process-generated.ts +226 -0
- package/open-api/regenerate-client.ts +117 -0
- package/open-api/schema/enhance-general.ts +111 -0
- package/open-api/schema/fix-arrays.ts +68 -0
- package/open-api/schema/tags/apps.ts +90 -0
- package/open-api/schema/tags/fields.ts +471 -0
- package/open-api/schema/tags/groups.ts +51 -0
- package/open-api/schema/tags/index.ts +66 -0
- package/open-api/schema/tags/records.ts +115 -0
- package/open-api/schema/tags/tables.ts +211 -0
- package/open-api/schema/tags/users.ts +47 -0
- package/open-api/types/spec.ts +42 -0
- package/open-api/utils/common.ts +29 -0
- package/open-api/utils/generateJsDoc.ts +74 -0
- package/open-api/utils/infer-schema.ts +40 -0
- package/open-api/utils/naming.ts +10 -0
- package/open-api/utils/sharedUtils.ts +352 -0
- package/package.json +96 -0
- package/playwright.config.ts +37 -0
- package/rollup.config.js +114 -0
- package/specs/QuickBase_RESTful_API_2025-03-04T06_22_39.725Z.json +46878 -0
- package/specs/split/apps.json +1315 -0
- package/specs/split/auth.json +191 -0
- package/specs/split/fields.json +3869 -0
- package/specs/split/records.json +754 -0
- package/specs/split/reports.json +619 -0
- package/specs/split/tables.json +1605 -0
- package/src/RateLimitError.ts +12 -0
- package/src/ThrottleBucket.ts +41 -0
- package/src/authorizationStrategy.ts +283 -0
- package/src/generated-unified/QuickbaseClient.ts +1135 -0
- package/src/generated-unified/missing-types-report.json +3 -0
- package/src/index.ts +1 -0
- package/src/invokeMethod.ts +245 -0
- package/src/quickbaseClient.ts +194 -0
- package/src/rateLimiter.ts +25 -0
- package/src/tokenCache.ts +35 -0
- package/src/utils.ts +50 -0
- package/tests/playwright/qb/auth/cacheSwitching.test.ts +159 -0
- package/tests/playwright/qb/auth/fetchTempToken401.test.ts +219 -0
- package/tests/playwright/qb/auth/getAppWithTempToken.test.ts +162 -0
- package/tests/playwright/qb/auth/getAppWithUserToken.test.ts +153 -0
- package/tests/playwright/qb/auth/getTempToken.test.ts +152 -0
- package/tests/playwright/qb/auth/tempTokenPrefetch.test.ts +179 -0
- package/tests/playwright/qb/auth/tempTokenRenewal.test.ts +133 -0
- package/tests/setup.ts +53 -0
- package/tests/vitest/qb/apps/copyApp.test.ts +76 -0
- package/tests/vitest/qb/apps/createApp.test.ts +64 -0
- package/tests/vitest/qb/apps/deleteApp.test.ts +76 -0
- package/tests/vitest/qb/apps/getApp.test.ts +44 -0
- package/tests/vitest/qb/apps/getAppEvents.test.ts +67 -0
- package/tests/vitest/qb/apps/updateApp.test.ts +58 -0
- package/tests/vitest/qb/auth/mockQuickbaseServer.ts +60 -0
- package/tests/vitest/qb/auth/retryUserToken401.test.ts +73 -0
- package/tests/vitest/qb/auth/ssoTokenIntegrationWithServer.test.ts +65 -0
- package/tests/vitest/qb/fields/createField.test.ts +77 -0
- package/tests/vitest/qb/fields/deleteFields.test.ts +83 -0
- package/tests/vitest/qb/fields/getField.test.ts +85 -0
- package/tests/vitest/qb/fields/getFieldUsage.test.ts +82 -0
- package/tests/vitest/qb/fields/getFields.test.ts +232 -0
- package/tests/vitest/qb/fields/getFieldsUsage.test.ts +77 -0
- package/tests/vitest/qb/fields/updateField.test.ts +93 -0
- package/tests/vitest/qb/formulas/runFormula.test.ts +96 -0
- package/tests/vitest/qb/index.ts +29 -0
- package/tests/vitest/qb/records/deleteRecords.test.ts +110 -0
- package/tests/vitest/qb/records/runQuery.test.ts +146 -0
- package/tests/vitest/qb/records/upsert.test.ts +102 -0
- package/tests/vitest/qb/tables/createRelationship.test.ts +102 -0
- package/tests/vitest/qb/tables/createTable.test.ts +55 -0
- package/tests/vitest/qb/tables/deleteRelationship.test.ts +143 -0
- package/tests/vitest/qb/tables/deleteTable.test.ts +50 -0
- package/tests/vitest/qb/tables/getAppTables.test.ts +46 -0
- package/tests/vitest/qb/tables/getRelationships.test.ts +80 -0
- package/tests/vitest/qb/tables/getTable.test.ts +26 -0
- package/tests/vitest/qb/tables/updateRelationship.test.ts +250 -0
- package/tests/vitest/qb/tables/updateTable.test.ts +48 -0
- package/tests/vitest/unit/ThrottleBucket.test.ts +95 -0
- package/tests/vitest/unit/apps/copyApp.test.ts +581 -0
- package/tests/vitest/unit/apps/createApp.test.ts +186 -0
- package/tests/vitest/unit/apps/deleteApp.test.ts +216 -0
- package/tests/vitest/unit/apps/getApp.test.ts +128 -0
- package/tests/vitest/unit/apps/getAppEvents.test.ts +193 -0
- package/tests/vitest/unit/apps/updateApp.test.ts +412 -0
- package/tests/vitest/unit/auth/fetchTempToken401.test.ts +63 -0
- package/tests/vitest/unit/auth/getTempToken.test.ts +119 -0
- package/tests/vitest/unit/auth/retryTempToken401.test.ts +95 -0
- package/tests/vitest/unit/auth/retryTempTokenMaxRetries.test.ts +206 -0
- package/tests/vitest/unit/auth/retryUserToken401.test.ts +69 -0
- package/tests/vitest/unit/auth/ssoTokenRefresh.test.ts +325 -0
- package/tests/vitest/unit/fields/createField.test.ts +451 -0
- package/tests/vitest/unit/fields/deleteFields.test.ts +141 -0
- package/tests/vitest/unit/fields/getField.test.ts +189 -0
- package/tests/vitest/unit/fields/getFieldUsage.test.ts +180 -0
- package/tests/vitest/unit/fields/getFields.test.ts +122 -0
- package/tests/vitest/unit/fields/getFieldsUsage.test.ts +160 -0
- package/tests/vitest/unit/fields/updateField.test.ts +285 -0
- package/tests/vitest/unit/formulas/runFormula.test.ts +205 -0
- package/tests/vitest/unit/index.ts +34 -0
- package/tests/vitest/unit/quickbaseClientHttpMethods.test.ts +139 -0
- package/tests/vitest/unit/rateLimit.test.ts +191 -0
- package/tests/vitest/unit/records/deleteRecords.test.ts +112 -0
- package/tests/vitest/unit/records/runQuery.test.ts +102 -0
- package/tests/vitest/unit/records/upsert.test.ts +234 -0
- package/tests/vitest/unit/tables/createRelationship.test.ts +212 -0
- package/tests/vitest/unit/tables/createTable.test.ts +70 -0
- package/tests/vitest/unit/tables/deleteRelationship.test.ts +97 -0
- package/tests/vitest/unit/tables/deleteTable.test.ts +77 -0
- package/tests/vitest/unit/tables/getAppTables.test.ts +85 -0
- package/tests/vitest/unit/tables/getRelationships.test.ts +259 -0
- package/tests/vitest/unit/tables/getTable.test.ts +233 -0
- package/tests/vitest/unit/tables/updateRelationship.test.ts +307 -0
- package/tests/vitest/unit/tables/updateTable.test.ts +80 -0
- package/tests/vitest/unit/tokenLifespan.test.ts +204 -0
- package/tests/vitest/unit/umd.test.ts +8 -0
- package/tools/log-gen.ts +251 -0
- package/tools/log-gen.yaml +4777 -0
- package/tools/openapi-jars/openapi-generator-cli-7.12.0.jar +0 -0
- package/tsconfig.build.json +17 -0
- package/tsconfig.json +32 -0
- package/versionrc.json +9 -0
- package/vitest.config.ts +27 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
createClient,
|
|
4
|
+
mockFetch,
|
|
5
|
+
QB_TABLE_ID_1,
|
|
6
|
+
QB_TABLE_ID_2,
|
|
7
|
+
} from "@tests/setup.ts";
|
|
8
|
+
import {
|
|
9
|
+
CreateRelationship200Response,
|
|
10
|
+
CreateRelationshipRequest,
|
|
11
|
+
} from "/home/drew/Projects/quickbase-js/src/generated/models";
|
|
12
|
+
|
|
13
|
+
describe("QuickbaseClient Unit - createRelationship", () => {
|
|
14
|
+
let client: ReturnType<typeof createClient>;
|
|
15
|
+
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
mockFetch.mockClear();
|
|
18
|
+
client = createClient(mockFetch, { debug: true });
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("initializes without errors", () => {
|
|
22
|
+
expect(client).toBeDefined();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("has createRelationship method", () => {
|
|
26
|
+
expect(typeof client.createRelationship).toBe("function");
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("sends correct request and handles successful response", async () => {
|
|
30
|
+
const mockResponse: CreateRelationship200Response = {
|
|
31
|
+
id: 6,
|
|
32
|
+
foreignKeyField: {
|
|
33
|
+
id: 6,
|
|
34
|
+
label: "my relationship field",
|
|
35
|
+
type: "numeric",
|
|
36
|
+
},
|
|
37
|
+
lookupFields: [
|
|
38
|
+
{ id: 7, label: "Field 1", type: "text" },
|
|
39
|
+
{ id: 8, label: "Field 2", type: "text" },
|
|
40
|
+
{ id: 9, label: "Field 3", type: "text" },
|
|
41
|
+
],
|
|
42
|
+
isCrossApp: false,
|
|
43
|
+
parentTableId: QB_TABLE_ID_1,
|
|
44
|
+
childTableId: QB_TABLE_ID_2,
|
|
45
|
+
summaryFields: [
|
|
46
|
+
{ id: 10, label: "my first summary field", type: "numeric" },
|
|
47
|
+
{ id: 11, label: "my second summary field", type: "numeric" },
|
|
48
|
+
],
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
mockFetch.mockResolvedValueOnce({
|
|
52
|
+
ok: true,
|
|
53
|
+
status: 200,
|
|
54
|
+
json: () => Promise.resolve(mockResponse),
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const requestBody: CreateRelationshipRequest = {
|
|
58
|
+
parentTableId: QB_TABLE_ID_1,
|
|
59
|
+
foreignKeyField: { label: "my relationship field" },
|
|
60
|
+
lookupFieldIds: [1, 2, 3],
|
|
61
|
+
summaryFields: [
|
|
62
|
+
{
|
|
63
|
+
summaryFid: 3,
|
|
64
|
+
label: "my first summary field",
|
|
65
|
+
accumulationType: "AVG",
|
|
66
|
+
where: "{'3'.EX.1}",
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
summaryFid: 4,
|
|
70
|
+
label: "my second summary field",
|
|
71
|
+
accumulationType: "SUM",
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const tableId = QB_TABLE_ID_2;
|
|
77
|
+
|
|
78
|
+
const result = await client.createRelationship({
|
|
79
|
+
tableId,
|
|
80
|
+
body: requestBody,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
expect(mockFetch).toHaveBeenCalledTimes(1);
|
|
84
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
85
|
+
`https://api.quickbase.com/v1/tables/${QB_TABLE_ID_2}/relationship`,
|
|
86
|
+
expect.objectContaining({
|
|
87
|
+
method: "POST",
|
|
88
|
+
headers: expect.objectContaining({
|
|
89
|
+
"Content-Type": "application/json",
|
|
90
|
+
"QB-Realm-Hostname": "builderprogram-dbradford6815.quickbase.com",
|
|
91
|
+
Authorization:
|
|
92
|
+
"QB-USER-TOKEN b9f3pk_q4jd_0_b4qu5eebyvuix3xs57ysd7zn3",
|
|
93
|
+
}),
|
|
94
|
+
body: JSON.stringify(requestBody),
|
|
95
|
+
})
|
|
96
|
+
);
|
|
97
|
+
expect(result).toEqual(mockResponse);
|
|
98
|
+
expect(result.id).toBe(6);
|
|
99
|
+
expect(result.parentTableId).toBe(QB_TABLE_ID_1);
|
|
100
|
+
expect(result.childTableId).toBe(QB_TABLE_ID_2);
|
|
101
|
+
expect(result.foreignKeyField).toBeDefined();
|
|
102
|
+
if (result.foreignKeyField) {
|
|
103
|
+
expect(result.foreignKeyField.label).toBe("my relationship field");
|
|
104
|
+
}
|
|
105
|
+
expect(result.lookupFields).toHaveLength(3);
|
|
106
|
+
expect(result.summaryFields).toBeDefined();
|
|
107
|
+
if (result.summaryFields) {
|
|
108
|
+
expect(result.summaryFields).toHaveLength(2);
|
|
109
|
+
expect(result.summaryFields[0].label).toBe("my first summary field");
|
|
110
|
+
expect(result.summaryFields[1].label).toBe("my second summary field");
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("handles error from TablesApi", async () => {
|
|
115
|
+
mockFetch.mockResolvedValueOnce({
|
|
116
|
+
ok: false,
|
|
117
|
+
status: 400,
|
|
118
|
+
json: () => Promise.resolve({ message: "Invalid request payload" }),
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
const requestBody: CreateRelationshipRequest = {
|
|
122
|
+
parentTableId: QB_TABLE_ID_1,
|
|
123
|
+
foreignKeyField: { label: "my relationship field" },
|
|
124
|
+
lookupFieldIds: [1, 2, 3],
|
|
125
|
+
summaryFields: [
|
|
126
|
+
{ summaryFid: 3, label: "invalid", accumulationType: "INVALID" },
|
|
127
|
+
],
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const tableId = QB_TABLE_ID_2;
|
|
131
|
+
|
|
132
|
+
await expect(
|
|
133
|
+
client.createRelationship({
|
|
134
|
+
tableId,
|
|
135
|
+
body: requestBody,
|
|
136
|
+
})
|
|
137
|
+
).rejects.toThrow("API Error: Invalid request payload (Status: 400)");
|
|
138
|
+
|
|
139
|
+
expect(mockFetch).toHaveBeenCalledTimes(1);
|
|
140
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
141
|
+
`https://api.quickbase.com/v1/tables/${QB_TABLE_ID_2}/relationship`,
|
|
142
|
+
expect.objectContaining({
|
|
143
|
+
method: "POST",
|
|
144
|
+
headers: expect.objectContaining({
|
|
145
|
+
"Content-Type": "application/json",
|
|
146
|
+
"QB-Realm-Hostname": "builderprogram-dbradford6815.quickbase.com",
|
|
147
|
+
Authorization:
|
|
148
|
+
"QB-USER-TOKEN b9f3pk_q4jd_0_b4qu5eebyvuix3xs57ysd7zn3",
|
|
149
|
+
}),
|
|
150
|
+
body: JSON.stringify(requestBody),
|
|
151
|
+
})
|
|
152
|
+
);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it("handles response with undefined foreignKeyField and summaryFields", async () => {
|
|
156
|
+
const mockResponse: CreateRelationship200Response = {
|
|
157
|
+
id: 6,
|
|
158
|
+
foreignKeyField: undefined,
|
|
159
|
+
lookupFields: [
|
|
160
|
+
{ id: 7, label: "Field 1", type: "text" },
|
|
161
|
+
{ id: 8, label: "Field 2", type: "text" },
|
|
162
|
+
{ id: 9, label: "Field 3", type: "text" },
|
|
163
|
+
],
|
|
164
|
+
isCrossApp: false,
|
|
165
|
+
parentTableId: QB_TABLE_ID_1,
|
|
166
|
+
childTableId: QB_TABLE_ID_2,
|
|
167
|
+
summaryFields: undefined,
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
mockFetch.mockResolvedValueOnce({
|
|
171
|
+
ok: true,
|
|
172
|
+
status: 200,
|
|
173
|
+
json: () => Promise.resolve(mockResponse),
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
const requestBody: CreateRelationshipRequest = {
|
|
177
|
+
parentTableId: QB_TABLE_ID_1,
|
|
178
|
+
foreignKeyField: undefined,
|
|
179
|
+
lookupFieldIds: [1, 2, 3],
|
|
180
|
+
summaryFields: undefined,
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
const tableId = QB_TABLE_ID_2;
|
|
184
|
+
|
|
185
|
+
const result = await client.createRelationship({
|
|
186
|
+
tableId,
|
|
187
|
+
body: requestBody,
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
expect(mockFetch).toHaveBeenCalledTimes(1);
|
|
191
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
192
|
+
`https://api.quickbase.com/v1/tables/${QB_TABLE_ID_2}/relationship`,
|
|
193
|
+
expect.objectContaining({
|
|
194
|
+
method: "POST",
|
|
195
|
+
headers: expect.objectContaining({
|
|
196
|
+
"Content-Type": "application/json",
|
|
197
|
+
"QB-Realm-Hostname": "builderprogram-dbradford6815.quickbase.com",
|
|
198
|
+
Authorization:
|
|
199
|
+
"QB-USER-TOKEN b9f3pk_q4jd_0_b4qu5eebyvuix3xs57ysd7zn3",
|
|
200
|
+
}),
|
|
201
|
+
body: JSON.stringify(requestBody),
|
|
202
|
+
})
|
|
203
|
+
);
|
|
204
|
+
expect(result).toEqual(mockResponse);
|
|
205
|
+
expect(result.id).toBe(6);
|
|
206
|
+
expect(result.parentTableId).toBe(QB_TABLE_ID_1);
|
|
207
|
+
expect(result.childTableId).toBe(QB_TABLE_ID_2);
|
|
208
|
+
expect(result.foreignKeyField).toBeUndefined();
|
|
209
|
+
expect(result.lookupFields).toHaveLength(3);
|
|
210
|
+
expect(result.summaryFields).toBeUndefined();
|
|
211
|
+
});
|
|
212
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// tests/vitest/unit/tables/deleteRelationship.test.ts
|
|
2
|
+
|
|
3
|
+
import { describe, it, expect, beforeEach } from "vitest";
|
|
4
|
+
import {
|
|
5
|
+
createClient,
|
|
6
|
+
mockFetch,
|
|
7
|
+
QB_TABLE_ID_2, // Child table
|
|
8
|
+
} from "@tests/setup.ts";
|
|
9
|
+
|
|
10
|
+
describe("QuickbaseClient Unit - deleteRelationship", () => {
|
|
11
|
+
let client: ReturnType<typeof createClient>;
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
mockFetch.mockClear();
|
|
15
|
+
client = createClient(mockFetch, { debug: true });
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("initializes without errors", () => {
|
|
19
|
+
expect(client).toBeDefined();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("has deleteRelationship method", () => {
|
|
23
|
+
expect(typeof client.deleteRelationship).toBe("function");
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("sends correct DELETE request and handles successful response", async () => {
|
|
27
|
+
// Mock response for a successful deletion
|
|
28
|
+
const mockResponse = {
|
|
29
|
+
deletedRelationshipId: 6, // Matches the relationshipId
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
mockFetch.mockResolvedValueOnce({
|
|
33
|
+
ok: true,
|
|
34
|
+
status: 200,
|
|
35
|
+
json: () => Promise.resolve(mockResponse),
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const tableId = QB_TABLE_ID_2; // Child table
|
|
39
|
+
const relationshipId = 6; // Example relationship ID (foreign key field ID)
|
|
40
|
+
|
|
41
|
+
const result = await client.deleteRelationship({
|
|
42
|
+
tableId,
|
|
43
|
+
relationshipId,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Verify the fetch call
|
|
47
|
+
expect(mockFetch).toHaveBeenCalledTimes(1);
|
|
48
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
49
|
+
`https://api.quickbase.com/v1/tables/${QB_TABLE_ID_2}/relationship/6`,
|
|
50
|
+
expect.objectContaining({
|
|
51
|
+
method: "DELETE",
|
|
52
|
+
headers: expect.objectContaining({
|
|
53
|
+
"Content-Type": "application/json",
|
|
54
|
+
"QB-Realm-Hostname": "builderprogram-dbradford6815.quickbase.com",
|
|
55
|
+
Authorization:
|
|
56
|
+
"QB-USER-TOKEN b9f3pk_q4jd_0_b4qu5eebyvuix3xs57ysd7zn3",
|
|
57
|
+
}),
|
|
58
|
+
})
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
// Verify the response
|
|
62
|
+
expect(result).toEqual(mockResponse);
|
|
63
|
+
expect(result.deletedRelationshipId).toBe(6);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("handles error when relationship is not found", async () => {
|
|
67
|
+
mockFetch.mockResolvedValueOnce({
|
|
68
|
+
ok: false,
|
|
69
|
+
status: 404,
|
|
70
|
+
json: () => Promise.resolve({ message: "Relationship not found" }),
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const tableId = QB_TABLE_ID_2;
|
|
74
|
+
const relationshipId = 999; // Non-existent relationship ID
|
|
75
|
+
|
|
76
|
+
await expect(
|
|
77
|
+
client.deleteRelationship({
|
|
78
|
+
tableId,
|
|
79
|
+
relationshipId,
|
|
80
|
+
})
|
|
81
|
+
).rejects.toThrow("API Error: Relationship not found (Status: 404)");
|
|
82
|
+
|
|
83
|
+
expect(mockFetch).toHaveBeenCalledTimes(1);
|
|
84
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
85
|
+
`https://api.quickbase.com/v1/tables/${QB_TABLE_ID_2}/relationship/999`,
|
|
86
|
+
expect.objectContaining({
|
|
87
|
+
method: "DELETE",
|
|
88
|
+
headers: expect.objectContaining({
|
|
89
|
+
"Content-Type": "application/json",
|
|
90
|
+
"QB-Realm-Hostname": "builderprogram-dbradford6815.quickbase.com",
|
|
91
|
+
Authorization:
|
|
92
|
+
"QB-USER-TOKEN b9f3pk_q4jd_0_b4qu5eebyvuix3xs57ysd7zn3",
|
|
93
|
+
}),
|
|
94
|
+
})
|
|
95
|
+
);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
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
|
+
});
|