1
0
Fork 0
mirror of synced 2024-07-01 04:21:06 +12:00

automation server tests updated

This commit is contained in:
Martin McKeaveney 2021-06-17 16:35:58 +01:00
parent 35942d27b4
commit f8fdae0604
6 changed files with 101 additions and 16 deletions

View file

@ -31,9 +31,10 @@ exports.patch = async ctx => {
}
try {
const { row, table } = await pickApi(tableId).patch(ctx)
ctx.status = 200
ctx.eventEmitter &&
ctx.eventEmitter.emitRow(`row:update`, appId, row, table)
ctx.message = `${table.name} updated successfully`
ctx.message = `${table.name} updated successfully.`
ctx.body = row
} catch (err) {
ctx.throw(400, err)
@ -50,6 +51,7 @@ exports.save = async function (ctx) {
}
try {
const { row, table } = await pickApi(tableId).save(ctx)
ctx.status = 200
ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:save`, appId, row, table)
ctx.message = `${table.name} saved successfully`
ctx.body = row

View file

@ -0,0 +1,92 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`/datasources fetch returns all the datasources from the server 1`] = `
Array [
Object {
"_id": "bb_internal",
"config": Object {},
"entities": Array [
Object {
"_id": "ta_users",
"_rev": "1-039883a06c1f9cb3945731d79838181e",
"name": "Users",
"primaryDisplay": "email",
"schema": Object {
"email": Object {
"constraints": Object {
"email": true,
"length": Object {
"maximum": "",
},
"presence": true,
"type": "string",
},
"fieldName": "email",
"name": "email",
"type": "string",
},
"firstName": Object {
"constraints": Object {
"presence": false,
"type": "string",
},
"fieldName": "firstName",
"name": "firstName",
"type": "string",
},
"lastName": Object {
"constraints": Object {
"presence": false,
"type": "string",
},
"fieldName": "lastName",
"name": "lastName",
"type": "string",
},
"roleId": Object {
"constraints": Object {
"inclusion": Array [
"ADMIN",
"POWER",
"BASIC",
"PUBLIC",
],
"presence": false,
"type": "string",
},
"fieldName": "roleId",
"name": "roleId",
"type": "options",
},
"status": Object {
"constraints": Object {
"inclusion": Array [
"active",
"inactive",
],
"presence": false,
"type": "string",
},
"fieldName": "status",
"name": "status",
"type": "options",
},
},
"type": "table",
"views": Object {},
},
],
"name": "Budibase DB",
"source": "BUDIBASE",
"type": "budibase",
},
Object {
"_id": "datasource_f8f81b1f0893478580b863fe96f1f3da",
"_rev": "1-1df90f81a2294ba7349f690f4a6df092",
"config": Object {},
"name": "Test",
"source": "POSTGRES",
"type": "datasource",
},
]
`;

View file

@ -40,13 +40,7 @@ describe("/datasources", () => {
.expect(200)
const datasources = res.body
expect(datasources).toEqual([
{
"_id": datasources[0]._id,
"_rev": datasources[0]._rev,
...basicDatasource()
}
])
expect(datasources).toMatchSnapshot()
})
it("should apply authorization to endpoint", async () => {
@ -93,10 +87,7 @@ describe("/datasources", () => {
.expect(200)
// this is mock data, can't test it
expect(res.body).toBeDefined()
expect(pg.queryMock).toHaveBeenCalledWith({
bindings: ["John%", 5000],
sql: `select "name", "age" from "users" where "name" like $1 limit $2`
})
expect(pg.queryMock).toHaveBeenCalledWith(`select "name", "age" from "users" where "name" like $1 limit $2`, ["John%", 5000])
})
})
@ -115,7 +106,7 @@ describe("/datasources", () => {
.expect('Content-Type', /json/)
.expect(200)
expect(res.body).toEqual([])
expect(res.body.length).toEqual(1)
})
it("should apply authorization to endpoint", async () => {

View file

@ -108,7 +108,7 @@ describe("/tables", () => {
.expect(200)
const fetchedTable = res.body[0]
expect(fetchedTable.name).toEqual(testTable.name)
expect(fetchedTable.type).toEqual("table")
expect(fetchedTable.type).toEqual("internal")
})
it("should apply authorization to endpoint", async () => {

View file

@ -11,7 +11,7 @@ function Request(appId, params) {
exports.getAllTableRows = async config => {
const req = new Request(config.appId, { tableId: config.table._id })
await rowController.fetchTableRows(req)
await rowController.fetch(req)
return req.body
}

View file

@ -215,7 +215,7 @@ class TestConfiguration {
if (!tableId && this.table) {
tableId = this.table._id
}
return this._req(null, { tableId }, controllers.row.fetchTableRows)
return this._req(null, { tableId }, controllers.row.fetch)
}
async createRole(config = null) {