Check schemas on patch
This commit is contained in:
parent
d440291ebc
commit
c425194a85
|
@ -92,7 +92,19 @@ export async function update(ctx: Ctx<UpdateViewRequest, ViewResponse>) {
|
|||
|
||||
const { tableId } = view
|
||||
|
||||
const result = await sdk.views.update(tableId, view)
|
||||
const schemaUI = await parseSchemaUI(ctx, view)
|
||||
const parsedView: ViewV2 = {
|
||||
id: view.id,
|
||||
name: view.name,
|
||||
version: view.version,
|
||||
tableId: view.tableId,
|
||||
query: view.query,
|
||||
sort: view.sort,
|
||||
columns: view.schema && Object.keys(view.schema),
|
||||
schemaUI,
|
||||
}
|
||||
|
||||
const result = await sdk.views.update(tableId, parsedView)
|
||||
ctx.body = {
|
||||
data: result,
|
||||
}
|
||||
|
|
|
@ -298,6 +298,94 @@ describe("/v2/views", () => {
|
|||
status: 400,
|
||||
})
|
||||
})
|
||||
|
||||
it("updates only UI schema overrides", async () => {
|
||||
await config.api.viewV2.update({
|
||||
...view,
|
||||
schema: {
|
||||
Price: {
|
||||
name: "Price",
|
||||
type: FieldType.NUMBER,
|
||||
visible: true,
|
||||
order: 1,
|
||||
width: 100,
|
||||
},
|
||||
Category: {
|
||||
name: "Category",
|
||||
type: FieldType.STRING,
|
||||
visible: false,
|
||||
icon: "ic",
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
expect(await config.api.viewV2.get(view.id)).toEqual({
|
||||
...view,
|
||||
schema: undefined,
|
||||
columns: ["Price", "Category"],
|
||||
schemaUI: {
|
||||
Price: {
|
||||
visible: true,
|
||||
order: 1,
|
||||
width: 100,
|
||||
},
|
||||
Category: {
|
||||
visible: false,
|
||||
icon: "ic",
|
||||
},
|
||||
},
|
||||
id: view.id,
|
||||
version: 2,
|
||||
})
|
||||
})
|
||||
|
||||
it("throw an exception if the schema overrides a non UI field", async () => {
|
||||
await config.api.viewV2.update(
|
||||
{
|
||||
...view,
|
||||
schema: {
|
||||
Price: {
|
||||
name: "Price",
|
||||
type: FieldType.NUMBER,
|
||||
visible: true,
|
||||
},
|
||||
Category: {
|
||||
name: "Category",
|
||||
type: FieldType.STRING,
|
||||
constraints: {
|
||||
type: "string",
|
||||
presence: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
expectStatus: 400,
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it("will not throw an exception if the schema is 'deleting' non UI fields", async () => {
|
||||
await config.api.viewV2.update(
|
||||
{
|
||||
...view,
|
||||
schema: {
|
||||
Price: {
|
||||
name: "Price",
|
||||
type: FieldType.NUMBER,
|
||||
visible: true,
|
||||
},
|
||||
Category: {
|
||||
name: "Category",
|
||||
type: FieldType.STRING,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
expectStatus: 200,
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("delete", () => {
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
import { CreateViewRequest, SortOrder, SortType, ViewV2 } from "@budibase/types"
|
||||
import {
|
||||
CreateViewRequest,
|
||||
SortOrder,
|
||||
SortType,
|
||||
UpdateViewRequest,
|
||||
ViewV2,
|
||||
} from "@budibase/types"
|
||||
import TestConfiguration from "../TestConfiguration"
|
||||
import { TestAPI } from "./base"
|
||||
import { generator } from "@budibase/backend-core/tests"
|
||||
|
@ -34,7 +40,7 @@ export class ViewV2API extends TestAPI {
|
|||
}
|
||||
|
||||
update = async (
|
||||
view: ViewV2,
|
||||
view: UpdateViewRequest,
|
||||
{
|
||||
expectStatus,
|
||||
handleResponse,
|
||||
|
|
|
@ -9,4 +9,7 @@ export interface CreateViewRequest
|
|||
schema?: Record<string, FieldSchema>
|
||||
}
|
||||
|
||||
export type UpdateViewRequest = ViewV2
|
||||
export interface UpdateViewRequest
|
||||
extends Omit<ViewV2, "columns" | "schemaUI"> {
|
||||
schema?: Record<string, FieldSchema>
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue