Skip to content

Commit

Permalink
Mobile: Create new Secure Messaging Threads endpoint (#12851)
Browse files Browse the repository at this point in the history
* 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
Tonksthebear authored Jun 5, 2023
1 parent 94ae98a commit 87d02f2
Show file tree
Hide file tree
Showing 8 changed files with 439 additions and 43 deletions.
24 changes: 24 additions & 0 deletions modules/mobile/app/controllers/mobile/v0/threads_controller.rb
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
1 change: 1 addition & 0 deletions modules/mobile/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@

resources :folders, only: %i[index show create destroy], defaults: { format: :json } do
resources :messages, only: [:index], defaults: { format: :json }
resources :threads, only: %i[index]
end

resources :messages, only: %i[show create destroy], defaults: { format: :json } do
Expand Down
96 changes: 53 additions & 43 deletions modules/mobile/docs/index.html

Large diffs are not rendered by default.

68 changes: 68 additions & 0 deletions modules/mobile/docs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2435,6 +2435,74 @@ paths:
security:
- Bearer: []
summary: /v0/messaging/health/folders/{id}/messages
/v0/messaging/health/folders/{id}/threads:
get:
description: List of threads in a secure messaging folder
operationId: get_folder_threads
parameters:
- description: The id of the folder that threads are being retrieved from
in: path
name: folderId
required: true
schema:
type: string
- description: The size of the pagination you want. Defaults to 10
in: query
name: pageSize,
schema:
type: string
- description: The page number to get based on your page size
in: query
name: page,
schema:
type: string
- description: The field to sort the results by
in: query
name: sortField,
schema:
type: string
enum: [ SENDER_NAME, RECIPIENT_NAME, SENT_DATE, DRAFT_DATE ]
- description: The order to sort the results by
in: query
name: sortOrder,
schema:
type: string
enum: [ ASC, DESC ]
- $ref: "#/components/parameters/InflectionHeader"
responses:
'200':
content:
application/json:
schema:
$ref: ./schemas/SecureMessageThreadList.yml
description: OK
'400':
content:
application/json:
example:
errors:
- code: 'VA900'
detail: 'Operation failed'
status: '400'
title: Operation failed
schema:
$ref: ./schemas/Errors.yml
description: Folder does not exist
'401':
content:
application/json:
schema:
$ref: ./schemas/Errors.yml
description: Unauthorized
'403':
content:
application/json:
schema:
$ref: ./schemas/Errors.yml
description: Not authorized for access to secure messages
security:
- Bearer: [ ]
summary: /v0/messaging/health/folders/{id}/threads
/v0/messaging/health/message_drafts:
post:
description: Save a new draft message
Expand Down
102 changes: 102 additions & 0 deletions modules/mobile/docs/schemas/SecureMessageThread.yml
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"
8 changes: 8 additions & 0 deletions modules/mobile/docs/schemas/SecureMessageThreadList.yml
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'
95 changes: 95 additions & 0 deletions modules/mobile/spec/request/threads_request_spec.rb
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
Loading

0 comments on commit 87d02f2

Please sign in to comment.