From 479d88a480813b40ffebb271e536d3d66c96e087 Mon Sep 17 00:00:00 2001 From: CristianDuta Date: Tue, 8 Nov 2022 01:02:45 +0100 Subject: [PATCH] fix: Identifier not persisted on customer created via Inbox API Channel (#5804) - Fixes the identifier not being used to identify the contact, this results in having a new contact created every time the email or phone is not supplied. Fixes: #5704 --- .../public/api/v1/inboxes/contacts_controller.rb | 2 +- .../public/api/v1/inbox/contacts_controller_spec.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/controllers/public/api/v1/inboxes/contacts_controller.rb b/app/controllers/public/api/v1/inboxes/contacts_controller.rb index 1fde3051e..b3ebd4ade 100644 --- a/app/controllers/public/api/v1/inboxes/contacts_controller.rb +++ b/app/controllers/public/api/v1/inboxes/contacts_controller.rb @@ -7,7 +7,7 @@ class Public::Api::V1::Inboxes::ContactsController < Public::Api::V1::InboxesCon @contact_inbox = ::ContactInboxWithContactBuilder.new( source_id: source_id, inbox: @inbox_channel.inbox, - contact_attributes: permitted_params.except(:identifier, :identifier_hash) + contact_attributes: permitted_params.except(:identifier_hash) ).perform end diff --git a/spec/controllers/public/api/v1/inbox/contacts_controller_spec.rb b/spec/controllers/public/api/v1/inbox/contacts_controller_spec.rb index 7bd707883..244d31c4d 100644 --- a/spec/controllers/public/api/v1/inbox/contacts_controller_spec.rb +++ b/spec/controllers/public/api/v1/inbox/contacts_controller_spec.rb @@ -15,6 +15,15 @@ RSpec.describe 'Public Inbox Contacts API', type: :request do expect(data['source_id']).not_to be_nil expect(data['pubsub_token']).not_to be_nil end + + it 'persists the identifier of the contact' do + identifier = 'contact-identifier' + post "/public/api/v1/inboxes/#{api_channel.identifier}/contacts", params: { identifier: identifier } + + expect(response).to have_http_status(:success) + db_contact = api_channel.account.contacts.find_by(identifier: identifier) + expect(db_contact).not_to be_nil + end end describe 'GET /public/api/v1/inboxes/{identifier}/contact/{source_id}' do