@@ -4,7 +4,7 @@ import { expect } from 'chai';
44import { before , describe , it , after } from 'mocha' ;
55import type { Response } from 'supertest' ;
66
7- import { getCredentials , api , request , credentials , methodCall } from '../../../data/api-data' ;
7+ import { getCredentials , api , request , credentials } from '../../../data/api-data' ;
88import { deleteDepartment } from '../../../data/livechat/department' ;
99import {
1010 closeOmnichannelRoom ,
@@ -19,7 +19,7 @@ import {
1919 startANewLivechatRoomAndTakeIt ,
2020 takeInquiry ,
2121} from '../../../data/livechat/rooms' ;
22- import { parseMethodResponse , sleep } from '../../../data/livechat/utils' ;
22+ import { sleep } from '../../../data/livechat/utils' ;
2323import {
2424 removePermissionFromAllRoles ,
2525 restorePermissionToRoles ,
@@ -324,7 +324,7 @@ describe('LIVECHAT - inquiries', () => {
324324 } ) ;
325325 } ) ;
326326
327- describe ( 'livechat: returnAsInquiry' , ( ) => {
327+ describe ( 'livechat/inquiries. returnAsInquiry' , ( ) => {
328328 let testUser : { user : IUser ; credentials : Credentials } ;
329329 before ( async ( ) => {
330330 const user = await createUser ( ) ;
@@ -344,81 +344,54 @@ describe('LIVECHAT - inquiries', () => {
344344 it ( 'should throw an error if user doesnt have view-l-room permission' , async ( ) => {
345345 await removePermissionFromAllRoles ( 'view-l-room' ) ;
346346 const { body } = await request
347- . post ( methodCall ( 'livechat: returnAsInquiry' ) )
347+ . post ( api ( 'livechat/inquiries. returnAsInquiry' ) )
348348 . set ( credentials )
349- . send ( {
350- message : JSON . stringify ( {
351- method : 'livechat:returnAsInquiry' ,
352- params : [ 'test' ] ,
353- id : 'id' ,
354- msg : 'method' ,
355- } ) ,
356- } )
349+ . send ( { roomId : 'test' } )
357350 . expect ( 'Content-Type' , 'application/json' )
358- . expect ( 200 ) ;
359-
360- const response = parseMethodResponse ( body ) ;
351+ . expect ( 403 ) ;
361352
362- expect ( response . error . error ) . to . be . equal ( 'error-not-allowed' ) ;
353+ expect ( body ) . to . have . property ( 'success' , false ) ;
354+ expect ( body . error ) . to . have . equal ( 'User does not have the permissions required for this action [error-unauthorized]' ) ;
363355 } ) ;
364356 it ( 'should fail if provided room doesnt exists' , async ( ) => {
365357 await restorePermissionToRoles ( 'view-l-room' ) ;
366358 const { body } = await request
367- . post ( methodCall ( 'livechat: returnAsInquiry' ) )
359+ . post ( api ( 'livechat/inquiries. returnAsInquiry' ) )
368360 . set ( credentials )
369361 . send ( {
370- message : JSON . stringify ( {
371- method : 'livechat:returnAsInquiry' ,
372- params : [ 'test' ] ,
373- id : 'id' ,
374- msg : 'method' ,
375- } ) ,
362+ roomId : 'test' ,
376363 } )
377364 . expect ( 'Content-Type' , 'application/json' )
378- . expect ( 200 ) ;
365+ . expect ( 400 ) ;
379366
380- const response = parseMethodResponse ( body ) ;
381- expect ( response . error . error ) . to . be . equal ( 'error-invalid- room' ) ;
367+ expect ( body ) . to . have . property ( 'success' , false ) ;
368+ expect ( body ) . to . have . property ( 'error' , 'error- room-not-found ') ;
382369 } ) ;
383370 it ( 'should fail if room is not a livechat room' , async ( ) => {
384371 const { body } = await request
385- . post ( methodCall ( 'livechat: returnAsInquiry' ) )
372+ . post ( api ( 'livechat/inquiries. returnAsInquiry' ) )
386373 . set ( credentials )
387- . send ( {
388- message : JSON . stringify ( {
389- method : 'livechat:returnAsInquiry' ,
390- params : [ 'GENERAL' ] ,
391- id : 'id' ,
392- msg : 'method' ,
393- } ) ,
394- } )
374+ . send ( { roomId : 'GENERAL' } )
395375 . expect ( 'Content-Type' , 'application/json' )
396- . expect ( 200 ) ;
376+ . expect ( 400 ) ;
397377
398- const response = parseMethodResponse ( body ) ;
399- expect ( response . error . error ) . to . be . equal ( 'error-invalid- room' ) ;
378+ expect ( body ) . to . have . property ( 'success' , false ) ;
379+ expect ( body ) . to . have . property ( 'error' , 'error- room-not-found ') ;
400380 } ) ;
401381 it ( 'should fail if room is closed' , async ( ) => {
402382 const visitor = await createVisitor ( ) ;
403383 const room = await createLivechatRoom ( visitor . token ) ;
404384 await closeOmnichannelRoom ( room . _id ) ;
405385
406386 const { body } = await request
407- . post ( methodCall ( 'livechat: returnAsInquiry' ) )
387+ . post ( api ( 'livechat/inquiries. returnAsInquiry' ) )
408388 . set ( credentials )
409- . send ( {
410- message : JSON . stringify ( {
411- method : 'livechat:returnAsInquiry' ,
412- params : [ room . _id ] ,
413- id : 'id' ,
414- msg : 'method' ,
415- } ) ,
416- } )
389+ . send ( { roomId : room . _id } )
417390 . expect ( 'Content-Type' , 'application/json' )
418- . expect ( 200 ) ;
391+ . expect ( 400 ) ;
419392
420- const response = parseMethodResponse ( body ) ;
421- expect ( response . error . error ) . to . be . equal ( 'room-closed' ) ;
393+ expect ( body ) . to . have . property ( 'success' , false ) ;
394+ expect ( body ) . to . have . property ( 'error' , 'room-closed' ) ;
422395 } ) ;
423396 describe ( 'no serving' , ( ) => {
424397 let room : IOmnichannelRoom ;
@@ -431,21 +404,14 @@ describe('LIVECHAT - inquiries', () => {
431404 } ) ;
432405 it ( 'should fail if no one is serving the room' , async ( ) => {
433406 const { body } = await request
434- . post ( methodCall ( 'livechat: returnAsInquiry' ) )
407+ . post ( api ( 'livechat/inquiries. returnAsInquiry' ) )
435408 . set ( credentials )
436- . send ( {
437- message : JSON . stringify ( {
438- method : 'livechat:returnAsInquiry' ,
439- params : [ room . _id ] ,
440- id : 'id' ,
441- msg : 'method' ,
442- } ) ,
443- } )
409+ . send ( { roomId : room . _id } )
444410 . expect ( 'Content-Type' , 'application/json' )
445411 . expect ( 200 ) ;
446412
447- const response = parseMethodResponse ( body ) ;
448- expect ( response . result ) . to . be . false ;
413+ expect ( body ) . to . have . property ( 'success' , true ) ;
414+ expect ( body ) . to . have . property ( 'result' , false ) ;
449415 } ) ;
450416 } ) ;
451417
@@ -460,21 +426,14 @@ describe('LIVECHAT - inquiries', () => {
460426 await takeInquiry ( inq . _id , testUser . credentials ) ;
461427
462428 const { body } = await request
463- . post ( methodCall ( 'livechat: returnAsInquiry' ) )
429+ . post ( api ( 'livechat/inquiries. returnAsInquiry' ) )
464430 . set ( testUser . credentials )
465- . send ( {
466- message : JSON . stringify ( {
467- method : 'livechat:returnAsInquiry' ,
468- params : [ room . _id ] ,
469- id : 'id' ,
470- msg : 'method' ,
471- } ) ,
472- } )
431+ . send ( { roomId : room . _id } )
473432 . expect ( 'Content-Type' , 'application/json' )
474433 . expect ( 200 ) ;
475434
476- const response = parseMethodResponse ( body ) ;
477- expect ( response . result ) . to . be . true ;
435+ expect ( body ) . to . have . property ( 'success' , true ) ;
436+ expect ( body ) . to . have . property ( 'result' , true ) ;
478437 } ) ;
479438 ( IS_EE ? it : it . skip ) ( 'should appear on users queued elements' , async ( ) => {
480439 const { body } = await request
@@ -554,16 +513,9 @@ describe('LIVECHAT - inquiries', () => {
554513 await request . post ( api ( 'livechat/message' ) ) . send ( { token : visitor . token , rid : room . _id , msg : msgText } ) . expect ( 200 ) ;
555514
556515 await request
557- . post ( methodCall ( 'livechat: returnAsInquiry' ) )
516+ . post ( api ( 'livechat/inquiries. returnAsInquiry' ) )
558517 . set ( credentials )
559- . send ( {
560- message : JSON . stringify ( {
561- method : 'livechat:returnAsInquiry' ,
562- params : [ room . _id ] ,
563- id : 'id' ,
564- msg : 'method' ,
565- } ) ,
566- } )
518+ . send ( { roomId : room . _id } )
567519 . expect ( 'Content-Type' , 'application/json' )
568520 . expect ( 200 ) ;
569521
0 commit comments