diff --git a/qa-core/src/internal-api/api/apis/AppAPI.ts b/qa-core/src/internal-api/api/apis/AppAPI.ts index bdbf5ba85d..992728899e 100644 --- a/qa-core/src/internal-api/api/apis/AppAPI.ts +++ b/qa-core/src/internal-api/api/apis/AppAPI.ts @@ -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 } diff --git a/qa-core/src/internal-api/api/apis/DatasourcesAPI.ts b/qa-core/src/internal-api/api/apis/DatasourcesAPI.ts index 15215b7ba4..f61692b02f 100644 --- a/qa-core/src/internal-api/api/apis/DatasourcesAPI.ts +++ b/qa-core/src/internal-api/api/apis/DatasourcesAPI.ts @@ -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 { const [response, json] = await this.client.del( `/datasources/${dataSourceId}/${revId}` diff --git a/qa-core/src/internal-api/fixtures/datasources.ts b/qa-core/src/internal-api/fixtures/datasources.ts index feb51add32..a8d59b88a1 100644 --- a/qa-core/src/internal-api/fixtures/datasources.ts +++ b/qa-core/src/internal-api/fixtures/datasources.ts @@ -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, diff --git a/qa-core/src/internal-api/tests/dataSources/example.spec.ts b/qa-core/src/internal-api/tests/dataSources/example.spec.ts deleted file mode 100644 index 0b8bc38a45..0000000000 --- a/qa-core/src/internal-api/tests/dataSources/example.spec.ts +++ /dev/null @@ -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]) - ) - } - }) -}) diff --git a/qa-core/src/internal-api/tests/dataSources/mariaDB.spec.ts b/qa-core/src/internal-api/tests/dataSources/mariaDB.spec.ts new file mode 100644 index 0000000000..4ff9a7cd0a --- /dev/null +++ b/qa-core/src/internal-api/tests/dataSources/mariaDB.spec.ts @@ -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(saveQueryJson._id) + + // Get Query permissions + const [getQueryPermissionsResponse, getQueryPermissionsJson] = + await config.api.datasources.getQueryPermissions( + saveQueryJson._id + ) + + // Delete data source + const deleteResponse = await config.api.datasources.delete( + updatedDataSourceJson.datasource._id, + updatedDataSourceJson.datasource._rev + ) + }) +}) diff --git a/qa-core/src/internal-api/tests/dataSources/mongoDB.spec.ts b/qa-core/src/internal-api/tests/dataSources/mongoDB.spec.ts new file mode 100644 index 0000000000..6c57467930 --- /dev/null +++ b/qa-core/src/internal-api/tests/dataSources/mongoDB.spec.ts @@ -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(saveQueryJson._id) + + // Get Query permissions + const [getQueryPermissionsResponse, getQueryPermissionsJson] = + await config.api.datasources.getQueryPermissions( + saveQueryJson._id + ) + + // Delete data source + const deleteResponse = await config.api.datasources.delete( + updatedDataSourceJson.datasource._id, + updatedDataSourceJson.datasource._rev + ) + }) +}) diff --git a/qa-core/src/internal-api/tests/dataSources/postgresSQL.spec.ts b/qa-core/src/internal-api/tests/dataSources/postgresSQL.spec.ts index b244cbde4b..83d1fc782d 100644 --- a/qa-core/src/internal-api/tests/dataSources/postgresSQL.spec.ts +++ b/qa-core/src/internal-api/tests/dataSources/postgresSQL.spec.ts @@ -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(saveQueryJson._id) + + // Get Query permissions + const [getQueryPermissionsResponse, getQueryPermissionsJson] = + await config.api.datasources.getQueryPermissions( + saveQueryJson._id + ) + // Delete data source const deleteResponse = await config.api.datasources.delete( updatedDataSourceJson.datasource._id,