Merge pull request #14937 from Budibase/fix/sample-data-add

Sample data fix
This commit is contained in:
Michael Drury 2024-11-01 14:37:33 +00:00 committed by GitHub
commit c40cb156d5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 3 deletions

View File

@ -136,16 +136,15 @@ export async function importToRows(
// We use a reference to table here and update it after input processing,
// so that we can auto increment auto IDs in imported data properly
const processed = await inputProcessing(userId, table, row, {
row = await inputProcessing(userId, table, row, {
noAutoRelationships: true,
})
row = processed
// However here we must reference the original table, as we want to mutate
// the real schema of the table passed in, not the clone used for
// incrementing auto IDs
for (const [fieldName, schema] of Object.entries(originalTable.schema)) {
if (schema.type === FieldType.LINK) {
if (schema.type === FieldType.LINK && data.find(row => row[fieldName])) {
throw new HTTPError(
`Can't bulk import relationship fields for internal databases, found value in field "${fieldName}"`,
400

View File

@ -1,3 +1,5 @@
import { DEFAULT_TABLES } from "../../../db/defaultData/datasource_bb_default"
jest.mock("../../../utilities/redis", () => ({
init: jest.fn(),
getLocksById: () => {
@ -447,4 +449,18 @@ describe("/applications", () => {
expect(devLogs.data.length).toBe(0)
})
})
describe("POST /api/applications/:appId/sample", () => {
it("should be able to add sample data", async () => {
await config.api.application.addSampleData(config.getAppId())
for (let table of DEFAULT_TABLES) {
const res = await config.api.row.search(
table._id!,
{ query: {} },
{ status: 200 }
)
expect(res.rows.length).not.toEqual(0)
}
})
})
})