-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from DSACMS/add-cbv-flow-controller
Add CbvFlows model and controller for flow logic (FFS-679)
- Loading branch information
Showing
18 changed files
with
234 additions
and
40 deletions.
There are no files selected for viewing
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,69 @@ | ||
class CbvFlowsController < ApplicationController | ||
USER_TOKEN_ENDPOINT = 'https://api-sandbox.argyle.com/v2/users'; | ||
|
||
before_action :set_cbv_flow | ||
|
||
def entry | ||
end | ||
|
||
def employer_search | ||
@argyle_user_token = fetch_and_store_argyle_token | ||
end | ||
|
||
def summary | ||
@employer = summary_employer_params[:employer] | ||
@payments = [ | ||
{ amount: 810, start: 'March 25', end: 'June 15', hours: 54, rate: 15 }, | ||
{ amount: 195, start: 'January 1', end: 'February 23', hours: 13, rate: 15 } | ||
] | ||
end | ||
|
||
def reset | ||
session[:cbv_flow_id] = nil | ||
session[:argyle_user_token] = nil | ||
redirect_to root_url | ||
end | ||
|
||
private | ||
|
||
def set_cbv_flow | ||
if session[:cbv_flow_id] | ||
@cbv_flow = CbvFlow.find(session[:cbv_flow_id]) | ||
else | ||
# TODO: This case_number would be provided by the case worker when they send the initial invite | ||
@cbv_flow = CbvFlow.create(case_number: 'ABC1234') | ||
session[:cbv_flow_id] = @cbv_flow.id | ||
end | ||
end | ||
|
||
def next_path | ||
case params[:action] | ||
when 'entry' | ||
cbv_flow_employer_search_path | ||
when 'employer_search' | ||
cbv_flow_summary_path | ||
when 'summary' | ||
root_url | ||
end | ||
end | ||
helper_method :next_path | ||
|
||
def fetch_and_store_argyle_token | ||
return session[:argyle_user_token] if session[:argyle_user_token].present? | ||
|
||
raise "ARGYLE_API_TOKEN environment variable is blank. Make sure you have the .env.local from 1Password." if ENV['ARGYLE_API_TOKEN'].blank? | ||
|
||
res = Net::HTTP.post(URI.parse(USER_TOKEN_ENDPOINT), "", {"Authorization" => "Basic #{ENV['ARGYLE_API_TOKEN']}"}) | ||
parsed = JSON.parse(res.body) | ||
raise "Argyle API error: #{parsed['detail']}" if res.code.to_i >= 400 | ||
|
||
@cbv_flow.update(argyle_user_id: parsed['id']) | ||
session[:argyle_user_token] = parsed['user_token'] | ||
|
||
parsed['user_token'] | ||
end | ||
|
||
def summary_employer_params | ||
params.permit(:employer) | ||
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
class PagesController < ApplicationController | ||
def welcome | ||
def home | ||
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 |
---|---|---|
@@ -1,26 +1,4 @@ | ||
class ProvidersController < ApplicationController | ||
USER_TOKEN_ENDPOINT = "https://api-sandbox.argyle.com/v2/users" | ||
|
||
def index | ||
res = Net::HTTP.post(URI.parse(USER_TOKEN_ENDPOINT), "", { "Authorization" => "Basic #{ENV['ARGYLE_API_TOKEN']}" }) | ||
|
||
@user_token = JSON.parse(res.body)["user_token"] | ||
end | ||
|
||
def search | ||
end | ||
|
||
def confirm | ||
@employer = employer_params[:employer] | ||
@payments = [ | ||
{ amount: 810, start: "March 25", end: "June 15", hours: 54, rate: 15 }, | ||
{ amount: 195, start: "January 1", end: "February 23", hours: 13, rate: 15 } | ||
] | ||
end | ||
|
||
private | ||
|
||
def employer_params | ||
params.permit(:employer) | ||
end | ||
end |
File renamed without changes.
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
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,2 @@ | ||
class CbvFlow < ApplicationRecord | ||
end |
10 changes: 5 additions & 5 deletions
10
app/views/providers/index.html.erb → app/views/cbv_flows/employer_search.html.erb
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 |
---|---|---|
@@ -1,16 +1,16 @@ | ||
<% content_for :head do %> | ||
<%= tag :meta, name: :argyle_user_token, content: @user_token %> | ||
<%= tag :meta, name: :argyle_user_token, content: @argyle_user_token %> | ||
<%= tag :meta, name: :argyle_sandbox, content: ENV['ARGYLE_SANDBOX'] %> | ||
<% end %> | ||
|
||
<h2>Get payment info from your employer.</h2> | ||
|
||
<form data-controller="providers" action="/providers/confirm" method="get"> | ||
<form data-controller="cbv-flows" action="<%= next_path %>" method="get"> | ||
<label class="usa-label" for="employer">Search for an employer</label> | ||
<div class="usa-combo-box margin-bottom-3" data-action="input->providers#search"> | ||
<select class="usa-select" name="employer" id="employer" data-providers-target="options" data-action="change->providers#select"> | ||
<div class="usa-combo-box margin-bottom-3" data-action="input->cbv-flows#search"> | ||
<select class="usa-select" name="employer" id="employer" data-cbv-flows-target="options" data-action="change->cbv-flows#select"> | ||
<option value>Select an employer</option> | ||
</select> | ||
</div> | ||
<button data-action="click->providers#submit" class="usa-button usa-button--outline" disabled="disabled" type="submit" data-providers-target="continue">Continue</button> | ||
<button data-action="click->cbv-flows#submit" class="usa-button usa-button--outline" disabled="disabled" type="submit" data-cbv-flows-target="continue">Continue</button> | ||
</form> |
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
File renamed without changes.
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,8 @@ | ||
<h1>Welcome to Verify.gov</h1> | ||
<h2>This website can help you get approved for Medicaid</h2> | ||
|
||
<p>Get started here by requesting a link from your caseworker.</p> | ||
|
||
<%= link_to cbv_flow_entry_path do %> | ||
<button class="usa-button usa-button--outline" type="button">Start Flow Manually</button> | ||
<% 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,9 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
|
||
yarn install | ||
bundle install | ||
|
||
bin/rails db:migrate | ||
|
||
echo "Done. Run bin/dev to run the local development server." |
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
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 @@ | ||
class CreateCbvFlows < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :cbv_flows do |t| | ||
t.string :case_number | ||
t.string :argyle_user_id | ||
|
||
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.
Binary file not shown.
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,97 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe CbvFlowsController do | ||
def stub_environment_variable(variable, value, &block) | ||
previous_value = ENV[variable] | ||
ENV[variable] = value | ||
block.call | ||
ENV[variable] = previous_value | ||
end | ||
|
||
around do |ex| | ||
stub_environment_variable("ARGYLE_API_TOKEN", "foobar", &ex) | ||
end | ||
|
||
describe "#entry" do | ||
render_views | ||
|
||
it "renders properly" do | ||
get :entry | ||
|
||
expect(response).to be_successful | ||
end | ||
|
||
it "sets a CbvFlow object in the session" do | ||
expect { get :entry } | ||
.to change { session[:cbv_flow_id] } | ||
.from(nil) | ||
.to(be_an(Integer)) | ||
end | ||
end | ||
|
||
describe "#employer_search" do | ||
let(:cbv_flow) { CbvFlow.create(case_number: "ABC1234") } | ||
let(:argyle_mock_response) do | ||
{ | ||
id: "abc-def-ghi", | ||
user_token: "foobar" | ||
} | ||
end | ||
|
||
before do | ||
session[:cbv_flow_id] = cbv_flow.id | ||
|
||
allow(Net::HTTP).to receive(:post) | ||
.with(URI(CbvFlowsController::USER_TOKEN_ENDPOINT), anything, anything) | ||
.and_return(instance_double(Net::HTTPOK, code: "200", body: JSON.generate(argyle_mock_response))) | ||
end | ||
|
||
context "when rendering views" do | ||
render_views | ||
|
||
it "renders properly" do | ||
get :employer_search | ||
expect(response).to be_successful | ||
end | ||
end | ||
|
||
context "when the user does not have an Argyle token" do | ||
it "requests a new token from Argyle" do | ||
get :employer_search | ||
expect(Net::HTTP).to have_received(:post).once | ||
end | ||
|
||
it "saves the token in the CbvFlow model" do | ||
expect { get :employer_search } | ||
.to change { cbv_flow.reload.argyle_user_id } | ||
.from(nil) | ||
.to(argyle_mock_response[:id]) | ||
end | ||
end | ||
|
||
context "when the user already has an Argyle token in their session" do | ||
before do | ||
session[:argyle_user_token] = argyle_mock_response[:user_token] | ||
end | ||
|
||
it "does not request a new User Token from Argyle" do | ||
get :employer_search | ||
expect(Net::HTTP).not_to have_received(:post) | ||
end | ||
end | ||
end | ||
|
||
describe "#summary" do | ||
render_views | ||
|
||
let(:cbv_flow) { CbvFlow.create(case_number: "ABC1234", argyle_user_id: "abc-def-ghi") } | ||
before do | ||
session[:cbv_flow_id] = cbv_flow.id | ||
end | ||
|
||
it "renders properly" do | ||
get :summary | ||
expect(response).to be_successful | ||
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,5 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe CbvFlow, type: :model do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
end |
4 changes: 2 additions & 2 deletions
4
spec/views/pages/welcome.html.erb_spec → spec/views/pages/home.html.erb_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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe "pages/welcome.html.erb", type: :view do | ||
RSpec.describe "pages/home.html.erb", type: :view do | ||
it "displays the gov banner" do | ||
render template: "pages/welcome", layout: "layouts/application" | ||
render template: "pages/home", layout: "layouts/application" | ||
expect(rendered).to match "An official website of the United States government" | ||
end | ||
end |