feat: do not send contact details to the widget (#9223)
* refactor: use has_email instead of email * feat: remove usage of details directly in forms * test: update payload * test: fix transcript test * refactor: use computed hasEmail --------- Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
This commit is contained in:
@@ -48,7 +48,9 @@ RSpec.describe '/api/v1/widget/contacts', type: :request do
|
||||
headers: { 'X-Auth-Token' => token },
|
||||
as: :json
|
||||
body = response.parsed_body
|
||||
expect(body['phone_number']).to eq('+745623239')
|
||||
expect(body['has_phone_number']).to be true
|
||||
contact.reload
|
||||
expect(contact.phone_number).to eq('+745623239')
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
|
||||
@@ -58,7 +60,9 @@ RSpec.describe '/api/v1/widget/contacts', type: :request do
|
||||
headers: { 'X-Auth-Token' => token },
|
||||
as: :json
|
||||
body = response.parsed_body
|
||||
expect(body['phone_number']).to eq('+245623239')
|
||||
expect(body['has_phone_number']).to be true
|
||||
contact.reload
|
||||
expect(contact.phone_number).to eq('+245623239')
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
|
||||
@@ -68,7 +72,33 @@ RSpec.describe '/api/v1/widget/contacts', type: :request do
|
||||
headers: { 'X-Auth-Token' => token },
|
||||
as: :json
|
||||
body = response.parsed_body
|
||||
expect(body['email']).to eq('test@test.com')
|
||||
expect(body['has_email']).to be true
|
||||
contact.reload
|
||||
expect(contact.email).to eq('test@test.com')
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
|
||||
it 'dont update email if empty value email passed' do
|
||||
patch '/api/v1/widget/contact',
|
||||
params: params.merge({ email: '' }),
|
||||
headers: { 'X-Auth-Token' => token },
|
||||
as: :json
|
||||
body = response.parsed_body
|
||||
expect(body['has_email']).to be true
|
||||
contact.reload
|
||||
expect(contact.email).to eq('test@test.com')
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
|
||||
it 'dont update email if nil value email passed' do
|
||||
patch '/api/v1/widget/contact',
|
||||
params: params.merge({ email: nil }),
|
||||
headers: { 'X-Auth-Token' => token },
|
||||
as: :json
|
||||
body = response.parsed_body
|
||||
expect(body['has_email']).to be true
|
||||
contact.reload
|
||||
expect(contact.email).to eq('test@test.com')
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
|
||||
@@ -78,7 +108,9 @@ RSpec.describe '/api/v1/widget/contacts', type: :request do
|
||||
headers: { 'X-Auth-Token' => token },
|
||||
as: :json
|
||||
body = response.parsed_body
|
||||
expect(body['email']).to eq('test-1@test.com')
|
||||
expect(body['has_email']).to be true
|
||||
contact.reload
|
||||
expect(contact.email).to eq('test-1@test.com')
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -190,17 +190,19 @@ RSpec.describe '/api/v1/widget/conversations/toggle_typing', type: :request do
|
||||
describe 'POST /api/v1/widget/conversations/transcript' do
|
||||
context 'with a conversation' do
|
||||
it 'sends transcript email' do
|
||||
contact.update(email: 'test@test.com')
|
||||
mailer = double
|
||||
allow(ConversationReplyMailer).to receive(:with).and_return(mailer)
|
||||
allow(mailer).to receive(:conversation_transcript)
|
||||
|
||||
post '/api/v1/widget/conversations/transcript',
|
||||
headers: { 'X-Auth-Token' => token },
|
||||
params: { website_token: web_widget.website_token, email: 'test@test.com' },
|
||||
params: { website_token: web_widget.website_token },
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(mailer).to have_received(:conversation_transcript).with(conversation, 'test@test.com')
|
||||
contact.update(email: nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user