Starting to fix up test cases.
This commit is contained in:
parent
45cc611e1e
commit
f3418044dc
|
@ -136,6 +136,7 @@ module.exports = (
|
|||
// allow configuring for public access
|
||||
if ((opts && opts.publicAllowed) || publicEndpoint) {
|
||||
finalise(ctx, { authenticated: false, version, publicEndpoint })
|
||||
return next()
|
||||
} else {
|
||||
ctx.throw(err.status || 403, err)
|
||||
}
|
||||
|
|
|
@ -78,6 +78,7 @@ exports.ObjectStore = bucket => {
|
|||
const config = {
|
||||
s3ForcePathStyle: true,
|
||||
signatureVersion: "v4",
|
||||
apiVersion: "2006-03-01",
|
||||
params: {
|
||||
Bucket: sanitizeBucket(bucket),
|
||||
},
|
||||
|
@ -102,17 +103,21 @@ exports.makeSureBucketExists = async (client, bucketName) => {
|
|||
.promise()
|
||||
} catch (err) {
|
||||
const promises = STATE.bucketCreationPromises
|
||||
const doesntExist = err.statusCode === 404,
|
||||
noAccess = err.statusCode === 403
|
||||
if (promises[bucketName]) {
|
||||
await promises[bucketName]
|
||||
} else if (err.statusCode === 404) {
|
||||
// bucket doesn't exist create it
|
||||
promises[bucketName] = client
|
||||
.createBucket({
|
||||
Bucket: bucketName,
|
||||
})
|
||||
.promise()
|
||||
await promises[bucketName]
|
||||
delete promises[bucketName]
|
||||
} else if (doesntExist || noAccess) {
|
||||
if (doesntExist) {
|
||||
// bucket doesn't exist create it
|
||||
promises[bucketName] = client
|
||||
.createBucket({
|
||||
Bucket: bucketName,
|
||||
})
|
||||
.promise()
|
||||
await promises[bucketName]
|
||||
delete promises[bucketName]
|
||||
}
|
||||
// public buckets are quite hidden in the system, make sure
|
||||
// no bucket is set accidentally
|
||||
if (PUBLIC_BUCKETS.includes(bucketName)) {
|
||||
|
@ -124,7 +129,7 @@ exports.makeSureBucketExists = async (client, bucketName) => {
|
|||
.promise()
|
||||
}
|
||||
} else {
|
||||
throw err
|
||||
throw new Error("Unable to write to object store bucket.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,12 @@ export async function search(ctx: any) {
|
|||
}
|
||||
|
||||
export async function create(ctx: any) {
|
||||
if (!ctx.request.body || !ctx.request.body.useTemplate) {
|
||||
ctx.request.body = {
|
||||
useTemplate: false,
|
||||
...ctx.request.body,
|
||||
}
|
||||
}
|
||||
await controller.create(ctx)
|
||||
await setResponseApp(ctx)
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ const read = [],
|
|||
*/
|
||||
write.push(
|
||||
new Endpoint("post", "/applications", controller.create).addMiddleware(
|
||||
applicationValidator
|
||||
applicationValidator()
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -65,7 +65,7 @@ write.push(
|
|||
*/
|
||||
write.push(
|
||||
new Endpoint("put", "/applications/:appId", controller.update).addMiddleware(
|
||||
applicationValidator
|
||||
applicationValidator()
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
@ -20,6 +20,9 @@ const publicRouter = new Router({
|
|||
})
|
||||
|
||||
function addMiddleware(endpoints: any, middleware: CtxFn) {
|
||||
if (!endpoints) {
|
||||
return
|
||||
}
|
||||
if (!Array.isArray(endpoints)) {
|
||||
endpoints = [endpoints]
|
||||
}
|
||||
|
@ -29,8 +32,10 @@ function addMiddleware(endpoints: any, middleware: CtxFn) {
|
|||
}
|
||||
|
||||
function addToRouter(endpoints: any) {
|
||||
for (let endpoint of endpoints) {
|
||||
endpoint.apply(publicRouter)
|
||||
if (endpoints) {
|
||||
for (let endpoint of endpoints) {
|
||||
endpoint.apply(publicRouter)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,10 +18,12 @@ beforeAll(async () => {
|
|||
|
||||
afterAll(setup.afterAll)
|
||||
|
||||
async function makeRequest(method, endpoint, body, appId) {
|
||||
async function makeRequest(method, endpoint, body, appId = config.getAppId()) {
|
||||
const extraHeaders = {
|
||||
"x-budibase-api-key": apiKey,
|
||||
"x-budibase-app-id": appId ? appId : config.getAppId(),
|
||||
}
|
||||
if (appId) {
|
||||
extraHeaders["x-budibase-app-id"] = appId
|
||||
}
|
||||
const req = request
|
||||
[method](checkSlashesInUrl(`/api/public/v1/${endpoint}`))
|
||||
|
@ -39,36 +41,115 @@ describe("check the applications endpoints", () => {
|
|||
const res = await makeRequest("post", "/applications/search")
|
||||
expect(res).toSatisfyApiSpec()
|
||||
})
|
||||
})
|
||||
|
||||
describe("check the tables endpoints", () => {
|
||||
it("should allow retrieving applications through search", async () => {
|
||||
const res = await makeRequest("post", "/tables/search")
|
||||
it("should allow creating an application", async () => {
|
||||
const res = await makeRequest("post", "/applications", {
|
||||
name: "new App"
|
||||
}, null)
|
||||
expect(res).toSatisfyApiSpec()
|
||||
})
|
||||
|
||||
it("should allow updating an application", async () => {
|
||||
const app = config.getApp()
|
||||
const appId = config.getAppId()
|
||||
const res = await makeRequest("put", `/applications/${appId}`, {
|
||||
...app,
|
||||
name: "updated app name",
|
||||
}, appId)
|
||||
expect(res).toSatisfyApiSpec()
|
||||
})
|
||||
|
||||
it("should allow retrieving an application", async () => {
|
||||
const res = await makeRequest("get", `/applications/${config.getAppId()}`)
|
||||
expect(res).toSatisfyApiSpec()
|
||||
})
|
||||
|
||||
it("should allow deleting an application", async () => {
|
||||
const res = await makeRequest("delete", `/applications/${config.getAppId()}`)
|
||||
expect(res).toSatisfyApiSpec()
|
||||
})
|
||||
})
|
||||
|
||||
describe("check the tables endpoints", () => {
|
||||
it("should allow retrieving tables through search", async () => {
|
||||
const res = await makeRequest("post", "/tables/search")
|
||||
expect(res).toSatisfyApiSpec()
|
||||
})
|
||||
|
||||
it("should allow creating a table", async () => {
|
||||
|
||||
})
|
||||
|
||||
it("should allow updating a table", async () => {
|
||||
|
||||
})
|
||||
|
||||
it("should allow retrieving a table", async () => {
|
||||
|
||||
})
|
||||
|
||||
it("should allow deleting a table", async () => {
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
describe("check the rows endpoints", () => {
|
||||
it("should allow retrieving applications through search", async () => {
|
||||
it("should allow retrieving rows through search", async () => {
|
||||
const res = await makeRequest("post", `/tables/${table._id}/rows/search`, {
|
||||
query: {
|
||||
},
|
||||
})
|
||||
expect(res).toSatisfyApiSpec()
|
||||
})
|
||||
|
||||
it("should allow creating a row", async () => {
|
||||
|
||||
})
|
||||
|
||||
it("should allow updating a row", async () => {
|
||||
|
||||
})
|
||||
|
||||
it("should allow retrieving a row", async () => {
|
||||
|
||||
})
|
||||
|
||||
it("should allow deleting a row", async () => {
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
describe("check the users endpoints", () => {
|
||||
it("should allow retrieving applications through search", async () => {
|
||||
it("should allow retrieving users through search", async () => {
|
||||
const res = await makeRequest("post", "/users/search")
|
||||
expect(res).toSatisfyApiSpec()
|
||||
})
|
||||
|
||||
it("should allow creating a user", async () => {
|
||||
|
||||
})
|
||||
|
||||
it("should allow updating a user", async () => {
|
||||
|
||||
})
|
||||
|
||||
it("should allow retrieving a user", async () => {
|
||||
|
||||
})
|
||||
|
||||
it("should allow deleting a user", async () => {
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
describe("check the queries endpoints", () => {
|
||||
it("should allow retrieving applications through search", async () => {
|
||||
it("should allow retrieving queries through search", async () => {
|
||||
const res = await makeRequest("post", "/queries/search")
|
||||
expect(res).toSatisfyApiSpec()
|
||||
})
|
||||
|
||||
it("should allow executing a query", async () => {
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
@ -205,4 +205,15 @@ exports.automationValidator = (existing = false) => {
|
|||
}).unknown(true))
|
||||
}
|
||||
|
||||
exports.applicationValidator = () => {}
|
||||
exports.applicationValidator = () => {
|
||||
// prettier-ignore
|
||||
return joiValidator.body(Joi.object({
|
||||
_id: OPTIONAL_STRING,
|
||||
_rev: OPTIONAL_STRING,
|
||||
name: Joi.string().required(),
|
||||
url: OPTIONAL_STRING,
|
||||
template: Joi.object({
|
||||
templateString: OPTIONAL_STRING,
|
||||
}).unknown(true),
|
||||
}).unknown(true))
|
||||
}
|
||||
|
|
|
@ -49,6 +49,10 @@ class TestConfiguration {
|
|||
return this.request
|
||||
}
|
||||
|
||||
getApp() {
|
||||
return this.app
|
||||
}
|
||||
|
||||
getAppId() {
|
||||
return this.appId
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue