Merge remote-tracking branch 'origin/develop' into feature/binding-v2-updates
This commit is contained in:
commit
e84939f8d1
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"version": "2.6.19-alpha.1",
|
"version": "2.6.19-alpha.5",
|
||||||
"npmClient": "yarn",
|
"npmClient": "yarn",
|
||||||
"packages": [
|
"packages": [
|
||||||
"packages/backend-core",
|
"packages/backend-core",
|
||||||
|
|
|
@ -25,6 +25,8 @@ export function createDatasourcesStore() {
|
||||||
store.update(state => ({
|
store.update(state => ({
|
||||||
...state,
|
...state,
|
||||||
selectedDatasourceId: id,
|
selectedDatasourceId: id,
|
||||||
|
// Remove any possible schema error
|
||||||
|
schemaError: null,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ import {
|
||||||
CreateDatasourceRequest,
|
CreateDatasourceRequest,
|
||||||
VerifyDatasourceRequest,
|
VerifyDatasourceRequest,
|
||||||
VerifyDatasourceResponse,
|
VerifyDatasourceResponse,
|
||||||
|
FetchDatasourceInfoResponse,
|
||||||
IntegrationBase,
|
IntegrationBase,
|
||||||
DatasourcePlus,
|
DatasourcePlus,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
|
@ -153,6 +154,21 @@ export async function verify(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function information(
|
||||||
|
ctx: UserCtx<void, FetchDatasourceInfoResponse>
|
||||||
|
) {
|
||||||
|
const datasourceId = ctx.params.datasourceId
|
||||||
|
const datasource = await sdk.datasources.get(datasourceId, { enriched: true })
|
||||||
|
const connector = (await getConnector(datasource)) as DatasourcePlus
|
||||||
|
if (!connector.getTableNames) {
|
||||||
|
ctx.throw(400, "Table name fetching not supported by datasource")
|
||||||
|
}
|
||||||
|
const tableNames = await connector.getTableNames()
|
||||||
|
ctx.body = {
|
||||||
|
tableNames,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function buildSchemaFromDb(ctx: UserCtx) {
|
export async function buildSchemaFromDb(ctx: UserCtx) {
|
||||||
const db = context.getAppDB()
|
const db = context.getAppDB()
|
||||||
const datasource = await sdk.datasources.get(ctx.params.datasourceId)
|
const datasource = await sdk.datasources.get(ctx.params.datasourceId)
|
||||||
|
|
|
@ -20,6 +20,11 @@ router
|
||||||
authorized(permissions.BUILDER),
|
authorized(permissions.BUILDER),
|
||||||
datasourceController.verify
|
datasourceController.verify
|
||||||
)
|
)
|
||||||
|
.get(
|
||||||
|
"/api/datasources/:datasourceId/info",
|
||||||
|
authorized(permissions.BUILDER),
|
||||||
|
datasourceController.information
|
||||||
|
)
|
||||||
.get(
|
.get(
|
||||||
"/api/datasources/:datasourceId",
|
"/api/datasources/:datasourceId",
|
||||||
authorized(
|
authorized(
|
||||||
|
|
|
@ -87,7 +87,7 @@ describe("/datasources", () => {
|
||||||
expect(contents.rows.length).toEqual(1)
|
expect(contents.rows.length).toEqual(1)
|
||||||
|
|
||||||
// update the datasource to remove the variables
|
// update the datasource to remove the variables
|
||||||
datasource.config.dynamicVariables = []
|
datasource.config!.dynamicVariables = []
|
||||||
const res = await request
|
const res = await request
|
||||||
.put(`/api/datasources/${datasource._id}`)
|
.put(`/api/datasources/${datasource._id}`)
|
||||||
.send(datasource)
|
.send(datasource)
|
||||||
|
|
|
@ -26,7 +26,7 @@ jest.setTimeout(30000)
|
||||||
|
|
||||||
jest.unmock("pg")
|
jest.unmock("pg")
|
||||||
|
|
||||||
describe("row api - postgres", () => {
|
describe("postgres integrations", () => {
|
||||||
let makeRequest: MakeRequestResponse,
|
let makeRequest: MakeRequestResponse,
|
||||||
postgresDatasource: Datasource,
|
postgresDatasource: Datasource,
|
||||||
primaryPostgresTable: Table,
|
primaryPostgresTable: Table,
|
||||||
|
@ -52,8 +52,8 @@ describe("row api - postgres", () => {
|
||||||
makeRequest = generateMakeRequest(apiKey, true)
|
makeRequest = generateMakeRequest(apiKey, true)
|
||||||
})
|
})
|
||||||
|
|
||||||
beforeEach(async () => {
|
function pgDatasourceConfig() {
|
||||||
postgresDatasource = await config.createDatasource({
|
return {
|
||||||
datasource: {
|
datasource: {
|
||||||
type: "datasource",
|
type: "datasource",
|
||||||
source: SourceName.POSTGRES,
|
source: SourceName.POSTGRES,
|
||||||
|
@ -70,7 +70,11 @@ describe("row api - postgres", () => {
|
||||||
ca: false,
|
ca: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
postgresDatasource = await config.createDatasource(pgDatasourceConfig())
|
||||||
|
|
||||||
async function createAuxTable(prefix: string) {
|
async function createAuxTable(prefix: string) {
|
||||||
return await config.createTable({
|
return await config.createTable({
|
||||||
|
@ -1024,4 +1028,43 @@ describe("row api - postgres", () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("POST /api/datasources/verify", () => {
|
||||||
|
it("should be able to verify the connection", async () => {
|
||||||
|
const config = pgDatasourceConfig()
|
||||||
|
const response = await makeRequest(
|
||||||
|
"post",
|
||||||
|
"/api/datasources/verify",
|
||||||
|
config
|
||||||
|
)
|
||||||
|
expect(response.status).toBe(200)
|
||||||
|
expect(response.body.connected).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should state an invalid datasource cannot connect", async () => {
|
||||||
|
const config = pgDatasourceConfig()
|
||||||
|
config.datasource.config.password = "wrongpassword"
|
||||||
|
const response = await makeRequest(
|
||||||
|
"post",
|
||||||
|
"/api/datasources/verify",
|
||||||
|
config
|
||||||
|
)
|
||||||
|
expect(response.status).toBe(200)
|
||||||
|
expect(response.body.connected).toBe(false)
|
||||||
|
expect(response.body.error).toBeDefined()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("GET /api/datasources/:datasourceId/info", () => {
|
||||||
|
it("should fetch information about postgres datasource", async () => {
|
||||||
|
const primaryName = primaryPostgresTable.name
|
||||||
|
const response = await makeRequest(
|
||||||
|
"get",
|
||||||
|
`/api/datasources/${postgresDatasource._id}/info`
|
||||||
|
)
|
||||||
|
expect(response.status).toBe(200)
|
||||||
|
expect(response.body.tableNames).toBeDefined()
|
||||||
|
expect(response.body.tableNames.indexOf(primaryName)).not.toBe(-1)
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -63,10 +63,13 @@ const SCHEMA: Integration = {
|
||||||
relationships: false,
|
relationships: false,
|
||||||
docs: "https://developers.google.com/sheets/api/quickstart/nodejs",
|
docs: "https://developers.google.com/sheets/api/quickstart/nodejs",
|
||||||
description:
|
description:
|
||||||
"Create and collaborate on online spreadsheets in real-time and from any device. ",
|
"Create and collaborate on online spreadsheets in real-time and from any device.",
|
||||||
friendlyName: "Google Sheets",
|
friendlyName: "Google Sheets",
|
||||||
type: "Spreadsheet",
|
type: "Spreadsheet",
|
||||||
features: [DatasourceFeature.CONNECTION_CHECKING],
|
features: [
|
||||||
|
DatasourceFeature.CONNECTION_CHECKING,
|
||||||
|
DatasourceFeature.FETCH_TABLE_NAMES,
|
||||||
|
],
|
||||||
datasource: {
|
datasource: {
|
||||||
spreadsheetId: {
|
spreadsheetId: {
|
||||||
display: "Google Sheet URL",
|
display: "Google Sheet URL",
|
||||||
|
@ -145,7 +148,6 @@ class GoogleSheetsIntegration implements DatasourcePlus {
|
||||||
async testConnection(): Promise<ConnectionInfo> {
|
async testConnection(): Promise<ConnectionInfo> {
|
||||||
try {
|
try {
|
||||||
await this.connect()
|
await this.connect()
|
||||||
await this.client.loadInfo()
|
|
||||||
return { connected: true }
|
return { connected: true }
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
return {
|
return {
|
||||||
|
@ -240,6 +242,12 @@ class GoogleSheetsIntegration implements DatasourcePlus {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getTableNames(): Promise<string[]> {
|
||||||
|
await this.connect()
|
||||||
|
const sheets = this.client.sheetsByIndex
|
||||||
|
return sheets.map(s => s.title)
|
||||||
|
}
|
||||||
|
|
||||||
getTableSchema(title: string, headerValues: string[], id?: string) {
|
getTableSchema(title: string, headerValues: string[], id?: string) {
|
||||||
// base table
|
// base table
|
||||||
const table: Table = {
|
const table: Table = {
|
||||||
|
|
|
@ -20,7 +20,6 @@ import {
|
||||||
} from "./utils"
|
} from "./utils"
|
||||||
import Sql from "./base/sql"
|
import Sql from "./base/sql"
|
||||||
import { MSSQLTablesResponse, MSSQLColumn } from "./base/types"
|
import { MSSQLTablesResponse, MSSQLColumn } from "./base/types"
|
||||||
|
|
||||||
const sqlServer = require("mssql")
|
const sqlServer = require("mssql")
|
||||||
const DEFAULT_SCHEMA = "dbo"
|
const DEFAULT_SCHEMA = "dbo"
|
||||||
|
|
||||||
|
@ -41,7 +40,10 @@ const SCHEMA: Integration = {
|
||||||
"Microsoft SQL Server is a relational database management system developed by Microsoft. ",
|
"Microsoft SQL Server is a relational database management system developed by Microsoft. ",
|
||||||
friendlyName: "MS SQL Server",
|
friendlyName: "MS SQL Server",
|
||||||
type: "Relational",
|
type: "Relational",
|
||||||
features: [DatasourceFeature.CONNECTION_CHECKING],
|
features: [
|
||||||
|
DatasourceFeature.CONNECTION_CHECKING,
|
||||||
|
DatasourceFeature.FETCH_TABLE_NAMES,
|
||||||
|
],
|
||||||
datasource: {
|
datasource: {
|
||||||
user: {
|
user: {
|
||||||
type: DatasourceFieldType.STRING,
|
type: DatasourceFieldType.STRING,
|
||||||
|
@ -284,6 +286,20 @@ class SqlServerIntegration extends Sql implements DatasourcePlus {
|
||||||
this.schemaErrors = final.errors
|
this.schemaErrors = final.errors
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async queryTableNames() {
|
||||||
|
let tableInfo: MSSQLTablesResponse[] = await this.runSQL(this.TABLES_SQL)
|
||||||
|
const schema = this.config.schema || DEFAULT_SCHEMA
|
||||||
|
return tableInfo
|
||||||
|
.filter((record: any) => record.TABLE_SCHEMA === schema)
|
||||||
|
.map((record: any) => record.TABLE_NAME)
|
||||||
|
.filter((name: string) => this.MASTER_TABLES.indexOf(name) === -1)
|
||||||
|
}
|
||||||
|
|
||||||
|
async getTableNames() {
|
||||||
|
await this.connect()
|
||||||
|
return this.queryTableNames()
|
||||||
|
}
|
||||||
|
|
||||||
async read(query: SqlQuery | string) {
|
async read(query: SqlQuery | string) {
|
||||||
await this.connect()
|
await this.connect()
|
||||||
const response = await this.internalQuery(getSqlQuery(query))
|
const response = await this.internalQuery(getSqlQuery(query))
|
||||||
|
|
|
@ -36,7 +36,10 @@ const SCHEMA: Integration = {
|
||||||
type: "Relational",
|
type: "Relational",
|
||||||
description:
|
description:
|
||||||
"MySQL Database Service is a fully managed database service to deploy cloud-native applications. ",
|
"MySQL Database Service is a fully managed database service to deploy cloud-native applications. ",
|
||||||
features: [DatasourceFeature.CONNECTION_CHECKING],
|
features: [
|
||||||
|
DatasourceFeature.CONNECTION_CHECKING,
|
||||||
|
DatasourceFeature.FETCH_TABLE_NAMES,
|
||||||
|
],
|
||||||
datasource: {
|
datasource: {
|
||||||
host: {
|
host: {
|
||||||
type: DatasourceFieldType.STRING,
|
type: DatasourceFieldType.STRING,
|
||||||
|
@ -214,20 +217,11 @@ class MySQLIntegration extends Sql implements DatasourcePlus {
|
||||||
|
|
||||||
async buildSchema(datasourceId: string, entities: Record<string, Table>) {
|
async buildSchema(datasourceId: string, entities: Record<string, Table>) {
|
||||||
const tables: { [key: string]: Table } = {}
|
const tables: { [key: string]: Table } = {}
|
||||||
const database = this.config.database
|
|
||||||
await this.connect()
|
await this.connect()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// get the tables first
|
// get the tables first
|
||||||
const tablesResp: Record<string, string>[] = await this.internalQuery(
|
const tableNames = await this.queryTableNames()
|
||||||
{ sql: "SHOW TABLES;" },
|
|
||||||
{ connect: false }
|
|
||||||
)
|
|
||||||
const tableNames: string[] = tablesResp.map(
|
|
||||||
(obj: any) =>
|
|
||||||
obj[`Tables_in_${database}`] ||
|
|
||||||
obj[`Tables_in_${database.toLowerCase()}`]
|
|
||||||
)
|
|
||||||
for (let tableName of tableNames) {
|
for (let tableName of tableNames) {
|
||||||
const primaryKeys = []
|
const primaryKeys = []
|
||||||
const schema: TableSchema = {}
|
const schema: TableSchema = {}
|
||||||
|
@ -274,6 +268,28 @@ class MySQLIntegration extends Sql implements DatasourcePlus {
|
||||||
this.schemaErrors = final.errors
|
this.schemaErrors = final.errors
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async queryTableNames() {
|
||||||
|
const database = this.config.database
|
||||||
|
const tablesResp: Record<string, string>[] = await this.internalQuery(
|
||||||
|
{ sql: "SHOW TABLES;" },
|
||||||
|
{ connect: false }
|
||||||
|
)
|
||||||
|
return tablesResp.map(
|
||||||
|
(obj: any) =>
|
||||||
|
obj[`Tables_in_${database}`] ||
|
||||||
|
obj[`Tables_in_${database.toLowerCase()}`]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async getTableNames() {
|
||||||
|
await this.connect()
|
||||||
|
try {
|
||||||
|
return this.queryTableNames()
|
||||||
|
} finally {
|
||||||
|
await this.disconnect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async create(query: SqlQuery | string) {
|
async create(query: SqlQuery | string) {
|
||||||
const results = await this.internalQuery(getSqlQuery(query))
|
const results = await this.internalQuery(getSqlQuery(query))
|
||||||
return results.length ? results : [{ created: true }]
|
return results.length ? results : [{ created: true }]
|
||||||
|
|
|
@ -50,7 +50,10 @@ const SCHEMA: Integration = {
|
||||||
type: "Relational",
|
type: "Relational",
|
||||||
description:
|
description:
|
||||||
"Oracle Database is an object-relational database management system developed by Oracle Corporation",
|
"Oracle Database is an object-relational database management system developed by Oracle Corporation",
|
||||||
features: [DatasourceFeature.CONNECTION_CHECKING],
|
features: [
|
||||||
|
DatasourceFeature.CONNECTION_CHECKING,
|
||||||
|
DatasourceFeature.FETCH_TABLE_NAMES,
|
||||||
|
],
|
||||||
datasource: {
|
datasource: {
|
||||||
host: {
|
host: {
|
||||||
type: DatasourceFieldType.STRING,
|
type: DatasourceFieldType.STRING,
|
||||||
|
@ -323,6 +326,13 @@ class OracleIntegration extends Sql implements DatasourcePlus {
|
||||||
this.schemaErrors = final.errors
|
this.schemaErrors = final.errors
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getTableNames() {
|
||||||
|
const columnsResponse = await this.internalQuery<OracleColumnsResponse>({
|
||||||
|
sql: this.COLUMNS_SQL,
|
||||||
|
})
|
||||||
|
return (columnsResponse.rows || []).map(row => row.TABLE_NAME)
|
||||||
|
}
|
||||||
|
|
||||||
async testConnection() {
|
async testConnection() {
|
||||||
const response: ConnectionInfo = {
|
const response: ConnectionInfo = {
|
||||||
connected: false,
|
connected: false,
|
||||||
|
|
|
@ -52,7 +52,10 @@ const SCHEMA: Integration = {
|
||||||
type: "Relational",
|
type: "Relational",
|
||||||
description:
|
description:
|
||||||
"PostgreSQL, also known as Postgres, is a free and open-source relational database management system emphasizing extensibility and SQL compliance.",
|
"PostgreSQL, also known as Postgres, is a free and open-source relational database management system emphasizing extensibility and SQL compliance.",
|
||||||
features: [DatasourceFeature.CONNECTION_CHECKING],
|
features: [
|
||||||
|
DatasourceFeature.CONNECTION_CHECKING,
|
||||||
|
DatasourceFeature.FETCH_TABLE_NAMES,
|
||||||
|
],
|
||||||
datasource: {
|
datasource: {
|
||||||
host: {
|
host: {
|
||||||
type: DatasourceFieldType.STRING,
|
type: DatasourceFieldType.STRING,
|
||||||
|
@ -126,14 +129,15 @@ class PostgresIntegration extends Sql implements DatasourcePlus {
|
||||||
|
|
||||||
COLUMNS_SQL!: string
|
COLUMNS_SQL!: string
|
||||||
|
|
||||||
PRIMARY_KEYS_SQL = `
|
PRIMARY_KEYS_SQL = () => `
|
||||||
select tc.table_schema, tc.table_name, kc.column_name as primary_key
|
SELECT pg_namespace.nspname table_schema
|
||||||
from information_schema.table_constraints tc
|
, pg_class.relname table_name
|
||||||
join
|
, pg_attribute.attname primary_key
|
||||||
information_schema.key_column_usage kc on kc.table_name = tc.table_name
|
FROM pg_class
|
||||||
and kc.table_schema = tc.table_schema
|
JOIN pg_index ON pg_class.oid = pg_index.indrelid AND pg_index.indisprimary
|
||||||
and kc.constraint_name = tc.constraint_name
|
JOIN pg_attribute ON pg_attribute.attrelid = pg_class.oid AND pg_attribute.attnum = ANY(pg_index.indkey)
|
||||||
where tc.constraint_type = 'PRIMARY KEY';
|
JOIN pg_namespace ON pg_namespace.oid = pg_class.relnamespace
|
||||||
|
WHERE pg_namespace.nspname = '${this.config.schema}';
|
||||||
`
|
`
|
||||||
|
|
||||||
constructor(config: PostgresConfig) {
|
constructor(config: PostgresConfig) {
|
||||||
|
@ -239,7 +243,9 @@ class PostgresIntegration extends Sql implements DatasourcePlus {
|
||||||
let tableKeys: { [key: string]: string[] } = {}
|
let tableKeys: { [key: string]: string[] } = {}
|
||||||
await this.openConnection()
|
await this.openConnection()
|
||||||
try {
|
try {
|
||||||
const primaryKeysResponse = await this.client.query(this.PRIMARY_KEYS_SQL)
|
const primaryKeysResponse = await this.client.query(
|
||||||
|
this.PRIMARY_KEYS_SQL()
|
||||||
|
)
|
||||||
for (let table of primaryKeysResponse.rows) {
|
for (let table of primaryKeysResponse.rows) {
|
||||||
const tableName = table.table_name
|
const tableName = table.table_name
|
||||||
if (!tableKeys[tableName]) {
|
if (!tableKeys[tableName]) {
|
||||||
|
@ -311,6 +317,17 @@ class PostgresIntegration extends Sql implements DatasourcePlus {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getTableNames() {
|
||||||
|
try {
|
||||||
|
await this.openConnection()
|
||||||
|
const columnsResponse: { rows: PostgresColumn[] } =
|
||||||
|
await this.client.query(this.COLUMNS_SQL)
|
||||||
|
return columnsResponse.rows.map(row => row.table_name)
|
||||||
|
} finally {
|
||||||
|
await this.closeConnection()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async create(query: SqlQuery | string) {
|
async create(query: SqlQuery | string) {
|
||||||
const response = await this.internalQuery(getSqlQuery(query))
|
const response = await this.internalQuery(getSqlQuery(query))
|
||||||
return response.rows.length ? response.rows : [{ created: true }]
|
return response.rows.length ? response.rows : [{ created: true }]
|
||||||
|
|
|
@ -17,14 +17,15 @@ jest.mock("google-spreadsheet")
|
||||||
const { GoogleSpreadsheet } = require("google-spreadsheet")
|
const { GoogleSpreadsheet } = require("google-spreadsheet")
|
||||||
|
|
||||||
const sheetsByTitle: { [title: string]: GoogleSpreadsheetWorksheet } = {}
|
const sheetsByTitle: { [title: string]: GoogleSpreadsheetWorksheet } = {}
|
||||||
|
const sheetsByIndex: GoogleSpreadsheetWorksheet[] = []
|
||||||
|
const mockGoogleIntegration = {
|
||||||
|
useOAuth2Client: jest.fn(),
|
||||||
|
loadInfo: jest.fn(),
|
||||||
|
sheetsByTitle,
|
||||||
|
sheetsByIndex,
|
||||||
|
}
|
||||||
|
|
||||||
GoogleSpreadsheet.mockImplementation(() => {
|
GoogleSpreadsheet.mockImplementation(() => mockGoogleIntegration)
|
||||||
return {
|
|
||||||
useOAuth2Client: jest.fn(),
|
|
||||||
loadInfo: jest.fn(),
|
|
||||||
sheetsByTitle,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
import { structures } from "@budibase/backend-core/tests"
|
import { structures } from "@budibase/backend-core/tests"
|
||||||
import TestConfiguration from "../../tests/utilities/TestConfiguration"
|
import TestConfiguration from "../../tests/utilities/TestConfiguration"
|
||||||
|
@ -53,6 +54,8 @@ describe("Google Sheets Integration", () => {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
await config.init()
|
await config.init()
|
||||||
|
|
||||||
|
jest.clearAllMocks()
|
||||||
})
|
})
|
||||||
|
|
||||||
function createBasicTable(name: string, columns: string[]): Table {
|
function createBasicTable(name: string, columns: string[]): Table {
|
||||||
|
@ -88,7 +91,7 @@ describe("Google Sheets Integration", () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("update table", () => {
|
describe("update table", () => {
|
||||||
test("adding a new field will be adding a new header row", async () => {
|
it("adding a new field will be adding a new header row", async () => {
|
||||||
await config.doInContext(structures.uuid(), async () => {
|
await config.doInContext(structures.uuid(), async () => {
|
||||||
const tableColumns = ["name", "description", "new field"]
|
const tableColumns = ["name", "description", "new field"]
|
||||||
const table = createBasicTable(structures.uuid(), tableColumns)
|
const table = createBasicTable(structures.uuid(), tableColumns)
|
||||||
|
@ -103,7 +106,7 @@ describe("Google Sheets Integration", () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
test("removing an existing field will remove the header from the google sheet", async () => {
|
it("removing an existing field will remove the header from the google sheet", async () => {
|
||||||
const sheet = await config.doInContext(structures.uuid(), async () => {
|
const sheet = await config.doInContext(structures.uuid(), async () => {
|
||||||
const tableColumns = ["name"]
|
const tableColumns = ["name"]
|
||||||
const table = createBasicTable(structures.uuid(), tableColumns)
|
const table = createBasicTable(structures.uuid(), tableColumns)
|
||||||
|
@ -123,4 +126,33 @@ describe("Google Sheets Integration", () => {
|
||||||
expect((sheet.setHeaderRow as any).mock.calls[0][0]).toHaveLength(1)
|
expect((sheet.setHeaderRow as any).mock.calls[0][0]).toHaveLength(1)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("getTableNames", () => {
|
||||||
|
it("can fetch table names", async () => {
|
||||||
|
await config.doInContext(structures.uuid(), async () => {
|
||||||
|
const sheetNames: string[] = []
|
||||||
|
for (let i = 0; i < 5; i++) {
|
||||||
|
const sheet = createSheet({ headerValues: [] })
|
||||||
|
sheetsByIndex.push(sheet)
|
||||||
|
sheetNames.push(sheet.title)
|
||||||
|
}
|
||||||
|
|
||||||
|
const res = await integration.getTableNames()
|
||||||
|
|
||||||
|
expect(mockGoogleIntegration.loadInfo).toBeCalledTimes(1)
|
||||||
|
expect(res).toEqual(sheetNames)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("testConnection", () => {
|
||||||
|
it("can test successful connections", async () => {
|
||||||
|
await config.doInContext(structures.uuid(), async () => {
|
||||||
|
const res = await integration.testConnection()
|
||||||
|
|
||||||
|
expect(mockGoogleIntegration.loadInfo).toBeCalledTimes(1)
|
||||||
|
expect(res).toEqual({ connected: true })
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -23,6 +23,10 @@ export interface VerifyDatasourceResponse {
|
||||||
error?: string
|
error?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface FetchDatasourceInfoResponse {
|
||||||
|
tableNames: string[]
|
||||||
|
}
|
||||||
|
|
||||||
export interface UpdateDatasourceRequest extends Datasource {
|
export interface UpdateDatasourceRequest extends Datasource {
|
||||||
datasource: Datasource
|
datasource: Datasource
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,4 +21,5 @@ export interface Screen extends Document {
|
||||||
width?: string
|
width?: string
|
||||||
routing: ScreenRouting
|
routing: ScreenRouting
|
||||||
props: ScreenProps
|
props: ScreenProps
|
||||||
|
name?: string
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,6 +75,7 @@ export enum FilterType {
|
||||||
|
|
||||||
export enum DatasourceFeature {
|
export enum DatasourceFeature {
|
||||||
CONNECTION_CHECKING = "connection",
|
CONNECTION_CHECKING = "connection",
|
||||||
|
FETCH_TABLE_NAMES = "fetch_table_names",
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface StepDefinition {
|
export interface StepDefinition {
|
||||||
|
@ -150,4 +151,5 @@ export interface DatasourcePlus extends IntegrationBase {
|
||||||
getBindingIdentifier(): string
|
getBindingIdentifier(): string
|
||||||
getStringConcat(parts: string[]): string
|
getStringConcat(parts: string[]): string
|
||||||
buildSchema(datasourceId: string, entities: Record<string, Table>): any
|
buildSchema(datasourceId: string, entities: Record<string, Table>): any
|
||||||
|
getTableNames(): Promise<string[]>
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -5,80 +5,71 @@ import {
|
||||||
AppPackageResponse,
|
AppPackageResponse,
|
||||||
DeployConfig,
|
DeployConfig,
|
||||||
MessageResponse,
|
MessageResponse,
|
||||||
|
CreateAppRequest,
|
||||||
} from "../../../types"
|
} from "../../../types"
|
||||||
import BudibaseInternalAPIClient from "../BudibaseInternalAPIClient"
|
import BudibaseInternalAPIClient from "../BudibaseInternalAPIClient"
|
||||||
|
import BaseAPI from "./BaseAPI"
|
||||||
|
|
||||||
export default class AppAPI {
|
interface RenameAppBody {
|
||||||
client: BudibaseInternalAPIClient
|
name: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class AppAPI extends BaseAPI {
|
||||||
constructor(client: BudibaseInternalAPIClient) {
|
constructor(client: BudibaseInternalAPIClient) {
|
||||||
this.client = client
|
super(client)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Fix the fetch apps to receive an optional number of apps and compare if the received app is more or less.
|
// TODO Fix the fetch apps to receive an optional number of apps and compare if the received app is more or less.
|
||||||
// each possible scenario should have its own method.
|
// each possible scenario should have its own method.
|
||||||
async fetchEmptyAppList(): Promise<[Response, App[]]> {
|
async fetchEmptyAppList(): Promise<[Response, App[]]> {
|
||||||
const [response, json] = await this.client.get(`/applications?status=all`)
|
const [response, json] = await this.get(`/applications?status=all`)
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
expect(json.length).toBeGreaterThanOrEqual(0)
|
expect(json.length).toBeGreaterThanOrEqual(0)
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchAllApplications(): Promise<[Response, App[]]> {
|
async fetchAllApplications(): Promise<[Response, App[]]> {
|
||||||
const [response, json] = await this.client.get(`/applications?status=all`)
|
const [response, json] = await this.get(`/applications?status=all`)
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
expect(json.length).toBeGreaterThanOrEqual(1)
|
expect(json.length).toBeGreaterThanOrEqual(1)
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
|
|
||||||
async canRender(): Promise<[Response, boolean]> {
|
async canRender(): Promise<[Response, boolean]> {
|
||||||
const [response, json] = await this.client.get("/routing/client")
|
const [response, json] = await this.get("/routing/client")
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
const publishedAppRenders = Object.keys(json.routes).length > 0
|
const publishedAppRenders = Object.keys(json.routes).length > 0
|
||||||
expect(publishedAppRenders).toBe(true)
|
expect(publishedAppRenders).toBe(true)
|
||||||
return [response, publishedAppRenders]
|
return [response, publishedAppRenders]
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAppPackage(appId: string): Promise<[Response, AppPackageResponse]> {
|
async getAppPackage(appId: string): Promise<[Response, AppPackageResponse]> {
|
||||||
const [response, json] = await this.client.get(
|
const [response, json] = await this.get(`/applications/${appId}/appPackage`)
|
||||||
`/applications/${appId}/appPackage`
|
|
||||||
)
|
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
expect(json.application.appId).toEqual(appId)
|
expect(json.application.appId).toEqual(appId)
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
|
|
||||||
async publish(appId: string | undefined): Promise<[Response, DeployConfig]> {
|
async publish(appId: string | undefined): Promise<[Response, DeployConfig]> {
|
||||||
const [response, json] = await this.client.post(
|
const [response, json] = await this.post(`/applications/${appId}/publish`)
|
||||||
`/applications/${appId}/publish`
|
|
||||||
)
|
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(body: any): Promise<App> {
|
async create(body: CreateAppRequest): Promise<App> {
|
||||||
const [response, json] = await this.client.post(`/applications`, { body })
|
const [response, json] = await this.post(`/applications`, body)
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
expect(json._id).toBeDefined()
|
expect(json._id).toBeDefined()
|
||||||
return json
|
return json
|
||||||
}
|
}
|
||||||
|
|
||||||
async read(id: string): Promise<[Response, App]> {
|
async read(id: string): Promise<[Response, App]> {
|
||||||
const [response, json] = await this.client.get(`/applications/${id}`)
|
const [response, json] = await this.get(`/applications/${id}`)
|
||||||
return [response, json.data]
|
return [response, json.data]
|
||||||
}
|
}
|
||||||
|
|
||||||
async sync(appId: string): Promise<[Response, MessageResponse]> {
|
async sync(appId: string): Promise<[Response, MessageResponse]> {
|
||||||
const [response, json] = await this.client.post(
|
const [response, json] = await this.post(`/applications/${appId}/sync`)
|
||||||
`/applications/${appId}/sync`
|
|
||||||
)
|
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
async updateClient(appId: string, body: any): Promise<[Response, App]> {
|
async updateClient(appId: string, body: any): Promise<[Response, App]> {
|
||||||
const [response, json] = await this.client.put(
|
const [response, json] = await this.put(
|
||||||
`/applications/${appId}/client/update`,
|
`/applications/${appId}/client/update`,
|
||||||
{ body }
|
{ body }
|
||||||
)
|
)
|
||||||
|
@ -86,8 +77,7 @@ export default class AppAPI {
|
||||||
}
|
}
|
||||||
|
|
||||||
async revertPublished(appId: string): Promise<[Response, MessageResponse]> {
|
async revertPublished(appId: string): Promise<[Response, MessageResponse]> {
|
||||||
const [response, json] = await this.client.post(`/dev/${appId}/revert`)
|
const [response, json] = await this.post(`/dev/${appId}/revert`)
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
expect(json).toEqual({
|
expect(json).toEqual({
|
||||||
message: "Reverted changes successfully.",
|
message: "Reverted changes successfully.",
|
||||||
})
|
})
|
||||||
|
@ -95,8 +85,11 @@ export default class AppAPI {
|
||||||
}
|
}
|
||||||
|
|
||||||
async revertUnpublished(appId: string): Promise<[Response, MessageResponse]> {
|
async revertUnpublished(appId: string): Promise<[Response, MessageResponse]> {
|
||||||
const [response, json] = await this.client.post(`/dev/${appId}/revert`)
|
const [response, json] = await this.post(
|
||||||
expect(response).toHaveStatusCode(400)
|
`/dev/${appId}/revert`,
|
||||||
|
undefined,
|
||||||
|
400
|
||||||
|
)
|
||||||
expect(json).toEqual({
|
expect(json).toEqual({
|
||||||
message: "App has not yet been deployed",
|
message: "App has not yet been deployed",
|
||||||
status: 400,
|
status: 400,
|
||||||
|
@ -105,32 +98,22 @@ export default class AppAPI {
|
||||||
}
|
}
|
||||||
|
|
||||||
async delete(appId: string): Promise<Response> {
|
async delete(appId: string): Promise<Response> {
|
||||||
const [response, _] = await this.client.del(`/applications/${appId}`)
|
const [response, _] = await this.del(`/applications/${appId}`)
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
async rename(
|
async rename(
|
||||||
appId: string,
|
appId: string,
|
||||||
oldName: string,
|
oldName: string,
|
||||||
body: any
|
body: RenameAppBody
|
||||||
): Promise<[Response, App]> {
|
): Promise<[Response, App]> {
|
||||||
const [response, json] = await this.client.put(`/applications/${appId}`, {
|
const [response, json] = await this.put(`/applications/${appId}`, body)
|
||||||
body,
|
|
||||||
})
|
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
expect(json.name).not.toEqual(oldName)
|
expect(json.name).not.toEqual(oldName)
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
|
|
||||||
async addScreentoApp(body: any): Promise<[Response, App]> {
|
|
||||||
const [response, json] = await this.client.post(`/screens`, { body })
|
|
||||||
return [response, json]
|
|
||||||
}
|
|
||||||
|
|
||||||
async getRoutes(screenExists?: boolean): Promise<[Response, RouteConfig]> {
|
async getRoutes(screenExists?: boolean): Promise<[Response, RouteConfig]> {
|
||||||
const [response, json] = await this.client.get(`/routing`)
|
const [response, json] = await this.get(`/routing`)
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
if (screenExists) {
|
if (screenExists) {
|
||||||
expect(json.routes["/test"]).toBeTruthy()
|
expect(json.routes["/test"]).toBeTruthy()
|
||||||
} else {
|
} else {
|
||||||
|
@ -141,16 +124,16 @@ export default class AppAPI {
|
||||||
}
|
}
|
||||||
|
|
||||||
async unpublish(appId: string): Promise<[Response]> {
|
async unpublish(appId: string): Promise<[Response]> {
|
||||||
const [response, json] = await this.client.post(
|
const [response, json] = await this.post(
|
||||||
`/applications/${appId}/unpublish`
|
`/applications/${appId}/unpublish`,
|
||||||
|
undefined,
|
||||||
|
204
|
||||||
)
|
)
|
||||||
expect(response).toHaveStatusCode(204)
|
|
||||||
return [response]
|
return [response]
|
||||||
}
|
}
|
||||||
|
|
||||||
async unlock(appId: string): Promise<[Response, MessageResponse]> {
|
async unlock(appId: string): Promise<[Response, MessageResponse]> {
|
||||||
const [response, json] = await this.client.del(`/dev/${appId}/lock`)
|
const [response, json] = await this.del(`/dev/${appId}/lock`)
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
expect(json.message).toEqual("Lock released successfully.")
|
expect(json.message).toEqual("Lock released successfully.")
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
|
@ -162,10 +145,7 @@ export default class AppAPI {
|
||||||
color: "var(--spectrum-global-color-red-400)",
|
color: "var(--spectrum-global-color-red-400)",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
const [response, json] = await this.client.put(`/applications/${appId}`, {
|
const [response, json] = await this.put(`/applications/${appId}`, body)
|
||||||
body,
|
|
||||||
})
|
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
expect(json.icon.name).toEqual(body.icon.name)
|
expect(json.icon.name).toEqual(body.icon.name)
|
||||||
expect(json.icon.color).toEqual(body.icon.color)
|
expect(json.icon.color).toEqual(body.icon.color)
|
||||||
return [response, json]
|
return [response, json]
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
import { Response } from "node-fetch"
|
||||||
|
import BudibaseInternalAPIClient from "../BudibaseInternalAPIClient"
|
||||||
|
|
||||||
|
export default class BaseAPI {
|
||||||
|
client: BudibaseInternalAPIClient
|
||||||
|
|
||||||
|
constructor(client: BudibaseInternalAPIClient) {
|
||||||
|
this.client = client
|
||||||
|
}
|
||||||
|
|
||||||
|
async get(url: string): Promise<[Response, any]> {
|
||||||
|
const [response, json] = await this.client.get(url)
|
||||||
|
expect(response).toHaveStatusCode(200)
|
||||||
|
return [response, json]
|
||||||
|
}
|
||||||
|
|
||||||
|
async post(
|
||||||
|
url: string,
|
||||||
|
body?: any,
|
||||||
|
statusCode?: number
|
||||||
|
): Promise<[Response, any]> {
|
||||||
|
const [response, json] = await this.client.post(url, { body })
|
||||||
|
expect(response).toHaveStatusCode(statusCode ? statusCode : 200)
|
||||||
|
return [response, json]
|
||||||
|
}
|
||||||
|
|
||||||
|
async put(
|
||||||
|
url: string,
|
||||||
|
body?: any,
|
||||||
|
statusCode?: number
|
||||||
|
): Promise<[Response, any]> {
|
||||||
|
const [response, json] = await this.client.put(url, { body })
|
||||||
|
expect(response).toHaveStatusCode(statusCode ? statusCode : 200)
|
||||||
|
return [response, json]
|
||||||
|
}
|
||||||
|
|
||||||
|
async patch(
|
||||||
|
url: string,
|
||||||
|
body?: any,
|
||||||
|
statusCode?: number
|
||||||
|
): Promise<[Response, any]> {
|
||||||
|
const [response, json] = await this.client.patch(url, { body })
|
||||||
|
expect(response).toHaveStatusCode(statusCode ? statusCode : 200)
|
||||||
|
return [response, json]
|
||||||
|
}
|
||||||
|
|
||||||
|
async del(
|
||||||
|
url: string,
|
||||||
|
statusCode?: number,
|
||||||
|
body?: any
|
||||||
|
): Promise<[Response, any]> {
|
||||||
|
const [response, json] = await this.client.del(url, { body })
|
||||||
|
expect(response).toHaveStatusCode(statusCode ? statusCode : 200)
|
||||||
|
return [response, json]
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,91 +5,58 @@ import {
|
||||||
UpdateDatasourceResponse,
|
UpdateDatasourceResponse,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import BudibaseInternalAPIClient from "../BudibaseInternalAPIClient"
|
import BudibaseInternalAPIClient from "../BudibaseInternalAPIClient"
|
||||||
|
import BaseAPI from "./BaseAPI"
|
||||||
|
import { DatasourceRequest } from "../../../types"
|
||||||
|
|
||||||
export default class DatasourcesAPI {
|
export default class DatasourcesAPI extends BaseAPI {
|
||||||
client: BudibaseInternalAPIClient
|
|
||||||
|
|
||||||
constructor(client: BudibaseInternalAPIClient) {
|
constructor(client: BudibaseInternalAPIClient) {
|
||||||
this.client = client
|
super(client)
|
||||||
}
|
}
|
||||||
|
|
||||||
async getIntegrations(): Promise<[Response, any]> {
|
async getIntegrations(): Promise<[Response, any]> {
|
||||||
const [response, json] = await this.client.get(`/integrations`)
|
const [response, json] = await this.get(`/integrations`)
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
const integrationsCount = Object.keys(json).length
|
const integrationsCount = Object.keys(json).length
|
||||||
expect(integrationsCount).toBe(16)
|
expect(integrationsCount).toBe(16)
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAll(): Promise<[Response, Datasource[]]> {
|
async getAll(): Promise<[Response, Datasource[]]> {
|
||||||
const [response, json] = await this.client.get(`/datasources`)
|
const [response, json] = await this.get(`/datasources`)
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
expect(json.length).toBeGreaterThan(0)
|
expect(json.length).toBeGreaterThan(0)
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTable(dataSourceId: string): Promise<[Response, Datasource]> {
|
async getTable(dataSourceId: string): Promise<[Response, Datasource]> {
|
||||||
const [response, json] = await this.client.get(
|
const [response, json] = await this.get(`/datasources/${dataSourceId}`)
|
||||||
`/datasources/${dataSourceId}`
|
|
||||||
)
|
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
expect(json._id).toEqual(dataSourceId)
|
expect(json._id).toEqual(dataSourceId)
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
|
|
||||||
async add(body: any): Promise<[Response, CreateDatasourceResponse]> {
|
async add(
|
||||||
const [response, json] = await this.client.post(`/datasources`, { body })
|
body: DatasourceRequest
|
||||||
expect(response).toHaveStatusCode(200)
|
): Promise<[Response, CreateDatasourceResponse]> {
|
||||||
|
const [response, json] = await this.post(`/datasources`, body)
|
||||||
expect(json.datasource._id).toBeDefined()
|
expect(json.datasource._id).toBeDefined()
|
||||||
expect(json.datasource._rev).toBeDefined()
|
expect(json.datasource._rev).toBeDefined()
|
||||||
|
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(body: any): Promise<[Response, UpdateDatasourceResponse]> {
|
async update(
|
||||||
const [response, json] = await this.client.put(`/datasources/${body._id}`, {
|
body: Datasource
|
||||||
body,
|
): Promise<[Response, UpdateDatasourceResponse]> {
|
||||||
})
|
const [response, json] = await this.put(`/datasources/${body._id}`, body)
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
expect(json.datasource._id).toBeDefined()
|
expect(json.datasource._id).toBeDefined()
|
||||||
expect(json.datasource._rev).toBeDefined()
|
expect(json.datasource._rev).toBeDefined()
|
||||||
|
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
|
|
||||||
async previewQuery(body: any): Promise<[Response, any]> {
|
|
||||||
const [response, json] = await this.client.post(`/queries/preview`, {
|
|
||||||
body,
|
|
||||||
})
|
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
return [response, json]
|
|
||||||
}
|
|
||||||
|
|
||||||
async saveQuery(body: any): Promise<[Response, any]> {
|
|
||||||
const [response, json] = await this.client.post(`/queries`, {
|
|
||||||
body,
|
|
||||||
})
|
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
return [response, json]
|
|
||||||
}
|
|
||||||
|
|
||||||
async getQuery(queryId: string): Promise<[Response, any]> {
|
|
||||||
const [response, json] = await this.client.get(`/queries/${queryId}`)
|
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
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> {
|
async delete(dataSourceId: string, revId: string): Promise<Response> {
|
||||||
const [response, json] = await this.client.del(
|
const [response, json] = await this.del(
|
||||||
`/datasources/${dataSourceId}/${revId}`
|
`/datasources/${dataSourceId}/${revId}`
|
||||||
)
|
)
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,14 @@
|
||||||
import { Response } from "node-fetch"
|
import { Response } from "node-fetch"
|
||||||
import BudibaseInternalAPIClient from "../BudibaseInternalAPIClient"
|
import BudibaseInternalAPIClient from "../BudibaseInternalAPIClient"
|
||||||
|
import BaseAPI from "./BaseAPI"
|
||||||
|
|
||||||
export default class IntegrationsAPI {
|
export default class IntegrationsAPI extends BaseAPI {
|
||||||
client: BudibaseInternalAPIClient
|
|
||||||
|
|
||||||
constructor(client: BudibaseInternalAPIClient) {
|
constructor(client: BudibaseInternalAPIClient) {
|
||||||
this.client = client
|
super(client)
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAll(): Promise<[Response, any]> {
|
async getAll(): Promise<[Response, any]> {
|
||||||
const [response, json] = await this.client.get(`/integrations`)
|
const [response, json] = await this.get(`/integrations`)
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
const integrationsCount = Object.keys(json).length
|
const integrationsCount = Object.keys(json).length
|
||||||
expect(integrationsCount).toBeGreaterThan(0)
|
expect(integrationsCount).toBeGreaterThan(0)
|
||||||
return [response, json]
|
return [response, json]
|
||||||
|
|
|
@ -1,16 +1,14 @@
|
||||||
import { Response } from "node-fetch"
|
import { Response } from "node-fetch"
|
||||||
import BudibaseInternalAPIClient from "../BudibaseInternalAPIClient"
|
import BudibaseInternalAPIClient from "../BudibaseInternalAPIClient"
|
||||||
|
import BaseAPI from "./BaseAPI"
|
||||||
|
|
||||||
export default class PermissionsAPI {
|
export default class PermissionsAPI extends BaseAPI {
|
||||||
client: BudibaseInternalAPIClient
|
|
||||||
|
|
||||||
constructor(client: BudibaseInternalAPIClient) {
|
constructor(client: BudibaseInternalAPIClient) {
|
||||||
this.client = client
|
super(client)
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAll(id: string): Promise<[Response, any]> {
|
async getAll(id: string): Promise<[Response, any]> {
|
||||||
const [response, json] = await this.client.get(`/permissions/${id}`)
|
const [response, json] = await this.get(`/permissions/${id}`)
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,33 +1,25 @@
|
||||||
import { Response } from "node-fetch"
|
import { Response } from "node-fetch"
|
||||||
import BudibaseInternalAPIClient from "../BudibaseInternalAPIClient"
|
import BudibaseInternalAPIClient from "../BudibaseInternalAPIClient"
|
||||||
import { PreviewQueryRequest, Query } from "@budibase/types"
|
import { PreviewQueryRequest, Query } from "@budibase/types"
|
||||||
|
import BaseAPI from "./BaseAPI"
|
||||||
|
|
||||||
export default class DatasourcesAPI {
|
export default class QueriesAPI extends BaseAPI {
|
||||||
client: BudibaseInternalAPIClient
|
|
||||||
|
|
||||||
constructor(client: BudibaseInternalAPIClient) {
|
constructor(client: BudibaseInternalAPIClient) {
|
||||||
this.client = client
|
super(client)
|
||||||
}
|
}
|
||||||
|
|
||||||
async preview(body: PreviewQueryRequest): Promise<[Response, any]> {
|
async preview(body: PreviewQueryRequest): Promise<[Response, any]> {
|
||||||
const [response, json] = await this.client.post(`/queries/preview`, {
|
const [response, json] = await this.post(`/queries/preview`, body)
|
||||||
body,
|
|
||||||
})
|
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
|
|
||||||
async save(body: Query): Promise<[Response, any]> {
|
async save(body: Query): Promise<[Response, any]> {
|
||||||
const [response, json] = await this.client.post(`/queries`, {
|
const [response, json] = await this.post(`/queries`, body)
|
||||||
body,
|
|
||||||
})
|
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
|
|
||||||
async get(queryId: string): Promise<[Response, any]> {
|
async getQuery(queryId: string): Promise<[Response, any]> {
|
||||||
const [response, json] = await this.client.get(`/queries/${queryId}`)
|
const [response, json] = await this.get(`/queries/${queryId}`)
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,23 +1,20 @@
|
||||||
import { Response } from "node-fetch"
|
import { Response } from "node-fetch"
|
||||||
import { Role, UserRoles } from "@budibase/types"
|
import { Role, UserRoles } from "@budibase/types"
|
||||||
import BudibaseInternalAPIClient from "../BudibaseInternalAPIClient"
|
import BudibaseInternalAPIClient from "../BudibaseInternalAPIClient"
|
||||||
|
import BaseAPI from "./BaseAPI"
|
||||||
|
|
||||||
export default class RoleAPI {
|
export default class RoleAPI extends BaseAPI {
|
||||||
client: BudibaseInternalAPIClient
|
|
||||||
|
|
||||||
constructor(client: BudibaseInternalAPIClient) {
|
constructor(client: BudibaseInternalAPIClient) {
|
||||||
this.client = client
|
super(client)
|
||||||
}
|
}
|
||||||
|
|
||||||
async getRoles(): Promise<[Response, Role[]]> {
|
async getRoles(): Promise<[Response, Role[]]> {
|
||||||
const [response, json] = await this.client.get(`/roles`)
|
const [response, json] = await this.get(`/roles`)
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
|
|
||||||
async createRole(body: Partial<UserRoles>): Promise<[Response, UserRoles]> {
|
async createRole(body: Partial<UserRoles>): Promise<[Response, UserRoles]> {
|
||||||
const [response, json] = await this.client.post(`/roles`, { body })
|
const [response, json] = await this.post(`/roles`, body)
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,29 +1,25 @@
|
||||||
import { Response } from "node-fetch"
|
import { Response } from "node-fetch"
|
||||||
import { Row } from "@budibase/types"
|
import { Row } from "@budibase/types"
|
||||||
import BudibaseInternalAPIClient from "../BudibaseInternalAPIClient"
|
import BudibaseInternalAPIClient from "../BudibaseInternalAPIClient"
|
||||||
|
import BaseAPI from "./BaseAPI"
|
||||||
|
|
||||||
export default class RowAPI {
|
export default class RowAPI extends BaseAPI {
|
||||||
rowAdded: boolean
|
rowAdded: boolean
|
||||||
client: BudibaseInternalAPIClient
|
|
||||||
|
|
||||||
constructor(client: BudibaseInternalAPIClient) {
|
constructor(client: BudibaseInternalAPIClient) {
|
||||||
this.client = client
|
super(client)
|
||||||
this.rowAdded = false
|
this.rowAdded = false
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAll(tableId: string): Promise<[Response, Row[]]> {
|
async getAll(tableId: string): Promise<[Response, Row[]]> {
|
||||||
const [response, json] = await this.client.get(`/${tableId}/rows`)
|
const [response, json] = await this.get(`/${tableId}/rows`)
|
||||||
if (this.rowAdded) {
|
if (this.rowAdded) {
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
expect(json.length).toBeGreaterThanOrEqual(1)
|
expect(json.length).toBeGreaterThanOrEqual(1)
|
||||||
}
|
}
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
async add(tableId: string, body: any): Promise<[Response, Row]> {
|
async add(tableId: string, body: Row): Promise<[Response, Row]> {
|
||||||
const [response, json] = await this.client.post(`/${tableId}/rows`, {
|
const [response, json] = await this.post(`/${tableId}/rows`, body)
|
||||||
body,
|
|
||||||
})
|
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
expect(json._id).toBeDefined()
|
expect(json._id).toBeDefined()
|
||||||
expect(json._rev).toBeDefined()
|
expect(json._rev).toBeDefined()
|
||||||
expect(json.tableId).toEqual(tableId)
|
expect(json.tableId).toEqual(tableId)
|
||||||
|
@ -31,34 +27,29 @@ export default class RowAPI {
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
|
|
||||||
async delete(tableId: string, body: any): Promise<[Response, Row[]]> {
|
async delete(tableId: string, body: Row): Promise<[Response, Row[]]> {
|
||||||
const [response, json] = await this.client.del(`/${tableId}/rows/`, {
|
const [response, json] = await this.del(
|
||||||
body,
|
`/${tableId}/rows/`,
|
||||||
})
|
undefined,
|
||||||
expect(response).toHaveStatusCode(200)
|
body
|
||||||
|
)
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
|
|
||||||
async searchNoPagination(
|
async searchNoPagination(
|
||||||
tableId: string,
|
tableId: string,
|
||||||
body: any
|
body: string
|
||||||
): Promise<[Response, Row[]]> {
|
): Promise<[Response, Row[]]> {
|
||||||
const [response, json] = await this.client.post(`/${tableId}/search`, {
|
const [response, json] = await this.post(`/${tableId}/search`, body)
|
||||||
body,
|
|
||||||
})
|
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
expect(json.hasNextPage).toEqual(false)
|
expect(json.hasNextPage).toEqual(false)
|
||||||
return [response, json.rows]
|
return [response, json.rows]
|
||||||
}
|
}
|
||||||
|
|
||||||
async searchWithPagination(
|
async searchWithPagination(
|
||||||
tableId: string,
|
tableId: string,
|
||||||
body: any
|
body: string
|
||||||
): Promise<[Response, Row[]]> {
|
): Promise<[Response, Row[]]> {
|
||||||
const [response, json] = await this.client.post(`/${tableId}/search`, {
|
const [response, json] = await this.post(`/${tableId}/search`, body)
|
||||||
body,
|
|
||||||
})
|
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
expect(json.hasNextPage).toEqual(true)
|
expect(json.hasNextPage).toEqual(true)
|
||||||
expect(json.rows.length).toEqual(10)
|
expect(json.rows.length).toEqual(10)
|
||||||
return [response, json.rows]
|
return [response, json.rows]
|
||||||
|
|
|
@ -1,27 +1,23 @@
|
||||||
import { Screen } from "@budibase/types"
|
|
||||||
import { Response } from "node-fetch"
|
import { Response } from "node-fetch"
|
||||||
|
import { Screen } from "@budibase/types"
|
||||||
|
import { ScreenRequest } from "../../../types/screens"
|
||||||
import BudibaseInternalAPIClient from "../BudibaseInternalAPIClient"
|
import BudibaseInternalAPIClient from "../BudibaseInternalAPIClient"
|
||||||
|
import BaseAPI from "./BaseAPI"
|
||||||
|
|
||||||
export default class ScreenAPI {
|
export default class ScreenAPI extends BaseAPI {
|
||||||
client: BudibaseInternalAPIClient
|
|
||||||
|
|
||||||
constructor(client: BudibaseInternalAPIClient) {
|
constructor(client: BudibaseInternalAPIClient) {
|
||||||
this.client = client
|
super(client)
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(body: any): Promise<[Response, Screen]> {
|
async create(body: ScreenRequest): Promise<[Response, Screen]> {
|
||||||
const [response, json] = await this.client.post(`/screens`, { body })
|
const [response, json] = await this.post(`/screens`, body)
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
expect(json._id).toBeDefined()
|
expect(json._id).toBeDefined()
|
||||||
expect(json.routing.roleId).toBe(body.routing.roleId)
|
expect(json.routing.roleId).toBe(body.routing.roleId)
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
|
|
||||||
async delete(screenId: string, rev: string): Promise<[Response, Screen]> {
|
async delete(screenId: string, rev: string): Promise<[Response, Screen]> {
|
||||||
const [response, json] = await this.client.del(
|
const [response, json] = await this.del(`/screens/${screenId}/${rev}`)
|
||||||
`/screens/${screenId}/${rev}`
|
|
||||||
)
|
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,31 +2,27 @@ import { Response } from "node-fetch"
|
||||||
import { User } from "@budibase/types"
|
import { User } from "@budibase/types"
|
||||||
import BudibaseInternalAPIClient from "../BudibaseInternalAPIClient"
|
import BudibaseInternalAPIClient from "../BudibaseInternalAPIClient"
|
||||||
import { ApiKeyResponse } from "../../../types"
|
import { ApiKeyResponse } from "../../../types"
|
||||||
|
import BaseAPI from "./BaseAPI"
|
||||||
|
|
||||||
export default class SelfAPI {
|
export default class SelfAPI extends BaseAPI {
|
||||||
client: BudibaseInternalAPIClient
|
|
||||||
|
|
||||||
constructor(client: BudibaseInternalAPIClient) {
|
constructor(client: BudibaseInternalAPIClient) {
|
||||||
this.client = client
|
super(client)
|
||||||
}
|
}
|
||||||
|
|
||||||
async getSelf(): Promise<[Response, Partial<User>]> {
|
async getSelf(): Promise<[Response, Partial<User>]> {
|
||||||
const [response, json] = await this.client.get(`/global/self`)
|
const [response, json] = await this.get(`/global/self`)
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
|
|
||||||
async changeSelfPassword(body: Partial<User>): Promise<[Response, User]> {
|
async changeSelfPassword(body: Partial<User>): Promise<[Response, User]> {
|
||||||
const [response, json] = await this.client.post(`/global/self`, { body })
|
const [response, json] = await this.post(`/global/self`, body)
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
expect(json._id).toEqual(body._id)
|
expect(json._id).toEqual(body._id)
|
||||||
expect(json._rev).not.toEqual(body._rev)
|
expect(json._rev).not.toEqual(body._rev)
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
|
|
||||||
async getApiKey(): Promise<ApiKeyResponse> {
|
async getApiKey(): Promise<ApiKeyResponse> {
|
||||||
const [response, json] = await this.client.get(`/global/self/api_key`)
|
const [response, json] = await this.get(`/global/self/api_key`)
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
expect(json).toHaveProperty("apiKey")
|
expect(json).toHaveProperty("apiKey")
|
||||||
return json
|
return json
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,31 +2,27 @@ import { Response } from "node-fetch"
|
||||||
import { Table } from "@budibase/types"
|
import { Table } from "@budibase/types"
|
||||||
import BudibaseInternalAPIClient from "../BudibaseInternalAPIClient"
|
import BudibaseInternalAPIClient from "../BudibaseInternalAPIClient"
|
||||||
import { MessageResponse } from "../../../types"
|
import { MessageResponse } from "../../../types"
|
||||||
|
import BaseAPI from "./BaseAPI"
|
||||||
|
|
||||||
export default class TableAPI {
|
export default class TableAPI extends BaseAPI {
|
||||||
client: BudibaseInternalAPIClient
|
|
||||||
|
|
||||||
constructor(client: BudibaseInternalAPIClient) {
|
constructor(client: BudibaseInternalAPIClient) {
|
||||||
this.client = client
|
super(client)
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAll(expectedNumber: Number): Promise<[Response, Table[]]> {
|
async getAll(expectedNumber: Number): Promise<[Response, Table[]]> {
|
||||||
const [response, json] = await this.client.get(`/tables`)
|
const [response, json] = await this.get(`/tables`)
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
expect(json.length).toBe(expectedNumber)
|
expect(json.length).toBe(expectedNumber)
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTableById(id: string): Promise<[Response, Table]> {
|
async getTableById(id: string): Promise<[Response, Table]> {
|
||||||
const [response, json] = await this.client.get(`/tables/${id}`)
|
const [response, json] = await this.get(`/tables/${id}`)
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
expect(json._id).toEqual(id)
|
expect(json._id).toEqual(id)
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
|
|
||||||
async save(body: any, columnAdded?: boolean): Promise<[Response, Table]> {
|
async save(body: any, columnAdded?: boolean): Promise<[Response, Table]> {
|
||||||
const [response, json] = await this.client.post(`/tables`, { body })
|
const [response, json] = await this.post(`/tables`, body)
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
expect(json._id).toBeDefined()
|
expect(json._id).toBeDefined()
|
||||||
expect(json._rev).toBeDefined()
|
expect(json._rev).toBeDefined()
|
||||||
if (columnAdded) {
|
if (columnAdded) {
|
||||||
|
@ -37,9 +33,7 @@ export default class TableAPI {
|
||||||
}
|
}
|
||||||
|
|
||||||
async forbiddenSave(body: any): Promise<[Response, Table]> {
|
async forbiddenSave(body: any): Promise<[Response, Table]> {
|
||||||
const [response, json] = await this.client.post(`/tables`, { body })
|
const [response, json] = await this.post(`/tables`, body, 403)
|
||||||
expect(response).toHaveStatusCode(403)
|
|
||||||
|
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,8 +41,7 @@ export default class TableAPI {
|
||||||
id: string,
|
id: string,
|
||||||
revId: string
|
revId: string
|
||||||
): Promise<[Response, MessageResponse]> {
|
): Promise<[Response, MessageResponse]> {
|
||||||
const [response, json] = await this.client.del(`/tables/${id}/${revId}`)
|
const [response, json] = await this.del(`/tables/${id}/${revId}`)
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
expect(json.message).toEqual(`Table ${id} deleted.`)
|
expect(json.message).toEqual(`Table ${id} deleted.`)
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,30 +2,29 @@ import { Response } from "node-fetch"
|
||||||
import { Role, User, UserDeletedEvent, UserRoles } from "@budibase/types"
|
import { Role, User, UserDeletedEvent, UserRoles } from "@budibase/types"
|
||||||
import BudibaseInternalAPIClient from "../BudibaseInternalAPIClient"
|
import BudibaseInternalAPIClient from "../BudibaseInternalAPIClient"
|
||||||
import { MessageResponse } from "../../../types"
|
import { MessageResponse } from "../../../types"
|
||||||
|
import BaseAPI from "./BaseAPI"
|
||||||
|
|
||||||
export default class UserAPI {
|
export default class UserAPI extends BaseAPI {
|
||||||
client: BudibaseInternalAPIClient
|
|
||||||
|
|
||||||
constructor(client: BudibaseInternalAPIClient) {
|
constructor(client: BudibaseInternalAPIClient) {
|
||||||
this.client = client
|
super(client)
|
||||||
}
|
}
|
||||||
|
|
||||||
async search(): Promise<[Response, Partial<User>[]]> {
|
async search(): Promise<[Response, Partial<User>[]]> {
|
||||||
const [response, json] = await this.client.post(`/global/users/search`, {})
|
const [response, json] = await this.post(`/global/users/search`, {})
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
expect(json.data.length).toBeGreaterThan(0)
|
expect(json.data.length).toBeGreaterThan(0)
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
|
|
||||||
async getSelf(): Promise<[Response, Partial<User>]> {
|
async getSelf(): Promise<[Response, Partial<User>]> {
|
||||||
const [response, json] = await this.client.get(`/global/self`)
|
const [response, json] = await this.get(`/global/self`)
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAll(): Promise<[Response, Partial<User>[]]> {
|
async getAll(): Promise<[Response, Partial<User>[]]> {
|
||||||
const [response, json] = await this.client.get(`/global/users`)
|
const [response, json] = await this.get(`/global/users`)
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
expect(json.length).toBeGreaterThan(0)
|
expect(json.length).toBeGreaterThan(0)
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
|
@ -38,10 +37,8 @@ export default class UserAPI {
|
||||||
groups: [],
|
groups: [],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
const [response, json] = await this.client.post(`/global/users/bulk`, {
|
const [response, json] = await this.post(`/global/users/bulk`, body)
|
||||||
body,
|
|
||||||
})
|
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
expect(json.created.unsuccessful.length).toEqual(0)
|
expect(json.created.unsuccessful.length).toEqual(0)
|
||||||
expect(json.created.successful.length).toEqual(body.create.users.length)
|
expect(json.created.successful.length).toEqual(body.create.users.length)
|
||||||
return [response, json]
|
return [response, json]
|
||||||
|
@ -53,73 +50,58 @@ export default class UserAPI {
|
||||||
userIds: [userId],
|
userIds: [userId],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
const [response, json] = await this.client.post(`/global/users/bulk`, {
|
const [response, json] = await this.post(`/global/users/bulk`, body)
|
||||||
body,
|
|
||||||
})
|
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
expect(json.deleted.successful.length).toEqual(1)
|
expect(json.deleted.successful.length).toEqual(1)
|
||||||
expect(json.deleted.unsuccessful.length).toEqual(0)
|
expect(json.deleted.unsuccessful.length).toEqual(0)
|
||||||
expect(json.deleted.successful[0].userId).toEqual(userId)
|
expect(json.deleted.successful[0].userId).toEqual(userId)
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
async delete(userId: string): Promise<[Response, UserDeletedEvent]> {
|
async delete(userId: string): Promise<[Response, UserDeletedEvent]> {
|
||||||
const [response, json] = await this.client.del(`/global/users/${userId}`)
|
const [response, json] = await this.del(`/global/users/${userId}`)
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
expect(json.message).toEqual(`User ${userId} deleted.`)
|
expect(json.message).toEqual(`User ${userId} deleted.`)
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
|
|
||||||
async invite(body: any): Promise<[Response, MessageResponse]> {
|
async invite(body: any): Promise<[Response, MessageResponse]> {
|
||||||
const [response, json] = await this.client.post(
|
const [response, json] = await this.post(`/global/users/multi/invite`, body)
|
||||||
`/global/users/multi/invite`,
|
|
||||||
{ body }
|
|
||||||
)
|
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
expect(json.unsuccessful.length).toEqual(0)
|
expect(json.unsuccessful.length).toEqual(0)
|
||||||
expect(json.successful.length).toEqual(body.length)
|
expect(json.successful.length).toEqual(body.length)
|
||||||
|
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
|
|
||||||
async getRoles(): Promise<[Response, Role[]]> {
|
async getRoles(): Promise<[Response, Role[]]> {
|
||||||
const [response, json] = await this.client.get(`/roles`)
|
const [response, json] = await this.get(`/roles`)
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateInfo(body: any): Promise<[Response, User]> {
|
async updateInfo(body: any): Promise<[Response, User]> {
|
||||||
const [response, json] = await this.client.post(`/global/users/`, { body })
|
const [response, json] = await this.post(`/global/users/`, body)
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
expect(json._id).toEqual(body._id)
|
expect(json._id).toEqual(body._id)
|
||||||
expect(json._rev).not.toEqual(body._rev)
|
expect(json._rev).not.toEqual(body._rev)
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
|
|
||||||
async forcePasswordReset(body: any): Promise<[Response, User]> {
|
async forcePasswordReset(body: any): Promise<[Response, User]> {
|
||||||
const [response, json] = await this.client.post(`/global/users/`, { body })
|
const [response, json] = await this.post(`/global/users/`, body)
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
expect(json._id).toEqual(body._id)
|
expect(json._id).toEqual(body._id)
|
||||||
expect(json._rev).not.toEqual(body._rev)
|
expect(json._rev).not.toEqual(body._rev)
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
|
|
||||||
async getInfo(userId: string): Promise<[Response, User]> {
|
async getInfo(userId: string): Promise<[Response, User]> {
|
||||||
const [response, json] = await this.client.get(`/global/users/${userId}`)
|
const [response, json] = await this.get(`/global/users/${userId}`)
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
|
|
||||||
async changeSelfPassword(body: Partial<User>): Promise<[Response, User]> {
|
async changeSelfPassword(body: Partial<User>): Promise<[Response, User]> {
|
||||||
const [response, json] = await this.client.post(`/global/self`, { body })
|
const [response, json] = await this.post(`/global/self`, body)
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
expect(json._id).toEqual(body._id)
|
expect(json._id).toEqual(body._id)
|
||||||
expect(json._rev).not.toEqual(body._rev)
|
expect(json._rev).not.toEqual(body._rev)
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
|
|
||||||
async createRole(body: Partial<UserRoles>): Promise<[Response, UserRoles]> {
|
async createRole(body: Partial<UserRoles>): Promise<[Response, UserRoles]> {
|
||||||
const [response, json] = await this.client.post(`/roles`, { body })
|
const [response, json] = await this.post(`/roles`, body)
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
import { DatasourceRequest } from "../../types"
|
||||||
// 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 = () => {
|
export const mongoDB = (): DatasourceRequest => {
|
||||||
return {
|
return {
|
||||||
datasource: {
|
datasource: {
|
||||||
name: "MongoDB",
|
name: "MongoDB",
|
||||||
|
@ -15,7 +16,7 @@ export const mongoDB = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const postgresSQL = () => {
|
export const postgresSQL = (): DatasourceRequest => {
|
||||||
return {
|
return {
|
||||||
datasource: {
|
datasource: {
|
||||||
name: "PostgresSQL",
|
name: "PostgresSQL",
|
||||||
|
@ -34,7 +35,7 @@ export const postgresSQL = () => {
|
||||||
fetchSchema: true,
|
fetchSchema: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export const mariaDB = () => {
|
export const mariaDB = (): DatasourceRequest => {
|
||||||
return {
|
return {
|
||||||
datasource: {
|
datasource: {
|
||||||
name: "MariaDB",
|
name: "MariaDB",
|
||||||
|
@ -54,7 +55,7 @@ export const mariaDB = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const restAPI = () => {
|
export const restAPI = (): DatasourceRequest => {
|
||||||
return {
|
return {
|
||||||
datasource: {
|
datasource: {
|
||||||
name: "RestAPI",
|
name: "RestAPI",
|
||||||
|
|
|
@ -57,7 +57,7 @@ export const expectedSchemaFields = {
|
||||||
running_time_secs: "number",
|
running_time_secs: "number",
|
||||||
title: "string",
|
title: "string",
|
||||||
year: "number",
|
year: "number",
|
||||||
_id: "json",
|
_id: "string",
|
||||||
},
|
},
|
||||||
postgres: {
|
postgres: {
|
||||||
address: "string",
|
address: "string",
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import { generator } from "../../shared"
|
import { generator } from "../../shared"
|
||||||
|
import { ScreenRequest } from "../../types"
|
||||||
const randomId = generator.guid()
|
const randomId = generator.guid()
|
||||||
|
|
||||||
export const generateScreen = (roleId: string): any => ({
|
export const generateScreen = (roleId: string): ScreenRequest => ({
|
||||||
showNavigation: true,
|
showNavigation: true,
|
||||||
width: "Large",
|
width: "Large",
|
||||||
name: randomId,
|
name: randomId,
|
||||||
|
|
|
@ -52,7 +52,7 @@ describe("Internal API - Data Sources: MariaDB", () => {
|
||||||
datasourcetoSave
|
datasourcetoSave
|
||||||
)
|
)
|
||||||
// Get Query
|
// Get Query
|
||||||
const [getQueryResponse, getQueryJson] = await config.api.queries.get(
|
const [getQueryResponse, getQueryJson] = await config.api.queries.getQuery(
|
||||||
<string>saveQueryJson._id
|
<string>saveQueryJson._id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ describe("Internal API - Data Sources: MongoDB", () => {
|
||||||
datasourcetoSave
|
datasourcetoSave
|
||||||
)
|
)
|
||||||
// Get Query
|
// Get Query
|
||||||
const [getQueryResponse, getQueryJson] = await config.api.queries.get(
|
const [getQueryResponse, getQueryJson] = await config.api.queries.getQuery(
|
||||||
<string>saveQueryJson._id
|
<string>saveQueryJson._id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ describe("Internal API - Data Sources: PostgresSQL", () => {
|
||||||
datasourcetoSave
|
datasourcetoSave
|
||||||
)
|
)
|
||||||
// Get Query
|
// Get Query
|
||||||
const [getQueryResponse, getQueryJson] = await config.api.queries.get(
|
const [getQueryResponse, getQueryJson] = await config.api.queries.getQuery(
|
||||||
saveQueryJson._id!
|
saveQueryJson._id!
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ describe("Internal API - Data Sources: REST API", () => {
|
||||||
datasourcetoSave
|
datasourcetoSave
|
||||||
)
|
)
|
||||||
// Get Query
|
// Get Query
|
||||||
const [getQueryResponse, getQueryJson] = await config.api.queries.get(
|
const [getQueryResponse, getQueryJson] = await config.api.queries.getQuery(
|
||||||
saveQueryJson._id!
|
saveQueryJson._id!
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
export interface DatasourceRequest {
|
||||||
|
datasource: {
|
||||||
|
name: string
|
||||||
|
plus?: boolean
|
||||||
|
source: string
|
||||||
|
type: string
|
||||||
|
config: {
|
||||||
|
connectionString?: string
|
||||||
|
db?: string
|
||||||
|
database?: string
|
||||||
|
host?: string
|
||||||
|
password?: string
|
||||||
|
port?: string
|
||||||
|
schema?: string
|
||||||
|
user?: string
|
||||||
|
defaultHeaders?: {}
|
||||||
|
rejectUnauthorized?: boolean
|
||||||
|
url?: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fetchSchema: boolean
|
||||||
|
}
|
|
@ -8,7 +8,7 @@ export * from "./responseMessage"
|
||||||
export * from "./routing"
|
export * from "./routing"
|
||||||
export * from "./state"
|
export * from "./state"
|
||||||
export * from "./unpublishAppResponse"
|
export * from "./unpublishAppResponse"
|
||||||
export * from "./addedDatasource"
|
export * from "./screens"
|
||||||
|
export * from "./datasources"
|
||||||
// re-export public api types
|
// re-export public api types
|
||||||
export * from "@budibase/server/api/controllers/public/mapping/types"
|
export * from "@budibase/server/api/controllers/public/mapping/types"
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
export interface ScreenRequest {
|
||||||
|
showNavigation: boolean
|
||||||
|
width: string
|
||||||
|
name: string
|
||||||
|
template: string
|
||||||
|
props: ScreenProps
|
||||||
|
routing: ScreenRouting
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ScreenProps {
|
||||||
|
_id: string
|
||||||
|
_component: string
|
||||||
|
_styles: {
|
||||||
|
normal: {}
|
||||||
|
hover: {}
|
||||||
|
active: {}
|
||||||
|
selected: {}
|
||||||
|
}
|
||||||
|
_children: []
|
||||||
|
_instanceName: string
|
||||||
|
direction: string
|
||||||
|
hAlign: string
|
||||||
|
vAlign: string
|
||||||
|
size: string
|
||||||
|
gap: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ScreenRouting {
|
||||||
|
route: string
|
||||||
|
roleId: string
|
||||||
|
homeScreen: boolean
|
||||||
|
}
|
|
@ -3,5 +3,4 @@ if [ -d "packages/pro/packages" ]; then
|
||||||
|
|
||||||
yarn
|
yarn
|
||||||
lerna bootstrap
|
lerna bootstrap
|
||||||
yarn setup
|
|
||||||
fi
|
fi
|
Loading…
Reference in New Issue