Browse Source

Test case log state machine

pull/50/head
baarkerlounger 3 years ago
parent
commit
882a1de227
  1. 4
      app/models/case_log.rb
  2. 17
      spec/models/case_log_spec.rb
  3. 13
      spec/requests/case_log_controller_spec.rb

4
app/models/case_log.rb

@ -51,11 +51,11 @@ class CaseLog < ApplicationRecord
end
def not_started?
status == "not started"
status == "not_started"
end
def in_progress?
status == "in progress"
status == "in_progress"
end
private

17
spec/models/case_log_spec.rb

@ -14,4 +14,21 @@ RSpec.describe Form, type: :model do
expect { CaseLog.create!(tenant_age: 0) }.to raise_error(ActiveRecord::RecordInvalid)
end
end
describe "status" do
let!(:empty_case_log) { FactoryBot.create(:case_log) }
let!(:in_progress_case_log) { FactoryBot.create(:case_log, :in_progress) }
it "is set to not started for an empty case log" do
expect(empty_case_log.not_started?).to be(true)
expect(empty_case_log.in_progress?).to be(false)
expect(empty_case_log.completed?).to be(false)
end
it "is set to not started for an empty case log" do
expect(in_progress_case_log.in_progress?).to be(true)
expect(in_progress_case_log.not_started?).to be(false)
expect(in_progress_case_log.completed?).to be(false)
end
end
end

13
spec/requests/case_log_controller_spec.rb

@ -127,6 +127,19 @@ RSpec.describe CaseLogsController, type: :request do
end
end
context "invalid case log params" do
let(:params) { {tenant_age: 200} }
it "returns 422" do
expect(response).to have_http_status(:unprocessable_entity)
end
it "returns an error message" do
json_response = JSON.parse(response.body)
expect(json_response["errors"]).to eq(["Tenant age must be between 0 and 120"])
end
end
context "request with invalid credentials" do
let(:basic_credentials) do
ActionController::HttpAuthentication::Basic.encode_credentials(api_username, "Oops")

Loading…
Cancel
Save