|
| 1 | +require 'rails_helper' |
| 2 | +require './lib/user_import_row' |
| 3 | + |
| 4 | +RSpec.describe UserImportRow do |
| 5 | + describe '#initialize' do |
| 6 | + it 'throws an error if the hash is missing required fields' do |
| 7 | + auth0_client = instance_double('auth0 client') |
| 8 | + |
| 9 | + data = { |
| 10 | + personname: 'Daffy Duck' |
| 11 | + } |
| 12 | + |
| 13 | + expect { UserImportRow.new(data, auth0_client) } |
| 14 | + .to raise_error('UserImportRow::MissingKey') |
| 15 | + end |
| 16 | + end |
| 17 | + |
| 18 | + describe '#import!' do |
| 19 | + it 'creates a new user on Auth0' do |
| 20 | + data = { |
| 21 | + frameworkreference: 'RM3756', |
| 22 | + supplierid: 1234, |
| 23 | + suppliername: 'Bob and Bucket LLP', |
| 24 | + lotid: 5678, |
| 25 | + lotnumber: 1, |
| 26 | + username: 'francis.brown', |
| 27 | + personname: 'Francis Brown', |
| 28 | + jobtitle: 'Big Cheese', |
| 29 | + contacttel: '02088118055', |
| 30 | + contactmobile: '07900111222', |
| 31 | + email: 'francis.brown@example.com', |
| 32 | + usercreationdate: '1/1/1970 18:00', |
| 33 | + lastlogindate: '1/7/2018 12:40' |
| 34 | + } |
| 35 | + |
| 36 | + auth0_client = instance_double('auth0 client') |
| 37 | + |
| 38 | + expect(auth0_client) |
| 39 | + .to receive(:create_user) |
| 40 | + .with( |
| 41 | + 'Francis Brown', |
| 42 | + a_hash_including( |
| 43 | + email: 'francis.brown@example.com' |
| 44 | + ) |
| 45 | + ) |
| 46 | + |
| 47 | + UserImportRow.new(data, auth0_client).import! |
| 48 | + end |
| 49 | + end |
| 50 | +end |
0 commit comments