Skip to content

Commit 5dbfa26

Browse files
committed
chore: handle unlisted field of catalog
follow up of podman-desktop/podman-desktop-catalog#36 Signed-off-by: Florent Benoit <[email protected]>
1 parent c1359ee commit 5dbfa26

File tree

4 files changed

+93
-0
lines changed

4 files changed

+93
-0
lines changed

packages/main/src/plugin/extensions-catalog/extensions-catalog-api.ts

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export interface CatalogExtension {
3636
extensionName: string;
3737
displayName: string;
3838
categories: string[];
39+
unlisted: boolean;
3940
versions: CatalogExtensionVersion[];
4041
}
4142

packages/main/src/plugin/extensions-catalog/extensions-catalog.spec.ts

+78
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const fooAssetIcon = {
3232
data: 'fooIcon',
3333
};
3434

35+
// unlisted field is not present (assuming it should be listed then)
3536
const fakePublishedExtension1 = {
3637
publisher: {
3738
publisherName: 'foo',
@@ -52,6 +53,52 @@ const fakePublishedExtension1 = {
5253
},
5354
],
5455
};
56+
57+
// this one is unlisted with field unlisted being true
58+
const fakePublishedExtension2 = {
59+
publisher: {
60+
publisherName: 'foo2',
61+
displayName: 'Foo publisher display name',
62+
},
63+
extensionName: 'fooName2',
64+
displayName: 'Foo2 extension display name',
65+
shortDescription: 'Foo2 extension short description',
66+
license: 'Apache-2.0',
67+
unlisted: true,
68+
categories: ['Kubernetes'],
69+
versions: [
70+
{
71+
version: '1.0.0',
72+
preview: false,
73+
lastUpdated: '2021-01-01T00:00:00.000Z',
74+
ociUri: 'oci-registry.foo/foo/bar',
75+
files: [fooAssetIcon],
76+
},
77+
],
78+
};
79+
80+
// this one is unlisted with field unlisted being false
81+
const fakePublishedExtension3 = {
82+
publisher: {
83+
publisherName: 'foo3',
84+
displayName: 'Foo publisher display name',
85+
},
86+
extensionName: 'fooName3',
87+
displayName: 'Foo3 extension display name',
88+
shortDescription: 'Foo3 extension short description',
89+
license: 'Apache-2.0',
90+
unlisted: false,
91+
categories: ['Kubernetes'],
92+
versions: [
93+
{
94+
version: '1.0.0',
95+
preview: false,
96+
lastUpdated: '2021-01-01T00:00:00.000Z',
97+
ociUri: 'oci-registry.foo/foo/bar',
98+
files: [fooAssetIcon],
99+
},
100+
],
101+
};
55102
const isEnabledProxyMock = vi.fn();
56103
const onDidUpdateProxyEmitter = new Emitter<ProxySettings>();
57104
const getAllCertificatesMock = vi.fn();
@@ -176,3 +223,34 @@ test('should get all extensions', async () => {
176223
// no error
177224
expect(console.error).not.toBeCalled();
178225
});
226+
227+
test('should get proper unlisted fields', async () => {
228+
const url = new URL(ExtensionsCatalog.ALL_EXTENSIONS_URL);
229+
const host = url.origin;
230+
const pathname = url.pathname;
231+
nock(host)
232+
.get(pathname)
233+
.reply(200, {
234+
extensions: [fakePublishedExtension1, fakePublishedExtension2, fakePublishedExtension3],
235+
});
236+
237+
const allExtensions = await extensionsCatalog.getExtensions();
238+
expect(allExtensions).toBeDefined();
239+
expect(allExtensions.length).toBe(3);
240+
241+
// check data
242+
const missingUnlistedExtension = allExtensions.find(e => e.id === 'foo.fooName');
243+
expect(missingUnlistedExtension).toBeDefined();
244+
expect(missingUnlistedExtension?.unlisted).toBeFalsy();
245+
246+
const unlistedTrueExtension = allExtensions.find(e => e.id === 'foo2.fooName2');
247+
expect(unlistedTrueExtension).toBeDefined();
248+
expect(unlistedTrueExtension?.unlisted).toBeTruthy();
249+
250+
const unlistedFalseExtension = allExtensions.find(e => e.id === 'foo3.fooName3');
251+
expect(unlistedFalseExtension).toBeDefined();
252+
expect(unlistedFalseExtension?.unlisted).toBeFalsy();
253+
254+
// no error
255+
expect(console.error).not.toBeCalled();
256+
});

packages/main/src/plugin/extensions-catalog/extensions-catalog.ts

+2
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export class ExtensionsCatalog {
100100
publisherName: extension.publisher.publisherName,
101101
publisherDisplayName: extension.publisher.displayName,
102102
categories: extension.categories,
103+
unlisted: extension.unlisted ?? false,
103104
extensionName: extension.extensionName,
104105
shortDescription: extension.shortDescription,
105106
displayName: extension.displayName,
@@ -217,6 +218,7 @@ interface InternalCatalogExtensionJSON {
217218
extensionName: string;
218219
displayName: string;
219220
categories: string[];
221+
unlisted?: boolean;
220222
shortDescription: string;
221223
versions: InternalCatalogExtensionVersionJSON[];
222224
}

packages/renderer/src/stores/catalog-extensions.spec.ts

+12
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ test('catalog extension should be updated in case of a container is removed', as
7272
extensionName: 'extension',
7373
shortDescription: 'short description',
7474
publisherDisplayName: 'Foo publisher display name',
75+
unlisted: false,
7576
categories: [],
7677
versions: [
7778
{
@@ -91,6 +92,7 @@ test('catalog extension should be updated in case of a container is removed', as
9192
shortDescription: 'short description',
9293
publisherDisplayName: 'Foo publisher display name',
9394
categories: [],
95+
unlisted: true,
9496
versions: [
9597
{
9698
version: '2.0.0',
@@ -117,4 +119,14 @@ test('catalog extension should be updated in case of a container is removed', as
117119
// check if the catalog has been updated
118120
const afterCatalogExtensions = get(catalogExtensionInfos);
119121
expect(afterCatalogExtensions.length).toBe(2);
122+
123+
// get first extension
124+
const firstExtension = afterCatalogExtensions.find(ext => ext.id === 'first.extension1');
125+
expect(firstExtension).toBeDefined();
126+
expect(firstExtension?.unlisted).toBeFalsy();
127+
128+
// get second extension
129+
const secondExtension = afterCatalogExtensions.find(ext => ext.id === 'second.extension2');
130+
expect(secondExtension).toBeDefined();
131+
expect(secondExtension?.unlisted).toBeTruthy();
120132
});

0 commit comments

Comments
 (0)