summaryrefslogtreecommitdiff
path: root/apps/web/src/services/storage/migrations/__tests__/v28-to-v29.test.ts
blob: 38a806e1fd7e36eb71843c7de189a34784d7ce28 (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
134
135
import { describe, expect, test } from "bun:test";
import { transformProjectV28ToV29 } from "../transformers/v28-to-v29";
import { asRecord, asRecordArray } from "./helpers";

describe("V28 to V29 Migration", () => {
	test("copies built-in element fields into params without deleting source fields", () => {
		const result = transformProjectV28ToV29({
			project: {
				id: "project-v28-builtins",
				version: 28,
				scenes: [
					{
						id: "scene-1",
						tracks: {
							main: {
								id: "main",
								type: "video",
								elements: [
									{
										id: "video-1",
										type: "video",
										name: "Video",
										transform: {
											position: { x: 12, y: -4 },
											scaleX: 1.25,
											scaleY: 0.75,
											rotate: 9,
										},
										opacity: 0.5,
										blendMode: "multiply",
										volume: -6,
										muted: true,
									},
								],
							},
							overlay: [
								{
									id: "text-track",
									type: "text",
									elements: [
										{
											id: "text-1",
											type: "text",
											name: "Text",
											content: "Hello",
											fontSize: 20,
											fontFamily: "Inter",
											color: "#eeeeee",
											textAlign: "left",
											fontWeight: "bold",
											fontStyle: "italic",
											textDecoration: "underline",
											letterSpacing: 1.5,
											lineHeight: 1.4,
											background: {
												enabled: true,
												color: "#111111",
												paddingX: 10,
												paddingY: 12,
											},
											transform: {
												position: { x: 1, y: 2 },
												scaleX: 1,
												scaleY: 1,
												rotate: 0,
											},
											opacity: 1,
										},
									],
								},
							],
							audio: [],
						},
					},
				],
			},
		});

		expect(result.skipped).toBe(false);
		expect(result.project.version).toBe(29);

		const scene = asRecordArray(result.project.scenes)[0];
		const tracks = asRecord(scene.tracks);
		const main = asRecord(tracks.main);
		const video = asRecordArray(main.elements)[0];
		expect(video.transform).toEqual({
			position: { x: 12, y: -4 },
			scaleX: 1.25,
			scaleY: 0.75,
			rotate: 9,
		});
		expect(video.opacity).toBe(0.5);
		expect(video.volume).toBe(-6);
		expect(video.muted).toBe(true);
		expect(video.params).toEqual({
			"transform.positionX": 12,
			"transform.positionY": -4,
			"transform.scaleX": 1.25,
			"transform.scaleY": 0.75,
			"transform.rotate": 9,
			opacity: 0.5,
			blendMode: "multiply",
			volume: -6,
			muted: true,
		});

		const overlay = asRecordArray(tracks.overlay)[0];
		const text = asRecordArray(asRecord(overlay).elements)[0];
		expect(text.content).toBe("Hello");
		expect(text.background).toEqual({
			enabled: true,
			color: "#111111",
			paddingX: 10,
			paddingY: 12,
		});
		expect(text.params).toMatchObject({
			content: "Hello",
			fontSize: 20,
			fontFamily: "Inter",
			color: "#eeeeee",
			textAlign: "left",
			fontWeight: "bold",
			fontStyle: "italic",
			textDecoration: "underline",
			letterSpacing: 1.5,
			lineHeight: 1.4,
			"background.enabled": true,
			"background.color": "#111111",
			"background.paddingX": 10,
			"background.paddingY": 12,
			"transform.positionX": 1,
			"transform.positionY": 2,
		});
	});
});