Merge branch 'master' of github.com:budibase/budibase into demock-dynamodb
This commit is contained in:
commit
9ada43371e
|
@ -26,7 +26,7 @@ export function csv(
|
||||||
headers.map(header => {
|
headers.map(header => {
|
||||||
const val = row[header]
|
const val = row[header]
|
||||||
if (typeof val === "object" && !(val instanceof Date)) {
|
if (typeof val === "object" && !(val instanceof Date)) {
|
||||||
return `"${JSON.stringify(val).replace(/"/g, "'")}"`
|
return `"${escapeCsvString(JSON.stringify(val))}"`
|
||||||
}
|
}
|
||||||
if (val !== undefined) {
|
if (val !== undefined) {
|
||||||
return `"${escapeCsvString(val.toString())}"`
|
return `"${escapeCsvString(val.toString())}"`
|
||||||
|
|
|
@ -1,19 +1,6 @@
|
||||||
import { DEFAULT_TABLES } from "../../../db/defaultData/datasource_bb_default"
|
import { DEFAULT_TABLES } from "../../../db/defaultData/datasource_bb_default"
|
||||||
import { setEnv } from "../../../environment"
|
import { setEnv } from "../../../environment"
|
||||||
|
|
||||||
jest.mock("../../../utilities/redis", () => ({
|
|
||||||
init: jest.fn(),
|
|
||||||
getLocksById: () => {
|
|
||||||
return {}
|
|
||||||
},
|
|
||||||
doesUserHaveLock: () => {
|
|
||||||
return true
|
|
||||||
},
|
|
||||||
updateLock: jest.fn(),
|
|
||||||
setDebounce: jest.fn(),
|
|
||||||
checkDebounce: jest.fn(),
|
|
||||||
shutdown: jest.fn(),
|
|
||||||
}))
|
|
||||||
import { checkBuilderEndpoint } from "./utilities/TestFunctions"
|
import { checkBuilderEndpoint } from "./utilities/TestFunctions"
|
||||||
import * as setup from "./utilities"
|
import * as setup from "./utilities"
|
||||||
import { AppStatus } from "../../../db/utils"
|
import { AppStatus } from "../../../db/utils"
|
||||||
|
|
|
@ -2515,15 +2515,14 @@ if (descriptions.length) {
|
||||||
csvString: exportedValue,
|
csvString: exportedValue,
|
||||||
})
|
})
|
||||||
|
|
||||||
const stringified = (value: string) =>
|
const stringified = (value: string) => JSON.stringify(value)
|
||||||
JSON.stringify(value).replace(/"/g, "'")
|
|
||||||
|
|
||||||
const matchingObject = (
|
const matchingObject = (
|
||||||
key: string,
|
key: string,
|
||||||
value: any,
|
value: any,
|
||||||
isArray: boolean
|
isArray: boolean
|
||||||
) => {
|
) => {
|
||||||
const objectMatcher = `{'${key}':'${value[key]}'.*?}`
|
const objectMatcher = `{"${key}":"${value[key]}".*?}`
|
||||||
if (isArray) {
|
if (isArray) {
|
||||||
return expect.stringMatching(
|
return expect.stringMatching(
|
||||||
new RegExp(`^\\[${objectMatcher}\\]$`)
|
new RegExp(`^\\[${objectMatcher}\\]$`)
|
||||||
|
|
|
@ -1246,10 +1246,7 @@ if (descriptions.length) {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe.each([
|
describe.each([
|
||||||
[
|
[RowExportFormat.CSV, (val: any) => JSON.stringify(val)],
|
||||||
RowExportFormat.CSV,
|
|
||||||
(val: any) => JSON.stringify(val).replace(/"/g, "'"),
|
|
||||||
],
|
|
||||||
[RowExportFormat.JSON, (val: any) => val],
|
[RowExportFormat.JSON, (val: any) => val],
|
||||||
])("import validation (%s)", (_, userParser) => {
|
])("import validation (%s)", (_, userParser) => {
|
||||||
const basicSchema: TableSchema = {
|
const basicSchema: TableSchema = {
|
||||||
|
|
|
@ -1,76 +0,0 @@
|
||||||
import { default as AirtableIntegration } from "../airtable"
|
|
||||||
|
|
||||||
jest.mock("airtable")
|
|
||||||
|
|
||||||
class TestConfiguration {
|
|
||||||
integration: any
|
|
||||||
client: any
|
|
||||||
|
|
||||||
constructor(config: any = {}) {
|
|
||||||
this.integration = new AirtableIntegration.integration(config)
|
|
||||||
this.client = {
|
|
||||||
create: jest.fn(),
|
|
||||||
select: jest.fn(() => ({
|
|
||||||
firstPage: jest.fn(() => []),
|
|
||||||
})),
|
|
||||||
update: jest.fn(),
|
|
||||||
destroy: jest.fn(),
|
|
||||||
}
|
|
||||||
this.integration.client = () => this.client
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("Airtable Integration", () => {
|
|
||||||
let config: any
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
config = new TestConfiguration()
|
|
||||||
})
|
|
||||||
|
|
||||||
it("calls the create method with the correct params", async () => {
|
|
||||||
await config.integration.create({
|
|
||||||
table: "test",
|
|
||||||
json: {},
|
|
||||||
})
|
|
||||||
expect(config.client.create).toHaveBeenCalledWith([
|
|
||||||
{
|
|
||||||
fields: {},
|
|
||||||
},
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
it("calls the read method with the correct params", async () => {
|
|
||||||
await config.integration.read({
|
|
||||||
table: "test",
|
|
||||||
view: "Grid view",
|
|
||||||
})
|
|
||||||
expect(config.client.select).toHaveBeenCalledWith({
|
|
||||||
maxRecords: 10,
|
|
||||||
view: "Grid view",
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it("calls the update method with the correct params", async () => {
|
|
||||||
await config.integration.update({
|
|
||||||
table: "table",
|
|
||||||
id: "123",
|
|
||||||
json: {
|
|
||||||
name: "test",
|
|
||||||
},
|
|
||||||
})
|
|
||||||
expect(config.client.update).toHaveBeenCalledWith([
|
|
||||||
{
|
|
||||||
id: "123",
|
|
||||||
fields: { name: "test" },
|
|
||||||
},
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
it("calls the delete method with the correct params", async () => {
|
|
||||||
const ids = [1, 2, 3, 4]
|
|
||||||
await config.integration.delete({
|
|
||||||
ids,
|
|
||||||
})
|
|
||||||
expect(config.client.destroy).toHaveBeenCalledWith(ids)
|
|
||||||
})
|
|
||||||
})
|
|
|
@ -270,6 +270,7 @@ function parseJsonExport<T>(value: any) {
|
||||||
if (typeof value !== "string") {
|
if (typeof value !== "string") {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const parsed = JSON.parse(value)
|
const parsed = JSON.parse(value)
|
||||||
|
|
||||||
|
@ -278,12 +279,17 @@ function parseJsonExport<T>(value: any) {
|
||||||
if (
|
if (
|
||||||
e.message.startsWith("Expected property name or '}' in JSON at position ")
|
e.message.startsWith("Expected property name or '}' in JSON at position ")
|
||||||
) {
|
) {
|
||||||
// This was probably converted as CSV and it has single quotes instead of double ones
|
// In order to store JSON within CSVs what we used to do is replace double
|
||||||
|
// quotes with single quotes. This results in invalid JSON, so the line
|
||||||
|
// below is a workaround to parse it. However, this method of storing JSON
|
||||||
|
// was never valid, and we don't do it anymore. However, people may have
|
||||||
|
// exported data and stored it, hoping to be able to restore it later, so
|
||||||
|
// we leave this in place to support that.
|
||||||
const parsed = JSON.parse(value.replace(/'/g, '"'))
|
const parsed = JSON.parse(value.replace(/'/g, '"'))
|
||||||
return parsed as T
|
return parsed as T
|
||||||
}
|
}
|
||||||
|
|
||||||
// It is no a valid JSON
|
// It is not valid JSON
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue