-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathManager.test.ts
More file actions
202 lines (179 loc) · 7.2 KB
/
Manager.test.ts
File metadata and controls
202 lines (179 loc) · 7.2 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import { expect, test } from 'vitest';
import {
PLUGIN,
PLUGIN_INCOMPATIBLE,
PLUGIN_PACKAGE,
PLUGIN_PACKAGE_EMPTY,
PLUGIN_PACKAGE_INCOMPATIBLE,
PLUGIN_PACKAGE_MULTIPLE,
} from '../data/Plugin';
import { Manager } from '../../src/classes/Manager';
import { RegistryType } from '../../src/types/Registry';
import { Package } from '../../src/classes/Package';
import { License } from '../../src/types/License';
import { SystemType } from '../../src/types/SystemType';
import { Architecture } from '../../src/types/Architecture';
import { packageCompatibleFiles } from '../../src/helpers/package';
test('Manager add multiple package versions', () => {
const manager = new Manager(RegistryType.Plugins);
const pkg = new Package(PLUGIN_PACKAGE.slug);
pkg.addVersion(PLUGIN_PACKAGE.version, PLUGIN);
pkg.addVersion('1.3.2', PLUGIN);
manager.addPackage(pkg);
expect(manager.toJSON()).toEqual({
[PLUGIN_PACKAGE.slug]: PLUGIN_PACKAGE_MULTIPLE,
});
});
test('Manager add same package multiple times', () => {
const manager = new Manager(RegistryType.Plugins);
const pkg = new Package(PLUGIN_PACKAGE.slug);
pkg.addVersion(PLUGIN_PACKAGE.version, PLUGIN);
manager.addPackage(pkg);
const pkg2 = new Package(PLUGIN_PACKAGE.slug);
pkg2.addVersion('1.3.2', { ...PLUGIN, name: 'Package version' });
manager.addPackage(pkg2);
const pkgReturned = manager.getPackage(PLUGIN_PACKAGE.slug);
expect(pkgReturned?.getVersion(PLUGIN_PACKAGE.version)).toEqual(PLUGIN);
expect(pkgReturned?.getVersion('1.3.2')?.name).toEqual('Package version');
});
test('Manager add and remove package', () => {
const manager = new Manager(RegistryType.Plugins);
const pkg = new Package(PLUGIN_PACKAGE.slug);
manager.addPackage(pkg);
manager.removePackage(pkg.slug);
expect(manager.toJSON()).toEqual({});
});
test('Manager add and remove package multiple times', () => {
const manager = new Manager(RegistryType.Plugins);
const pkg = new Package(PLUGIN_PACKAGE.slug);
manager.addPackage(pkg);
manager.removePackage(pkg.slug);
manager.removePackage(pkg.slug);
expect(manager.toJSON()).toEqual({});
});
test('Manager remove multiple package versions', () => {
const manager = new Manager(RegistryType.Plugins);
const pkg = new Package(PLUGIN_PACKAGE.slug);
pkg.addVersion(PLUGIN_PACKAGE.version, PLUGIN);
pkg.removeVersion(PLUGIN_PACKAGE.version);
pkg.removeVersion(PLUGIN_PACKAGE.version);
manager.addPackage(pkg);
expect(manager.toJSON()).toEqual({
[PLUGIN_PACKAGE.slug]: PLUGIN_PACKAGE_EMPTY,
});
});
test('Manager get package', () => {
const manager = new Manager(RegistryType.Plugins);
const pkg = new Package(PLUGIN_PACKAGE.slug);
pkg.addVersion(PLUGIN_PACKAGE.version, PLUGIN);
manager.addPackage(pkg);
expect(manager.getPackage(PLUGIN_PACKAGE.slug)).toEqual(pkg);
});
test('Manager get report', () => {
const manager = new Manager(RegistryType.Plugins);
const pkg = new Package(PLUGIN_PACKAGE.slug);
pkg.addVersion(PLUGIN_PACKAGE.version, PLUGIN);
manager.addPackage(pkg);
expect(manager.getReport()).toEqual({
'surge-synthesizer/surge': {
'1.3.1': {
recs: [
{
field: 'url',
rec: 'requires mounting step, consider .pkg instead',
},
],
},
},
});
});
test('Manager output report', () => {
const manager = new Manager(RegistryType.Plugins);
const pkg = new Package(PLUGIN_PACKAGE.slug);
pkg.addVersion(PLUGIN_PACKAGE.version, PLUGIN);
manager.addPackage(pkg);
// TODO add test support for sdout, or update report to return a testable string.
// manager.logEnable();
expect(manager.outputReport()).toEqual(undefined);
});
test('Manager list packages', () => {
const manager = new Manager(RegistryType.Plugins);
const pkg = new Package(PLUGIN_PACKAGE.slug);
pkg.addVersion(PLUGIN_PACKAGE.version, PLUGIN);
manager.addPackage(pkg);
expect(manager.listPackages()).toEqual([pkg]);
expect(manager.listPackages(true)).toEqual([]);
expect(manager.listPackages(false)).toEqual([pkg]);
});
test('Manager list packages incompatible', () => {
const manager = new Manager(RegistryType.Plugins);
const pkgNoWin = new Package(PLUGIN_PACKAGE_INCOMPATIBLE.slug);
pkgNoWin.addVersion(PLUGIN_PACKAGE_INCOMPATIBLE.version, PLUGIN_INCOMPATIBLE);
manager.addPackage(pkgNoWin);
expect(manager.listPackages(undefined, Architecture.X64, SystemType.Win)).toEqual([]);
expect(manager.listPackages(undefined, Architecture.X64, SystemType.Linux)).toEqual([pkgNoWin]);
});
test('Manager filter packages', () => {
const manager = new Manager(RegistryType.Plugins);
const pkg = new Package(PLUGIN_PACKAGE.slug);
pkg.addVersion(PLUGIN_PACKAGE.version, PLUGIN);
manager.addPackage(pkg);
expect(manager.filter(pkgVersion => pkgVersion.name === 'Surge XT')).toEqual([pkg]);
expect(manager.filter(pkgVersion => pkgVersion.name === 'Surge X')).toEqual([]);
expect(manager.filter(pkgVersion => pkgVersion.license === License.GNUGeneralPublicLicensev3)).toEqual([pkg]);
expect(
manager.filter(pkgVersion => {
return (
pkgVersion.license === License.GNUGeneralPublicLicensev3 || pkgVersion.license === License.AcademicFreeLicensev3
);
}),
).toEqual([pkg]);
expect(manager.filter(pkgVersion => pkgVersion.license === License.AcademicFreeLicensev3)).toEqual([]);
expect(
manager.filter(pkgVersion => {
return packageCompatibleFiles(pkgVersion, [Architecture.X64], [SystemType.Linux]).length > 0;
}),
).toEqual([pkg]);
expect(
manager.filter(pkgVersion => {
return packageCompatibleFiles(pkgVersion, [Architecture.Arm32], [SystemType.Linux]).length > 0;
}),
).toEqual([]);
});
test('Manager filter packages without versions', () => {
const manager = new Manager(RegistryType.Plugins);
const pkg = new Package(PLUGIN_PACKAGE.slug);
manager.addPackage(pkg);
expect(manager.filter(pkgVersion => pkgVersion.name === 'Surge XT')).toEqual([]);
expect(manager.filter(pkgVersion => pkgVersion.name === 'Surge X')).toEqual([]);
});
test('Manager search packages', () => {
const manager = new Manager(RegistryType.Plugins);
const pkg = new Package(PLUGIN_PACKAGE.slug);
pkg.addVersion(PLUGIN_PACKAGE.version, PLUGIN);
manager.addPackage(pkg);
expect(manager.search('XT')).toEqual([pkg]);
expect(manager.search('ZXT')).toEqual([]);
});
test('Manager search packages without versions', () => {
const manager = new Manager(RegistryType.Plugins);
const pkg = new Package(PLUGIN_PACKAGE.slug);
manager.addPackage(pkg);
expect(manager.search('XT')).toEqual([]);
expect(manager.search('ZXT')).toEqual([]);
});
test('Manager sync from registries', async () => {
const manager = new Manager(RegistryType.Plugins);
await manager.sync();
const pkg = manager.getPackage(PLUGIN_PACKAGE.slug);
expect(pkg?.getVersion(PLUGIN_PACKAGE.version)).toEqual(PLUGIN);
});
test('Manager sync with existing package', async () => {
const manager = new Manager(RegistryType.Plugins);
const pkg = new Package(PLUGIN_PACKAGE.slug);
pkg.addVersion(PLUGIN_PACKAGE.version, { ...PLUGIN, name: 'Surge modified' });
manager.addPackage(pkg);
await manager.sync();
const pkgReturned = manager.getPackage(PLUGIN_PACKAGE.slug);
expect(pkgReturned?.getVersion(PLUGIN_PACKAGE.version)?.name).toEqual('Surge XT');
});