summaryrefslogtreecommitdiff
path: root/spec/support/shared_examples/lib/api/ai_workhorse_shared_examples.rb
blob: 3faa8f9c032975f86fc453707071ac73df581dac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# frozen_string_literal: true

RSpec.shared_examples 'delegates AI request to Workhorse' do
  context 'when openai_experimentation is disabled' do
    before do
      stub_feature_flags(openai_experimentation: false)
    end

    it 'responds as not found' do
      post api(url, current_user), params: input_params

      expect(response).to have_gitlab_http_status(:not_found)
    end
  end

  context 'when ai_experimentation_api is disabled' do
    before do
      stub_feature_flags(ai_experimentation_api: false)
    end

    it 'responds as not found' do
      post api(url, current_user), params: input_params

      expect(response).to have_gitlab_http_status(:not_found)
    end
  end

  it 'responds with Workhorse send-url headers' do
    post api(url, current_user), params: input_params

    expect(response.body).to eq('""')
    expect(response).to have_gitlab_http_status(:ok)

    send_url_prefix, encoded_data = response.headers['Gitlab-Workhorse-Send-Data'].split(':')
    data = Gitlab::Json.parse(Base64.urlsafe_decode64(encoded_data))

    expect(send_url_prefix).to eq('send-url')
    expect(data).to eq({
      'AllowRedirects' => false,
      'Method' => 'POST'
    }.merge(expected_params))
  end
end