Skip to content

Commit

Permalink
fix getLinkedRows
Browse files Browse the repository at this point in the history
  • Loading branch information
narthur committed Apr 17, 2024
1 parent d58e3b6 commit ef2459b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
41 changes: 41 additions & 0 deletions src/row.spec.ts
Original file line number Diff line number Diff line change
@@ -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<Row<RowType, Factory>[]> {
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,
}),
]),
}),
}),
);
});
});
5 changes: 3 additions & 2 deletions src/row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,17 @@ export abstract class Row<

protected getLinkedRows<T extends Row, R extends RowType, F extends Factory>(
tableId: number,
field: string | number,
fieldId: number,
defaultClass: RowClass<R, F>,
): Promise<T[]> {
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(),
},
],
Expand Down

0 comments on commit ef2459b

Please sign in to comment.