Fetch client information before request grant

Change-Id: I101d2750bce4f28397f225b4d68cffd88f5ed1fb
diff --git a/t/plugin/auth-oauth.t b/t/plugin/auth-oauth.t
index 478c164..80afe05 100644
--- a/t/plugin/auth-oauth.t
+++ b/t/plugin/auth-oauth.t
@@ -787,6 +787,15 @@
   ->tx->res->dom->at('input[name=csrf_token]')->attr('value')
   ;
 
+$fake_backend_app->add_client({
+  "client_id" => 'xyz',
+  "client_name" => 'New added client',
+  "client_description" => 'This is a new client',
+  "client_url" => 'http://example.com',
+  "client_type" => 'CONFIDENTIAL'
+#  "client_redirect_uri" => $redirect_uri
+});
+
 $fwd = $t->get_ok(Mojo::URL->new('/settings/oauth/authorize')->query({
   client_id => 'xyz',
   state => 'abcde',
@@ -796,9 +805,8 @@
   ->status_is(200)
   ->attr_is('input[name=client_id]','value','xyz')
   ->attr_is('input[name=state]','value','abcde')
-  ->attr_is('input[name=name]','value','xyz')
   ->attr_like('input[name=fwd]','value',qr!test\.com!)
-  ->text_is('span.client-name','xyz')
+  ->text_is('span.client-name','New added client')
   ->text_is('div.intro p:nth-child(2)', 'Please log in!')
   ->tx->res->dom->at('input[name=fwd]')->attr('value')
   ;
@@ -822,10 +830,9 @@
   ->status_is(200)
   ->attr_is('input[name=client_id]','value','xyz')
   ->attr_is('input[name=state]','value','abcde')
-  ->attr_is('input[name=name]','value','xyz')
   ->text_is('ul#scopes li:nth-child(1)','search')
   ->text_is('ul#scopes li:nth-child(2)','match')
-  ->text_is('span.client-name','xyz')
+  ->text_is('span.client-name','New added client')
   ->attr_is('a.form-button','href','http://test.com/')
   ->attr_is('a.embedded-link', 'href', '/doc/korap/kalamar')
   ;
@@ -839,10 +846,9 @@
   ->status_is(200)
   ->attr_is('input[name=client_id]','value','xyz')
   ->attr_is('input[name=state]','value','abcde')
-  ->attr_is('input[name=name]','value','xyz')
   ->text_is('ul#scopes li:nth-child(1)','search')
   ->text_is('ul#scopes li:nth-child(2)','match')
-  ->text_is('span.client-name','xyz')
+  ->text_is('span.client-name','New added client')
   ->attr_is('a.form-button','href','http://test.com/')
   ->attr_is('a.embedded-link', 'href', '/doc/korap/kalamar')
   ;
diff --git a/t/server/mock.pl b/t/server/mock.pl
index 8064208..1f32a39 100644
--- a/t/server/mock.pl
+++ b/t/server/mock.pl
@@ -67,6 +67,15 @@
   return $c->app->defaults('auth_' . $auth);
 };
 
+
+helper 'add_client' => sub {
+  my $c = shift;
+  my $client = shift;
+  my $list = $c->app->defaults('oauth.client_list');
+  push @$list, $client;
+};
+
+
 # Load fixture responses
 helper 'load_response' => sub {
   my $c = shift;