summaryrefslogtreecommitdiff
path: root/spec/controllers/v1/company_licenses_controller_spec.rb
blob: 0ba61eba820bc80299afbb8df23c8c88945a2e00 (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
require "spec_helper"

describe V1::CompanyLicensesController do
  describe :index do
    let(:company) { Company.new }
    let(:company_id) { SecureRandom.uuid }
    let(:active_licenses) { ["active"] }
    let(:active_licenses_in_township) { ["active township"] }

    before :each do
      Company.stub(:find).with(company_id).and_return(company)
      active_licenses.stub(:township).with("123").and_return(active_licenses_in_township)
    end

    it "returns the active licenses" do
      company.stub(:filter_licenses_using).with({status: LicenseStatus::ACTIVE, township: nil}).and_return(active_licenses)
      get :index, company_id: company_id
      assigns(:licenses).should == active_licenses
    end

    it "returns the active licenses for a given township" do
      company.stub(:filter_licenses_using).with({status: LicenseStatus::ACTIVE, township: "123"}).and_return(active_licenses_in_township)
      get :index, company_id: company_id, township: "123"
      assigns(:licenses).should == active_licenses_in_township
    end
  end

  describe :integration do
    describe :index do
      let(:company) { Company.create(name: 'ABC Resources Ltd.') }
      let(:location) { Location.new(latitude: 51.06, longitude: -114.09, township: '1') }
      let!(:license) { company.licenses.create(well_type: WellType::DEV, location: location, issued_at: 2.days.ago, expired_at: 1.day.ago) }

      it "finds expired licenses from a specific township" do
        get :index, company_id: company.id, status: "expired", township: "1"
        assigns(:licenses).should include(license)
      end
    end
  end
end