Fixed bug #1663 - Exchange integration tries to import user twice and fails.
This commit is contained in:
parent
b9d728f890
commit
492ca261ce
3 changed files with 96 additions and 1 deletions
|
@ -12,7 +12,7 @@ class Sequencer
|
|||
|
||||
def process
|
||||
state.provide(:remote_id) do
|
||||
resource.fetch(attribute)
|
||||
resource.fetch(attribute).dup.to_s.downcase
|
||||
end
|
||||
rescue KeyError => e
|
||||
handle_failure(e)
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Sequencer::Unit::Import::Common::Model::Attributes::RemoteId, sequencer: :unit do
|
||||
|
||||
it 'takes remote_id from id' do
|
||||
parameters = {
|
||||
resource: {
|
||||
id: '123abc',
|
||||
}
|
||||
}
|
||||
|
||||
provided = process(parameters)
|
||||
|
||||
expect(provided).to include(remote_id: '123abc')
|
||||
end
|
||||
|
||||
it 'takes remote_id from attribute method result' do
|
||||
parameters = {
|
||||
resource: {
|
||||
other_attribute: '123abc',
|
||||
}
|
||||
}
|
||||
|
||||
provided = process(parameters) do |instance|
|
||||
expect(instance).to receive(:attribute).and_return(:other_attribute)
|
||||
end
|
||||
|
||||
expect(provided).to include(remote_id: '123abc')
|
||||
end
|
||||
|
||||
it 'converts value to a String' do
|
||||
parameters = {
|
||||
resource: {
|
||||
id: 1337,
|
||||
}
|
||||
}
|
||||
|
||||
provided = process(parameters)
|
||||
|
||||
expect(provided).to include(remote_id: '1337')
|
||||
end
|
||||
|
||||
it 'downcases the value to prevent case sensivity issues with the ORM' do
|
||||
parameters = {
|
||||
resource: {
|
||||
id: 'AbCdEfG',
|
||||
}
|
||||
}
|
||||
|
||||
provided = process(parameters)
|
||||
|
||||
expect(provided[:remote_id]).to eq(parameters[:resource][:id].downcase)
|
||||
end
|
||||
|
||||
it 'duplicates the value to prevent attribute changes' do
|
||||
parameters = {
|
||||
resource: {
|
||||
id: 'this is',
|
||||
}
|
||||
}
|
||||
|
||||
provided = process(parameters)
|
||||
|
||||
expect(provided[:remote_id]).to eq(parameters[:resource][:id])
|
||||
|
||||
parameters[:resource][:id] += ' a test'
|
||||
|
||||
expect(provided[:remote_id]).not_to eq(parameters[:resource][:id])
|
||||
end
|
||||
end
|
|
@ -0,0 +1,25 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Sequencer::Unit::Import::Common::Model::ExternalSync::Lookup, sequencer: :unit do
|
||||
|
||||
it 'finds model_class instances by remote_id' do
|
||||
user = create(:user)
|
||||
external_sync_source = 'test'
|
||||
remote_id = '1337'
|
||||
|
||||
ExternalSync.create(
|
||||
source: external_sync_source,
|
||||
source_id: remote_id,
|
||||
o_id: user.id,
|
||||
object: user.class,
|
||||
)
|
||||
|
||||
provided = process(
|
||||
remote_id: remote_id,
|
||||
model_class: user.class,
|
||||
external_sync_source: external_sync_source,
|
||||
)
|
||||
|
||||
expect(provided[:instance]).to eq(user)
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue