|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | + |
| 3 | +import { |
| 4 | + createBlocks, |
| 5 | + createLevelState, |
| 6 | + createPlacementColumn |
| 7 | +} from "@/game/factories"; |
| 8 | + |
| 9 | +import { migrateLevelState } from "./migrateLevelState"; |
| 10 | + |
| 11 | +describe(migrateLevelState, () => { |
| 12 | + it("returns the same value if it is already up to date", () => { |
| 13 | + const value = createLevelState([ |
| 14 | + createPlacementColumn(4, createBlocks("red", "green", "blue")) |
| 15 | + ]); |
| 16 | + expect(migrateLevelState(value)).toEqual(value); |
| 17 | + }); |
| 18 | + |
| 19 | + it("returns the an up to date version if version 1 is passed in", () => { |
| 20 | + const value = { |
| 21 | + colors: ["blue", "green", "red"], |
| 22 | + columns: [ |
| 23 | + { |
| 24 | + type: "placement", |
| 25 | + locked: false, |
| 26 | + columnSize: 4, |
| 27 | + blocks: [ |
| 28 | + { color: "red", revealed: true }, |
| 29 | + { color: "green", revealed: true }, |
| 30 | + { color: "blue", revealed: true } |
| 31 | + ] |
| 32 | + } |
| 33 | + ], |
| 34 | + moves: [] |
| 35 | + } as unknown; |
| 36 | + |
| 37 | + const expectedResult = { |
| 38 | + blockTypes: ["blue", "green", "red"], |
| 39 | + columns: [ |
| 40 | + { |
| 41 | + type: "placement", |
| 42 | + locked: false, |
| 43 | + columnSize: 4, |
| 44 | + blocks: [ |
| 45 | + { blockType: "red", revealed: true }, |
| 46 | + { blockType: "green", revealed: true }, |
| 47 | + { blockType: "blue", revealed: true } |
| 48 | + ] |
| 49 | + } |
| 50 | + ], |
| 51 | + moves: [] |
| 52 | + } as unknown; |
| 53 | + expect(migrateLevelState(value)).toEqual(expectedResult); |
| 54 | + }); |
| 55 | +}); |
0 commit comments