<commit_before>require 'rails_helper'

RSpec.describe 'Order Items API' do
  let(:default_params) { { format: :json } }
  let(:project) { create :project }
  let(:product) { create :product }

  before(:each) do
    @order = Order.create(staff_id: 1, order_items_attributes: [{ product_id: product.id, project_id: project.id }, { product_id: product.id, project_id: project.id }])
    sign_in_as create :staff, :admin
    @order_item = @order.order_items.first
  end

  describe 'GET show' do
    it 'returns an order item', :show_in_doc do
      get "/orders/#{@order.id}/items/#{@order_item.id}"
      expect(response.body).to eq(@order_item.to_json)
    end

    it 'returns an error when the order item does not exist' do
      get "/orders/#{@order.id}/items/#{@order_item.id + 999}"
      expect(response.status).to eq(404)
      expect(json).to eq('error' => 'Not found.')
    end

    it 'returns an error when the order does not exist' do
      get "/orders/#{@order.id + 999}/items/#{@order_item.id}"
      expect(response.status).to eq(404)
      expect(json).to eq('error' => 'Not found.')
    end
  end

  describe 'PUT update' do
    it 'update an order item', :show_in_doc do
      put "/orders/#{@order.id}/items/#{@order_item.id}", port: 123, host: 'www.example.com'

      @order_item.provision_status
      expect(response.status).to eq(204)
    end

    it 'returns an error when the order item does not exist' do
      get "/orders/#{@order.id}/items/#{@order_item.id + 999}"
      expect(response.status).to eq(404)
      expect(json).to eq('error' => 'Not found.')
    end

    it 'returns an error when the order does not exist' do
      get "/orders/#{@order.id + 999}/items/#{@order_item.id}"
      expect(response.status).to eq(404)
      expect(json).to eq('error' => 'Not found.')
    end
  end

  describe 'DELETE destroy' do
    before :each do
      @order = Order.create(staff_id: 1, order_items_attributes: [{ product_id: product.id, project_id: project.id }])
      @order_item = @order.order_items.first
    end

    it 'removes the order item', :show_in_doc do
      delete "/orders/#{@order.id}/items/#{@order_item.id}"
      expect(response.status).to eq(204)
    end

    it 'returns an error when the order item does not exist' do
      delete "/orders/#{@order.id}/items/#{@order_item.id + 999}"
      expect(response.status).to eq(404)
      expect(json).to eq('error' => 'Not found.')
    end
  end

  describe 'Item service start / stop' do
    it 'can be started', :show_in_doc do
      put "/orders/#{@order.id}/items/#{@order_item.id}/start_service"
      expect(response.status).to eq(200)
    end

    it 'can be stopped', :show_in_doc do
      put "/orders/#{@order.id}/items/#{@order_item.id}/stop_service"
      expect(response.status).to eq(200)
    end
  end

  describe 'Provision request response' do
    it 'stores and updates', :show_in_doc do
      put "/order_items/#{@order_item.id}/provision_update"
      expect(response.status).to eq(204)
    end

    it 'returns an error when the order item does not exist' do
      put "/order_items/#{@order_item.id}/provision_update"
      expect(response.status).to eq(404)
      expect(json).to eq('error' => 'Not found.')
    end
  end
end<commit_msg>Rspec tests should now all pass.<commit_after>require 'rails_helper'

RSpec.describe 'Order Items API' do
  let(:default_params) { { format: :json } }
  let(:project) { create :project }
  let(:product) { create :product }

  before(:each) do
    @order = Order.create(staff_id: 1, order_items_attributes: [{ product_id: product.id, project_id: project.id }, { product_id: product.id, project_id: project.id }])
    sign_in_as create :staff, :admin
    @order_item = @order.order_items.first
  end

  describe 'GET show' do
    it 'returns an order item', :show_in_doc do
      get "/orders/#{@order.id}/items/#{@order_item.id}"
      expect(response.body).to eq(@order_item.to_json)
    end

    it 'returns an error when the order item does not exist' do
      get "/orders/#{@order.id}/items/#{@order_item.id + 999}"
      expect(response.status).to eq(404)
      expect(json).to eq('error' => 'Not found.')
    end

    it 'returns an error when the order does not exist' do
      get "/orders/#{@order.id + 999}/items/#{@order_item.id}"
      expect(response.status).to eq(404)
      expect(json).to eq('error' => 'Not found.')
    end
  end

  describe 'PUT update' do
    it 'update an order item', :show_in_doc do
      put "/orders/#{@order.id}/items/#{@order_item.id}", port: 123, host: 'www.example.com'

      @order_item.provision_status
      expect(response.status).to eq(204)
    end

    it 'returns an error when the order item does not exist' do
      get "/orders/#{@order.id}/items/#{@order_item.id + 999}"
      expect(response.status).to eq(404)
      expect(json).to eq('error' => 'Not found.')
    end

    it 'returns an error when the order does not exist' do
      get "/orders/#{@order.id + 999}/items/#{@order_item.id}"
      expect(response.status).to eq(404)
      expect(json).to eq('error' => 'Not found.')
    end
  end

  describe 'DELETE destroy' do
    before :each do
      @order = Order.create(staff_id: 1, order_items_attributes: [{ product_id: product.id, project_id: project.id }])
      @order_item = @order.order_items.first
    end

    it 'removes the order item', :show_in_doc do
      delete "/orders/#{@order.id}/items/#{@order_item.id}"
      expect(response.status).to eq(204)
    end

    it 'returns an error when the order item does not exist' do
      delete "/orders/#{@order.id}/items/#{@order_item.id + 999}"
      expect(response.status).to eq(404)
      expect(json).to eq('error' => 'Not found.')
    end
  end

  describe 'Item service start / stop' do
    it 'can be started', :show_in_doc do
      put "/orders/#{@order.id}/items/#{@order_item.id}/start_service"
      expect(response.status).to eq(200)
    end

    it 'can be stopped', :show_in_doc do
      put "/orders/#{@order.id}/items/#{@order_item.id}/stop_service"
      expect(response.status).to eq(200)
    end
  end

  describe 'PUT provision request response' do
    before :each do
      @order = Order.create(staff_id: 1, order_items_attributes: [{ product_id: product.id, project_id: project.id }])
      @order_item = @order.order_items.first
    end

    it 'updates the order item with the payload and its data' do
      put "/order_items/#{@order_item.id}/provision_update", status: 'OK', message: '', info: { provision_status: 'ok', uuid: "#{@order_item.uuid}" }
      expect(response.status).to eq(204)
    end

    it 'returns an error when the order item does not exist' do
      put "/order_items/#{@order_item.id + 999}/provision_update", status: 'OK', message: '', info: { provision_status: 'ok', uuid: "#{@order_item.uuid}" }
      expect(response.status).to eq(404)
      expect(json).to eq('error' => 'Not found.')
    end

    it 'with missing or invalid parameters' do
      put "/order_items/#{@order_item.id}/provision_update"
      expect(response.status).to eq(422)
    end
  end
end
{'fraction_non_alphanumeric': 0.14732835189623572, 'fraction_numerical': 0.01593119977442549, 'mean_word_length': 3.1364431486880466, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4533551', 'n_tokens_mistral': 2461, 'n_tokens_neox': 2334, 'n_words': 620}