1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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([]);
});
});
|