@@ -104,4 +104,107 @@ module.exports = () => {
104104 } ) ;
105105 } ) ;
106106 } ) ;
107+
108+ describe ( 'GET /api/tags/:tagId' , ( ) => {
109+ it ( 'should return 400 if the tag id is not a number' , ( done ) => {
110+ request ( server )
111+ . get ( '/api/tags/abc' )
112+ . expect ( 400 )
113+ . end ( ( err , res ) => {
114+ if ( err ) {
115+ done ( err ) ;
116+ return ;
117+ }
118+
119+ // Response must satisfy the OpenAPI specification
120+ expect ( res ) . to . satisfyApiSpec ;
121+
122+ const { errors } = res . body ;
123+ const titleError = errors . find ( ( err ) => err . source . pointer === '/data/attributes/params/tagId' ) ;
124+ expect ( titleError . detail ) . to . equal ( '"params.tagId" must be a number' ) ;
125+
126+ done ( ) ;
127+ } ) ;
128+ } ) ;
129+
130+ it ( 'should return 400 if the tag id is not positive' , ( done ) => {
131+ request ( server )
132+ . get ( '/api/tags/-1' )
133+ . expect ( 400 )
134+ . end ( ( err , res ) => {
135+ if ( err ) {
136+ done ( err ) ;
137+ return ;
138+ }
139+
140+ // Response must satisfy the OpenAPI specification
141+ expect ( res ) . to . satisfyApiSpec ;
142+
143+ const { errors } = res . body ;
144+ const titleError = errors . find ( ( err ) => err . source . pointer === '/data/attributes/params/tagId' ) ;
145+ expect ( titleError . detail ) . to . equal ( '"params.tagId" must be a positive number' ) ;
146+
147+ done ( ) ;
148+ } ) ;
149+ } ) ;
150+
151+ it ( 'should return 400 if the tag id is not a whole number' , ( done ) => {
152+ request ( server )
153+ . get ( '/api/tags/0.5' )
154+ . expect ( 400 )
155+ . end ( ( err , res ) => {
156+ if ( err ) {
157+ done ( err ) ;
158+ return ;
159+ }
160+
161+ // Response must satisfy the OpenAPI specification
162+ expect ( res ) . to . satisfyApiSpec ;
163+
164+ const { errors } = res . body ;
165+ const titleError = errors . find ( ( err ) => err . source . pointer === '/data/attributes/params/tagId' ) ;
166+ expect ( titleError . detail ) . to . equal ( '"params.tagId" must be an integer' ) ;
167+
168+ done ( ) ;
169+ } ) ;
170+ } ) ;
171+
172+ it ( 'should return 404 if the tag could not be found' , ( done ) => {
173+ request ( server )
174+ . get ( '/api/tags/999999999' )
175+ . expect ( 404 )
176+ . end ( ( err , res ) => {
177+ if ( err ) {
178+ done ( err ) ;
179+ return ;
180+ }
181+
182+ // Response must satisfy the OpenAPI specification
183+ expect ( res ) . to . satisfyApiSpec ;
184+
185+ expect ( res . body . errors [ 0 ] . title ) . to . equal ( 'Tag with this id (999999999) could not be found' ) ;
186+
187+ done ( ) ;
188+ } ) ;
189+ } ) ;
190+
191+ it ( 'should return 200 in all other cases' , ( done ) => {
192+ request ( server )
193+ . get ( '/api/tags/1' )
194+ . expect ( 200 )
195+ . end ( ( err , res ) => {
196+ if ( err ) {
197+ done ( err ) ;
198+ return ;
199+ }
200+
201+ // Response must satisfy the OpenAPI specification
202+ expect ( res ) . to . satisfyApiSpec ;
203+
204+ expect ( res . body . data . id ) . to . equal ( 1 ) ;
205+
206+ done ( ) ;
207+ } ) ;
208+ } ) ;
209+ } ) ;
107210} ;
0 commit comments