-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '97-add_endpoint_for_avg_number_of_days' into 97-average…
…_number_of_days_db
- Loading branch information
Showing
6 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
app/controllers/v0/average_days_for_claim_completion_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# 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 | ||
render json: { | ||
average_days: rtn.present? ? rtn.average_days : -1.0 | ||
} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# frozen_string_literal: true | ||
|
||
class AverageDaysForClaimCompletion < ApplicationRecord | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
db/migrate/20240411153944_create_average_days_for_claim_completions.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# This migration comes from vye (originally 20240229184515) | ||
class CreateAverageDaysForClaimCompletions < ActiveRecord::Migration[7.1] | ||
def change | ||
create_table :average_days_for_claim_completions do |t| | ||
t.float average_days | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
39 changes: 39 additions & 0 deletions
39
spec/controllers/v0/average_days_for_claim_completion_controller_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |