Add test for relationship creation for MySQL
This commit is contained in:
parent
6e23d78677
commit
0498ad6e54
|
@ -12,7 +12,7 @@ export interface Datasource extends Document {
|
||||||
}
|
}
|
||||||
plus?: boolean
|
plus?: boolean
|
||||||
entities?: {
|
entities?: {
|
||||||
[key: string]: Table
|
[key: string]: any
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,8 @@
|
||||||
"test:smoke": "yarn run test --testPathIgnorePatterns=/.+\\.integration\\.spec\\.ts",
|
"test:smoke": "yarn run test --testPathIgnorePatterns=/.+\\.integration\\.spec\\.ts",
|
||||||
"test:ci": "start-server-and-test dev:built http://localhost:4001/health test:smoke",
|
"test:ci": "start-server-and-test dev:built http://localhost:4001/health test:smoke",
|
||||||
"serve": "start-server-and-test dev:built http://localhost:4001/health",
|
"serve": "start-server-and-test dev:built http://localhost:4001/health",
|
||||||
"dev:built": "cd ../ && yarn dev:built"
|
"dev:built": "cd ../ && yarn dev:built",
|
||||||
|
"test:datasources": "jest --runInBand --json --outputFile=testResults.json --testPathPattern='datasources/.*\\.spec\\.(ts|js)$'"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@budibase/types": "^2.3.17",
|
"@budibase/types": "^2.3.17",
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
|
import { Datasource } from "@budibase/types"
|
||||||
import { DatasourceRequest } from "../../types"
|
import { DatasourceRequest } from "../../types"
|
||||||
|
import { generator } from "../../shared"
|
||||||
|
|
||||||
// Add information about the data source to the fixtures file from 1password
|
// Add information about the data source to the fixtures file from 1password
|
||||||
export const mongoDB = (): DatasourceRequest => {
|
export const mongoDB = (): DatasourceRequest => {
|
||||||
return {
|
return {
|
||||||
|
@ -70,3 +73,50 @@ export const restAPI = (): DatasourceRequest => {
|
||||||
fetchSchema: false,
|
fetchSchema: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const generateRelationshipForMySQL = (
|
||||||
|
updatedDataSourceJson: any
|
||||||
|
): Datasource => {
|
||||||
|
const entities = updatedDataSourceJson!.datasource!.entities!
|
||||||
|
const datasourceId = updatedDataSourceJson!.datasource!._id!
|
||||||
|
const relationShipBody = {
|
||||||
|
...updatedDataSourceJson.datasource,
|
||||||
|
entities: {
|
||||||
|
...updatedDataSourceJson.datasource.entities,
|
||||||
|
employees: {
|
||||||
|
...entities.employees,
|
||||||
|
schema: {
|
||||||
|
...entities.employees.schema,
|
||||||
|
salaries: {
|
||||||
|
tableId: `${datasourceId}__salaries`,
|
||||||
|
name: "salaries",
|
||||||
|
relationshipType: "many-to-one",
|
||||||
|
fieldName: "salary",
|
||||||
|
type: "link",
|
||||||
|
main: true,
|
||||||
|
_id: generator.string(),
|
||||||
|
foreignKey: "emp_no",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
titles: {
|
||||||
|
...entities.titles,
|
||||||
|
schema: {
|
||||||
|
...entities.titles.schema,
|
||||||
|
employees: {
|
||||||
|
tableId: `${datasourceId}__employees`,
|
||||||
|
name: "employees",
|
||||||
|
relationshipType: "one-to-many",
|
||||||
|
fieldName: "emp_no",
|
||||||
|
type: "link",
|
||||||
|
main: true,
|
||||||
|
_id: generator.string(),
|
||||||
|
foreignKey: "emp_no",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return relationShipBody
|
||||||
|
}
|
||||||
|
|
|
@ -66,4 +66,41 @@ describe("Internal API - Data Sources: MariaDB", () => {
|
||||||
updatedDataSourceJson.datasource._rev!
|
updatedDataSourceJson.datasource._rev!
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("Create a relationship", async () => {
|
||||||
|
// Create app
|
||||||
|
await config.createApp()
|
||||||
|
|
||||||
|
// Get all integrations
|
||||||
|
await config.api.integrations.getAll()
|
||||||
|
|
||||||
|
// Add data source
|
||||||
|
const [dataSourceResponse, dataSourceJson] =
|
||||||
|
await config.api.datasources.add(fixtures.datasources.mariaDB())
|
||||||
|
|
||||||
|
// Update data source
|
||||||
|
const newDataSourceInfo = {
|
||||||
|
...dataSourceJson.datasource,
|
||||||
|
name: "MariaDB2",
|
||||||
|
}
|
||||||
|
const [updatedDataSourceResponse, updatedDataSourceJson] =
|
||||||
|
await config.api.datasources.update(newDataSourceInfo)
|
||||||
|
|
||||||
|
// Query data source
|
||||||
|
const [queryResponse, queryJson] = await config.api.queries.preview(
|
||||||
|
fixtures.queries.mariaDB(updatedDataSourceJson.datasource._id!)
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(queryJson.rows.length).toEqual(10)
|
||||||
|
expect(queryJson.schemaFields).toEqual(
|
||||||
|
fixtures.queries.expectedSchemaFields.mariaDB
|
||||||
|
)
|
||||||
|
|
||||||
|
// Add relationship
|
||||||
|
const relationShipBody = fixtures.datasources.generateRelationshipForMySQL(
|
||||||
|
updatedDataSourceJson
|
||||||
|
)
|
||||||
|
const [relationshipResponse, relationshipJson] =
|
||||||
|
await config.api.datasources.update(relationShipBody)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -37,7 +37,7 @@ describe("Internal API - Data Sources: PostgresSQL", () => {
|
||||||
fixtures.queries.postgres(updatedDataSourceJson.datasource._id!)
|
fixtures.queries.postgres(updatedDataSourceJson.datasource._id!)
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(queryJson.rows.length).toEqual(91)
|
expect(queryJson.rows.length).toEqual(92)
|
||||||
expect(queryJson.schemaFields).toEqual(
|
expect(queryJson.schemaFields).toEqual(
|
||||||
fixtures.queries.expectedSchemaFields.postgres
|
fixtures.queries.expectedSchemaFields.postgres
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue