-
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.
arf-80297 load ogc_number and poa_codes into the RepresentatveUserLoader
- Loading branch information
1 parent
4f082e5
commit 9eb26e1
Showing
9 changed files
with
174 additions
and
51 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
...igrate/20240418233828_create_accredited_representative_portal_verified_representatives.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,18 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateAccreditedRepresentativePortalVerifiedRepresentatives < ActiveRecord::Migration[7.1] | ||
def change | ||
create_table :accredited_representative_portal_verified_representatives do |t| | ||
t.string :ogc_registration_number, null: false | ||
t.string :first_name | ||
t.string :last_name | ||
t.string :middle_initial | ||
t.string :email, null: false | ||
|
||
t.timestamps | ||
|
||
t.index 'ogc_registration_number', unique: true, name: 'index_verified_representatives_on_ogc_number' | ||
t.index 'email', unique: true, name: 'index_verified_representatives_on_email' | ||
end | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
30 changes: 30 additions & 0 deletions
30
...resentative_portal/app/models/accredited_representative_portal/verified_representative.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,30 @@ | ||
# frozen_string_literal: true | ||
|
||
module AccreditedRepresentativePortal | ||
# Represents a verified representative within the Accredited Representative Portal. | ||
# This class is responsible for managing the data associated with individuals who have | ||
# been verified as representatives by the ARF Team. The model includes validations to ensure the presence and | ||
# uniqueness of identifiers such as the OGC registration number and email. | ||
# | ||
# Currently, this model is populated manually by engineers as users are accepted into the pilot program. | ||
# There is potential for a UI to be developed in the future that would facilitate administrative tasks | ||
# related to managing verified representatives. | ||
# | ||
# A more automated process may be possible once OGC and MPI data facilitate such a process. | ||
# | ||
# == Associations | ||
# This model may eventually be associated with AccreditedIndividuals to pull POA codes, | ||
# if they exist, based on the OGC registration number. It currently does so via a helper method. | ||
class VerifiedRepresentative < ApplicationRecord | ||
validates :ogc_registration_number, presence: true, uniqueness: { case_sensitive: false } | ||
validates :first_name, presence: true | ||
validates :last_name, presence: true | ||
validates :email, presence: true, uniqueness: true, format: { with: URI::MailTo::EMAIL_REGEXP } | ||
|
||
# NOTE: given there will be RepresentativeUsers who are not VerifiedRepresentatives, | ||
# it's okay for this to return nil | ||
def poa_codes | ||
AccreditedIndividual.find_by(registration_number: ogc_registration_number)&.poa_codes | ||
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
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
11 changes: 11 additions & 0 deletions
11
modules/accredited_representative_portal/spec/factories/verified_representative.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,11 @@ | ||
# frozen_string_literal: true | ||
|
||
FactoryBot.define do | ||
factory :verified_representative, class: 'AccreditedRepresentativePortal::VerifiedRepresentative' do | ||
ogc_registration_number { Faker::Number.unique.number(digits: 6).to_s } | ||
first_name { Faker::Name.first_name } | ||
last_name { Faker::Name.last_name } | ||
middle_initial { Faker::Name.middle_name } | ||
email { Faker::Internet.unique.email } | ||
end | ||
end |
49 changes: 49 additions & 0 deletions
49
...tive_portal/spec/models/accredited_representatiive_portal/verified_representative_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,49 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe AccreditedRepresentativePortal::VerifiedRepresentative, type: :model do | ||
describe 'validations' do | ||
subject { build(:verified_representative) } | ||
|
||
it { is_expected.to validate_presence_of(:ogc_registration_number) } | ||
it { is_expected.to validate_uniqueness_of(:ogc_registration_number).case_insensitive } | ||
it { is_expected.to validate_presence_of(:first_name) } | ||
it { is_expected.to validate_presence_of(:last_name) } | ||
it { is_expected.to validate_presence_of(:email) } | ||
it { is_expected.to validate_uniqueness_of(:email) } | ||
|
||
it do | ||
expect(subject).to allow_value('[email protected]').for(:email) | ||
expect(subject).not_to allow_value('invalid_email').for(:email) | ||
end | ||
end | ||
|
||
describe '#poa_codes' do | ||
let(:ogc_registration_number) { '12345' } | ||
|
||
context 'when an AccreditedIndividual with a matching registration number exists' do | ||
let!(:accredited_individual) do | ||
create(:accredited_individual, :with_organizations, registration_number: ogc_registration_number) | ||
end | ||
let(:verified_representative) do | ||
create(:verified_representative, ogc_registration_number:) | ||
end | ||
|
||
it 'returns the correct POA codes' do | ||
expect(verified_representative.poa_codes).to be_present | ||
expect(verified_representative.poa_codes).to match_array(accredited_individual.poa_codes) | ||
end | ||
end | ||
|
||
context 'when no AccreditedIndividual with a matching registration number exists' do | ||
let(:verified_representative) do | ||
create(:verified_representative, ogc_registration_number:) | ||
end | ||
|
||
it 'returns nil' do | ||
expect(verified_representative.poa_codes).to be_nil | ||
end | ||
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