@@ -185,14 +185,14 @@ describe('Quizzes', () => {
185185 done ( ) ;
186186 } ) ;
187187 } ) ;
188- describe ( 'DELETE /:id' , ( ) => {
189- it ( 'should return 404 if the quizz doesn\'t exist and therefore can\'t be deleted' , function ( done ) {
188+ describe ( 'DELETE /:id' , ( ) => {
189+ it ( 'should return 404 if the quizz doesn\'t exist and therefore can\'t be deleted' , function ( done ) {
190190 chai
191- . request ( app )
192- . delete ( '/quizzes/1024/delete' )
193- . end ( ( err , res ) => {
194- res . should . have . status ( 404 ) ;
195- } ) ;
191+ . request ( app )
192+ . delete ( '/quizzes/1024/delete' )
193+ . end ( ( err , res ) => {
194+ res . should . have . status ( 404 ) ;
195+ } ) ;
196196 done ( ) ;
197197 } ) ;
198198 it ( 'should return 204 if deleted successfully' , function ( done ) {
@@ -205,4 +205,82 @@ describe('Quizzes', () => {
205205 done ( ) ;
206206 } ) ;
207207 } ) ;
208+ describe ( 'PATCH /:id' , ( ) => {
209+ it ( 'should return 204 if we try to modify both the path_file and add a new image' , function ( done ) {
210+ chai
211+ . request ( app )
212+ . patch ( '/quizzes/1' )
213+ . field ( 'path_file' , 'matrix.jpg' )
214+ . attach ( 'file' , fs . readFileSync ( path . join ( __dirname , '/assets/matrix.jpg' ) ) , 'matrix.jpg' )
215+ . end ( ( err , res ) => {
216+ res . should . have . status ( 204 ) ;
217+ } ) ;
218+ done ( ) ;
219+ } ) ;
220+ it ( 'should return 404 if the quizz doesn\'t exist and therefore can\'t be patched' , function ( done ) {
221+ chai
222+ . request ( app )
223+ . patch ( '/quizzes/1024' )
224+ . field ( 'title' , 'Totoro' )
225+ . end ( ( err , res ) => {
226+ res . should . have . status ( 404 ) ;
227+ } ) ;
228+ done ( ) ;
229+ } ) ;
230+ it ( 'should return 204 and patch title' , function ( done ) {
231+ chai
232+ . request ( app )
233+ . patch ( '/quizzes/1' )
234+ . field ( 'title' , "les animaux d''afrique" )
235+ . end ( ( err , res ) => {
236+ res . should . have . status ( 204 ) ;
237+ } ) ;
238+ done ( ) ;
239+ } ) ;
240+ it ( 'should return 204 and patch difficulty' , function ( done ) {
241+ chai
242+ . request ( app )
243+ . patch ( '/quizzes/1' )
244+ . field ( 'difficulty' , 3 )
245+ . end ( ( err , res ) => {
246+ res . should . have . status ( 204 ) ;
247+ } ) ;
248+ done ( ) ;
249+ } ) ;
250+ it ( 'should return 500 if we try to modify the path_file without a new fille associated' , function ( done ) {
251+ chai
252+ . request ( app )
253+ . patch ( '/quizzes/1' )
254+ . field ( 'path_file' , 'test.jpg' )
255+ . end ( ( err , res ) => {
256+ res . should . have . status ( 500 ) ;
257+ } ) ;
258+ done ( ) ;
259+ } ) ;
260+ it ( 'should return 500 if we try to modify the path_file and another field without a new fille associated' , function ( done ) {
261+ chai
262+ . request ( app )
263+ . patch ( '/quizzes/1' )
264+ . field ( 'path_file' , 'test.jpg' )
265+ . field ( 'title' , 'Matrix' )
266+ . end ( ( err , res ) => {
267+ res . should . have . status ( 500 ) ;
268+ } ) ;
269+ done ( ) ;
270+ } ) ;
271+ it ( 'should return 204 if we try to modify all infos of a quizz but also the image' , function ( done ) {
272+ chai
273+ . request ( app )
274+ . patch ( '/quizzes/4' )
275+ . field ( 'title' , 'Matrix' )
276+ . field ( 'difficulty' , 2 )
277+ . field ( 'id_creator' , 1 )
278+ . field ( 'path_file' , 'matrix.jpg' )
279+ . attach ( 'file' , fs . readFileSync ( path . join ( __dirname , '/assets/matrix.jpg' ) ) , 'matrix.jpg' )
280+ . end ( ( err , res ) => {
281+ res . should . have . status ( 204 ) ;
282+ } ) ;
283+ done ( ) ;
284+ } ) ;
285+ } ) ;
208286} ) ;
0 commit comments