Merge pull request #10736 from Budibase/test/qa-20-Add-relationship-tests-to-datasources
Test/qa 20 add relationship tests to datasources
This commit is contained in:
commit
ace2d8c2e1
|
@ -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).toBeGreaterThan(9)
|
||||||
|
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).toBeGreaterThan(10)
|
||||||
expect(queryJson.schemaFields).toEqual(
|
expect(queryJson.schemaFields).toEqual(
|
||||||
fixtures.queries.expectedSchemaFields.postgres
|
fixtures.queries.expectedSchemaFields.postgres
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue