Remove wrong describe

This commit is contained in:
Adria Navarro 2023-07-24 16:04:54 +02:00
parent 77a004f19a
commit d8b801e647
1 changed files with 233 additions and 235 deletions

View File

@ -4,65 +4,132 @@ import sdk from "../../.."
describe("table sdk", () => { describe("table sdk", () => {
describe("enrichViewSchemas", () => { describe("enrichViewSchemas", () => {
describe("fetch", () => { const basicTable: Table = {
const basicTable: Table = { _id: generator.guid(),
_id: generator.guid(), name: "TestTable",
name: "TestTable", type: "table",
type: "table", schema: {
schema: { name: {
name: { type: FieldType.STRING,
type: FieldType.STRING, name: "name",
name: "name", visible: true,
visible: true, width: 80,
width: 80, order: 2,
order: 2, constraints: {
constraints: { type: "string",
type: "string",
},
}, },
description: { },
type: FieldType.STRING, description: {
name: "description", type: FieldType.STRING,
visible: true, name: "description",
width: 200, visible: true,
constraints: { width: 200,
type: "string", constraints: {
}, type: "string",
}, },
id: { },
type: FieldType.NUMBER, id: {
name: "id", type: FieldType.NUMBER,
visible: true, name: "id",
order: 1, visible: true,
constraints: { order: 1,
type: "number", constraints: {
}, type: "number",
}, },
hiddenField: { },
type: FieldType.STRING, hiddenField: {
name: "hiddenField", type: FieldType.STRING,
visible: false, name: "hiddenField",
constraints: { visible: false,
type: "string", constraints: {
type: "string",
},
},
},
}
it("should fetch the default schema if not overriden", async () => {
const tableId = basicTable._id!
const view: ViewV2 = {
version: 2,
id: generator.guid(),
name: generator.guid(),
tableId,
}
const res = sdk.tables.enrichViewSchemas({
...basicTable,
views: { [view.name]: view },
})
expect(res).toEqual({
...basicTable,
views: {
[view.name]: {
...view,
schema: {
name: {
type: "string",
name: "name",
visible: true,
order: 2,
width: 80,
constraints: {
type: "string",
},
},
description: {
type: "string",
name: "description",
visible: true,
width: 200,
constraints: {
type: "string",
},
},
id: {
type: "number",
name: "id",
visible: true,
order: 1,
constraints: {
type: "number",
},
},
hiddenField: {
type: "string",
name: "hiddenField",
visible: false,
constraints: {
type: "string",
},
},
}, },
}, },
}, },
})
})
it("if view schema only defines visiblility, should only fetch the selected fields", async () => {
const tableId = basicTable._id!
const view: ViewV2 = {
version: 2,
id: generator.guid(),
name: generator.guid(),
tableId,
columns: {
name: { visible: true },
id: { visible: true },
description: { visible: false },
},
} }
it("should fetch the default schema if not overriden", async () => { const res = sdk.tables.enrichViewSchemas({
const tableId = basicTable._id! ...basicTable,
const view: ViewV2 = { views: { [view.name]: view },
version: 2, })
id: generator.guid(),
name: generator.guid(),
tableId,
}
const res = sdk.tables.enrichViewSchemas({
...basicTable,
views: { [view.name]: view },
})
expect(res).toEqual({ expect(res).toEqual(
expect.objectContaining({
...basicTable, ...basicTable,
views: { views: {
[view.name]: { [view.name]: {
@ -78,15 +145,6 @@ describe("table sdk", () => {
type: "string", type: "string",
}, },
}, },
description: {
type: "string",
name: "description",
visible: true,
width: 200,
constraints: {
type: "string",
},
},
id: { id: {
type: "number", type: "number",
name: "id", name: "id",
@ -96,10 +154,41 @@ describe("table sdk", () => {
type: "number", type: "number",
}, },
}, },
hiddenField: { },
},
},
})
)
})
it("schema does not break if the view has corrupted columns", async () => {
const tableId = basicTable._id!
const view: ViewV2 = {
version: 2,
id: generator.guid(),
name: generator.guid(),
tableId,
columns: { unnexisting: { visible: true }, name: { visible: true } },
}
const res = sdk.tables.enrichViewSchemas({
...basicTable,
views: { [view.name]: view },
})
expect(res).toEqual(
expect.objectContaining({
...basicTable,
views: {
[view.name]: {
...view,
schema: {
name: {
type: "string", type: "string",
name: "hiddenField", name: "name",
visible: false, order: 2,
visible: true,
width: 80,
constraints: { constraints: {
type: "string", type: "string",
}, },
@ -108,201 +197,110 @@ describe("table sdk", () => {
}, },
}, },
}) })
)
})
it("if view schema only defines visiblility, should only fetch the selected fields", async () => {
const tableId = basicTable._id!
const view: ViewV2 = {
version: 2,
id: generator.guid(),
name: generator.guid(),
tableId,
columns: {
name: { visible: true },
id: { visible: true },
description: { visible: false },
},
}
const res = sdk.tables.enrichViewSchemas({
...basicTable,
views: { [view.name]: view },
}) })
it("if view schema only defines visiblility, should only fetch the selected fields", async () => { expect(res).toEqual(
const tableId = basicTable._id! expect.objectContaining({
const view: ViewV2 = {
version: 2,
id: generator.guid(),
name: generator.guid(),
tableId,
columns: {
name: { visible: true },
id: { visible: true },
description: { visible: false },
},
}
const res = sdk.tables.enrichViewSchemas({
...basicTable, ...basicTable,
views: { [view.name]: view }, views: {
}) [view.name]: {
...view,
expect(res).toEqual( schema: {
expect.objectContaining({ name: {
...basicTable, type: "string",
views: { name: "name",
[view.name]: { order: 2,
...view, visible: true,
schema: { width: 80,
name: { constraints: {
type: "string", type: "string",
name: "name",
visible: true,
order: 2,
width: 80,
constraints: {
type: "string",
},
}, },
id: { },
id: {
type: "number",
name: "id",
order: 1,
visible: true,
constraints: {
type: "number", type: "number",
name: "id",
visible: true,
order: 1,
constraints: {
type: "number",
},
}, },
}, },
}, },
}, },
})
)
})
it("schema does not break if the view has corrupted columns", async () => {
const tableId = basicTable._id!
const view: ViewV2 = {
version: 2,
id: generator.guid(),
name: generator.guid(),
tableId,
columns: { unnexisting: { visible: true }, name: { visible: true } },
}
const res = sdk.tables.enrichViewSchemas({
...basicTable,
views: { [view.name]: view },
})
expect(res).toEqual(
expect.objectContaining({
...basicTable,
views: {
[view.name]: {
...view,
schema: {
name: {
type: "string",
name: "name",
order: 2,
visible: true,
width: 80,
constraints: {
type: "string",
},
},
},
},
},
})
)
})
it("if view schema only defines visiblility, should only fetch the selected fields", async () => {
const tableId = basicTable._id!
const view: ViewV2 = {
version: 2,
id: generator.guid(),
name: generator.guid(),
tableId,
columns: {
name: { visible: true },
id: { visible: true },
description: { visible: false },
}, },
}
const res = sdk.tables.enrichViewSchemas({
...basicTable,
views: { [view.name]: view },
}) })
)
})
expect(res).toEqual( it("if view defines order, the table schema order should be ignored", async () => {
expect.objectContaining({ const tableId = basicTable._id!
...basicTable, const view: ViewV2 = {
views: { version: 2,
[view.name]: { id: generator.guid(),
...view, name: generator.guid(),
schema: { tableId,
name: { columns: {
name: { visible: true, order: 1 },
id: { visible: true },
description: { visible: false, order: 2 },
},
}
const res = sdk.tables.enrichViewSchemas({
...basicTable,
views: { [view.name]: view },
})
expect(res).toEqual(
expect.objectContaining({
...basicTable,
views: {
[view.name]: {
...view,
schema: {
name: {
type: "string",
name: "name",
order: 1,
visible: true,
width: 80,
constraints: {
type: "string", type: "string",
name: "name",
order: 2,
visible: true,
width: 80,
constraints: {
type: "string",
},
}, },
id: { },
id: {
type: "number",
name: "id",
visible: true,
constraints: {
type: "number", type: "number",
name: "id",
order: 1,
visible: true,
constraints: {
type: "number",
},
}, },
}, },
}, },
}, },
})
)
})
it("if view defines order, the table schema order should be ignored", async () => {
const tableId = basicTable._id!
const view: ViewV2 = {
version: 2,
id: generator.guid(),
name: generator.guid(),
tableId,
columns: {
name: { visible: true, order: 1 },
id: { visible: true },
description: { visible: false, order: 2 },
}, },
}
const res = sdk.tables.enrichViewSchemas({
...basicTable,
views: { [view.name]: view },
}) })
)
expect(res).toEqual(
expect.objectContaining({
...basicTable,
views: {
[view.name]: {
...view,
schema: {
name: {
type: "string",
name: "name",
order: 1,
visible: true,
width: 80,
constraints: {
type: "string",
},
},
id: {
type: "number",
name: "id",
visible: true,
constraints: {
type: "number",
},
},
},
},
},
})
)
})
}) })
}) })
}) })