Skip to content

Commit

Permalink
[wip] [ARP-86023] ARP IPF: Refactor ARP user request spec.
Browse files Browse the repository at this point in the history
  • Loading branch information
nihil2501 committed Sep 6, 2024
1 parent 88d388d commit 3a3cf9e
Showing 1 changed file with 63 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,47 +1,78 @@
# frozen_string_literal: true

require 'rails_helper'
require_relative '../../../rails_helper'
require_relative '../../../support/authentication'

RSpec.describe 'AccreditedRepresentativePortal::V0::User', type: :request do
describe '#show' do
context 'when authenticated' do
let(:arp_client_id) { 'arp' }
let(:current_representative_user) { create(:representative_user) }
let!(:in_progress_form) do
create(
:in_progress_form,
user_uuid: current_representative_user.uuid,
status: 'pending'
)
end

before do
login_as(current_representative_user)
end

it 'responds with the current_user' do
context 'when not authenticated' do
it 'responds with unauthorized' do
get '/accredited_representative_portal/v0/user'

expect(response).to have_http_status(:ok)
response_body = JSON.parse(response.body)
expect(response_body['account']['account_uuid']).to eq(current_representative_user.uuid)
expect(response_body['profile']).to eq(
{
'first_name' => current_representative_user.first_name,
'last_name' => current_representative_user.last_name,
'verified' => true
}
)
expect(response_body['in_progress_forms'][0]['form']).to eq(in_progress_form.form_id)
expect(response).to have_http_status(:unauthorized)
end
end

context 'when not authenticated' do
it 'responds with unauthorized' do
get '/accredited_representative_portal/v0/user'
context 'when authenticated' do
before { login_as(user) }

expect(response).to have_http_status(:unauthorized)
context 'as a user with an in progress form' do
first_name = Faker::Name.first_name
last_name = Faker::Name.last_name
sign_in_service_name = Faker::Company.name
in_progress_form_id = Faker::Form.id
in_progress_form_return_url = Faker::Internet.url

let(:user) do
create(:representative_user, :with_in_progress_form, {
first_name:, last_name:, sign_in_service_name:,

Check failure on line 28 in modules/accredited_representative_portal/spec/requests/accredited_representative_portal/v0/user_spec.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Layout/FirstHashElementIndentation: Use 2 spaces for indentation in a hash, relative to the first position after the preceding left parenthesis.
in_progress_form_id:, in_progress_form_return_url:
})

Check failure on line 30 in modules/accredited_representative_portal/spec/requests/accredited_representative_portal/v0/user_spec.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Layout/FirstHashElementIndentation: Indent the right brace the same as the first position after the preceding left parenthesis.
end

it 'responds with the user and their in progress form' do
get '/accredited_representative_portal/v0/user'

expect(response).to have_http_status(:ok)
expect(parsed_response).to eq({
"account" => {

Check failure on line 38 in modules/accredited_representative_portal/spec/requests/accredited_representative_portal/v0/user_spec.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Layout/FirstHashElementIndentation: Use 2 spaces for indentation in a hash, relative to the first position after the preceding left parenthesis.

Check failure on line 38 in modules/accredited_representative_portal/spec/requests/accredited_representative_portal/v0/user_spec.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
"account_uuid" => user.user_account.id

Check failure on line 39 in modules/accredited_representative_portal/spec/requests/accredited_representative_portal/v0/user_spec.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
},
"profile" => {

Check failure on line 41 in modules/accredited_representative_portal/spec/requests/accredited_representative_portal/v0/user_spec.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
"first_name" => first_name,

Check failure on line 42 in modules/accredited_representative_portal/spec/requests/accredited_representative_portal/v0/user_spec.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
"last_name" => last_name,

Check failure on line 43 in modules/accredited_representative_portal/spec/requests/accredited_representative_portal/v0/user_spec.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
"verified" => true,
"sign_in" => {
"service_name" => sign_in_service_name
}
},
"prefills_available" => [],
"in_progress_forms" => [
{
"form" => in_progress_form_id,
"metadata" => {
"version" => 1,
"return_url" => in_progress_form_return_url,
"submission" => {
"status" => false,
"error_message" => false,
"id" => false,
"timestamp" => false,
"has_attempted_submit" => false
},
"createdAt" => Time.current.to_i,
"expiresAt" => 60.days.from_now.to_i,
"lastUpdated" => Time.current.to_i,
"inProgressFormId" => InProgressForm.find_by(
form_id: in_progress_form_id,
user_account_id: user.user_account.id
).id
},
"lastUpdated" => Time.current.to_i
}
]
})
end
end
end
end
Expand Down

0 comments on commit 3a3cf9e

Please sign in to comment.