summaryrefslogtreecommitdiff
path: root/apps/web/src/services/storage/migrations/__tests__/v16-to-v17.test.ts
blob: 10a792caea319c0ff9d16824beac38de8aa04c74 (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import { describe, expect, test } from "bun:test";
import { transformProjectV16ToV17 } from "../transformers/v16-to-v17";
import { asRecord, asRecordArray } from "./helpers";

describe("V16 to V17 Migration", () => {
	test("adds center stroke alignment to masks that do not have it", () => {
		const result = transformProjectV16ToV17({
			project: {
				id: "project-v16",
				version: 16,
				metadata: {
					id: "project-v16",
					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-video",
								type: "video",
								name: "Video Track",
								hidden: false,
								elements: [
									{
										id: "video-1",
										type: "video",
										name: "Clip",
										mediaId: "media-1",
										duration: 5,
										startTime: 0,
										trimStart: 0,
										trimEnd: 0,
										transform: {
											scaleX: 1,
											scaleY: 1,
											position: { x: 0, y: 0 },
											rotate: 0,
										},
										opacity: 1,
										masks: [
											{
												id: "mask-1",
												type: "rectangle",
												params: {
													feather: 0,
													inverted: false,
													strokeColor: "#ffffff",
													strokeWidth: 8,
													centerX: 0,
													centerY: 0,
													width: 0.6,
													height: 0.6,
													rotation: 0,
													scale: 1,
												},
											},
											{
												id: "mask-2",
												type: "ellipse",
												params: {
													feather: 0,
													inverted: false,
													strokeColor: "#ffffff",
													strokeWidth: 8,
													strokeAlign: "outside",
													centerX: 0,
													centerY: 0,
													width: 0.6,
													height: 0.6,
													rotation: 0,
													scale: 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(17);

		const firstScene = asRecordArray(result.project.scenes)[0];
		const firstTrack = asRecordArray(firstScene.tracks)[0];
		const firstElement = asRecordArray(firstTrack.elements)[0];
		const migratedMasks = asRecordArray(firstElement.masks);

		expect(asRecord(migratedMasks[0].params).strokeAlign).toBe("center");
		expect(asRecord(migratedMasks[1].params).strokeAlign).toBe("outside");
	});

	test("skips projects already on v17", () => {
		const result = transformProjectV16ToV17({
			project: {
				id: "project-v17",
				version: 17,
			},
		});

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

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

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