Merge branch 'feature/opinionated-sql' of github.com:Budibase/budibase into feature/opinionated-sql
This commit is contained in:
commit
7f33dd3f0d
|
@ -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
|
||||
|
|
|
@ -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",
|
||||
},
|
||||
]
|
||||
`;
|
|
@ -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 () => {
|
||||
|
|
|
@ -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 () => {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue