From ef2459b7e825d7ed8f5767d41ca37409d6cdfc98 Mon Sep 17 00:00:00 2001 From: Nathan Arthur Date: Wed, 17 Apr 2024 15:41:04 -0400 Subject: [PATCH] fix getLinkedRows --- src/row.spec.ts | 41 +++++++++++++++++++++++++++++++++++++++++ src/row.ts | 5 +++-- 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 src/row.spec.ts diff --git a/src/row.spec.ts b/src/row.spec.ts new file mode 100644 index 0000000..3de16bb --- /dev/null +++ b/src/row.spec.ts @@ -0,0 +1,41 @@ +import { Factory } from "."; +import { Row, RowType } from "./row.js"; +import { describe, it, expect, vi } from "vitest"; + +class MyRow extends Row { + public async doSomething(): Promise[]> { + return this.getLinkedRows(1, 2, MyRow); + } +} + +describe("Row", () => { + it("should do something", async () => { + const getMany = vi.fn(); + + const row = new MyRow({ + tableId: 1, + rowId: 2, + row: { id: 2, order: "1" }, + sdk: {} as any, + repository: { + getMany, + } as any, + }); + + await row.doSomething(); + + expect(getMany).toBeCalledWith( + expect.anything(), + expect.anything(), + expect.objectContaining({ + filters: expect.objectContaining({ + filters: expect.arrayContaining([ + expect.objectContaining({ + field: 2, + }), + ]), + }), + }), + ); + }); +}); diff --git a/src/row.ts b/src/row.ts index acda408..a40f28a 100644 --- a/src/row.ts +++ b/src/row.ts @@ -52,16 +52,17 @@ export abstract class Row< protected getLinkedRows( tableId: number, - field: string | number, + fieldId: number, defaultClass: RowClass, ): Promise { return this.repository.getMany(tableId, defaultClass, { + user_field_names: false, filters: { filter_type: "AND", filters: [ { type: "link_row_has", - field: field.toString(), + field: fieldId, value: this.getId().toString(), }, ],