|
| 1 | +import { describe, expect, it } from "bun:test"; |
| 2 | +import { getForgejoUserContribution } from ".."; |
| 3 | + |
| 4 | +describe("getForgejoUserContribution", () => { |
| 5 | + const promise = getForgejoUserContribution("Codeberg"); |
| 6 | + |
| 7 | + it("should resolve", async () => { |
| 8 | + await promise; |
| 9 | + }); |
| 10 | + |
| 11 | + it("should get around 365 cells", async () => { |
| 12 | + const cells = await promise; |
| 13 | + |
| 14 | + expect(cells.length).toBeGreaterThanOrEqual(365); |
| 15 | + expect(cells.length).toBeLessThanOrEqual(365 + 7); |
| 16 | + }); |
| 17 | + |
| 18 | + it("cells should cover a full 7-row grid with no gaps", async () => { |
| 19 | + const cells = await promise; |
| 20 | + |
| 21 | + expect(cells.length).toBeGreaterThan(300); |
| 22 | + |
| 23 | + const maxX = Math.max(...cells.map((c) => c.x)); |
| 24 | + |
| 25 | + // every (x, y) pair from (0,0) to (maxX-1, 6) must be present |
| 26 | + const missing = Array.from({ length: maxX }, (_, x) => |
| 27 | + Array.from({ length: 7 }, (_, y) => ({ x, y })), |
| 28 | + ) |
| 29 | + .flat() |
| 30 | + .filter(({ x, y }) => !cells.some((c) => c.x === x && c.y === y)); |
| 31 | + |
| 32 | + expect(missing).toEqual([]); |
| 33 | + }); |
| 34 | + |
| 35 | + it("cells should have level between 0 and 4", async () => { |
| 36 | + const cells = await promise; |
| 37 | + |
| 38 | + for (const c of cells) { |
| 39 | + expect(c.level).toBeGreaterThanOrEqual(0); |
| 40 | + expect(c.level).toBeLessThanOrEqual(4); |
| 41 | + } |
| 42 | + }); |
| 43 | +}); |
0 commit comments