diff options
| author | Karan Jayachandra <mail@karanjayachandra.com> | 2026-08-30 22:43:21 +0200 |
|---|---|---|
| committer | Karan Jayachandra <mail@karanjayachandra.com> | 2026-08-30 22:43:21 +0200 |
| commit | fc8d8ab8d0da95ec79056f59e14a150df6fcea89 (patch) | |
| tree | 33f8050b2f2920c0f1b884a205a8aa4c81d7687c /src/lib/logic/csv.test.js | |
| parent | d37ebfda883bcd03b146a85bc3e5a4657d0abd73 (diff) | |
Moved to sveltemain
Diffstat (limited to 'src/lib/logic/csv.test.js')
| -rw-r--r-- | src/lib/logic/csv.test.js | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/lib/logic/csv.test.js b/src/lib/logic/csv.test.js new file mode 100644 index 0000000..0381c06 --- /dev/null +++ b/src/lib/logic/csv.test.js @@ -0,0 +1,27 @@ +import { describe, it, expect } from "vitest"; +import { parseLineToPlayer, parseCsv } from "./csv.js"; + +describe("parseLineToPlayer", () => { + it("parses id, name, and level columns", () => { + const player = parseLineToPlayer("3, Jane, Doe, 7"); + expect(player.id).toBe(3); + expect(player.firstName).toBe("Jane"); + expect(player.lastName).toBe("Doe"); + expect(player.level).toBe(7); + expect(player.games).toBe(0); + }); +}); + +describe("parseCsv", () => { + it("skips the header row and blank lines", () => { + const csv = "id,firstName,lastName,level\n0, Jane, Doe, 7\n\n1, John, Smith, 3\n"; + const players = parseCsv(csv); + expect(players).toHaveLength(2); + expect(players[0].firstName).toBe("Jane"); + expect(players[1].firstName).toBe("John"); + }); + + it("returns an empty array when there's only a header", () => { + expect(parseCsv("id,firstName,lastName,level")).toEqual([]); + }); +}); |
