Commit 336ebb41 authored by Illya Klymov's avatar Illya Klymov

Fix passing params between bulk import controller and service

- properly pass data from POST create call
- add new field to entity serializer
- update relevant tests
parent c9f1648c
......@@ -57,7 +57,7 @@ class Import::BulkImportsController < ApplicationController
end
def create_params
params.permit(:bulk_import, [*bulk_import_params])
params.permit(bulk_import: bulk_import_params)[:bulk_import]
end
def bulk_import_params
......@@ -127,7 +127,7 @@ class Import::BulkImportsController < ApplicationController
def credentials
{
url: session[url_key],
access_token: [access_token_key]
access_token: session[access_token_key]
}
end
end
......@@ -12,4 +12,8 @@ class Import::BulkImportEntity < Grape::Entity
expose :full_path do |entity|
entity['full_path']
end
expose :web_url do |entity|
entity['web_url']
end
end
......@@ -57,8 +57,8 @@ RSpec.describe Import::BulkImportsController do
let(:client_response) do
double(
parsed_response: [
{ 'id' => 1, 'full_name' => 'group1', 'full_path' => 'full/path/group1' },
{ 'id' => 2, 'full_name' => 'group2', 'full_path' => 'full/path/group2' }
{ 'id' => 1, 'full_name' => 'group1', 'full_path' => 'full/path/group1', 'web_url' => 'http://demo.host/full/path/group1' },
{ 'id' => 2, 'full_name' => 'group2', 'full_path' => 'full/path/group2', 'web_url' => 'http://demo.host/full/path/group1' }
]
)
end
......@@ -132,12 +132,27 @@ RSpec.describe Import::BulkImportsController do
end
describe 'POST create' do
let(:instance_url) { "http://fake-intance" }
let(:pat) { "fake-pat" }
before do
session[:bulk_import_gitlab_access_token] = pat
session[:bulk_import_gitlab_url] = instance_url
end
it 'executes BulkImportService' do
expect_next_instance_of(BulkImportService) do |service|
bulk_import_params = [{ "source_type" => "group_entity",
"source_full_path" => "full_path",
"destination_name" =>
"destination_name",
"destination_namespace" => "root" }]
expect_next_instance_of(
BulkImportService, user, bulk_import_params, { url: instance_url, access_token: pat }) do |service|
expect(service).to receive(:execute)
end
post :create
post :create, params: { bulk_import: bulk_import_params }
expect(response).to have_gitlab_http_status(:ok)
end
......
......@@ -7,14 +7,15 @@ RSpec.describe Import::BulkImportEntity do
{
'id' => 1,
'full_name' => 'test',
'full_path' => 'full/path/test',
'full_path' => 'full/path/tes',
'web_url' => 'http://web.url/path',
'foo' => 'bar'
}
end
subject { described_class.represent(importable_data).as_json }
%w[id full_name full_path].each do |attribute|
%w[id full_name full_path web_url].each do |attribute|
it "exposes #{attribute}" do
expect(subject[attribute.to_sym]).to eq(importable_data[attribute])
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment