@@ -4,7 +4,7 @@ import { setup } from './helpers.js'
44
55const VALID_MESSAGE_ID = '11111111-1111-4111-8111-111111111111' ;
66const NOT_FOUND_MESSAGE_ID = '00000000-0000-4000-8000-000000000404' ;
7- const TOO_MANY_RESPONSES_MESSAGE_ID = '00000000-0000-4000-8000-000000000422 ' ;
7+ const TOO_MANY_RESPONSES_MESSAGE_ID = '00000000-0000-4000-8000-000000000500 ' ;
88
99describe ( '/api/v1/message-responses/:messageId' , ( ) => {
1010 let env ;
@@ -34,7 +34,14 @@ describe('/api/v1/message-responses/:messageId', () => {
3434 . get ( `/api/v1/message-responses/${ VALID_MESSAGE_ID } ` )
3535 . set ( { Authorization : 'banned' } )
3636 . expect ( 403 , {
37- error : 'Forbidden'
37+ errors : [
38+ {
39+ code : 'CM_FORBIDDEN' ,
40+ status : '403' ,
41+ title : 'Forbidden' ,
42+ detail : 'Client not recognised or not yet onboarded.'
43+ }
44+ ]
3845 } )
3946 . expect ( 'Content-Type' , / j s o n / , done ) ;
4047 } ) ;
@@ -43,7 +50,15 @@ describe('/api/v1/message-responses/:messageId', () => {
4350 request ( server )
4451 . get ( '/api/v1/message-responses/not-a-valid-uuid' )
4552 . expect ( 400 , {
46- error : 'Invalid messageId format'
53+ errors : [
54+ {
55+ code : 'CM_INVALID_REQUEST' ,
56+ status : '400' ,
57+ title : 'Invalid Request' ,
58+ detail : 'The messageId path parameter is not a valid UUID.' ,
59+ source : { parameter : 'messageId' }
60+ }
61+ ]
4762 } )
4863 . expect ( 'Content-Type' , / j s o n / , done ) ;
4964 } ) ;
@@ -52,17 +67,30 @@ describe('/api/v1/message-responses/:messageId', () => {
5267 request ( server )
5368 . get ( `/api/v1/message-responses/${ NOT_FOUND_MESSAGE_ID } ` )
5469 . expect ( 404 , {
55- error : 'No responses found for the specified messageId'
70+ errors : [
71+ {
72+ code : 'CM_NOT_FOUND' ,
73+ status : '404' ,
74+ title : 'Resource not found' ,
75+ detail : 'The resource at the requested URI was not found.'
76+ }
77+ ]
5678 } )
5779 . expect ( 'Content-Type' , / j s o n / , done ) ;
5880 } ) ;
5981
6082 it ( 'returns a 500 when too many responses are returned' , ( done ) => {
6183 request ( server )
6284 . get ( `/api/v1/message-responses/${ TOO_MANY_RESPONSES_MESSAGE_ID } ` )
63- . expect ( 422 , {
64- error : 'response_too_large' ,
65- message : 'There are too many responses to return.'
85+ . expect ( 500 , {
86+ errors : [
87+ {
88+ code : 'CM_TOO_MANY_RESPONSES' ,
89+ status : '500' ,
90+ title : 'Too many responses' ,
91+ detail : 'There are too many responses to return.'
92+ }
93+ ]
6694 } )
6795 . expect ( 'Content-Type' , / j s o n / , done ) ;
6896 } ) ;
@@ -72,7 +100,15 @@ describe('/api/v1/message-responses/:messageId', () => {
72100 . get ( `/api/v1/message-responses/${ VALID_MESSAGE_ID } ` )
73101 . set ( 'Content-Type' , 'text/plain' )
74102 . expect ( 415 , {
75- message : 'Unsupported media type.'
103+ errors : [
104+ {
105+ code : 'CM_UNSUPPORTED_MEDIA' ,
106+ status : '415' ,
107+ title : 'Unsupported media' ,
108+ detail : 'Invalid content-type, this API only supports application/vnd.api+json or application/json.' ,
109+ source : { header : 'Content-Type' }
110+ }
111+ ]
76112 } )
77113 . expect ( 'Content-Type' , / j s o n / , done ) ;
78114 } ) ;
@@ -82,7 +118,14 @@ describe('/api/v1/message-responses/:messageId', () => {
82118 . get ( `/api/v1/message-responses/${ VALID_MESSAGE_ID } ` )
83119 . set ( 'Prefer' , 'code=429' )
84120 . expect ( 429 , {
85- message : 'Too many requests.'
121+ errors : [
122+ {
123+ code : 'CM_QUOTA' ,
124+ status : '429' ,
125+ title : 'Too many requests' ,
126+ detail : 'You have made too many requests. Re-send the request after the time (in seconds) specified `Retry-After` header.'
127+ }
128+ ]
86129 } )
87130 . expect ( 'Content-Type' , / j s o n / , done ) ;
88131 } ) ;
@@ -94,17 +137,19 @@ describe('/api/v1/message-responses/:messageId', () => {
94137 . expect ( 'Content-Type' , / j s o n / )
95138 . expect ( ( res ) => {
96139 const { body } = res ;
97- if ( ! Array . isArray ( body ) ) throw new Error ( 'response must be an array' ) ;
98- const first = body [ 0 ] ;
99- if ( ! first . responseId ) throw new Error ( 'missing responseId' ) ;
100- if ( first . messageId !== VALID_MESSAGE_ID ) throw new Error ( 'incorrect messageId' ) ;
101- if ( ! first . messageReference ) throw new Error ( 'missing messageReference' ) ;
102- if ( ! first . code ) throw new Error ( 'missing code' ) ;
103- if ( ! first . channel ) throw new Error ( 'missing channel' ) ;
104- if ( ! first . channelStatus ) throw new Error ( 'missing channelStatus' ) ;
105- if ( ! first . cascadeType ) throw new Error ( 'missing cascadeType' ) ;
106- if ( ! first . authoredAt ) throw new Error ( 'missing authoredAt' ) ;
107- if ( ! first . timestamp ) throw new Error ( 'missing timestamp' ) ;
140+ if ( ! Array . isArray ( body . data ) ) throw new Error ( 'response must contain a data array' ) ;
141+ const first = body . data [ 0 ] ;
142+ if ( ! first . id ) throw new Error ( 'missing id' ) ;
143+ if ( first . type !== 'RecipientResponseSnapshot' ) throw new Error ( 'incorrect type' ) ;
144+ const { attributes } = first ;
145+ if ( attributes . messageId !== VALID_MESSAGE_ID ) throw new Error ( 'incorrect messageId' ) ;
146+ if ( ! attributes . messageReference ) throw new Error ( 'missing messageReference' ) ;
147+ if ( ! attributes . code ) throw new Error ( 'missing code' ) ;
148+ if ( ! attributes . channel ) throw new Error ( 'missing channel' ) ;
149+ if ( ! attributes . channelStatus ) throw new Error ( 'missing channelStatus' ) ;
150+ if ( ! attributes . cascadeType ) throw new Error ( 'missing cascadeType' ) ;
151+ if ( ! attributes . authoredAt ) throw new Error ( 'missing authoredAt' ) ;
152+ if ( ! attributes . timestamp ) throw new Error ( 'missing timestamp' ) ;
108153 } )
109154 . end ( done ) ;
110155 } ) ;
0 commit comments