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("enrichViewSchemas", () => {
describe("fetch", () => {
const basicTable: Table = {
_id: generator.guid(),
name: "TestTable",
type: "table",
schema: {
name: {
type: FieldType.STRING,
name: "name",
visible: true,
width: 80,
order: 2,
constraints: {
type: "string",
},
const basicTable: Table = {
_id: generator.guid(),
name: "TestTable",
type: "table",
schema: {
name: {
type: FieldType.STRING,
name: "name",
visible: true,
width: 80,
order: 2,
constraints: {
type: "string",
},
description: {
type: FieldType.STRING,
name: "description",
visible: true,
width: 200,
constraints: {
type: "string",
},
},
description: {
type: FieldType.STRING,
name: "description",
visible: true,
width: 200,
constraints: {
type: "string",
},
id: {
type: FieldType.NUMBER,
name: "id",
visible: true,
order: 1,
constraints: {
type: "number",
},
},
id: {
type: FieldType.NUMBER,
name: "id",
visible: true,
order: 1,
constraints: {
type: "number",
},
hiddenField: {
type: FieldType.STRING,
name: "hiddenField",
visible: false,
constraints: {
type: "string",
},
hiddenField: {
type: FieldType.STRING,
name: "hiddenField",
visible: false,
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 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 },
})
const res = sdk.tables.enrichViewSchemas({
...basicTable,
views: { [view.name]: view },
})
expect(res).toEqual({
expect(res).toEqual(
expect.objectContaining({
...basicTable,
views: {
[view.name]: {
@ -78,15 +145,6 @@ describe("table sdk", () => {
type: "string",
},
},
description: {
type: "string",
name: "description",
visible: true,
width: 200,
constraints: {
type: "string",
},
},
id: {
type: "number",
name: "id",
@ -96,10 +154,41 @@ describe("table sdk", () => {
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",
name: "hiddenField",
visible: false,
name: "name",
order: 2,
visible: true,
width: 80,
constraints: {
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 () => {
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({
expect(res).toEqual(
expect.objectContaining({
...basicTable,
views: { [view.name]: view },
})
expect(res).toEqual(
expect.objectContaining({
...basicTable,
views: {
[view.name]: {
...view,
schema: {
name: {
views: {
[view.name]: {
...view,
schema: {
name: {
type: "string",
name: "name",
order: 2,
visible: true,
width: 80,
constraints: {
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",
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(
expect.objectContaining({
...basicTable,
views: {
[view.name]: {
...view,
schema: {
name: {
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",
name: "name",
order: 2,
visible: true,
width: 80,
constraints: {
type: "string",
},
},
id: {
},
id: {
type: "number",
name: "id",
visible: true,
constraints: {
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",
},
},
},
},
},
})
)
})
)
})
})
})