More tests

This commit is contained in:
Adria Navarro 2023-07-31 13:24:08 +02:00
parent 30c3c6e5ad
commit 70cd44ba2a
1 changed files with 36 additions and 11 deletions

View File

@ -92,25 +92,26 @@ describe("trimViewRowInfo middleware", () => {
beforeEach(() => { beforeEach(() => {
jest.resetAllMocks() jest.resetAllMocks()
})
it("when no columns are defined, same data is returned", async () => {
mockGetView.mockResolvedValue({
version: 2,
id: generator.guid(),
name: generator.guid(),
tableId: generator.guid(),
})
mockGetTable.mockResolvedValue(table) mockGetTable.mockResolvedValue(table)
})
const viewId = utils.generateViewID(table._id!) const getRandomData = () => ({
const data = {
_id: generator.guid(), _id: generator.guid(),
name: generator.name(), name: generator.name(),
age: generator.age(), age: generator.age(),
address: generator.address(), address: generator.address(),
} })
it("when no columns are defined, same data is returned", async () => {
const viewId = utils.generateViewID(table._id!)
mockGetView.mockResolvedValue({
version: 2,
id: viewId,
name: generator.guid(),
tableId: table._id!,
})
const data = getRandomData()
await config.executeMiddleware(viewId, { await config.executeMiddleware(viewId, {
_viewId: viewId, _viewId: viewId,
...data, ...data,
@ -119,4 +120,28 @@ describe("trimViewRowInfo middleware", () => {
expect(config.request?.body).toEqual(data) expect(config.request?.body).toEqual(data)
expect(config.params.tableId).toEqual(table._id) expect(config.params.tableId).toEqual(table._id)
}) })
it("when columns are defined, trimmed data is returned", async () => {
const viewId = utils.generateViewID(table._id!)
mockGetView.mockResolvedValue({
version: 2,
id: viewId,
name: generator.guid(),
tableId: table._id!,
columns: { name: { visible: true }, address: { visible: true } },
})
const data = getRandomData()
await config.executeMiddleware(viewId, {
_viewId: viewId,
...data,
})
expect(config.request?.body).toEqual({
_id: data._id,
name: data.name,
address: data.address,
})
expect(config.params.tableId).toEqual(table._id)
})
}) })