Skip to content

Commit

Permalink
97 Added SPEC file for unittest coverage and also linted everything.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbackfieldVA committed Apr 12, 2024
1 parent 6cbd764 commit 823a1e8
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# frozen_string_literal: true

module V0
class AverageDaysForClaimCompletionController < ApplicationController
service_tag 'average-days-to-completion'
skip_before_action :authenticate, only: :index

def index
rtn = AverageDaysForClaimCompletion.order("created_at DESC").first
rtn = AverageDaysForClaimCompletion.order('created_at DESC').first
render json: {
average_days: rtn.present? ? rtn.average_days : -1.0
}
Expand Down
4 changes: 3 additions & 1 deletion app/models/average_days_for_claim_completion.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

class AverageDaysForClaimCompletion < ApplicationRecord
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe V0::AverageDaysForClaimCompletionController, type: :controller do
context 'when querying with nothing in db' do
it 'returns -1 for value' do
get :index
expect(response).to have_http_status(:ok)
expect(JSON.parse(response.body)['average_days']).to eq(-1.0)
end
end

context 'when querying with record in db' do
before do
AverageDaysForClaimCompletion.create(average_days: 100)
end

it 'returns the value' do
get :index
expect(response).to have_http_status(:ok)
expect(JSON.parse(response.body)['average_days']).to eq(100.0)
end
end

context 'when querying with multiple records in db' do
before do
AverageDaysForClaimCompletion.create(average_days: 100)
AverageDaysForClaimCompletion.create(average_days: 200)
AverageDaysForClaimCompletion.create(average_days: 300)
end

it 'returns the value' do
get :index
expect(response).to have_http_status(:ok)
expect(JSON.parse(response.body)['average_days']).to eq(300.0)
end
end
end

0 comments on commit 823a1e8

Please sign in to comment.