Add tests for datasources
This commit is contained in:
parent
fe17abd7be
commit
0562cf511c
|
@ -60,7 +60,6 @@ export default class AppAPI {
|
|||
const [response, json] = await this.client.post(`/applications`, { body })
|
||||
expect(response).toHaveStatusCode(200)
|
||||
expect(json._id).toBeDefined()
|
||||
this.client.state.appId = json._id
|
||||
return json
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,6 @@ export default class DatasourcesAPI {
|
|||
}
|
||||
|
||||
async add(body: any): Promise<[Response, AddedDatasource]> {
|
||||
//temporarily using a hard coded datasource to test 500 error
|
||||
const [response, json] = await this.client.post(`/datasources`, { body })
|
||||
expect(response).toHaveStatusCode(200)
|
||||
expect(json.datasource._id).toBeDefined()
|
||||
|
@ -77,6 +76,12 @@ export default class DatasourcesAPI {
|
|||
return [response, json]
|
||||
}
|
||||
|
||||
async getQueryPermissions(queryId: string): Promise<[Response, any]> {
|
||||
const [response, json] = await this.client.get(`/permissions/${queryId}`)
|
||||
expect(response).toHaveStatusCode(200)
|
||||
return [response, json]
|
||||
}
|
||||
|
||||
async delete(dataSourceId: string, revId: string): Promise<Response> {
|
||||
const [response, json] = await this.client.del(
|
||||
`/datasources/${dataSourceId}/${revId}`
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
// Add information about the data source to the fixtures file from 1password
|
||||
|
||||
export const mongoDB = () => {
|
||||
return {
|
||||
datasource: {
|
||||
|
@ -7,8 +6,8 @@ export const mongoDB = () => {
|
|||
source: "MONGODB",
|
||||
type: "datasource",
|
||||
config: {
|
||||
connectionString: "",
|
||||
db: "",
|
||||
connectionString: process.env.MONGODB_CONNECTION_STRING,
|
||||
db: process.env.MONGODB_DB,
|
||||
},
|
||||
},
|
||||
|
||||
|
@ -24,12 +23,33 @@ export const postgresSQL = () => {
|
|||
source: "POSTGRES",
|
||||
type: "datasource",
|
||||
config: {
|
||||
database: "",
|
||||
host: "",
|
||||
password: "",
|
||||
port: 1111,
|
||||
database: process.env.POSTGRES_DB,
|
||||
host: process.env.POSTGRES_HOST,
|
||||
password: process.env.POSTGRES_PASSWORD,
|
||||
port: process.env.POSTGRES_PORT,
|
||||
schema: "public",
|
||||
user: "",
|
||||
user: process.env.POSTGRES_USER,
|
||||
},
|
||||
},
|
||||
fetchSchema: true,
|
||||
}
|
||||
}
|
||||
|
||||
// Add the data source for MariaDB to the this file in the same style as above
|
||||
export const mariaDB = () => {
|
||||
return {
|
||||
datasource: {
|
||||
name: "MariaDB",
|
||||
plus: true,
|
||||
source: "MYSQL",
|
||||
type: "datasource",
|
||||
config: {
|
||||
database: process.env.MARIADB_DB,
|
||||
host: process.env.MARIADB_HOST,
|
||||
password: process.env.MARIADB_PASSWORD,
|
||||
port: process.env.MARIADB_PORT,
|
||||
schema: "public",
|
||||
user: process.env.MARIADB_USER,
|
||||
},
|
||||
},
|
||||
fetchSchema: true,
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
import TestConfiguration from "../../config/TestConfiguration"
|
||||
import * as fixtures from "../../fixtures"
|
||||
|
||||
describe("Internal API - Data Sources", () => {
|
||||
const config = new TestConfiguration()
|
||||
|
||||
beforeAll(async () => {
|
||||
await config.beforeAll()
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await config.afterAll()
|
||||
})
|
||||
|
||||
it("Create an app with a data source", async () => {
|
||||
// Create app
|
||||
await config.createApp()
|
||||
|
||||
// Create Screen
|
||||
const roleArray = ["BASIC", "POWER", "ADMIN", "PUBLIC"]
|
||||
for (let role in roleArray) {
|
||||
const [response, screen] = await config.api.screens.create(
|
||||
fixtures.screens.generateScreen(roleArray[role])
|
||||
)
|
||||
}
|
||||
})
|
||||
})
|
|
@ -0,0 +1,71 @@
|
|||
import TestConfiguration from "../../config/TestConfiguration"
|
||||
import * as fixtures from "../../fixtures"
|
||||
|
||||
describe("Internal API - Data Sources: MariaDB", () => {
|
||||
const config = new TestConfiguration()
|
||||
|
||||
beforeAll(async () => {
|
||||
await config.beforeAll()
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await config.afterAll()
|
||||
})
|
||||
|
||||
it("Create an app with a data source - MariaDB", async () => {
|
||||
// Create app
|
||||
await config.createApp()
|
||||
|
||||
// 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)
|
||||
|
||||
const dataSourceQuery = {
|
||||
datasourceId: updatedDataSourceJson.datasource._id,
|
||||
fields: {
|
||||
sql: "SELECT * FROM employees;",
|
||||
},
|
||||
name: "Query 1",
|
||||
parameters: {},
|
||||
queryVerb: "read",
|
||||
schema: {},
|
||||
transformer: "return data",
|
||||
}
|
||||
// Query data source
|
||||
|
||||
const [queryResponse, queryJson] =
|
||||
await config.api.datasources.previewQuery(dataSourceQuery)
|
||||
|
||||
// Save query
|
||||
const datasourcetoSave = {
|
||||
...dataSourceQuery,
|
||||
parameters: [],
|
||||
}
|
||||
|
||||
const [saveQueryResponse, saveQueryJson] =
|
||||
await config.api.datasources.saveQuery(datasourcetoSave)
|
||||
// Get Query
|
||||
const [getQueryResponse, getQueryJson] =
|
||||
await config.api.datasources.getQuery(<string>saveQueryJson._id)
|
||||
|
||||
// Get Query permissions
|
||||
const [getQueryPermissionsResponse, getQueryPermissionsJson] =
|
||||
await config.api.datasources.getQueryPermissions(
|
||||
<string>saveQueryJson._id
|
||||
)
|
||||
|
||||
// Delete data source
|
||||
const deleteResponse = await config.api.datasources.delete(
|
||||
<string>updatedDataSourceJson.datasource._id,
|
||||
<string>updatedDataSourceJson.datasource._rev
|
||||
)
|
||||
})
|
||||
})
|
|
@ -0,0 +1,75 @@
|
|||
import TestConfiguration from "../../config/TestConfiguration"
|
||||
import * as fixtures from "../../fixtures"
|
||||
|
||||
describe("Internal API - Data Sources: MongoDB", () => {
|
||||
const config = new TestConfiguration()
|
||||
|
||||
beforeAll(async () => {
|
||||
await config.beforeAll()
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await config.afterAll()
|
||||
})
|
||||
|
||||
it("Create an app with a data source - MongoDB", async () => {
|
||||
// Create app
|
||||
await config.createApp()
|
||||
|
||||
// Add data source
|
||||
const [dataSourceResponse, dataSourceJson] =
|
||||
await config.api.datasources.add(fixtures.datasources.mongoDB())
|
||||
|
||||
// Update data source
|
||||
const newDataSourceInfo = {
|
||||
...dataSourceJson.datasource,
|
||||
name: "MongoDB2",
|
||||
}
|
||||
const [updatedDataSourceResponse, updatedDataSourceJson] =
|
||||
await config.api.datasources.update(newDataSourceInfo)
|
||||
|
||||
const dataSourceQuery = {
|
||||
datasourceId: updatedDataSourceJson.datasource._id,
|
||||
fields: {
|
||||
extra: {
|
||||
collection: "movies",
|
||||
actionType: "find",
|
||||
},
|
||||
json: "",
|
||||
},
|
||||
name: "Test Query",
|
||||
parameters: {},
|
||||
queryVerb: "read",
|
||||
schema: {},
|
||||
transformer: "return data",
|
||||
}
|
||||
// Query data source
|
||||
|
||||
const [queryResponse, queryJson] =
|
||||
await config.api.datasources.previewQuery(dataSourceQuery)
|
||||
|
||||
// Save query
|
||||
const datasourcetoSave = {
|
||||
...dataSourceQuery,
|
||||
parameters: [],
|
||||
}
|
||||
|
||||
const [saveQueryResponse, saveQueryJson] =
|
||||
await config.api.datasources.saveQuery(datasourcetoSave)
|
||||
// Get Query
|
||||
const [getQueryResponse, getQueryJson] =
|
||||
await config.api.datasources.getQuery(<string>saveQueryJson._id)
|
||||
|
||||
// Get Query permissions
|
||||
const [getQueryPermissionsResponse, getQueryPermissionsJson] =
|
||||
await config.api.datasources.getQueryPermissions(
|
||||
<string>saveQueryJson._id
|
||||
)
|
||||
|
||||
// Delete data source
|
||||
const deleteResponse = await config.api.datasources.delete(
|
||||
<string>updatedDataSourceJson.datasource._id,
|
||||
<string>updatedDataSourceJson.datasource._rev
|
||||
)
|
||||
})
|
||||
})
|
|
@ -14,14 +14,13 @@ describe("Internal API - Data Sources: PostgresSQL", () => {
|
|||
|
||||
it("Create an app with a data source - PostgresSQL", async () => {
|
||||
// Create app
|
||||
const app = await config.api.apps.create({
|
||||
...fixtures.apps.generateApp(),
|
||||
useTemplate: "false",
|
||||
})
|
||||
await config.createApp()
|
||||
|
||||
// Add data source
|
||||
const [dataSourceResponse, dataSourceJson] =
|
||||
await config.api.datasources.add(fixtures.datasources.postgresSQL())
|
||||
|
||||
// Update data source
|
||||
const newDataSourceInfo = {
|
||||
...dataSourceJson.datasource,
|
||||
name: "PostgresSQL2",
|
||||
|
@ -46,11 +45,23 @@ describe("Internal API - Data Sources: PostgresSQL", () => {
|
|||
await config.api.datasources.previewQuery(dataSourceQuery)
|
||||
|
||||
// Save query
|
||||
const datasourcetoSave = {
|
||||
...dataSourceQuery,
|
||||
parameters: [],
|
||||
}
|
||||
|
||||
const [saveQueryResponse, saveQueryJson] =
|
||||
await config.api.datasources.saveQuery(dataSourceQuery)
|
||||
await config.api.datasources.saveQuery(datasourcetoSave)
|
||||
// Get Query
|
||||
const [getQueryResponse, getQueryJson] =
|
||||
await config.api.datasources.getQuery(<string>saveQueryJson._id)
|
||||
|
||||
// Get Query permissions
|
||||
const [getQueryPermissionsResponse, getQueryPermissionsJson] =
|
||||
await config.api.datasources.getQueryPermissions(
|
||||
<string>saveQueryJson._id
|
||||
)
|
||||
|
||||
// Delete data source
|
||||
const deleteResponse = await config.api.datasources.delete(
|
||||
<string>updatedDataSourceJson.datasource._id,
|
||||
|
|
Loading…
Reference in New Issue