Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
fix: plugin min version (#1859)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbarnsley authored Mar 24, 2020
1 parent 05a23a1 commit d328443
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
33 changes: 33 additions & 0 deletions __tests__/unit/services/plugin-manager.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { createLocalVue } from '@vue/test-utils'
import { PLUGINS } from '@config'
import { PluginManager } from '@/services/plugin-manager'
import { PluginSandbox } from '@/services/plugin-manager/plugin-sandbox'
import { PluginSetup } from '@/services/plugin-manager/plugin-setup'
import npmAdapter from '@/services/plugin-manager/adapters/npm-adapter'
import nock from 'nock'

jest.mock('@/services/plugin-manager/plugin-sandbox.js')
Expand Down Expand Up @@ -84,6 +86,37 @@ describe('Plugin Manager', () => {
await pluginManager.fetchPlugins(true)
expect(pluginManager.fetchPluginsFromAdapter).toHaveBeenCalled()
})

describe('fetchPluginsFromAdapter', () => {
it('should exclude plugins with minimum version above wallet version', async () => {
const validPlugin = {
name: 'test-plugin-1',
keywords: PLUGINS.keywords,
'desktop-wallet': {
minVersion: '1.0'
}
}
const invalidPlugin = {
name: 'test-plugin-2',
keywords: PLUGINS.keywords,
'desktop-wallet': {
minVersion: '3.0'
}
}

jest.spyOn(pluginManager, 'fetchLogo').mockReturnValue(null)
jest.spyOn(pluginManager, 'fetchImages').mockReturnValue([])
const spyNpm = jest.spyOn(npmAdapter, 'all').mockReturnValue([validPlugin, invalidPlugin])

pluginManager.setAdapter('npm')
await pluginManager.fetchPluginsFromAdapter()

expect(mockDispatch.mock.calls[0][0]).toBe('plugin/setAvailable')
expect(Object.keys(mockDispatch.mock.calls[0][1])).toEqual(['test-plugin-1'])

spyNpm.mockRestore()
})
})
})

describe('Enable plugin', () => {
Expand Down
10 changes: 6 additions & 4 deletions src/renderer/services/plugin-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ export class PluginManager {
plugin.images = []
}

return plugin
}))

configs = configs.filter(plugin => {
const validName = validatePackageName(plugin.id).validForNewPackages
if (!validName) {
console.info(`${plugin.id} is not a valid package name`)
Expand All @@ -259,10 +263,8 @@ export class PluginManager {
console.info(`${plugin.id} requires a higher wallet version`)
}

if (validName && minVersionSatisfied) {
return plugin
}
}))
return validName && minVersionSatisfied
})

const plugins = configs.reduce((plugins, config) => {
plugins[config.id] = { config }
Expand Down

0 comments on commit d328443

Please sign in to comment.