Some test updates to make the fetchSchema tableFilter prop usable.
This commit is contained in:
parent
9cd7c144f4
commit
5de2dc8382
|
@ -341,7 +341,7 @@ describe("/datasources", () => {
|
|||
)
|
||||
|
||||
const persisted = await config.api.datasource.get(datasourceId)
|
||||
await config.api.datasource.fetchSchema(datasourceId)
|
||||
await config.api.datasource.fetchSchema({ datasourceId })
|
||||
|
||||
const updated = await config.api.datasource.get(datasourceId)
|
||||
const expected: Datasource = {
|
||||
|
|
|
@ -1097,12 +1097,11 @@ describe("postgres integrations", () => {
|
|||
it("recognises when a table has no primary key", async () => {
|
||||
await rawQuery(rawDatasource, `CREATE TABLE "${tableName}" (id SERIAL)`)
|
||||
|
||||
const response = await makeRequest(
|
||||
"post",
|
||||
`/api/datasources/${datasource._id}/schema`
|
||||
)
|
||||
const response = await config.api.datasource.fetchSchema({
|
||||
datasourceId: datasource._id!,
|
||||
})
|
||||
|
||||
expect(response.body.errors).toEqual({
|
||||
expect(response.errors).toEqual({
|
||||
[tableName]: "Table must have a primary key.",
|
||||
})
|
||||
})
|
||||
|
@ -1113,12 +1112,11 @@ describe("postgres integrations", () => {
|
|||
`CREATE TABLE "${tableName}" (_id SERIAL PRIMARY KEY) `
|
||||
)
|
||||
|
||||
const response = await makeRequest(
|
||||
"post",
|
||||
`/api/datasources/${datasource._id}/schema`
|
||||
)
|
||||
const response = await config.api.datasource.fetchSchema({
|
||||
datasourceId: datasource._id!,
|
||||
})
|
||||
|
||||
expect(response.body.errors).toEqual({
|
||||
expect(response.errors).toEqual({
|
||||
[tableName]: "Table contains invalid columns.",
|
||||
})
|
||||
})
|
||||
|
@ -1143,15 +1141,14 @@ describe("postgres integrations", () => {
|
|||
`
|
||||
)
|
||||
|
||||
const response = await makeRequest(
|
||||
"post",
|
||||
`/api/datasources/${datasource._id}/schema`
|
||||
)
|
||||
const response = await config.api.datasource.fetchSchema({
|
||||
datasourceId: datasource._id!,
|
||||
})
|
||||
|
||||
const table = response.body.datasource.entities[tableName]
|
||||
const table = response.datasource.entities?.[tableName]
|
||||
|
||||
expect(table).toBeDefined()
|
||||
expect(table.schema[enumColumnName].type).toEqual(FieldType.OPTIONS)
|
||||
expect(table?.schema[enumColumnName].type).toEqual(FieldType.OPTIONS)
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -1215,20 +1212,16 @@ describe("postgres integrations", () => {
|
|||
rawDatasource,
|
||||
`CREATE TABLE "${schema2}".${repeated_table_name} (id2 SERIAL PRIMARY KEY, val2 TEXT);`
|
||||
)
|
||||
const response = await makeRequest(
|
||||
"post",
|
||||
`/api/datasources/${datasource._id}/schema`,
|
||||
{
|
||||
tablesFilter: [repeated_table_name],
|
||||
}
|
||||
)
|
||||
expect(response.status).toBe(200)
|
||||
|
||||
const response = await config.api.datasource.fetchSchema({
|
||||
datasourceId: datasource._id!,
|
||||
tablesFilter: [repeated_table_name],
|
||||
})
|
||||
expect(
|
||||
response.body.datasource.entities[repeated_table_name].schema
|
||||
response.datasource.entities?.[repeated_table_name].schema
|
||||
).toBeDefined()
|
||||
const schema =
|
||||
response.body.datasource.entities[repeated_table_name].schema
|
||||
expect(Object.keys(schema).sort()).toEqual(["id", "val1"])
|
||||
const schema = response.datasource.entities?.[repeated_table_name].schema
|
||||
expect(Object.keys(schema || {}).sort()).toEqual(["id", "val1"])
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -1246,16 +1239,14 @@ describe("postgres integrations", () => {
|
|||
})
|
||||
|
||||
it("should handle binary columns", async () => {
|
||||
const response = await makeRequest(
|
||||
"post",
|
||||
`/api/datasources/${datasource._id}/schema`
|
||||
)
|
||||
expect(response.body).toBeDefined()
|
||||
expect(response.body.datasource.entities).toBeDefined()
|
||||
const table = response.body.datasource.entities["binarytable"]
|
||||
const response = await config.api.datasource.fetchSchema({
|
||||
datasourceId: datasource._id!,
|
||||
})
|
||||
expect(response.datasource.entities).toBeDefined()
|
||||
const table = response.datasource.entities?.["binarytable"]
|
||||
expect(table).toBeDefined()
|
||||
expect(table.schema.id.externalType).toBe("bytea")
|
||||
const row = await config.api.row.save(table._id, {
|
||||
expect(table?.schema.id.externalType).toBe("bytea")
|
||||
const row = await config.api.row.save(table?._id!, {
|
||||
id: "1111",
|
||||
column1: "hello",
|
||||
column2: 222,
|
||||
|
@ -1279,33 +1270,31 @@ describe("postgres integrations", () => {
|
|||
})
|
||||
|
||||
it("should be able to change the table to allow nullable and refetch this", async () => {
|
||||
const response = await makeRequest(
|
||||
"post",
|
||||
`/api/datasources/${datasource._id}/schema`
|
||||
)
|
||||
const entities = response.body.datasource.entities
|
||||
const response = await config.api.datasource.fetchSchema({
|
||||
datasourceId: datasource._id!,
|
||||
})
|
||||
const entities = response.datasource.entities
|
||||
expect(entities).toBeDefined()
|
||||
const nullableTable = entities["nullabletable"]
|
||||
const nullableTable = entities?.["nullabletable"]
|
||||
expect(nullableTable).toBeDefined()
|
||||
expect(nullableTable.schema["order_number"].constraints.presence).toEqual(
|
||||
true
|
||||
)
|
||||
expect(
|
||||
nullableTable?.schema["order_number"].constraints?.presence
|
||||
).toEqual(true)
|
||||
await rawQuery(
|
||||
rawDatasource,
|
||||
`ALTER TABLE nullableTable
|
||||
ALTER COLUMN order_number DROP NOT NULL;
|
||||
`
|
||||
)
|
||||
const responseAfter = await makeRequest(
|
||||
"post",
|
||||
`/api/datasources/${datasource._id}/schema`
|
||||
)
|
||||
const entitiesAfter = responseAfter.body.datasource.entities
|
||||
const responseAfter = await config.api.datasource.fetchSchema({
|
||||
datasourceId: datasource._id!,
|
||||
})
|
||||
const entitiesAfter = responseAfter.datasource.entities
|
||||
expect(entitiesAfter).toBeDefined()
|
||||
const nullableTableAfter = entitiesAfter["nullabletable"]
|
||||
const nullableTableAfter = entitiesAfter?.["nullabletable"]
|
||||
expect(nullableTableAfter).toBeDefined()
|
||||
expect(
|
||||
nullableTableAfter.schema["order_number"].constraints.presence
|
||||
nullableTableAfter?.schema["order_number"].constraints?.presence
|
||||
).toEqual(false)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -71,11 +71,20 @@ export class DatasourceAPI extends TestAPI {
|
|||
})
|
||||
}
|
||||
|
||||
fetchSchema = async (id: string, expectations?: Expectations) => {
|
||||
fetchSchema = async (
|
||||
{
|
||||
datasourceId,
|
||||
tablesFilter,
|
||||
}: { datasourceId: string; tablesFilter?: string[] },
|
||||
expectations?: Expectations
|
||||
) => {
|
||||
return await this._post<BuildSchemaFromSourceResponse>(
|
||||
`/api/datasources/${id}/schema`,
|
||||
`/api/datasources/${datasourceId}/schema`,
|
||||
{
|
||||
expectations,
|
||||
expectations: expectations,
|
||||
body: {
|
||||
tablesFilter: tablesFilter,
|
||||
},
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue