Skip to content

Commit 1a53bde

Browse files
committed
(feature) SupplierImportRow can create suppliers from a hash
Given a hash of data from a MISO supplier contacts export, we can create a supplier and link it to a given framework.
1 parent aa1c584 commit 1a53bde

4 files changed

Lines changed: 57 additions & 0 deletions

File tree

lib/supplier_import.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class SupplierImport
2+
end

lib/supplier_import_row.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class SupplierImportRow
2+
def initialize(row)
3+
@row = row
4+
end
5+
6+
def import!
7+
supplier = Supplier.create!(name: @row[:suppliername])
8+
framework = Framework.find_by!(short_name: @row[:frameworkreference])
9+
10+
supplier.agreements.create!(framework: framework)
11+
end
12+
end
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
require 'rails_helper'
2+
require './lib/supplier_import_row'
3+
4+
RSpec.describe SupplierImportRow do
5+
describe '#import!' do
6+
it 'creates a new supplier and adds it to the framework' do
7+
framework = FactoryBot.create(:framework, short_name: 'RM3756')
8+
9+
data = {
10+
frameworkreference: 'RM3756',
11+
supplierid: 1234,
12+
suppliername: 'Bob and Bucket LLP',
13+
lotid: 5678,
14+
lotnumber: 1,
15+
username: 'francis.brown',
16+
personname: 'Francis Brown',
17+
jobtitle: 'Big Cheese',
18+
contacttel: '02088118055',
19+
contactmobile: '07900111222',
20+
email: 'francis.brown@example.com',
21+
usercreationdate: '1/1/1970 18:00',
22+
lastlogindate: '1/7/2018 12:40'
23+
}
24+
25+
row = SupplierImportRow.new(data)
26+
27+
expect { row.import! }.to change { Supplier.count }.by(1)
28+
29+
supplier = Supplier.first
30+
expect(supplier.name).to eql 'Bob and Bucket LLP'
31+
expect(supplier.frameworks).to contain_exactly(framework)
32+
end
33+
end
34+
end

spec/lib/supplier_import_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require 'rails_helper'
2+
require 'supplier_import'
3+
4+
RSpec.describe SupplierImport do
5+
describe '#initialize' do
6+
it 'accepts CSV data as a string input' do
7+
end
8+
end
9+
end

0 commit comments

Comments
 (0)