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

refactor: plugin sandbox composition #1507

Merged
merged 54 commits into from
Oct 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
2c5f807
wip
luciorubeens Sep 27, 2019
19efeeb
refactor: move component sandbox methods to specific folder
luciorubeens Sep 27, 2019
a2dc9dc
feat: add PROFILE_ALL permission
luciorubeens Sep 27, 2019
08e3a28
feat: add PROFILE_CURRENT permission
luciorubeens Sep 27, 2019
9e95cb1
feat: add PEER_CURRENT permission
luciorubeens Sep 27, 2019
6abb87c
feat: add STORAGE permission
luciorubeens Sep 27, 2019
06e1022
feat: add AUDIO permission
luciorubeens Sep 27, 2019
1ed3f22
feat: add EVENTS permission
luciorubeens Sep 27, 2019
646cafb
feat: add ALERTS permission
luciorubeens Sep 27, 2019
d351e6c
fix: component validation
luciorubeens Sep 27, 2019
2d844dd
refactor: move THEMES permission to setup
luciorubeens Sep 27, 2019
5cd61d4
test: add component validation specs
luciorubeens Sep 27, 2019
1e6086a
refactor: timers and websocket sandbox specs
luciorubeens Sep 27, 2019
e241dd3
test: add audio sandbox specs
luciorubeens Sep 27, 2019
81cc984
test: add http sandbox specs
luciorubeens Sep 27, 2019
6b0964d
test: add profile-all sandbox specs
luciorubeens Sep 27, 2019
00c5067
test: add alerts and events sandbox specs
luciorubeens Sep 30, 2019
e3c0090
test: add font awesome and messaging sandbox specs
luciorubeens Sep 30, 2019
59efddc
test: fix profile all sandbox
luciorubeens Sep 30, 2019
a2d0b00
test: add profile current and webframe sandbox specs
luciorubeens Sep 30, 2019
f117074
'test: add ui components and storage sandbox specs
luciorubeens Sep 30, 2019
70d6375
test: peer current and route sandbox specs
luciorubeens Sep 30, 2019
d231e24
test: add avatars setup specs
luciorubeens Sep 30, 2019
4800866
test: add wallet tabs setup specs
luciorubeens Sep 30, 2019
068216b
test: register setup specs
luciorubeens Sep 30, 2019
e11a7e1
fix: ui components sandbox
luciorubeens Oct 3, 2019
9e234c3
test: add menu items setup specs
luciorubeens Oct 3, 2019
ff78650
test: add routes setup specs
luciorubeens Oct 3, 2019
44cecf2
test: add themes setup specs
luciorubeens Oct 3, 2019
b027a1e
test: add prepare context specs
luciorubeens Oct 3, 2019
b139e54
test: add define context specs
luciorubeens Oct 4, 2019
092aa52
fix: relative imports
luciorubeens Oct 8, 2019
7b64f3b
refactor: create safe component
luciorubeens Oct 8, 2019
dd5018f
test: add components setup specs
luciorubeens Oct 9, 2019
72a6400
feat: global components
luciorubeens Oct 9, 2019
a05c9de
fix: compile template
luciorubeens Oct 9, 2019
13b9a2b
fix: don't load a disabled plugin
luciorubeens Oct 10, 2019
c1f7912
test: add plugin-manager specs
luciorubeens Oct 10, 2019
9a00011
fix: lint
luciorubeens Oct 16, 2019
36e0827
fix: remove document object from component sandbox
luciorubeens Oct 17, 2019
7723229
fix: props
alexbarnsley Oct 18, 2019
2ce4895
fix: sync changes on props
luciorubeens Oct 21, 2019
8b0c419
refactor: block ref methods
alexbarnsley Oct 21, 2019
043f73f
test: blocked ref methods
alexbarnsley Oct 21, 2019
e1c9815
fix: component name output in log
alexbarnsley Oct 23, 2019
3d3e5ee
style: validate component method
alexbarnsley Oct 23, 2019
0ef42fe
fix: global components
luciorubeens Oct 23, 2019
3328769
fix: computed data
luciorubeens Oct 23, 2019
bd5c40b
test: add methods
luciorubeens Oct 24, 2019
4a6bffb
fix: add root path to sandbox external modules
luciorubeens Oct 24, 2019
b09d5e6
fix: pass arguments to plugin methods
luciorubeens Oct 24, 2019
77722b9
fix: resolve method
luciorubeens Oct 24, 2019
17d4f15
fix: regex check for html events
alexbarnsley Oct 28, 2019
8446d1c
Merge branch 'develop' into refactor/plugin-manager
luciorubeens Oct 30, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default jest.fn().mockImplementation(() => ({
compileTemplate: jest.fn((vm, template) => {
const { compileToFunctions } = require('vue-template-compiler')
return compileToFunctions(template)
})
}))
194 changes: 194 additions & 0 deletions __tests__/unit/services/plugin-manager.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
import * as fs from 'fs'
import * as fsExtra from 'fs-extra'
import { createLocalVue } from '@vue/test-utils'
import { PluginManager } from '@/services/plugin-manager'
import { PluginSandbox } from '@/services/plugin-manager/plugin-sandbox'
import { PluginSetup } from '@/services/plugin-manager/plugin-setup'

jest.mock('@/services/plugin-manager/plugin-sandbox.js')
jest.mock('@/services/plugin-manager/plugin-setup.js')

jest.mock('fs-extra', () => ({
ensureDirSync: jest.fn(),
readdirSync: jest.fn(() => []),
lstatSync: jest.fn(() => ({
isDirectory: jest.fn(() => true)
}))
}))

jest.mock('@/services/plugin-manager/utils/validate-plugin-path.js', () => ({
validatePluginPath: jest.fn()
}))

const mockDispatch = jest.fn()
const mockSandboxInstall = jest.fn()
const mockSandboxSetup = jest.fn()

PluginSandbox.mockImplementation(() => ({
install: mockSandboxInstall
}))

PluginSetup.mockImplementation(() => ({
install: mockSandboxSetup
}))

const localVue = createLocalVue()

const pkg = {
name: 'plugin-test',
description: 'Test',
title: 'Plugin Test',
version: '0.0.1'
}

const app = {
$store: {
dispatch: mockDispatch,
getters: {
'plugin/isEnabled': jest.fn((pluginId) => pluginId === 'plugin-test'),
'profile/byId': jest.fn(() => {})
}
}
}

let pluginManager

beforeEach(() => {
mockDispatch.mockReset()
pluginManager = new PluginManager()
pluginManager.setVue(localVue)
})

describe('Plugin Manager', () => {
it('should load plugins on init', async () => {
await pluginManager.init(app)
expect(app.$store.dispatch).toHaveBeenNthCalledWith(1, 'plugin/init')
expect(app.$store.dispatch).toHaveBeenNthCalledWith(2, 'plugin/loadPluginsForProfiles')
})

describe('Fetch plugins', () => {
it('should read plugins from path', async () => {
jest.spyOn(fsExtra, 'readdirSync').mockReturnValue(['plugin-1'])
jest.spyOn(fs, 'readFileSync').mockReturnValue(JSON.stringify(pkg))

await pluginManager.init(app)

expect(app.$store.dispatch).toHaveBeenCalledWith('plugin/setAvailable',
expect.objectContaining({
config: expect.any(Object),
fullPath: expect.any(String)
})
)
})
})

describe('Enable plugin', () => {
it('should throw not initiated error', async () => {
expect.assertions(1)
try {
await pluginManager.enablePlugin('plugin-1', 'p-1')
} catch (e) {
expect(e.message).toBe('Plugin Manager not initiated')
}
})

it('should throw not found error', async () => {
expect.assertions(1)
await pluginManager.init(app)
try {
await pluginManager.enablePlugin('plugin-not-loaded', 'p-1')
} catch (e) {
expect(e.message).toBe('Plugin not found')
}
})

it('should throw not enabled error', async () => {
expect.assertions(2)
await pluginManager.init(app)
pluginManager.plugins = {
'plugin-not-enabled': {
config: {
id: '1'
}
}
}
try {
await pluginManager.enablePlugin('plugin-not-enabled', 'p-1')
} catch (e) {
expect(e.message).toBe('Plugin is not enabled')
expect(app.$store.getters['plugin/isEnabled']).toHaveBeenCalled()
}
})

it('should enable', async () => {
await pluginManager.init(app)

pluginManager.plugins = {
[pkg.name]: {
config: {
id: pkg.name
},
fullPath: './test'
}
}

await pluginManager.enablePlugin(pkg.name, 'p-1')
expect(mockDispatch).toHaveBeenCalledWith('plugin/setLoaded', expect.any(Object))
expect(mockSandboxInstall).toHaveBeenCalled()
expect(mockSandboxSetup).toHaveBeenCalled()
})
})

describe('Disable plugin', () => {
it('should throw not initiated error', async () => {
expect.assertions(1)
try {
await pluginManager.disablePlugin('plugin-1', 'p-1')
} catch (e) {
expect(e.message).toBe('Plugin Manager not initiated')
}
})

it('should throw not found error', async () => {
expect.assertions(1)
await pluginManager.init(app)
try {
await pluginManager.disablePlugin('plugin-not-loaded', 'p-1')
} catch (e) {
expect(e.message).toBe('Plugin `plugin-not-loaded` not found')
}
})

it('should disable', async () => {
await pluginManager.init(app)
pluginManager.plugins = {
[pkg.name]: {
config: {
id: pkg.name,
permissions: []
}
}
}

await pluginManager.disablePlugin(pkg.name, 'p-1')
expect(mockDispatch).toHaveBeenCalledWith('plugin/deleteLoaded', pkg.name)
})

it('should unload theme', async () => {
await pluginManager.init(app)
pluginManager.plugins = {
[pkg.name]: {
config: {
id: pkg.name,
permissions: ['THEMES']
}
}
}

await pluginManager.disablePlugin(pkg.name, 'p-1')
expect(mockDispatch).toHaveBeenCalledWith('plugin/deleteLoaded', pkg.name)
expect(mockDispatch).toHaveBeenCalledWith('session/setTheme', expect.any(String))
expect(mockDispatch).toHaveBeenCalledWith('profile/update', expect.any(Object))
})
})
})
Loading