-
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.
Mobile: Create new Secure Messaging Threads endpoint (#12851)
* Create new endpoint * Rubocop * Update documentation and add new error response * Update parameter name to what front end uses * Update spec to new directory structure * Reference correct 200 schema * Update spec to check specific return * Remove required from parameters that aren't required * Update documentation description
- Loading branch information
1 parent
94ae98a
commit 87d02f2
Showing
8 changed files
with
439 additions
and
43 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
modules/mobile/app/controllers/mobile/v0/threads_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,24 @@ | ||
# frozen_string_literal: true | ||
|
||
module Mobile | ||
module V0 | ||
class ThreadsController < MessagingController | ||
def index | ||
resource = client.get_folder_threads( | ||
params[:folder_id].to_s, | ||
params[:page_size], | ||
params[:page], | ||
params[:sort_field], | ||
params[:sort_order] | ||
) | ||
|
||
raise Common::Exceptions::RecordNotFound, params[:folder_id] if resource.blank? | ||
|
||
render json: resource.data, | ||
serializer: CollectionSerializer, | ||
each_serializer: MyHealth::V1::ThreadsSerializer, | ||
meta: resource.metadata | ||
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
Large diffs are not rendered by default.
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
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,102 @@ | ||
type: object | ||
required: | ||
- id | ||
- type | ||
- attributes | ||
- links | ||
properties: | ||
id: | ||
type: string | ||
example: 0 | ||
type: | ||
type: string | ||
example: "message_threads" | ||
attributes: | ||
type: object | ||
required: | ||
- threadId | ||
- folderId | ||
- messageId | ||
- threadPageSize | ||
- messageCount | ||
- category | ||
- subject | ||
- triageGroupName | ||
- sentDate | ||
- draftDate | ||
- senderId | ||
- senderName | ||
- recipientName | ||
- recipientId | ||
- proxySenderName | ||
- hasAttachment | ||
- unsentDrafts | ||
- unreadMessages | ||
properties: | ||
threadId: | ||
type: integer | ||
example: 1234567 | ||
folderId: | ||
type: integer | ||
example: 0 | ||
messageId: | ||
type: integer | ||
example: 1234567 | ||
threadPageSize: | ||
type: integer | ||
example: 123 | ||
messageCount: | ||
type: integer | ||
example: 123 | ||
category: | ||
type: string | ||
enum: [OTHERS, COVID, APPOINTMENTS, MEDICATIONS, TEST_RESULT, EDUCATION] | ||
example: MEDICATIONS | ||
subject: | ||
type: string | ||
example: Medication Inquiry | ||
triageGroupName: | ||
type: string | ||
nullable: true | ||
example: "Triage_Group_5" | ||
sentDate: | ||
type: string | ||
nullable: true | ||
example: 2017-09-01T16:09:56.000Z | ||
draftDate: | ||
type: string | ||
nullable: true | ||
example: 2017-09-01T16:09:56.000Z | ||
senderId: | ||
type: integer | ||
example: 541200 | ||
senderName: | ||
type: string | ||
example: "DOE, JANE" | ||
recipientId: | ||
type: integer | ||
example: 399955 | ||
recipientName: | ||
type: string | ||
example: "ROE, RICHARD" | ||
proxySenderName: | ||
type: string | ||
nullable: true | ||
example: "SMITH, JOHN" | ||
hasAttachment: | ||
type: boolean | ||
example: false | ||
unsentDrafts: | ||
type: boolean | ||
example: false | ||
unreadMessages: | ||
type: boolean | ||
example: true | ||
links: | ||
type: object | ||
required: | ||
- self | ||
properties: | ||
self: | ||
type: string | ||
example: http://www.example.com/my_health/v1/messaging/threads/7298505" |
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 @@ | ||
type: object | ||
required: | ||
- data | ||
properties: | ||
data: | ||
type: array | ||
items: | ||
$ref: './SecureMessageThread.yml' |
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,95 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
require_relative '../support/helpers/iam_session_helper' | ||
require_relative '../support/helpers/mobile_sm_client_helper' | ||
|
||
RSpec.describe 'Mobile Messages Integration', type: :request do | ||
include Mobile::MessagingClientHelper | ||
include SchemaMatchers | ||
|
||
let(:user_id) { '10616687' } | ||
let(:inbox_id) { 0 } | ||
let(:message_id) { 573_059 } | ||
let(:va_patient) { true } | ||
|
||
before do | ||
allow_any_instance_of(MHVAccountTypeService).to receive(:mhv_account_type).and_return(mhv_account_type) | ||
allow(Mobile::V0::Messaging::Client).to receive(:new).and_return(authenticated_client) | ||
iam_sign_in(build(:iam_user, iam_mhv_id: '123')) | ||
end | ||
|
||
context 'Basic User' do | ||
let(:mhv_account_type) { 'Basic' } | ||
|
||
it 'is not authorized' do | ||
get "/mobile/v0/messaging/health/folders/#{inbox_id}/threads", | ||
headers: iam_headers, | ||
params: { page_size: '5', page: '1', sort_field: 'SENDER_NAME', sort_order: 'ASC' } | ||
expect(response).not_to be_successful | ||
expect(response).to have_http_status(:forbidden) | ||
end | ||
end | ||
|
||
context 'Advanced User' do | ||
let(:mhv_account_type) { 'Advanced' } | ||
|
||
it 'is not authorized' do | ||
get "/mobile/v0/messaging/health/folders/#{inbox_id}/threads", | ||
headers: iam_headers, | ||
params: { page_size: '5', page: '1', sort_field: 'SENDER_NAME', sort_order: 'ASC' } | ||
expect(response).not_to be_successful | ||
expect(response).to have_http_status(:forbidden) | ||
end | ||
end | ||
|
||
context 'Premium User' do | ||
let(:mhv_account_type) { 'Premium' } | ||
let(:example_thread) do | ||
{ 'id' => '7298505', | ||
'type' => 'message_threads', | ||
'attributes' => | ||
{ 'threadId' => 7_298_505, | ||
'folderId' => 0, | ||
'messageId' => 7_298_506, | ||
'threadPageSize' => 454, | ||
'messageCount' => 1, | ||
'category' => 'EDUCATION', | ||
'subject' => 'Education Inquiry', | ||
'triageGroupName' => 'WORKLOAD CAPTURE_SLC 4_Mohammad', | ||
'sentDate' => '2023-02-15T17:01:55.000Z', | ||
'draftDate' => nil, | ||
'senderId' => 20_029, | ||
'senderName' => 'ISLAM, MOHAMMAD RAFIQ', | ||
'recipientName' => 'ECSTEN, THOMAS ', | ||
'recipientId' => 6_820_911, | ||
'proxySenderName' => nil, | ||
'hasAttachment' => false, | ||
'unsentDrafts' => false, | ||
'unreadMessages' => false }, | ||
'links' => { 'self' => 'http://www.example.com/my_health/v1/messaging/threads/7298505' } } | ||
end | ||
|
||
it 'responds to GET #index' do | ||
VCR.use_cassette('sm_client/threads/gets_threads_in_a_folder') do | ||
get "/mobile/v0/messaging/health/folders/#{inbox_id}/threads", | ||
headers: iam_headers, | ||
params: { page_size: '5', page: '1', sort_field: 'SENDER_NAME', sort_order: 'ASC' } | ||
end | ||
|
||
expect(response).to be_successful | ||
first_thread = response.parsed_body.dig('data', 0) | ||
expect(first_thread).to match(example_thread) | ||
end | ||
|
||
it 'responds 400 to GET #index with none existent folder' do | ||
VCR.use_cassette('mobile/messages/get_threads_in_folder_400') do | ||
get '/mobile/v0/messaging/health/folders/100/threads', | ||
headers: iam_headers, | ||
params: { page_size: '5', page: '1', sort_field: 'SENDER_NAME', sort_order: 'ASC' } | ||
end | ||
|
||
expect(response).to have_http_status(:bad_request) | ||
end | ||
end | ||
end |
Oops, something went wrong.