summaryrefslogtreecommitdiff
path: root/apps/web/src/services/storage/migrations/__tests__/v15-to-v16.test.ts
blob: 1af445ace96334456733d74015a21385dc0ae5df (plain) (blame)
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { describe, expect, test } from "bun:test";
import { transformProjectV15ToV16 } from "../transformers/v15-to-v16";
import { asRecordArray } from "./helpers";

describe("V15 to V16 Migration", () => {
	test("renames sticker tracks to graphic tracks", () => {
		const result = transformProjectV15ToV16({
			project: {
				id: "project-v15",
				version: 15,
				metadata: {
					id: "project-v15",
					name: "Project",
					createdAt: "2024-01-01T00:00:00.000Z",
					updatedAt: "2024-01-01T00:00:00.000Z",
				},
				settings: {
					fps: 30,
					canvasSize: { width: 1920, height: 1080 },
					background: { type: "color", color: "#000000" },
				},
				currentSceneId: "scene-main",
				scenes: [
					{
						id: "scene-main",
						name: "Main scene",
						isMain: true,
						tracks: [
							{
								id: "track-graphic",
								type: "sticker",
								name: "Sticker Track",
								hidden: false,
								elements: [
									{
										id: "sticker-1",
										type: "sticker",
										name: "Logo",
										stickerId: "icons:mdi:home",
										duration: 5,
										startTime: 0,
										trimStart: 0,
										trimEnd: 0,
										transform: {
											scaleX: 1,
											scaleY: 1,
											position: { x: 0, y: 0 },
											rotate: 0,
										},
										opacity: 1,
									},
								],
							},
						],
						bookmarks: [],
						createdAt: "2024-01-01T00:00:00.000Z",
						updatedAt: "2024-01-01T00:00:00.000Z",
					},
				],
			},
		});

		expect(result.skipped).toBe(false);
		expect(result.project.version).toBe(16);
		const firstTrack = asRecordArray(
			asRecordArray(result.project.scenes)[0].tracks,
		)[0];
		expect(firstTrack.type).toBe("graphic");
	});

	test("skips projects already on v16", () => {
		const result = transformProjectV15ToV16({
			project: {
				id: "project-v16",
				version: 16,
			},
		});

		expect(result.skipped).toBe(true);
		expect(result.reason).toBe("already v16");
	});

	test("skips projects with no id", () => {
		const result = transformProjectV15ToV16({
			project: {
				version: 15,
				scenes: [],
			},
		});

		expect(result.skipped).toBe(true);
		expect(result.reason).toBe("no project id");
	});
});