Commit 3fa034df authored by Illya Klymov's avatar Illya Klymov

Address reviewer comments

* use Array.wrap in bulk import service for better DX
parent 007f6f27
......@@ -40,7 +40,7 @@ class Import::BulkImportsController < ApplicationController
end
def create
responses = create_params.map { |entry| ::BulkImports::CreateService.new(current_user, [entry], credentials).execute }
responses = create_params.map { |entry| ::BulkImports::CreateService.new(current_user, entry, credentials).execute }
render json: responses.map { |response| { success: response.success?, id: response.payload[:id], message: response.message } }
end
......
......@@ -59,7 +59,7 @@ module BulkImports
)
bulk_import.create_configuration!(credentials.slice(:url, :access_token))
params.each do |entity|
Array.wrap(params).each do |entity|
BulkImports::Entity.create!(
bulk_import: bulk_import,
source_type: entity[:source_type],
......
......@@ -233,11 +233,11 @@ RSpec.describe Import::BulkImportsController do
error_response = ServiceResponse.error(message: 'Record invalid', http_status: :unprocessable_entity)
expect_next_instance_of(
::BulkImports::CreateService, user, [bulk_import_params[0]], { url: instance_url, access_token: pat }) do |service|
::BulkImports::CreateService, user, bulk_import_params[0], { url: instance_url, access_token: pat }) do |service|
allow(service).to receive(:execute).and_return(ServiceResponse.success(payload: bulk_import))
end
expect_next_instance_of(
::BulkImports::CreateService, user, [bulk_import_params[1]], { url: instance_url, access_token: pat }) do |service|
::BulkImports::CreateService, user, bulk_import_params[1], { url: instance_url, access_token: pat }) do |service|
allow(service).to receive(:execute).and_return(error_response)
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