| 
									
										
										
										
											2016-10-14 21:48:38 +03:00
										 |  |  | 'use strict'; | 
					
						
							| 
									
										
										
										
											2017-02-17 21:55:19 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-14 21:48:38 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:06:15 -07:00
										 |  |  | const	assert = require('assert'); | 
					
						
							|  |  |  | const path = require('path'); | 
					
						
							|  |  |  | const nconf = require('nconf'); | 
					
						
							|  |  |  | const request = require('request'); | 
					
						
							|  |  |  | const fs = require('fs'); | 
					
						
							| 
									
										
										
										
											2016-10-14 21:48:38 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:06:15 -07:00
										 |  |  | const db = require('./mocks/databasemock'); | 
					
						
							|  |  |  | const plugins = require('../src/plugins'); | 
					
						
							| 
									
										
										
										
											2016-10-14 21:48:38 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | describe('Plugins', () => { | 
					
						
							|  |  |  | 	it('should load plugin data', (done) => { | 
					
						
							| 
									
										
										
										
											2021-02-04 00:06:15 -07:00
										 |  |  | 		const pluginId = 'nodebb-plugin-markdown'; | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		plugins.loadPlugin(path.join(nconf.get('base_dir'), `node_modules/${pluginId}`), (err) => { | 
					
						
							| 
									
										
										
										
											2016-10-14 21:48:38 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert(plugins.libraries[pluginId]); | 
					
						
							|  |  |  | 			assert(plugins.loadedHooks['static:app.load']); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	it('should return true if hook has listeners', (done) => { | 
					
						
							| 
									
										
										
										
											2021-01-27 17:36:58 -05:00
										 |  |  | 		assert(plugins.hooks.hasListeners('filter:parse.post')); | 
					
						
							| 
									
										
										
										
											2016-10-14 21:48:38 +03:00
										 |  |  | 		done(); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	it('should register and fire a filter hook', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-14 21:48:38 +03:00
										 |  |  | 		function filterMethod1(data, callback) { | 
					
						
							| 
									
										
										
										
											2017-02-18 01:12:18 -07:00
										 |  |  | 			data.foo += 1; | 
					
						
							| 
									
										
										
										
											2016-10-14 21:48:38 +03:00
										 |  |  | 			callback(null, data); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		function filterMethod2(data, callback) { | 
					
						
							|  |  |  | 			data.foo += 5; | 
					
						
							|  |  |  | 			callback(null, data); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-27 17:36:58 -05:00
										 |  |  | 		plugins.hooks.register('test-plugin', { hook: 'filter:test.hook', method: filterMethod1 }); | 
					
						
							|  |  |  | 		plugins.hooks.register('test-plugin', { hook: 'filter:test.hook', method: filterMethod2 }); | 
					
						
							| 
									
										
										
										
											2016-10-14 21:48:38 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		plugins.hooks.fire('filter:test.hook', { foo: 1 }, (err, data) => { | 
					
						
							| 
									
										
										
										
											2016-10-14 21:48:38 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert.equal(data.foo, 7); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	it('should register and fire a filter hook having 2 methods, one returning a promise and the other calling the callback', (done) => { | 
					
						
							| 
									
										
										
										
											2019-06-10 19:05:27 +03:00
										 |  |  | 		function method1(data, callback) { | 
					
						
							|  |  |  | 			data.foo += 1; | 
					
						
							|  |  |  | 			callback(null, data); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		function method2(data) { | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 			return new Promise((resolve) => { | 
					
						
							| 
									
										
										
										
											2019-06-10 19:05:27 +03:00
										 |  |  | 				data.foo += 5; | 
					
						
							|  |  |  | 				resolve(data); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-27 17:36:58 -05:00
										 |  |  | 		plugins.hooks.register('test-plugin', { hook: 'filter:test.hook2', method: method1 }); | 
					
						
							|  |  |  | 		plugins.hooks.register('test-plugin', { hook: 'filter:test.hook2', method: method2 }); | 
					
						
							| 
									
										
										
										
											2019-06-10 19:05:27 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		plugins.hooks.fire('filter:test.hook2', { foo: 1 }, (err, data) => { | 
					
						
							| 
									
										
										
										
											2019-06-10 19:05:27 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert.equal(data.foo, 7); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	it('should register and fire a filter hook that returns a promise that gets rejected', (done) => { | 
					
						
							| 
									
										
										
										
											2019-06-10 19:05:27 +03:00
										 |  |  | 		function method(data) { | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 			return new Promise((resolve, reject) => { | 
					
						
							| 
									
										
										
										
											2019-06-10 19:05:27 +03:00
										 |  |  | 				data.foo += 5; | 
					
						
							|  |  |  | 				reject(new Error('nope')); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-01-27 17:36:58 -05:00
										 |  |  | 		plugins.hooks.register('test-plugin', { hook: 'filter:test.hook3', method: method }); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		plugins.hooks.fire('filter:test.hook3', { foo: 1 }, (err) => { | 
					
						
							| 
									
										
										
										
											2019-06-10 19:05:27 +03:00
										 |  |  | 			assert(err); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	it('should register and fire an action hook', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-14 21:48:38 +03:00
										 |  |  | 		function actionMethod(data) { | 
					
						
							|  |  |  | 			assert.equal(data.bar, 'test'); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-27 17:36:58 -05:00
										 |  |  | 		plugins.hooks.register('test-plugin', { hook: 'action:test.hook', method: actionMethod }); | 
					
						
							|  |  |  | 		plugins.hooks.fire('action:test.hook', { bar: 'test' }); | 
					
						
							| 
									
										
										
										
											2016-10-14 21:48:38 +03:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	it('should register and fire a static hook', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-14 21:48:38 +03:00
										 |  |  | 		function actionMethod(data, callback) { | 
					
						
							|  |  |  | 			assert.equal(data.bar, 'test'); | 
					
						
							|  |  |  | 			callback(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-27 17:36:58 -05:00
										 |  |  | 		plugins.hooks.register('test-plugin', { hook: 'static:test.hook', method: actionMethod }); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		plugins.hooks.fire('static:test.hook', { bar: 'test' }, (err) => { | 
					
						
							| 
									
										
										
										
											2016-10-14 21:48:38 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2016-10-25 21:34:47 +02:00
										 |  |  | 			done(); | 
					
						
							| 
									
										
										
										
											2016-10-14 21:48:38 +03:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	it('should register and fire a static hook returning a promise', (done) => { | 
					
						
							| 
									
										
										
										
											2019-06-10 19:05:27 +03:00
										 |  |  | 		function method(data) { | 
					
						
							|  |  |  | 			assert.equal(data.bar, 'test'); | 
					
						
							|  |  |  | 			return new Promise((resolve) => { | 
					
						
							|  |  |  | 				resolve(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-01-27 17:36:58 -05:00
										 |  |  | 		plugins.hooks.register('test-plugin', { hook: 'static:test.hook', method: method }); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		plugins.hooks.fire('static:test.hook', { bar: 'test' }, (err) => { | 
					
						
							| 
									
										
										
										
											2019-06-10 19:05:27 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	it('should register and fire a static hook returning a promise that gets rejected with a error', (done) => { | 
					
						
							| 
									
										
										
										
											2019-06-10 19:05:27 +03:00
										 |  |  | 		function method(data) { | 
					
						
							|  |  |  | 			assert.equal(data.bar, 'test'); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 			return new Promise((resolve, reject) => { | 
					
						
							| 
									
										
										
										
											2019-06-10 19:05:27 +03:00
										 |  |  | 				reject(new Error('just because')); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-01-27 17:36:58 -05:00
										 |  |  | 		plugins.hooks.register('test-plugin', { hook: 'static:test.hook', method: method }); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		plugins.hooks.fire('static:test.hook', { bar: 'test' }, (err) => { | 
					
						
							| 
									
										
										
										
											2020-01-17 13:30:57 -05:00
										 |  |  | 			assert.strictEqual(err.message, 'just because'); | 
					
						
							| 
									
										
										
										
											2021-01-27 17:36:58 -05:00
										 |  |  | 			plugins.hooks.unregister('test-plugin', 'static:test.hook', method); | 
					
						
							| 
									
										
										
										
											2019-06-10 19:05:27 +03:00
										 |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	it('should register and timeout a static hook returning a promise but takes too long', (done) => { | 
					
						
							| 
									
										
										
										
											2019-06-10 19:05:27 +03:00
										 |  |  | 		function method(data) { | 
					
						
							|  |  |  | 			assert.equal(data.bar, 'test'); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 			return new Promise((resolve) => { | 
					
						
							| 
									
										
										
										
											2019-06-10 19:05:27 +03:00
										 |  |  | 				setTimeout(resolve, 6000); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-01-27 17:36:58 -05:00
										 |  |  | 		plugins.hooks.register('test-plugin', { hook: 'static:test.hook', method: method }); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		plugins.hooks.fire('static:test.hook', { bar: 'test' }, (err) => { | 
					
						
							| 
									
										
										
										
											2019-06-10 19:05:27 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2021-01-27 17:36:58 -05:00
										 |  |  | 			plugins.hooks.unregister('test-plugin', 'static:test.hook', method); | 
					
						
							| 
									
										
										
										
											2019-06-10 19:05:27 +03:00
										 |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	it('should get plugin data from nbbpm', (done) => { | 
					
						
							|  |  |  | 		plugins.get('nodebb-plugin-markdown', (err, data) => { | 
					
						
							| 
									
										
										
										
											2016-10-27 11:57:07 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:06:15 -07:00
										 |  |  | 			const keys = ['id', 'name', 'url', 'description', 'latest', 'installed', 'active', 'latest']; | 
					
						
							| 
									
										
										
										
											2016-10-27 11:57:07 +03:00
										 |  |  | 			assert.equal(data.name, 'nodebb-plugin-markdown'); | 
					
						
							|  |  |  | 			assert.equal(data.id, 'nodebb-plugin-markdown'); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 			keys.forEach((key) => { | 
					
						
							| 
									
										
										
										
											2016-10-27 11:57:07 +03:00
										 |  |  | 				assert(data.hasOwnProperty(key)); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	it('should get a list of plugins', (done) => { | 
					
						
							|  |  |  | 		plugins.list((err, data) => { | 
					
						
							| 
									
										
										
										
											2016-10-27 11:57:07 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:06:15 -07:00
										 |  |  | 			const keys = ['id', 'name', 'url', 'description', 'latest', 'installed', 'active', 'latest']; | 
					
						
							| 
									
										
										
										
											2016-10-27 11:57:07 +03:00
										 |  |  | 			assert(Array.isArray(data)); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 			keys.forEach((key) => { | 
					
						
							| 
									
										
										
										
											2016-10-27 11:57:07 +03:00
										 |  |  | 				assert(data[0].hasOwnProperty(key)); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	it('should show installed plugins', (done) => { | 
					
						
							| 
									
										
										
										
											2021-02-04 00:06:15 -07:00
										 |  |  | 		const nodeModulesPath = plugins.nodeModulesPath; | 
					
						
							| 
									
										
										
										
											2017-07-19 11:38:51 -06:00
										 |  |  | 		plugins.nodeModulesPath = path.join(__dirname, './mocks/plugin_modules'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		plugins.showInstalled((err, pluginsData) => { | 
					
						
							| 
									
										
										
										
											2017-07-19 11:38:51 -06:00
										 |  |  | 			assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:06:15 -07:00
										 |  |  | 			const paths = pluginsData.map(plugin => path.relative(plugins.nodeModulesPath, plugin.path).replace(/\\/g, '/')); | 
					
						
							| 
									
										
										
										
											2017-07-19 11:38:51 -06:00
										 |  |  | 			assert(paths.indexOf('nodebb-plugin-xyz') > -1); | 
					
						
							|  |  |  | 			assert(paths.indexOf('@nodebb/nodebb-plugin-abc') > -1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			plugins.nodeModulesPath = nodeModulesPath; | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('install/activate/uninstall', () => { | 
					
						
							| 
									
										
										
										
											2021-02-04 00:06:15 -07:00
										 |  |  | 		let latest; | 
					
						
							|  |  |  | 		const pluginName = 'nodebb-plugin-imgur'; | 
					
						
							| 
									
										
										
										
											2016-11-18 14:03:06 +03:00
										 |  |  | 		it('should install a plugin', function (done) { | 
					
						
							| 
									
										
										
										
											2018-09-29 06:45:12 -04:00
										 |  |  | 			this.timeout(0); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 			plugins.toggleInstall(pluginName, '1.0.16', (err, pluginData) => { | 
					
						
							| 
									
										
										
										
											2016-11-18 14:03:06 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2020-09-08 11:42:35 -04:00
										 |  |  | 				latest = pluginData.latest; | 
					
						
							| 
									
										
										
										
											2016-11-18 14:03:06 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				assert.equal(pluginData.name, pluginName); | 
					
						
							|  |  |  | 				assert.equal(pluginData.id, pluginName); | 
					
						
							|  |  |  | 				assert.equal(pluginData.url, 'https://github.com/barisusakli/nodebb-plugin-imgur#readme'); | 
					
						
							|  |  |  | 				assert.equal(pluginData.description, 'A Plugin that uploads images to imgur'); | 
					
						
							|  |  |  | 				assert.equal(pluginData.active, false); | 
					
						
							|  |  |  | 				assert.equal(pluginData.installed, true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:06:15 -07:00
										 |  |  | 				const packageFile = JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json'), 'utf8')); | 
					
						
							| 
									
										
										
										
											2017-11-02 12:12:05 -06:00
										 |  |  | 				assert(packageFile.dependencies[pluginName]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-18 14:03:06 +03:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should activate plugin', (done) => { | 
					
						
							|  |  |  | 			plugins.toggleActive(pluginName, (err) => { | 
					
						
							| 
									
										
										
										
											2016-11-18 14:03:06 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 				plugins.isActive(pluginName, (err, isActive) => { | 
					
						
							| 
									
										
										
										
											2016-11-18 14:03:06 +03:00
										 |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					assert(isActive); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should upgrade plugin', function (done) { | 
					
						
							| 
									
										
										
										
											2018-09-29 06:45:12 -04:00
										 |  |  | 			this.timeout(0); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 			plugins.upgrade(pluginName, 'latest', (err, isActive) => { | 
					
						
							| 
									
										
										
										
											2016-11-18 14:03:06 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert(isActive); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 				plugins.loadPluginInfo(path.join(nconf.get('base_dir'), 'node_modules', pluginName), (err, pluginInfo) => { | 
					
						
							| 
									
										
										
										
											2016-11-18 14:03:06 +03:00
										 |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					assert.equal(pluginInfo.version, latest); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should uninstall a plugin', function (done) { | 
					
						
							| 
									
										
										
										
											2018-09-29 06:45:12 -04:00
										 |  |  | 			this.timeout(0); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 			plugins.toggleInstall(pluginName, 'latest', (err, pluginData) => { | 
					
						
							| 
									
										
										
										
											2016-11-18 14:03:06 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(pluginData.installed, false); | 
					
						
							|  |  |  | 				assert.equal(pluginData.active, false); | 
					
						
							| 
									
										
										
										
											2017-11-02 12:12:05 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:06:15 -07:00
										 |  |  | 				const packageFile = JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json'), 'utf8')); | 
					
						
							| 
									
										
										
										
											2017-11-02 12:12:05 -06:00
										 |  |  | 				assert(!packageFile.dependencies[pluginName]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-18 14:03:06 +03:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('static assets', () => { | 
					
						
							|  |  |  | 		it('should 404 if resource does not exist', (done) => { | 
					
						
							|  |  |  | 			request.get(`${nconf.get('url')}/plugins/doesnotexist/should404.tpl`, (err, res, body) => { | 
					
						
							| 
									
										
										
										
											2016-11-30 18:21:30 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(res.statusCode, 404); | 
					
						
							|  |  |  | 				assert(body); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should 404 if resource does not exist', (done) => { | 
					
						
							|  |  |  | 			request.get(`${nconf.get('url')}/plugins/nodebb-plugin-dbsearch/dbsearch/templates/admin/plugins/should404.tpl`, (err, res, body) => { | 
					
						
							| 
									
										
										
										
											2016-11-30 18:21:30 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(res.statusCode, 404); | 
					
						
							|  |  |  | 				assert(body); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should get resource', (done) => { | 
					
						
							|  |  |  | 			request.get(`${nconf.get('url')}/plugins/nodebb-plugin-dbsearch/dbsearch/templates/admin/plugins/dbsearch.tpl`, (err, res, body) => { | 
					
						
							| 
									
										
										
										
											2016-11-30 18:21:30 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(res.statusCode, 200); | 
					
						
							|  |  |  | 				assert(body); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2016-10-14 21:48:38 +03:00
										 |  |  | }); |