|
| 1 | +import { Repository } from "../../src/repository/repository"; |
| 2 | +import { |
| 3 | + DomainPost, |
| 4 | + DomainUser, |
| 5 | + executor, |
| 6 | + seedTestData, |
| 7 | + setupTestTables, |
| 8 | +} from "../../test-setup"; |
| 9 | + |
| 10 | +describe("Repository Joins", () => { |
| 11 | + let userRepository: Repository<DomainUser>; |
| 12 | + let postRepository: Repository<DomainPost>; |
| 13 | + |
| 14 | + beforeAll(async () => { |
| 15 | + await setupTestTables(); |
| 16 | + await seedTestData(); |
| 17 | + userRepository = new Repository("users", executor); |
| 18 | + postRepository = new Repository("posts", executor); |
| 19 | + }); |
| 20 | + |
| 21 | + afterAll(async () => { |
| 22 | + // await cleanupTestData(); |
| 23 | + }); |
| 24 | + |
| 25 | + it("true", () => { |
| 26 | + expect(true).toBe(true); |
| 27 | + }); |
| 28 | + |
| 29 | + // it("should perform an inner join between users and posts", async () => { |
| 30 | + // const result = await userRepository.findRows({ |
| 31 | + // joins: [ |
| 32 | + // { |
| 33 | + // table: "posts", |
| 34 | + // type: "inner", |
| 35 | + // on: { localField: "id", foreignField: "author_id" }, |
| 36 | + // columns: ["title", "content"], |
| 37 | + // }, |
| 38 | + // ], |
| 39 | + // }); |
| 40 | + // |
| 41 | + // expect(result).toBeDefined(); |
| 42 | + // expect(result.length).toBeGreaterThan(0); |
| 43 | + // result.forEach((user) => { |
| 44 | + // expect(user).toHaveProperty("posts"); |
| 45 | + // expect(user.posts).toBeDefined(); |
| 46 | + // }); |
| 47 | + // }); |
| 48 | + // |
| 49 | + // it("should perform a left join between users and posts", async () => { |
| 50 | + // const result = await userRepository.findRows({ |
| 51 | + // joins: [ |
| 52 | + // { |
| 53 | + // table: "posts", |
| 54 | + // type: "left", |
| 55 | + // on: { localField: "id", foreignField: "author_id" }, |
| 56 | + // columns: ["title", "content"], |
| 57 | + // }, |
| 58 | + // ], |
| 59 | + // }); |
| 60 | + // |
| 61 | + // expect(result).toBeDefined(); |
| 62 | + // expect(result.length).toBeGreaterThan(0); |
| 63 | + // result.forEach((user) => { |
| 64 | + // expect(user).toHaveProperty("posts"); |
| 65 | + // }); |
| 66 | + // }); |
| 67 | + // |
| 68 | + |
| 69 | + it("should perform a right join between users and posts", async () => { |
| 70 | + // |
| 71 | + |
| 72 | + const result = await postRepository.findRows({ |
| 73 | + joins: [ |
| 74 | + { |
| 75 | + table: "users", |
| 76 | + as: "author", |
| 77 | + type: "left", |
| 78 | + on: { localField: "author_id", foreignField: "id" }, |
| 79 | + columns: ["name", "email"], |
| 80 | + }, |
| 81 | + ], |
| 82 | + }); |
| 83 | + |
| 84 | + console.log(result); |
| 85 | + |
| 86 | + // expect(result).toBeDefined(); |
| 87 | + // expect(result.length).toBeGreaterThan(0); |
| 88 | + // result.forEach((post) => { |
| 89 | + // expect(post).toHaveProperty("users"); |
| 90 | + // }); |
| 91 | + }); |
| 92 | +}); |
0 commit comments