summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--spec/requests/v1/company_licenses_spec.rb68
1 files changed, 68 insertions, 0 deletions
diff --git a/spec/requests/v1/company_licenses_spec.rb b/spec/requests/v1/company_licenses_spec.rb
new file mode 100644
index 0000000..21a3a7d
--- /dev/null
+++ b/spec/requests/v1/company_licenses_spec.rb
@@ -0,0 +1,68 @@
+require "spec_helper"
+
+describe "companies/:company_id/licenses" do
+ let!(:company) { Company.create(name: 'ABC Resources Ltd.') }
+ let!(:user) { User.create(company: company) }
+ let!(:township_1) { Location.create(latitude: 51.06, longitude: -114.09, township: '1') }
+ let!(:township_2) { Location.create(latitude: 91.06, longitude: -14.09, township: '2') }
+ let!(:well_type) { WellType::DEV }
+ let!(:active_license) { License.create(id: SecureRandom.uuid, company: company, applicant: user, location: township_1, issued_at: 2.days.ago, expired_at: 1.day.from_now, well_type: well_type) }
+ let!(:expired_license) { License.create(id: SecureRandom.uuid, company: company, applicant: user, location: township_2, issued_at: 2.days.ago, expired_at: 1.day.ago, well_type: well_type) }
+ let!(:confidential_license) { License.create(id: SecureRandom.uuid, company: company, applicant: user, location: township_1, issued_at: 2.days.ago, expired_at: 1.day.from_now, well_type: well_type, confidential: true) }
+
+ describe "companies/:company_id/licenses" do
+ it "returns all active licenses" do
+ get "v1/companies/#{company.id}/licenses"
+ response.should be_success
+ result = JSON.parse(response.body)
+ result["licenses"].first["id"].should == active_license.id
+ result["licenses"].first["issued_at"].should == active_license.issued_at.to_s
+ result["licenses"].first["expired_at"].should == active_license.expired_at.to_s
+ result["licenses"].first["company"]["name"].should == active_license.company.name
+ result["licenses"].first["well_type"]["id"].should == well_type.id
+ result["licenses"].first["well_type"]["acronym"].should == well_type.acronym
+ result["licenses"].first["well_type"]["name"].should == well_type.name
+ result["licenses"].first["location"]["latitude"].should == township_1.latitude
+ result["licenses"].first["location"]["longitude"].should == township_1.longitude
+ result["licenses"].first["location"]["township"].should == township_1.township
+ WellType::ALL.each do |well_type|
+ row = result["well_types"].find { |x| x['id'] == well_type.id }
+ row['acronym'].should == well_type.acronym
+ row['name'].should == well_type.name
+ end
+ LicenseStatus::ALL.each do |status|
+ row = result["license_statuses"].find { |x| x['name'] == status.to_s }
+ row.should_not be_nil
+ end
+ end
+
+ it "returns all expired licenses" do
+ get "v1/companies/#{company.id}/licenses?status=expired"
+ response.should be_success
+ result = JSON.parse(response.body)
+ result["licenses"].first["id"].should == expired_license.id
+ end
+
+ it "returns all confidential licenses" do
+ get "v1/companies/#{company.id}/licenses?status=confidential"
+ response.should be_success
+ result = JSON.parse(response.body)
+ result["licenses"].first["id"].should == confidential_license.id
+ end
+
+ it "returns all licenses from a township" do
+ get "v1/companies/#{company.id}/licenses?township=1"
+ response.should be_success
+ result = JSON.parse(response.body)
+ result["licenses"].first["id"].should == active_license.id
+ result["licenses"].last["id"].should == confidential_license.id
+ end
+
+ it "returns all expired licenses from a township" do
+ get "v1/companies/#{company.id}/licenses?township=2&status=expired"
+ response.should be_success
+ result = JSON.parse(response.body)
+ result["licenses"].first["id"].should == expired_license.id
+ end
+ end
+end