Sha256: 857e2a82f56b98b37c2394cdb5ba1447c26bda558ce28e848686e1810882a2da

Contents?: true

Size: 1.42 KB

Versions: 34

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

module Spree
  describe Api::CountriesController, type: :request do
    before do
      stub_authentication!
      @state = create(:state)
      @country = @state.country
    end

    it "gets all countries" do
      get spree.api_countries_path
      expect(json_response['countries'].first['iso3']).to eq @country.iso3
    end

    context "with two countries" do
      before { @zambia = create(:country, name: "Zambia") }

      it "can view all countries" do
        get spree.api_countries_path
        expect(json_response['count']).to eq(2)
        expect(json_response['current_page']).to eq(1)
        expect(json_response['pages']).to eq(1)
      end

      it 'can query the results through a paramter' do
        get spree.api_countries_path, params: { q: { name_cont: 'zam' } }
        expect(json_response['count']).to eq(1)
        expect(json_response['countries'].first['name']).to eq @zambia.name
      end

      it 'can control the page size through a parameter' do
        get spree.api_countries_path, params: { per_page: 1 }
        expect(json_response['count']).to eq(1)
        expect(json_response['current_page']).to eq(1)
        expect(json_response['pages']).to eq(2)
      end
    end

    it "includes states" do
      get spree.api_country_path(@country.id)
      states = json_response['states']
      expect(states.first['name']).to eq @state.name
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
solidus_api-2.10.5 spec/requests/spree/api/countries_controller_spec.rb
solidus_api-2.10.3 spec/requests/spree/api/countries_controller_spec.rb
solidus_api-2.10.2 spec/requests/spree/api/countries_controller_spec.rb
solidus_api-2.9.6 spec/requests/spree/api/countries_controller_spec.rb
solidus_api-2.8.6 spec/requests/spree/api/countries_controller_spec.rb
solidus_api-2.10.1 spec/requests/spree/api/countries_controller_spec.rb
solidus_api-2.9.5 spec/requests/spree/api/countries_controller_spec.rb
solidus_api-2.10.0 spec/requests/spree/api/countries_controller_spec.rb
solidus_api-2.9.4 spec/requests/spree/api/countries_controller_spec.rb
solidus_api-2.6.6 spec/requests/spree/api/countries_controller_spec.rb
solidus_api-2.7.4 spec/requests/spree/api/countries_controller_spec.rb
solidus_api-2.8.5 spec/requests/spree/api/countries_controller_spec.rb
solidus_api-2.9.3 spec/requests/spree/api/countries_controller_spec.rb
solidus_api-2.9.2 spec/requests/spree/api/countries_controller_spec.rb
solidus_api-2.10.0.beta1 spec/requests/spree/api/countries_controller_spec.rb
solidus_api-2.7.3 spec/requests/spree/api/countries_controller_spec.rb
solidus_api-2.6.5 spec/requests/spree/api/countries_controller_spec.rb
solidus_api-2.9.1 spec/requests/spree/api/countries_controller_spec.rb
solidus_api-2.9.0 spec/requests/spree/api/countries_controller_spec.rb
solidus_api-2.9.0.rc.1 spec/requests/spree/api/countries_controller_spec.rb