Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adrinr committed Dec 19, 2024
1 parent 7cc03b1 commit 16fb865
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
4 changes: 2 additions & 2 deletions packages/server/src/api/controllers/row/utils/sqlUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ export async function buildSqlFieldList(

if (
isView &&
source.schema?.[field.name] &&
!helpers.views.isVisible(source.schema[field.name]) &&
(!source.schema?.[field.name] ||
!helpers.views.isVisible(source.schema[field.name])) &&
!containsFormula
) {
continue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,21 +362,25 @@ describe("buildSqlFieldList", () => {
expect(result).toEqual(["table.amount"])
})

it("includes relationships fields when flagged", async () => {
it("includes relationships columns", async () => {
const otherTable = new TableConfig("linkedTable")
.withField("id", FieldType.NUMBER)
.withField("formula", FieldType.FORMULA)
.withPrimary("id")
.withDisplay("name")
.create()

const table = new TableConfig("table")
.withRelation("link", otherTable._id)
.withField("formula", FieldType.FORMULA)
.create()

const view = new ViewConfig(table)
.withVisible("name")
.withHidden("amount")
.withVisible("link")
.withRelationshipColumns("link", {
name: { visible: false },
amount: { visible: true },
formula: { visible: false },
})
.create()

const result = await buildSqlFieldList(view, allTables, {
Expand All @@ -385,39 +389,31 @@ describe("buildSqlFieldList", () => {
expect(result).toEqual([
"table.name",
"linkedTable.id",
"linkedTable.name",
"linkedTable.amount",
])
})

it("includes relationships columns", async () => {
it("excludes relationships fields when view is not included in the view", async () => {
const otherTable = new TableConfig("linkedTable")
.withField("id", FieldType.NUMBER)
.withField("formula", FieldType.FORMULA)
.withPrimary("id")
.withDisplay("name")
.create()

const table = new TableConfig("table")
.withRelation("link", otherTable._id)
.withField("formula", FieldType.FORMULA)
.create()

const view = new ViewConfig(table)
.withVisible("name")
.withVisible("link")
.withRelationshipColumns("link", {
name: { visible: false },
amount: { visible: true },
formula: { visible: false },
})
.withHidden("amount")
.create()

const result = await buildSqlFieldList(view, allTables, {
relationships: true,
})
expect(result).toEqual([
"table.name",
"linkedTable.id",
"linkedTable.amount",
])
expect(result).toEqual(["table.name"])
})

it("does not include relationships columns for hidden links", async () => {
Expand Down

0 comments on commit 16fb865

Please sign in to comment.