summaryrefslogtreecommitdiff
path: root/spec/support/shared_examples/requests/post_request.rb
blob: 6ea2a8631729490860fd79a189f531418cb28f17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
RSpec.shared_examples 'a POST request' do
  let(:headers) { { 'CONTENT_TYPE' => 'application/json' } }

  context 'with correct parameters' do
    it 'returns a successful http status and a response to the posted data' do
      post(route, params: params.to_json, headers:)
      expect(response).to have_http_status(200)
      expect(response.body).to include_strings(expected_text)
    end
  end

  context 'with incorrect parameters' do
    it 'returns a client side error http status and a error message' do
      post('/api/authenticate', params: wrong_params.to_json, headers:)
      expect(response).to have_http_status(desired_error_status)
      expect(response.body).to include(expected_error_message)
    end
  end
end