# frozen_string_literal: true
class Api::SalmonController < Api::BaseController
+ include SignatureVerification
+
before_action :set_account
respond_to :txt
process_salmon
head 202
elsif payload.present?
- [signature_verification_failure_reason, 401]
+ render plain: signature_verification_failure_reason, status: 401
else
head 400
end
end
end
- context 'with invalid post data' do
+ context 'with empty post data' do
before do
request.env['RAW_POST_DATA'] = ''
post :update, params: { id: account.id }
expect(response).to have_http_status(400)
end
end
+
+ context 'with invalid post data' do
+ before do
+ service = double(call: false)
+ allow(VerifySalmonService).to receive(:new).and_return(service)
+
+ request.env['RAW_POST_DATA'] = File.read(File.join(Rails.root, 'spec', 'fixtures', 'salmon', 'mention.xml'))
+ post :update, params: { id: account.id }
+ end
+
+ it 'returns http client error' do
+ expect(response).to have_http_status(401)
+ end
+ end
end
end