1
0
Fork 0
mirror of synced 2024-10-03 19:43:32 +13:00

Check schemas on patch

This commit is contained in:
Adria Navarro 2023-08-01 11:38:36 +02:00
parent d440291ebc
commit c425194a85
4 changed files with 113 additions and 4 deletions

View file

@ -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,
}

View file

@ -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", () => {

View file

@ -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,

View file

@ -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>
}