-
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.
- Loading branch information
Showing
15 changed files
with
514 additions
and
66 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
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,58 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'active_model' | ||
require 'common/models/form' | ||
|
||
module VAOS | ||
class MessageForm < Common::Form | ||
attribute :message_text, String # only this attribute gets set by user, everything else is overridden | ||
attribute :url, String | ||
attribute :sender_id, String | ||
attribute :appointment_request_id, String | ||
attribute :message_date_time, String | ||
attribute :message_sent, Boolean | ||
attribute :is_last_message, Boolean | ||
attribute :_appointment_request_id, String | ||
|
||
def initialize(user, request_id, json_hash = {}) | ||
super(json_hash) | ||
@user = user | ||
@appointment_request_id = request_id | ||
end | ||
|
||
# DOWNSTREAM_BUG: addresses the fact that downstream requires this as AppointmentRequestId (upper camelcase) | ||
def _appointment_request_id | ||
appointment_request_id | ||
end | ||
|
||
def url | ||
'' | ||
end | ||
|
||
def sender_id | ||
@user.icn | ||
end | ||
|
||
def message_date_time | ||
'' | ||
end | ||
|
||
def message_sent | ||
true | ||
end | ||
|
||
# rubocop:disable Naming/PredicateName | ||
def is_last_message | ||
true | ||
end | ||
# rubocop:enable Naming/PredicateName | ||
|
||
validates :message_text, length: { minimum: 1, maximum: 100 } | ||
|
||
def params | ||
raise Common::Exceptions::ValidationErrors, self unless valid? | ||
|
||
attributes | ||
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
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
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,42 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
describe VAOS::MessageForm, type: :model do | ||
let(:user) { build(:user, :vaos) } | ||
let(:request_id) { 'fake_request_id' } | ||
|
||
describe 'invalid object' do | ||
subject { described_class.new(user, request_id) } | ||
|
||
it 'validates presence of required attributes' do | ||
expect(subject).not_to be_valid | ||
expect(subject.errors.keys).to contain_exactly(:message_text) | ||
end | ||
|
||
it 'raises a Common::Exceptions::ValidationErrors when trying to fetch coerced params' do | ||
expect { subject.params }.to raise_error(Common::Exceptions::ValidationErrors) | ||
end | ||
|
||
context 'message_text length > 100' do | ||
subject do | ||
described_class.new(user, request_id, message_text: Faker::Lorem.characters(101)) | ||
end | ||
|
||
it 'raises a custom error message' do | ||
expect(subject).not_to be_valid | ||
expect(subject.errors.full_messages).to eq(['Message text is too long (maximum is 100 characters)']) | ||
end | ||
end | ||
end | ||
|
||
describe 'valid object' do | ||
subject do | ||
described_class.new(user, request_id, message_text: 'I want to see doctor Jeckyl please.') | ||
end | ||
|
||
it 'validates presence of required attributes' do | ||
expect(subject).to be_valid | ||
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
Oops, something went wrong.