Skip to content
Snippets Groups Projects
Commit f1d30708 authored by Xavier Jouslin de Noray's avatar Xavier Jouslin de Noray
Browse files

Id: difference between id and name

Change-Id: Id499dd1bf51a1303d97028f89929cbbdc54424a2
parent c2487908
Branches
No related tags found
No related merge requests found
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
export interface Plugins { export interface Plugins {
id: string;
name: string; name: string;
version: string; version: string;
description: string; description: string;
......
...@@ -57,6 +57,7 @@ export class PluginsManager { ...@@ -57,6 +57,7 @@ export class PluginsManager {
return this.plugins return this.plugins
.map((plugin: Plugins) => { .map((plugin: Plugins) => {
return { return {
id: plugin.id,
name: plugin.name, name: plugin.name,
version: plugin.version, version: plugin.version,
description: plugin.description, description: plugin.description,
...@@ -66,11 +67,12 @@ export class PluginsManager { ...@@ -66,11 +67,12 @@ export class PluginsManager {
author: plugin.author, author: plugin.author,
}; };
}) })
.filter(plugin => this.isPluginAvailable(plugin.name, arch)); .filter(plugin => this.isPluginAvailable(plugin.id, arch));
} }
async getPlugin(id: string): Promise< async getPlugin(id: string): Promise<
| { | {
id: string;
name: string; name: string;
version: string; version: string;
description: string; description: string;
...@@ -84,11 +86,12 @@ export class PluginsManager { ...@@ -84,11 +86,12 @@ export class PluginsManager {
if (this.plugins.length === 0) { if (this.plugins.length === 0) {
await this.setPlugins(); await this.setPlugins();
} }
const plugin = this.plugins.find((plugin: Plugins) => plugin.name === id); const plugin = this.plugins.find((plugin: Plugins) => plugin.id === id);
return plugin === undefined return plugin === undefined
? undefined ? undefined
: { : {
id: plugin.id,
name: plugin.name, name: plugin.name,
version: plugin.version, version: plugin.version,
description: plugin.description, description: plugin.description,
...@@ -103,7 +106,7 @@ export class PluginsManager { ...@@ -103,7 +106,7 @@ export class PluginsManager {
if (this.plugins.length === 0) { if (this.plugins.length === 0) {
await this.setPlugins(); await this.setPlugins();
} }
const plugin = this.plugins.find((plugin: Plugins) => plugin.name === id); const plugin = this.plugins.find((plugin: Plugins) => plugin.id === id);
if ( if (
plugin === undefined || plugin === undefined ||
!this.isPluginAvailable(id, arch) || !this.isPluginAvailable(id, arch) ||
...@@ -117,11 +120,11 @@ export class PluginsManager { ...@@ -117,11 +120,11 @@ export class PluginsManager {
'/../..' + '/../..' +
process.env.DATA_DIRECTORY + process.env.DATA_DIRECTORY +
'/' + '/' +
plugin.name + id +
'/' + '/' +
arch + arch +
'/' + '/' +
plugin.name + id +
'.jpl' '.jpl'
); );
} }
...@@ -141,6 +144,7 @@ export class PluginsManager { ...@@ -141,6 +144,7 @@ export class PluginsManager {
return; return;
} }
return { return {
id: plugin.id,
name: plugin.name, name: plugin.name,
version: plugin.version, version: plugin.version,
description: plugin.description, description: plugin.description,
...@@ -159,13 +163,13 @@ export class PluginsManager { ...@@ -159,13 +163,13 @@ export class PluginsManager {
private isPluginAvailable(id: string, arch: string): boolean { private isPluginAvailable(id: string, arch: string): boolean {
const plugin = this.plugins.find((plugin: Plugins) => { const plugin = this.plugins.find((plugin: Plugins) => {
return plugin.name === id && plugin.arches.includes(arch); return plugin.id === id && plugin.arches.includes(arch);
}); });
return plugin !== undefined; return plugin !== undefined;
} }
removePlugin(id: string): void { removePlugin(id: string): void {
this.plugins = this.plugins.filter((plugin: Plugins) => plugin.name !== id); this.plugins = this.plugins.filter((plugin: Plugins) => plugin.id !== id);
} }
private async readManifest(path: string): Promise<{ private async readManifest(path: string): Promise<{
...@@ -180,7 +184,7 @@ export class PluginsManager { ...@@ -180,7 +184,7 @@ export class PluginsManager {
await this.fileManager.readArchive(path, 'manifest.json') await this.fileManager.readArchive(path, 'manifest.json')
); );
return { return {
id: manifest.name, id: manifest.id === undefined ? manifest.name : manifest.id,
name: manifest.name, name: manifest.name,
version: manifest.version, version: manifest.version,
description: manifest.description, description: manifest.description,
...@@ -198,7 +202,7 @@ export class PluginsManager { ...@@ -198,7 +202,7 @@ export class PluginsManager {
} }
const plugin = this.plugins.find( const plugin = this.plugins.find(
(plugin: Plugins) => (plugin: Plugins) =>
plugin.name === id && plugin.id === id &&
plugin.arches.includes(arch as string) && plugin.arches.includes(arch as string) &&
arch !== undefined arch !== undefined
); );
...@@ -216,11 +220,11 @@ export class PluginsManager { ...@@ -216,11 +220,11 @@ export class PluginsManager {
'/../..' + '/../..' +
process.env.DATA_DIRECTORY + process.env.DATA_DIRECTORY +
'/' + '/' +
id + plugin.id +
'/' + '/' +
arch + arch +
'/' + '/' +
id + plugin.id +
'.jpl', '.jpl',
'data/' + plugin.icon 'data/' + plugin.icon
); );
...@@ -235,7 +239,7 @@ export class PluginsManager { ...@@ -235,7 +239,7 @@ export class PluginsManager {
const version = plugin.version; const version = plugin.version;
if (version !== undefined) { if (version !== undefined) {
versions.push({ versions.push({
id: plugin.name, id: plugin.id,
version, version,
}); });
} }
......
...@@ -47,6 +47,7 @@ describe('Routes', function () { ...@@ -47,6 +47,7 @@ describe('Routes', function () {
it("should fetch all plugins", (done) => { it("should fetch all plugins", (done) => {
const expectedPlugins = [ const expectedPlugins = [
{ {
id: 'test',
name: 'test', name: 'test',
version: '', version: '',
description: '', description: '',
...@@ -88,7 +89,7 @@ describe('Routes', function () { ...@@ -88,7 +89,7 @@ describe('Routes', function () {
}); });
it("should fetch plugin details", (done) => { it("should fetch plugin details", (done) => {
const expectedPlugin = { name: 'test', version: '', description: '', icon: '', background: '', author: '', timestamp: '' }; const expectedPlugin = { id: 'test', name: 'test', version: '', description: '', icon: '', author: '', timestamp: '', background: '' };
pluginsManagerServiceStub.getPlugin.resolves(expectedPlugin); pluginsManagerServiceStub.getPlugin.resolves(expectedPlugin);
request(expressApp) request(expressApp)
...@@ -131,7 +132,7 @@ describe('Routes', function () { ...@@ -131,7 +132,7 @@ describe('Routes', function () {
it("should download a plugin", (done) => { it("should download a plugin", (done) => {
pluginsManagerServiceStub.getPluginPath.resolves('test'); pluginsManagerServiceStub.getPluginPath.resolves('test');
const expectedPlugin = { name: 'test', version: '', description: '', icon: '', author: '', timestamp: '', background: '' }; const expectedPlugin = { id: 'test', name: 'test', version: '', description: '', icon: '', author: '', timestamp: '', background: '' };
pluginsManagerServiceStub.getPlugin.resolves(expectedPlugin); pluginsManagerServiceStub.getPlugin.resolves(expectedPlugin);
fs.writeFileSync('test', 'test'); fs.writeFileSync('test', 'test');
......
...@@ -42,6 +42,7 @@ describe('Plugins manager service tests', function () { ...@@ -42,6 +42,7 @@ describe('Plugins manager service tests', function () {
it('should return a list of plugins', async () => { it('should return a list of plugins', async () => {
const fakePlugin = [ const fakePlugin = [
{ {
id: 'test',
name: 'test', name: 'test',
version: '', version: '',
description: '', description: '',
...@@ -54,6 +55,7 @@ describe('Plugins manager service tests', function () { ...@@ -54,6 +55,7 @@ describe('Plugins manager service tests', function () {
const expectedPlugin = [ const expectedPlugin = [
{ {
id: 'test',
name: 'test', name: 'test',
version: '', version: '',
description: '', description: '',
...@@ -72,6 +74,7 @@ describe('Plugins manager service tests', function () { ...@@ -72,6 +74,7 @@ describe('Plugins manager service tests', function () {
it('should return a plugin', async () => { it('should return a plugin', async () => {
const plugin = const plugin =
{ {
id: 'test',
name: 'test', name: 'test',
version: '1.0.0', version: '1.0.0',
description: 'test', description: 'test',
...@@ -100,6 +103,7 @@ describe('Plugins manager service tests', function () { ...@@ -100,6 +103,7 @@ describe('Plugins manager service tests', function () {
it('should return plugin path', async () => { it('should return plugin path', async () => {
const plugin = { const plugin = {
id: 'test',
name: 'test', name: 'test',
version: '1.0.0', version: '1.0.0',
description: 'test', description: 'test',
...@@ -195,6 +199,7 @@ describe('Plugins manager service tests', function () { ...@@ -195,6 +199,7 @@ describe('Plugins manager service tests', function () {
it('should return true if plugin is available', () => { it('should return true if plugin is available', () => {
const plugin = { const plugin = {
id: 'test',
name: 'test', name: 'test',
version: '1.0.0', version: '1.0.0',
description: 'test', description: 'test',
...@@ -249,6 +254,7 @@ describe('Plugins manager service tests', function () { ...@@ -249,6 +254,7 @@ describe('Plugins manager service tests', function () {
it('should return the icon content for a valid plugin', async () => { it('should return the icon content for a valid plugin', async () => {
const plugin = { const plugin = {
id: 'test',
name: 'test', name: 'test',
version: '1.0.0', version: '1.0.0',
description: 'test', description: 'test',
...@@ -285,6 +291,7 @@ describe('Plugins manager service tests', function () { ...@@ -285,6 +291,7 @@ describe('Plugins manager service tests', function () {
it('should return an array of plugin versions', async () => { it('should return an array of plugin versions', async () => {
const plugins = [ const plugins = [
{ {
id: 'plugin1',
name: 'plugin1', name: 'plugin1',
version: '1.0.0', version: '1.0.0',
description: 'Plugin 1', description: 'Plugin 1',
...@@ -295,6 +302,7 @@ describe('Plugins manager service tests', function () { ...@@ -295,6 +302,7 @@ describe('Plugins manager service tests', function () {
author: 'author1', author: 'author1',
}, },
{ {
id: 'plugin2',
name: 'plugin2', name: 'plugin2',
version: '2.0.0', version: '2.0.0',
description: 'Plugin 2', description: 'Plugin 2',
...@@ -305,6 +313,7 @@ describe('Plugins manager service tests', function () { ...@@ -305,6 +313,7 @@ describe('Plugins manager service tests', function () {
author: 'author2', author: 'author2',
}, },
{ {
id: 'plugin3',
name: 'plugin3', name: 'plugin3',
version: '3.0.0', version: '3.0.0',
description: 'Plugin 3', description: 'Plugin 3',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment