mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
test: submitUsage
This commit is contained in:
@@ -17,9 +17,10 @@ module.exports = function (Plugins) {
|
|||||||
}), null, true);
|
}), null, true);
|
||||||
};
|
};
|
||||||
|
|
||||||
Plugins.submitUsageData = function () {
|
Plugins.submitUsageData = function (callback) {
|
||||||
|
callback = callback || function () {};
|
||||||
if (!meta.config.submitPluginUsage || !Plugins.loadedPlugins.length || global.env !== 'production') {
|
if (!meta.config.submitPluginUsage || !Plugins.loadedPlugins.length || global.env !== 'production') {
|
||||||
return;
|
return callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
const hash = crypto.createHash('sha256');
|
const hash = crypto.createHash('sha256');
|
||||||
@@ -33,10 +34,14 @@ module.exports = function (Plugins) {
|
|||||||
timeout: 5000,
|
timeout: 5000,
|
||||||
}, (err, res, body) => {
|
}, (err, res, body) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return winston.error(err.stack);
|
winston.error(err.stack);
|
||||||
|
return callback(err);
|
||||||
}
|
}
|
||||||
if (res.statusCode !== 200) {
|
if (res.statusCode !== 200) {
|
||||||
winston.error(`[plugins.submitUsageData] received ${res.statusCode} ${body}`);
|
winston.error(`[plugins.submitUsageData] received ${res.statusCode} ${body}`);
|
||||||
|
callback(new Error(`[[error:nbbpm-${res.statusCode}]]`));
|
||||||
|
} else {
|
||||||
|
callback();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -210,6 +210,13 @@ describe('Plugins', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should submit usage info', (done) => {
|
||||||
|
plugins.submitUsage((err) => {
|
||||||
|
assert.ifError(err);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('install/activate/uninstall', () => {
|
describe('install/activate/uninstall', () => {
|
||||||
let latest;
|
let latest;
|
||||||
const pluginName = 'nodebb-plugin-imgur';
|
const pluginName = 'nodebb-plugin-imgur';
|
||||||
|
|||||||
Reference in New Issue
Block a user