Fix unauthorised tests
This commit is contained in:
parent
3ac1343b08
commit
0ece6a4d2d
|
@ -8,6 +8,7 @@ import {
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import * as setup from "./utilities"
|
import * as setup from "./utilities"
|
||||||
import { generator } from "@budibase/backend-core/tests"
|
import { generator } from "@budibase/backend-core/tests"
|
||||||
|
import { Expectations } from "../../../tests/utilities/api/base"
|
||||||
|
|
||||||
const expectAutomationId = () =>
|
const expectAutomationId = () =>
|
||||||
expect.stringMatching(`^${DocumentType.AUTOMATION}_.+`)
|
expect.stringMatching(`^${DocumentType.AUTOMATION}_.+`)
|
||||||
|
@ -43,11 +44,14 @@ describe("/rowsActions", () => {
|
||||||
.map(name => ({ name }))
|
.map(name => ({ name }))
|
||||||
}
|
}
|
||||||
|
|
||||||
function unauthorisedTests() {
|
function unauthorisedTests(
|
||||||
|
apiDelegate: (
|
||||||
|
expectations: Expectations,
|
||||||
|
testConfig?: { publicUser?: boolean }
|
||||||
|
) => Promise<any>
|
||||||
|
) {
|
||||||
it("returns unauthorised (401) for unauthenticated requests", async () => {
|
it("returns unauthorised (401) for unauthenticated requests", async () => {
|
||||||
await createRowAction(
|
await apiDelegate(
|
||||||
tableId,
|
|
||||||
createRowActionRequest(),
|
|
||||||
{
|
{
|
||||||
status: 401,
|
status: 401,
|
||||||
body: {
|
body: {
|
||||||
|
@ -77,7 +81,14 @@ describe("/rowsActions", () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("create", () => {
|
describe("create", () => {
|
||||||
unauthorisedTests()
|
unauthorisedTests((expectations, testConfig) =>
|
||||||
|
createRowAction(
|
||||||
|
tableId,
|
||||||
|
createRowActionRequest(),
|
||||||
|
expectations,
|
||||||
|
testConfig
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
it("creates new row actions for tables without existing actions", async () => {
|
it("creates new row actions for tables without existing actions", async () => {
|
||||||
const rowAction = createRowActionRequest()
|
const rowAction = createRowActionRequest()
|
||||||
|
@ -247,7 +258,9 @@ describe("/rowsActions", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("find", () => {
|
describe("find", () => {
|
||||||
unauthorisedTests()
|
unauthorisedTests((expectations, testConfig) =>
|
||||||
|
config.api.rowAction.find(tableId, expectations, testConfig)
|
||||||
|
)
|
||||||
|
|
||||||
it("returns only the actions for the requested table", async () => {
|
it("returns only the actions for the requested table", async () => {
|
||||||
const rowActions: RowActionResponse[] = []
|
const rowActions: RowActionResponse[] = []
|
||||||
|
@ -279,7 +292,15 @@ describe("/rowsActions", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("update", () => {
|
describe("update", () => {
|
||||||
unauthorisedTests()
|
unauthorisedTests((expectations, testConfig) =>
|
||||||
|
config.api.rowAction.update(
|
||||||
|
tableId,
|
||||||
|
generator.guid(),
|
||||||
|
createRowActionRequest(),
|
||||||
|
expectations,
|
||||||
|
testConfig
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
it("can update existing actions", async () => {
|
it("can update existing actions", async () => {
|
||||||
for (const rowAction of createRowActionRequests(3)) {
|
for (const rowAction of createRowActionRequests(3)) {
|
||||||
|
@ -398,7 +419,14 @@ describe("/rowsActions", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("delete", () => {
|
describe("delete", () => {
|
||||||
unauthorisedTests()
|
unauthorisedTests((expectations, testConfig) =>
|
||||||
|
config.api.rowAction.delete(
|
||||||
|
tableId,
|
||||||
|
generator.guid(),
|
||||||
|
expectations,
|
||||||
|
testConfig
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
it("can delete existing actions", async () => {
|
it("can delete existing actions", async () => {
|
||||||
const actions: RowActionResponse[] = []
|
const actions: RowActionResponse[] = []
|
||||||
|
@ -464,7 +492,15 @@ describe("/rowsActions", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("setViewPermission", () => {
|
describe("setViewPermission", () => {
|
||||||
// unauthorisedTests()
|
unauthorisedTests((expectations, testConfig) =>
|
||||||
|
config.api.rowAction.setViewPermission(
|
||||||
|
tableId,
|
||||||
|
generator.guid(),
|
||||||
|
generator.guid(),
|
||||||
|
expectations,
|
||||||
|
testConfig
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
it("can set permission views", async () => {
|
it("can set permission views", async () => {
|
||||||
for (const rowAction of createRowActionRequests(3)) {
|
for (const rowAction of createRowActionRequests(3)) {
|
||||||
|
@ -529,7 +565,15 @@ describe("/rowsActions", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("unsetViewPermission", () => {
|
describe("unsetViewPermission", () => {
|
||||||
// unauthorisedTests()
|
unauthorisedTests((expectations, testConfig) =>
|
||||||
|
config.api.rowAction.unsetViewPermission(
|
||||||
|
tableId,
|
||||||
|
generator.guid(),
|
||||||
|
generator.guid(),
|
||||||
|
expectations,
|
||||||
|
testConfig
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
it("can unset permission views", async () => {
|
it("can unset permission views", async () => {
|
||||||
for (const rowAction of createRowActionRequests(3)) {
|
for (const rowAction of createRowActionRequests(3)) {
|
||||||
|
|
Loading…
Reference in New Issue