Merge pull request #14937 from Budibase/fix/sample-data-add
Sample data fix
This commit is contained in:
commit
c40cb156d5
|
@ -136,16 +136,15 @@ export async function importToRows(
|
||||||
|
|
||||||
// We use a reference to table here and update it after input processing,
|
// 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
|
// 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,
|
noAutoRelationships: true,
|
||||||
})
|
})
|
||||||
row = processed
|
|
||||||
|
|
||||||
// However here we must reference the original table, as we want to mutate
|
// 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
|
// the real schema of the table passed in, not the clone used for
|
||||||
// incrementing auto IDs
|
// incrementing auto IDs
|
||||||
for (const [fieldName, schema] of Object.entries(originalTable.schema)) {
|
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(
|
throw new HTTPError(
|
||||||
`Can't bulk import relationship fields for internal databases, found value in field "${fieldName}"`,
|
`Can't bulk import relationship fields for internal databases, found value in field "${fieldName}"`,
|
||||||
400
|
400
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { DEFAULT_TABLES } from "../../../db/defaultData/datasource_bb_default"
|
||||||
|
|
||||||
jest.mock("../../../utilities/redis", () => ({
|
jest.mock("../../../utilities/redis", () => ({
|
||||||
init: jest.fn(),
|
init: jest.fn(),
|
||||||
getLocksById: () => {
|
getLocksById: () => {
|
||||||
|
@ -447,4 +449,18 @@ describe("/applications", () => {
|
||||||
expect(devLogs.data.length).toBe(0)
|
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)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue