mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-21 17:12:43 +00:00
refactor: throw an error when removing a non-existing plugin
Related to #2
This commit is contained in:
committed by
Rainer Killinger
parent
992a0a6f2c
commit
3ea2c3b98d
@@ -14,6 +14,7 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
import {
|
import {
|
||||||
|
SCNotFoundErrorResponse,
|
||||||
SCPluginAlreadyRegisteredErrorResponse,
|
SCPluginAlreadyRegisteredErrorResponse,
|
||||||
SCPluginMetaData,
|
SCPluginMetaData,
|
||||||
SCPluginRegisterRequest,
|
SCPluginRegisterRequest,
|
||||||
@@ -85,11 +86,9 @@ function addPlugin(plugin: SCPluginMetaData): SCPluginRegisterResponse {
|
|||||||
*/
|
*/
|
||||||
function removePlugin(route: string): SCPluginRegisterResponse {
|
function removePlugin(route: string): SCPluginRegisterResponse {
|
||||||
if (!plugins.has(route)) {
|
if (!plugins.has(route)) {
|
||||||
// TODO: throw error when plugin that is to be removed is not already registered (after @openstapps/core update)
|
throw new SCNotFoundErrorResponse(
|
||||||
// throw new SCNotFoundErrorResponse(
|
isTestEnvironment,
|
||||||
// isTestEnvironment,
|
);
|
||||||
// );
|
|
||||||
return {success: false};
|
|
||||||
}
|
}
|
||||||
// remove the plugin information using its route as a key
|
// remove the plugin information using its route as a key
|
||||||
plugins.delete(route);
|
plugins.delete(route);
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ export class AppPluginRegisterSpec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test
|
@test
|
||||||
async 'should response with false when deleting non previously registered plugin'() {
|
async 'should response with 404 when deleting non previously registered plugin'() {
|
||||||
// lets simulate that the plugin is already registered
|
// lets simulate that the plugin is already registered
|
||||||
plugins.set(registerAddRequest.plugin.route, registerAddRequest.plugin);
|
plugins.set(registerAddRequest.plugin.route, registerAddRequest.plugin);
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ export class AppPluginRegisterSpec {
|
|||||||
.set('Accept', 'application/json')
|
.set('Accept', 'application/json')
|
||||||
// using a different route for the remove request
|
// using a different route for the remove request
|
||||||
.send({action: 'remove', route: '/not-foo'} as SCPluginRemove)
|
.send({action: 'remove', route: '/not-foo'} as SCPluginRemove)
|
||||||
.expect(200, {success: false});
|
.expect(404);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import {
|
|||||||
SCPluginAdd,
|
SCPluginAdd,
|
||||||
SCPluginAlreadyRegisteredErrorResponse,
|
SCPluginAlreadyRegisteredErrorResponse,
|
||||||
SCPluginRemove,
|
SCPluginRemove,
|
||||||
|
SCNotFoundErrorResponse,
|
||||||
} from '@openstapps/core';
|
} from '@openstapps/core';
|
||||||
import {should, use} from 'chai';
|
import {should, use} from 'chai';
|
||||||
import {slow, timeout} from 'mocha-typescript';
|
import {slow, timeout} from 'mocha-typescript';
|
||||||
@@ -94,17 +95,12 @@ export class PluginRegisterRouteSpec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test
|
@test
|
||||||
async 'should return false when removing a plugin whose route doesn\'t exist'() {
|
async 'should throw a "not found" error when removing a plugin whose route doesn\'t exist'() {
|
||||||
// register one plugin
|
// register one plugin
|
||||||
await pluginRegisterHandler(registerAddRequest, {});
|
await pluginRegisterHandler(registerAddRequest, {});
|
||||||
|
|
||||||
const response = await pluginRegisterHandler({...registerRemoveRequest, route: '/not-foo'}, {});
|
return pluginRegisterHandler({...registerRemoveRequest, route: '/not-foo'}, {})
|
||||||
|
.should.eventually.be.rejectedWith('Resource not found')
|
||||||
return response.should.eql({success: false});
|
.and.be.an.instanceOf(SCNotFoundErrorResponse);
|
||||||
|
|
||||||
// TODO: use 404 response
|
|
||||||
// return pluginRegisterHandler({...registerRemoveRequest, route: '/bar'}, {})
|
|
||||||
// .should.eventually.be.rejectedWith('Resource not found')
|
|
||||||
// .and.be.an.instanceOf(SCNotFoundErrorResponse);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user