quickbase-js 1.1.0-beta.3 → 1.1.0-beta.4
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 +23 -0
- package/README.md +61 -5
- package/dist/quickbase.d.ts +1108 -349
- package/dist/quickbase.js +828 -263
- package/dist/quickbase.js.map +1 -1
- package/examples/react.js +12 -12
- package/examples/vanillajs.html +12 -12
- package/log-gen.yaml +4622 -759
- package/package.json +12 -14
- package/playwright-results.txt/.last-run.json +4 -0
- package/playwright.config.ts +1 -1
- package/src/code-generation/definitions/apps.ts +274 -0
- package/src/code-generation/definitions/auth.ts +10 -0
- package/src/code-generation/definitions/fields.ts +751 -0
- package/src/code-generation/definitions/index.ts +18 -0
- package/src/code-generation/definitions/records.ts +269 -0
- package/src/code-generation/definitions/relationships.ts +90 -0
- package/src/code-generation/definitions/reports.ts +10 -0
- package/src/code-generation/definitions/tables.ts +112 -0
- package/src/code-generation/fix-spec-main.ts +2 -2
- package/src/code-generation/output/quickbase-fixed.json +3244 -4586
- package/src/code-generation/paths/apps.ts +100 -0
- package/src/code-generation/paths/auth.ts +25 -0
- package/src/code-generation/paths/fields.ts +207 -0
- package/src/code-generation/paths/index.ts +17 -0
- package/src/code-generation/paths/records.ts +68 -0
- package/src/code-generation/paths/relationships.ts +32 -0
- package/src/code-generation/paths/reports.ts +34 -0
- package/src/code-generation/paths/tables.ts +162 -0
- package/src/generated-unified/QuickbaseClient.ts +7 -6
- package/src/log-gen.ts +8 -6
- package/tests/vitest/qb/fields/createField.test.ts +78 -0
- package/tests/vitest/qb/fields/deleteFields.test.ts +89 -0
- package/tests/vitest/qb/fields/getField.test.ts +85 -0
- package/tests/vitest/qb/fields/getFieldUsage.test.ts +174 -0
- package/tests/vitest/qb/fields/getFieldsUsage.test.ts +77 -0
- package/tests/vitest/qb/index.ts +25 -1
- package/tests/vitest/unit/fields/createField.test.ts +391 -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 +147 -0
- package/tests/vitest/unit/fields/getFieldsUsage.test.ts +160 -0
- package/tests/vitest/unit/index.ts +30 -1
- package/src/code-generation/fix-spec-definitions.ts +0 -809
- package/src/code-generation/fix-spec-paths.ts +0 -439
- package/test-artifacts/test-results.json +0 -829
package/src/log-gen.ts
CHANGED
|
@@ -13,13 +13,15 @@ const excludeDirs: string[] = ["node_modules", ".git", "specs"];
|
|
|
13
13
|
// prettier-ignore
|
|
14
14
|
const includeFolders: string[] = [
|
|
15
15
|
// "src/code-generation",
|
|
16
|
+
// "src/code-generation/definitions",
|
|
17
|
+
// "src/code-generation/paths",
|
|
16
18
|
];
|
|
17
19
|
|
|
18
20
|
// prettier-ignore
|
|
19
21
|
const includeRecursiveFolders: string[] = [
|
|
20
|
-
|
|
22
|
+
"tests",
|
|
21
23
|
"tests/vitest/unit",
|
|
22
|
-
|
|
24
|
+
"tests/vitest/qb"
|
|
23
25
|
];
|
|
24
26
|
|
|
25
27
|
// prettier-ignore
|
|
@@ -30,8 +32,8 @@ const includeFiles: string[] = [
|
|
|
30
32
|
// "vitest.config.ts",
|
|
31
33
|
// "src/utils.ts",
|
|
32
34
|
// "src/tokenCache.ts",
|
|
33
|
-
"src/generated-unified/QuickbaseClient.ts",
|
|
34
|
-
"src/quickbaseClient.ts",
|
|
35
|
+
// "src/generated-unified/QuickbaseClient.ts",
|
|
36
|
+
// "src/quickbaseClient.ts",
|
|
35
37
|
];
|
|
36
38
|
|
|
37
39
|
const projectGoals: string[] = [
|
|
@@ -75,8 +77,8 @@ const pipelineOverview: string[] = [
|
|
|
75
77
|
"getTempTokenDBID() method is wrapped to enhance temporary token generation reuse interacting with a token cache.",
|
|
76
78
|
"#",
|
|
77
79
|
"npm run fix-spec: Generates quickbase-fixed.json from the latest QuickBase_RESTful*.json file.",
|
|
78
|
-
"npm run regenerate: Generates raw TypeScript-fetch files in src/generated/.",
|
|
79
|
-
"npm run generate
|
|
80
|
+
"npm run regenerate:openapi Generates raw TypeScript-fetch files in src/generated/.",
|
|
81
|
+
"npm run generate:unified: Generates a unified QuickbaseClient.ts interface in src/generated-unified/.",
|
|
80
82
|
];
|
|
81
83
|
|
|
82
84
|
interface TreeNode {
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// tests/vitest/qb/fields/createField.test.ts (updated)
|
|
2
|
+
import { describe, it, expect, afterAll } from "vitest";
|
|
3
|
+
import { createClient, QB_TABLE_ID_1 } from "../../../setup.ts";
|
|
4
|
+
|
|
5
|
+
describe("QuickbaseClient Integration - createField", () => {
|
|
6
|
+
const client = createClient();
|
|
7
|
+
|
|
8
|
+
const createdFieldIds: number[] = [];
|
|
9
|
+
|
|
10
|
+
afterAll(async () => {
|
|
11
|
+
if (createdFieldIds.length > 0) {
|
|
12
|
+
try {
|
|
13
|
+
const response = await client.deleteFields({
|
|
14
|
+
tableId: QB_TABLE_ID_1,
|
|
15
|
+
body: { fieldIds: createdFieldIds },
|
|
16
|
+
});
|
|
17
|
+
console.log(
|
|
18
|
+
`Cleaned up fields: ${JSON.stringify(response.deletedFieldIds)}`,
|
|
19
|
+
response.errors && response.errors.length > 0
|
|
20
|
+
? `Errors: ${response.errors}`
|
|
21
|
+
: ""
|
|
22
|
+
);
|
|
23
|
+
} catch (error) {
|
|
24
|
+
console.error("Cleanup failed:", error);
|
|
25
|
+
console.log(`Fields left in table: ${createdFieldIds}`);
|
|
26
|
+
}
|
|
27
|
+
} else {
|
|
28
|
+
console.log("No fields to clean up.");
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("creates a field with user token", async () => {
|
|
33
|
+
const uniqueLabel = `TestField_${Date.now()}`;
|
|
34
|
+
const response = await client.createField({
|
|
35
|
+
tableId: QB_TABLE_ID_1,
|
|
36
|
+
body: {
|
|
37
|
+
label: uniqueLabel,
|
|
38
|
+
fieldType: "text",
|
|
39
|
+
fieldHelp: "Created via integration test",
|
|
40
|
+
addToForms: true,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
expect(response.id).toBeDefined();
|
|
45
|
+
expect(response.label).toBe(uniqueLabel);
|
|
46
|
+
expect(response.fieldType).toBe("text");
|
|
47
|
+
expect(response.fieldHelp).toBe("Created via integration test");
|
|
48
|
+
|
|
49
|
+
createdFieldIds.push(response.id);
|
|
50
|
+
console.log(`Created field ${uniqueLabel} with ID ${response.id}`);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("fails with invalid field type", async () => {
|
|
54
|
+
const uniqueLabel = `InvalidField_${Date.now()}`;
|
|
55
|
+
await expect(
|
|
56
|
+
client.createField({
|
|
57
|
+
tableId: QB_TABLE_ID_1,
|
|
58
|
+
body: {
|
|
59
|
+
label: uniqueLabel,
|
|
60
|
+
fieldType: "invalid_type" as "text", // Type assertion to bypass compile-time check
|
|
61
|
+
fieldHelp: "Should fail",
|
|
62
|
+
},
|
|
63
|
+
})
|
|
64
|
+
).rejects.toThrow("API Error: Bad Request (Status: 400)");
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("fails with missing label", async () => {
|
|
68
|
+
await expect(
|
|
69
|
+
client.createField({
|
|
70
|
+
tableId: QB_TABLE_ID_1,
|
|
71
|
+
body: {
|
|
72
|
+
label: "",
|
|
73
|
+
fieldType: "text",
|
|
74
|
+
},
|
|
75
|
+
})
|
|
76
|
+
).rejects.toThrow("API Error: Invalid input (Status: 400)");
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// tests/vitest/qb/fields/deleteFields.test.ts
|
|
2
|
+
import { describe, it, expect, beforeAll } from "vitest";
|
|
3
|
+
import { createClient, QB_TABLE_ID_1 } from "../../../setup.ts";
|
|
4
|
+
|
|
5
|
+
describe("QuickbaseClient Integration - deleteFields", () => {
|
|
6
|
+
const client = createClient();
|
|
7
|
+
|
|
8
|
+
let fieldIdsToDelete: number[] = [];
|
|
9
|
+
|
|
10
|
+
beforeAll(async () => {
|
|
11
|
+
try {
|
|
12
|
+
// Create test fields to delete
|
|
13
|
+
const fieldLabels = ["DeleteTest1", "DeleteTest2"];
|
|
14
|
+
for (const label of fieldLabels) {
|
|
15
|
+
const response = await client.createField({
|
|
16
|
+
tableId: QB_TABLE_ID_1,
|
|
17
|
+
body: {
|
|
18
|
+
label,
|
|
19
|
+
fieldType: "text",
|
|
20
|
+
fieldHelp: "Test field for deletion",
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
fieldIdsToDelete.push(response.id);
|
|
24
|
+
console.log(`Created field ${label} with ID ${response.id}`);
|
|
25
|
+
}
|
|
26
|
+
if (fieldIdsToDelete.length !== 2) {
|
|
27
|
+
throw new Error("Failed to create all test fields");
|
|
28
|
+
}
|
|
29
|
+
} catch (error) {
|
|
30
|
+
console.error("beforeAll failed:", error);
|
|
31
|
+
throw error; // Fail the suite if setup fails
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("deletes fields successfully with user token", async () => {
|
|
36
|
+
try {
|
|
37
|
+
const response = await client.deleteFields({
|
|
38
|
+
tableId: QB_TABLE_ID_1,
|
|
39
|
+
body: {
|
|
40
|
+
fieldIds: fieldIdsToDelete,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
console.log("deleteFields response:", JSON.stringify(response, null, 2));
|
|
45
|
+
|
|
46
|
+
expect(response).toBeDefined();
|
|
47
|
+
expect(response.deletedFieldIds).toEqual(
|
|
48
|
+
expect.arrayContaining(fieldIdsToDelete)
|
|
49
|
+
);
|
|
50
|
+
expect(response.errors ?? []).toHaveLength(0); // Handle undefined errors
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.error("deleteFields failed:", error);
|
|
53
|
+
throw error; // Re-throw to fail the test with details
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("handles partial success with errors", async () => {
|
|
58
|
+
const newField = await client.createField({
|
|
59
|
+
tableId: QB_TABLE_ID_1,
|
|
60
|
+
body: {
|
|
61
|
+
label: "DeleteTest3",
|
|
62
|
+
fieldType: "text",
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
console.log(`Created field DeleteTest3 with ID ${newField.id}`);
|
|
66
|
+
|
|
67
|
+
const invalidFieldId = 999999; // Assume this ID doesn’t exist
|
|
68
|
+
const fieldIds = [newField.id, invalidFieldId];
|
|
69
|
+
|
|
70
|
+
const response = await client.deleteFields({
|
|
71
|
+
tableId: QB_TABLE_ID_1,
|
|
72
|
+
body: { fieldIds },
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
expect(response.deletedFieldIds).toContain(newField.id);
|
|
76
|
+
expect(response.deletedFieldIds).not.toContain(invalidFieldId);
|
|
77
|
+
expect(response.errors).toHaveLength(1);
|
|
78
|
+
expect(response.errors[0]).toMatch(/Field: 999999 was not found/i);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("fails with invalid request (empty fieldIds)", async () => {
|
|
82
|
+
await expect(
|
|
83
|
+
client.deleteFields({
|
|
84
|
+
tableId: QB_TABLE_ID_1,
|
|
85
|
+
body: { fieldIds: [] },
|
|
86
|
+
})
|
|
87
|
+
).rejects.toThrow("API Error: Bad Request (Status: 400)");
|
|
88
|
+
});
|
|
89
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// tests/vitest/qb/fields/getField.test.ts
|
|
2
|
+
import { describe, it, expect } from "vitest";
|
|
3
|
+
import { createClient, QB_TABLE_ID_1 } from "../../../setup.ts";
|
|
4
|
+
|
|
5
|
+
describe("QuickbaseClient Integration - getField", () => {
|
|
6
|
+
const client = createClient();
|
|
7
|
+
|
|
8
|
+
it("retrieves an existing field with user token", async () => {
|
|
9
|
+
// Create a field to ensure we have a known field ID to retrieve
|
|
10
|
+
const uniqueLabel = `TestField_${Date.now()}`;
|
|
11
|
+
const createResponse = await client.createField({
|
|
12
|
+
tableId: QB_TABLE_ID_1,
|
|
13
|
+
body: {
|
|
14
|
+
label: uniqueLabel,
|
|
15
|
+
fieldType: "text",
|
|
16
|
+
fieldHelp: "Created for getField integration test",
|
|
17
|
+
addToForms: true,
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
expect(createResponse.id).toBeDefined();
|
|
22
|
+
const fieldId = createResponse.id;
|
|
23
|
+
console.log(`Created field ${uniqueLabel} with ID ${fieldId} for testing`);
|
|
24
|
+
|
|
25
|
+
// Test getField with the created field
|
|
26
|
+
const response = await client.getField({
|
|
27
|
+
fieldId: fieldId,
|
|
28
|
+
tableId: QB_TABLE_ID_1,
|
|
29
|
+
includeFieldPerms: true,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
expect(response.id).toBe(fieldId);
|
|
33
|
+
expect(response.label).toBe(uniqueLabel);
|
|
34
|
+
expect(response.fieldType).toBe("text");
|
|
35
|
+
expect(response.fieldHelp).toBe("Created for getField integration test");
|
|
36
|
+
expect(response.permissions).toBeDefined();
|
|
37
|
+
expect(Array.isArray(response.permissions)).toBe(true);
|
|
38
|
+
console.log(`Retrieved field ${response.label} with ID ${response.id}`);
|
|
39
|
+
|
|
40
|
+
// Clean up the created field
|
|
41
|
+
try {
|
|
42
|
+
const deleteResponse = await client.deleteFields({
|
|
43
|
+
tableId: QB_TABLE_ID_1,
|
|
44
|
+
body: { fieldIds: [fieldId] },
|
|
45
|
+
});
|
|
46
|
+
console.log(
|
|
47
|
+
`Cleaned up field ${fieldId}: ${JSON.stringify(deleteResponse)}`
|
|
48
|
+
);
|
|
49
|
+
} catch (error) {
|
|
50
|
+
console.error(`Failed to clean up field ${fieldId}:`, error);
|
|
51
|
+
}
|
|
52
|
+
}, 10000); // Increase timeout to 10 seconds
|
|
53
|
+
|
|
54
|
+
it("fails with non-existent field ID", async () => {
|
|
55
|
+
const nonExistentFieldId = 999999; // Assuming this ID doesn’t exist
|
|
56
|
+
await expect(
|
|
57
|
+
client.getField({
|
|
58
|
+
fieldId: nonExistentFieldId,
|
|
59
|
+
tableId: QB_TABLE_ID_1,
|
|
60
|
+
})
|
|
61
|
+
).rejects.toMatchObject({
|
|
62
|
+
message: expect.stringContaining(
|
|
63
|
+
"API Error: No such field (Status: 404)"
|
|
64
|
+
),
|
|
65
|
+
});
|
|
66
|
+
console.log(
|
|
67
|
+
`Confirmed 404 for non-existent field ID ${nonExistentFieldId}`
|
|
68
|
+
);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("fails with invalid table ID", async () => {
|
|
72
|
+
const invalidTableId = "invalid_dbid";
|
|
73
|
+
await expect(
|
|
74
|
+
client.getField({
|
|
75
|
+
fieldId: 1, // Arbitrary field ID
|
|
76
|
+
tableId: invalidTableId,
|
|
77
|
+
})
|
|
78
|
+
).rejects.toMatchObject({
|
|
79
|
+
message: expect.stringContaining(
|
|
80
|
+
"API Error: Invalid request (Status: 400)"
|
|
81
|
+
),
|
|
82
|
+
});
|
|
83
|
+
console.log(`Confirmed 400 for invalid table ID ${invalidTableId}`);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
// tests/vitest/qb/fields/getFieldUsage.test.ts
|
|
2
|
+
import { describe, it, expect, afterAll } from "vitest";
|
|
3
|
+
import {
|
|
4
|
+
createClient,
|
|
5
|
+
QB_REALM,
|
|
6
|
+
QB_USER_TOKEN,
|
|
7
|
+
QB_TABLE_ID_1,
|
|
8
|
+
} from "../../../setup.ts";
|
|
9
|
+
import { FieldUsage } from "@/generated/models";
|
|
10
|
+
|
|
11
|
+
describe("QuickbaseClient Integration - getFieldUsage", () => {
|
|
12
|
+
const client = createClient();
|
|
13
|
+
const createdFieldIds: number[] = [];
|
|
14
|
+
|
|
15
|
+
afterAll(async () => {
|
|
16
|
+
if (createdFieldIds.length > 0) {
|
|
17
|
+
try {
|
|
18
|
+
const response = await client.deleteFields({
|
|
19
|
+
tableId: QB_TABLE_ID_1,
|
|
20
|
+
body: { fieldIds: createdFieldIds },
|
|
21
|
+
});
|
|
22
|
+
console.log(
|
|
23
|
+
`Cleaned up fields: ${JSON.stringify(response.deletedFieldIds)}`,
|
|
24
|
+
response.errors && response.errors.length > 0
|
|
25
|
+
? `Errors: ${response.errors}`
|
|
26
|
+
: ""
|
|
27
|
+
);
|
|
28
|
+
} catch (error) {
|
|
29
|
+
console.error("Cleanup failed:", error);
|
|
30
|
+
console.log(`Fields left in table: ${createdFieldIds}`);
|
|
31
|
+
}
|
|
32
|
+
} else {
|
|
33
|
+
console.log("No fields to clean up.");
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it(
|
|
38
|
+
"creates a field, retrieves its usage statistics, and deletes it",
|
|
39
|
+
async () => {
|
|
40
|
+
// Step 1: Create a field
|
|
41
|
+
const uniqueLabel = `TestField_${Date.now()}`;
|
|
42
|
+
console.log("Creating field with label:", uniqueLabel);
|
|
43
|
+
const createResponse = await client.createField({
|
|
44
|
+
tableId: QB_TABLE_ID_1,
|
|
45
|
+
body: {
|
|
46
|
+
label: uniqueLabel,
|
|
47
|
+
fieldType: "text",
|
|
48
|
+
fieldHelp: "Created for getFieldUsage integration test",
|
|
49
|
+
addToForms: true,
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
expect(createResponse.id).toBeDefined();
|
|
54
|
+
const fieldId = createResponse.id;
|
|
55
|
+
createdFieldIds.push(fieldId);
|
|
56
|
+
console.log(`Created field ${uniqueLabel} with ID ${fieldId}`);
|
|
57
|
+
|
|
58
|
+
// Brief delay to ensure field is registered
|
|
59
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
60
|
+
|
|
61
|
+
// Step 2: Get field usage with raw response logging
|
|
62
|
+
console.log("Fetching field usage for:", {
|
|
63
|
+
tableId: QB_TABLE_ID_1,
|
|
64
|
+
fieldId,
|
|
65
|
+
});
|
|
66
|
+
const rawResponse = await fetch(
|
|
67
|
+
`https://api.quickbase.com/v1/fields/usage/${fieldId}?tableId=${QB_TABLE_ID_1}`,
|
|
68
|
+
{
|
|
69
|
+
method: "GET",
|
|
70
|
+
headers: {
|
|
71
|
+
"QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
|
|
72
|
+
Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
|
|
73
|
+
"Content-Type": "application/json",
|
|
74
|
+
},
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
const rawBody = await rawResponse.text();
|
|
78
|
+
console.log("Raw API response:", {
|
|
79
|
+
status: rawResponse.status,
|
|
80
|
+
statusText: rawResponse.statusText,
|
|
81
|
+
body: rawBody,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
const responseArray: FieldUsage[] = await client.getFieldUsage({
|
|
85
|
+
fieldId,
|
|
86
|
+
tableId: QB_TABLE_ID_1,
|
|
87
|
+
});
|
|
88
|
+
console.log("Parsed API response (array):", responseArray);
|
|
89
|
+
|
|
90
|
+
// Validate response structure (unwrap the array)
|
|
91
|
+
expect(responseArray).toBeDefined();
|
|
92
|
+
expect(responseArray).toHaveLength(1); // Expect a single-item array
|
|
93
|
+
const response = responseArray[0];
|
|
94
|
+
|
|
95
|
+
expect(response).toBeDefined();
|
|
96
|
+
expect(response.field).toHaveProperty("id", fieldId);
|
|
97
|
+
expect(response.field).toHaveProperty("name", uniqueLabel);
|
|
98
|
+
expect(response.field).toHaveProperty("type", "text");
|
|
99
|
+
expect(typeof response.field.name).toBe("string");
|
|
100
|
+
expect(typeof response.field.type).toBe("string");
|
|
101
|
+
|
|
102
|
+
expect(response.usage).toBeDefined();
|
|
103
|
+
expect(typeof response.usage).toBe("object");
|
|
104
|
+
expect(response.usage).toHaveProperty("actions");
|
|
105
|
+
expect(response.usage.actions).toHaveProperty("count");
|
|
106
|
+
expect(typeof response.usage.actions.count).toBe("number");
|
|
107
|
+
expect(response.usage).toHaveProperty("appHomePages");
|
|
108
|
+
expect(response.usage).toHaveProperty("dashboards");
|
|
109
|
+
expect(response.usage).toHaveProperty("defaultReports");
|
|
110
|
+
expect(response.usage).toHaveProperty("exactForms");
|
|
111
|
+
expect(response.usage).toHaveProperty("fields");
|
|
112
|
+
expect(response.usage).toHaveProperty("forms");
|
|
113
|
+
expect(response.usage).toHaveProperty("notifications");
|
|
114
|
+
expect(response.usage).toHaveProperty("personalReports");
|
|
115
|
+
expect(response.usage).toHaveProperty("pipelines");
|
|
116
|
+
expect(response.usage).toHaveProperty("relationships");
|
|
117
|
+
expect(response.usage).toHaveProperty("reminders");
|
|
118
|
+
expect(response.usage).toHaveProperty("reports");
|
|
119
|
+
expect(response.usage).toHaveProperty("roles");
|
|
120
|
+
expect(response.usage).toHaveProperty("tableImports");
|
|
121
|
+
expect(response.usage).toHaveProperty("tableRules");
|
|
122
|
+
expect(response.usage).toHaveProperty("webhooks");
|
|
123
|
+
|
|
124
|
+
// Since it’s a new field, expect minimal usage
|
|
125
|
+
expect(response.usage.forms.count).toBeGreaterThanOrEqual(0); // May be 1 if addToForms worked
|
|
126
|
+
},
|
|
127
|
+
{ timeout: 30000 } // 30-second timeout for create + get + delete
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
it("fails with non-existent field ID", { timeout: 15000 }, async () => {
|
|
131
|
+
const nonExistentFieldId = 999999;
|
|
132
|
+
|
|
133
|
+
console.log("Attempting to fetch usage for non-existent field:", {
|
|
134
|
+
tableId: QB_TABLE_ID_1,
|
|
135
|
+
fieldId: nonExistentFieldId,
|
|
136
|
+
});
|
|
137
|
+
await expect(
|
|
138
|
+
client.getFieldUsage({
|
|
139
|
+
fieldId: nonExistentFieldId,
|
|
140
|
+
tableId: QB_TABLE_ID_1,
|
|
141
|
+
})
|
|
142
|
+
).rejects.toMatchObject({
|
|
143
|
+
message: expect.stringContaining(
|
|
144
|
+
"API Error: No such field (Status: 404)"
|
|
145
|
+
),
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
console.log(
|
|
149
|
+
`Confirmed 404 for non-existent field ID ${nonExistentFieldId}`
|
|
150
|
+
);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("fails with invalid table ID", { timeout: 15000 }, async () => {
|
|
154
|
+
const invalidTableId = "invalid_dbid";
|
|
155
|
+
const fieldId = 6;
|
|
156
|
+
|
|
157
|
+
console.log("Attempting to fetch usage with invalid table ID:", {
|
|
158
|
+
tableId: invalidTableId,
|
|
159
|
+
fieldId,
|
|
160
|
+
});
|
|
161
|
+
await expect(
|
|
162
|
+
client.getFieldUsage({
|
|
163
|
+
fieldId,
|
|
164
|
+
tableId: invalidTableId,
|
|
165
|
+
})
|
|
166
|
+
).rejects.toMatchObject({
|
|
167
|
+
message: expect.stringContaining(
|
|
168
|
+
"API Error: Access denied (Status: 401)"
|
|
169
|
+
),
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
console.log(`Confirmed 401 for invalid table ID ${invalidTableId}`);
|
|
173
|
+
});
|
|
174
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// tests/vitest/qb/fields/getFieldsUsage.test.ts
|
|
2
|
+
import { describe, it, expect } from "vitest";
|
|
3
|
+
import { createClient, QB_TABLE_ID_1 } from "../../../setup.ts";
|
|
4
|
+
import { FieldUsage } from "@/generated/models";
|
|
5
|
+
|
|
6
|
+
describe("QuickbaseClient Integration - getFieldsUsage", () => {
|
|
7
|
+
const client = createClient();
|
|
8
|
+
|
|
9
|
+
it("retrieves field usage statistics for a valid table", async () => {
|
|
10
|
+
console.log("Starting retrieval of full field usage list");
|
|
11
|
+
const response = await client.getFieldsUsage({
|
|
12
|
+
tableId: QB_TABLE_ID_1,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
expect(response).toBeInstanceOf(Array);
|
|
16
|
+
expect(response.length).toBeGreaterThan(0); // Assumes the table has fields
|
|
17
|
+
response.forEach((usage: FieldUsage) => {
|
|
18
|
+
expect(usage.field).toHaveProperty("id");
|
|
19
|
+
expect(usage.field).toHaveProperty("name");
|
|
20
|
+
expect(usage.field).toHaveProperty("type");
|
|
21
|
+
expect(usage.usage).toHaveProperty("actions");
|
|
22
|
+
expect(usage.usage.actions).toHaveProperty("count");
|
|
23
|
+
expect(typeof usage.usage.actions.count).toBe("number");
|
|
24
|
+
expect(usage.usage).toHaveProperty("dashboards");
|
|
25
|
+
expect(usage.usage).toHaveProperty("forms");
|
|
26
|
+
expect(usage.usage).toHaveProperty("reports");
|
|
27
|
+
});
|
|
28
|
+
console.log(
|
|
29
|
+
`Retrieved ${response.length} field usage entries for table ${QB_TABLE_ID_1}`
|
|
30
|
+
);
|
|
31
|
+
}, 15000); // 15-second timeout
|
|
32
|
+
|
|
33
|
+
it("retrieves field usage with skip and top parameters", async () => {
|
|
34
|
+
console.log(
|
|
35
|
+
"Starting retrieval of full field usage list for skip/top test"
|
|
36
|
+
);
|
|
37
|
+
const fullResponse = await client.getFieldsUsage({
|
|
38
|
+
tableId: QB_TABLE_ID_1,
|
|
39
|
+
});
|
|
40
|
+
console.log(`Full list retrieved: ${fullResponse.length} fields`);
|
|
41
|
+
|
|
42
|
+
const totalFields = fullResponse.length;
|
|
43
|
+
if (totalFields <= 1) {
|
|
44
|
+
console.log("Skipping skip/top test: table has too few fields");
|
|
45
|
+
return; // Skip if not enough fields to test pagination
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
console.log("Starting retrieval with skip=1 and top=1");
|
|
49
|
+
const response = await client.getFieldsUsage({
|
|
50
|
+
tableId: QB_TABLE_ID_1,
|
|
51
|
+
skip: 1,
|
|
52
|
+
top: 1,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
expect(response).toBeInstanceOf(Array);
|
|
56
|
+
expect(response.length).toBe(1); // Should return exactly 1 field
|
|
57
|
+
expect(response[0].field.id).not.toBe(fullResponse[0].field.id); // Should skip the first field
|
|
58
|
+
console.log(
|
|
59
|
+
`Retrieved ${response.length} field usage entries with skip=1 and top=1`
|
|
60
|
+
);
|
|
61
|
+
}, 15000); // 15-second timeout
|
|
62
|
+
|
|
63
|
+
it("fails with invalid table ID", async () => {
|
|
64
|
+
const invalidTableId = "invalid_dbid";
|
|
65
|
+
console.log(`Starting retrieval with invalid table ID ${invalidTableId}`);
|
|
66
|
+
await expect(
|
|
67
|
+
client.getFieldsUsage({
|
|
68
|
+
tableId: invalidTableId,
|
|
69
|
+
})
|
|
70
|
+
).rejects.toMatchObject({
|
|
71
|
+
message: expect.stringContaining(
|
|
72
|
+
"API Error: Access denied (Status: 401)"
|
|
73
|
+
),
|
|
74
|
+
});
|
|
75
|
+
console.log(`Confirmed 401 for invalid table ID ${invalidTableId}`);
|
|
76
|
+
}, 15000); // 15-second timeout
|
|
77
|
+
});
|
package/tests/vitest/qb/index.ts
CHANGED
|
@@ -1,4 +1,28 @@
|
|
|
1
|
-
//
|
|
1
|
+
// tests/vitest/qb/index.ts
|
|
2
|
+
|
|
3
|
+
// Apps
|
|
4
|
+
export * from "./apps/copyApp.test.ts";
|
|
5
|
+
export * from "./apps/createApp.test.ts";
|
|
6
|
+
export * from "./apps/deleteApp.test.ts";
|
|
2
7
|
export * from "./apps/getApp.test.ts";
|
|
8
|
+
|
|
9
|
+
// Fields
|
|
10
|
+
export * from "./fields/createField.test.ts";
|
|
11
|
+
export * from "./fields/deleteFields.test.ts";
|
|
3
12
|
export * from "./fields/getFields.test.ts";
|
|
13
|
+
export * from "./fields/getField.test.ts"; // Added new getField test
|
|
14
|
+
export * from "./fields/getFieldsUsage.test.ts";
|
|
15
|
+
export * from "./fields/getFieldUsage.test.ts";
|
|
16
|
+
|
|
17
|
+
// Records
|
|
18
|
+
export * from "./records/deleteRecords.test.ts";
|
|
19
|
+
export * from "./records/runQuery.test.ts";
|
|
20
|
+
export * from "./records/upsert.test.ts";
|
|
21
|
+
|
|
22
|
+
// Tables
|
|
23
|
+
export * from "./tables/createTable.test.ts";
|
|
24
|
+
export * from "./tables/deleteTable.test.ts";
|
|
4
25
|
export * from "./tables/getAppTables.test.ts";
|
|
26
|
+
export * from "./tables/getRelationships.test.ts";
|
|
27
|
+
export * from "./tables/getTable.test.ts";
|
|
28
|
+
export * from "./tables/updateTable.test.ts";
|