Fix tests

This commit is contained in:
Adria Navarro 2024-05-27 14:31:45 +02:00
parent 1eb929736c
commit 422b1e2753
2 changed files with 100 additions and 85 deletions

View File

@ -106,6 +106,10 @@ export const useViewPermissions = () => {
return useFeature(Feature.VIEW_PERMISSIONS) return useFeature(Feature.VIEW_PERMISSIONS)
} }
export const useViewReadonlyColumns = () => {
return useFeature(Feature.VIEW_READONLY_COLUMNS)
}
// QUOTAS // QUOTAS
export const setAutomationLogsQuota = (value: number) => { export const setAutomationLogsQuota = (value: number) => {

View File

@ -104,6 +104,10 @@ describe.each([
setup.afterAll() setup.afterAll()
}) })
beforeEach(() => {
mocks.licenses.useCloudFree()
})
const getRowUsage = async () => { const getRowUsage = async () => {
const { total } = await config.doInContext(undefined, () => const { total } = await config.doInContext(undefined, () =>
quotas.getCurrentUsageValues(QuotaUsageType.STATIC, StaticQuotaName.ROWS) quotas.getCurrentUsageValues(QuotaUsageType.STATIC, StaticQuotaName.ROWS)
@ -269,26 +273,43 @@ describe.each([
}) })
}) })
it("readonly fields are persisted", async () => { describe("readonly fields", () => {
const table = await config.api.table.save( beforeEach(() => {
saveTableRequest({ mocks.licenses.useViewReadonlyColumns()
})
it("readonly fields are persisted", async () => {
const table = await config.api.table.save(
saveTableRequest({
schema: {
name: {
name: "name",
type: FieldType.STRING,
},
description: {
name: "description",
type: FieldType.STRING,
},
},
})
)
const newView: CreateViewRequest = {
name: generator.name(),
tableId: table._id!,
schema: { schema: {
name: { name: {
name: "name", visible: true,
type: FieldType.STRING, readonly: true,
}, },
description: { description: {
name: "description", visible: true,
type: FieldType.STRING, readonly: true,
}, },
}, },
}) }
)
const newView: CreateViewRequest = { const res = await config.api.viewV2.create(newView)
name: generator.name(), expect(res.schema).toEqual({
tableId: table._id!,
schema: {
name: { name: {
visible: true, visible: true,
readonly: true, readonly: true,
@ -297,93 +318,82 @@ describe.each([
visible: true, visible: true,
readonly: true, readonly: true,
}, },
}, })
}
const res = await config.api.viewV2.create(newView)
expect(res.schema).toEqual({
name: {
visible: true,
readonly: true,
},
description: {
visible: true,
readonly: true,
},
}) })
})
it("required fields cannot be marked as readonly", async () => { it("required fields cannot be marked as readonly", async () => {
const isRequiredSpy = jest.spyOn(schemaUtils, "isRequired") const isRequiredSpy = jest.spyOn(schemaUtils, "isRequired")
isRequiredSpy.mockReturnValueOnce(true) isRequiredSpy.mockReturnValueOnce(true)
const table = await config.api.table.save( const table = await config.api.table.save(
saveTableRequest({ saveTableRequest({
schema: {
name: {
name: "name",
type: FieldType.STRING,
},
description: {
name: "description",
type: FieldType.STRING,
},
},
})
)
const newView: CreateViewRequest = {
name: generator.name(),
tableId: table._id!,
schema: { schema: {
name: { name: {
name: "name", readonly: true,
type: FieldType.STRING,
},
description: {
name: "description",
type: FieldType.STRING,
}, },
}, },
}
await config.api.viewV2.create(newView, {
status: 400,
body: {
message:
'Field "name" cannot be readonly as it is a required field',
status: 400,
},
}) })
)
const newView: CreateViewRequest = {
name: generator.name(),
tableId: table._id!,
schema: {
name: {
readonly: true,
},
},
}
await config.api.viewV2.create(newView, {
status: 400,
body: {
message: 'Field "name" cannot be readonly as it is a required field',
status: 400,
},
}) })
})
it("readonly fields must be visible", async () => { it("readonly fields must be visible", async () => {
const table = await config.api.table.save( const table = await config.api.table.save(
saveTableRequest({ saveTableRequest({
schema: {
name: {
name: "name",
type: FieldType.STRING,
},
description: {
name: "description",
type: FieldType.STRING,
},
},
})
)
const newView: CreateViewRequest = {
name: generator.name(),
tableId: table._id!,
schema: { schema: {
name: { name: {
name: "name", visible: false,
type: FieldType.STRING, readonly: true,
},
description: {
name: "description",
type: FieldType.STRING,
}, },
}, },
}
await config.api.viewV2.create(newView, {
status: 400,
body: {
message: 'Field "name" cannot be readonly and not visible',
status: 400,
},
}) })
)
const newView: CreateViewRequest = {
name: generator.name(),
tableId: table._id!,
schema: {
name: {
visible: false,
readonly: true,
},
},
}
await config.api.viewV2.create(newView, {
status: 400,
body: {
message: 'Field "name" cannot be readonly and not visible',
status: 400,
},
}) })
}) })
}) })
@ -423,6 +433,7 @@ describe.each([
}) })
it("can update all fields", async () => { it("can update all fields", async () => {
mocks.licenses.useViewReadonlyColumns()
const tableId = table._id! const tableId = table._id!
const updatedData: Required<UpdateViewRequest> = { const updatedData: Required<UpdateViewRequest> = {