Marketplace Uninstall Plugins

Change-Id: Ic5bd2aad8803097f37849cdcec549a76c5e17195
diff --git a/t/plugin/auth-oauth.t b/t/plugin/auth-oauth.t
index 16b0f6e..a67b98b 100644
--- a/t/plugin/auth-oauth.t
+++ b/t/plugin/auth-oauth.t
@@ -1021,16 +1021,13 @@
   ->text_is('ul.plugin-list > li + li >p.plugin-desc','Description Plugin 2')
   ;
 
-$t->ua->max_redirects(0);
-
-$t->post_ok('/settings/marketplace', form => {'client-id' => '52abc'})
+$t->post_ok('/settings/marketplace/install', form => {'client-id' => '52abc'})
   ->status_is(302)
   ->header_is(location => '/settings/marketplace')
   ;
-
 $t->ua->max_redirects(1);
 
-$t->post_ok('/settings/marketplace', form => {'client-id' => '52abc'})
+$t->post_ok('/settings/marketplace/install', form => {'client-id' => '52abc'})
   ->status_is(200)
   ->element_exists('ul.plugin-list')
   ->element_exists('ul.plugin-list > li')
@@ -1045,18 +1042,35 @@
 
 $t->ua->max_redirects(0);
 
- $t->post_ok('/settings/marketplace', form => {'client-id' => 'unsinn31'})
+ $t->post_ok('/settings/marketplace/install', form => {'client-id' => 'unsinn31'})
   ->status_is(302)
   ->header_is(location => '/settings/marketplace')
   ;
 
 $t->ua->max_redirects(1);
 
-$t->post_ok('/settings/marketplace', form => {'client-id' => 'unsinn31'})
+$t->post_ok('/settings/marketplace/install', form => {'client-id' => 'unsinn31'})
   ->status_is(200)
   ->text_is('div.notify-error', 'Plugin could not be installed')
   ;
 
+$t->post_ok('/settings/marketplace/uninstall', form => {'client-id' => '52abc'})
+  ->status_is(200)
+  ->element_exists('ul.plugin-list')
+  ->element_exists('ul.plugin-list > li')
+  ->text_is('span.client-name','Plugin 1')
+  ->text_is('p.plugin-desc','Description Plugin 1')
+  ->element_exists('ul.plugin-list > li + li')
+  ->text_is('ul.plugin-list > li + li >span.client-name','Plugin 2')
+  ->text_is('ul.plugin-list > li + li >p.plugin-desc','Description Plugin 2')
+  ->element_exists_not('ul.plugin_in-list')
+  ;
+
+$t->post_ok('/settings/marketplace/uninstall', form => {'client-id' => 'quatsch12'})
+  ->status_is(200)
+  ->text_is('div.notify-error', 'Plugin could not be uninstalled')
+  ;
+
 $t->ua->max_redirects(0);
 
 $t->get_ok(Mojo::URL->new('/settings/oauth/authorize')->query({
diff --git a/t/server/mock.pl b/t/server/mock.pl
index e76f8c5..e27542a 100644
--- a/t/server/mock.pl
+++ b/t/server/mock.pl
@@ -649,6 +649,35 @@
   );
 };
 
+# Mock API plugin uninstallation
+post '/v1.0/plugins/uninstall' => sub {
+  my $c = shift;
+  my $v = $c->validation;
+  $v->required('super_client_id');
+  $v->required('super_client_secret');
+  $v->required('client_id');
+  if ($v->has_error) {
+    return $c->render(
+      json => [],
+      status => 400
+    );
+  };
+  my $cl_id = $c->param('client_id');
+
+  my $plin_list =  $c->app->defaults('oauth.pluginin_list');
+  my @new_list = grep{!($_->{client_id} eq $cl_id)}@$plin_list;
+  $c->app->defaults('oauth.pluginin_list' => \@new_list);
+  
+  if(scalar @new_list eq scalar @$plin_list){
+    return $c->render(
+      status => 404
+     );
+  }
+  return $c->render(
+   json => $c->stash('oauth.pluginin_list'),
+    status => 200
+  );
+  };
 
 # Register a client
 post '/v1.0/oauth2/client/list' => sub {