@ -3,18 +3,12 @@ import { describe, it, beforeEach, after } from 'mocha';
import proxyquire from 'proxyquire' ;
import sinon from 'sinon' ;
const setStub = sinon . stub ( ) ;
const workOnPdfStub = sinon . stub ( ) ;
const queueWorkStub = sinon . stub ( ) ;
const { requestPdfTranscript } = proxyquire
. noCallThru ( )
. load ( '../../../../../ee/app/livechat-enterprise/server/lib/requestPdfTranscript.ts' , {
'@rocket.chat/models' : {
LivechatRooms : {
setTranscriptRequestedPdfById : setStub ,
} ,
} ,
'@rocket.chat/core-services' : {
OmnichannelTranscript : {
workOnPdf : workOnPdfStub ,
@ -29,7 +23,6 @@ describe('requestPdfTranscript', () => {
const currentTestModeValue = process . env . TEST_MODE ;
beforeEach ( ( ) = > {
setStub . reset ( ) ;
workOnPdfStub . reset ( ) ;
queueWorkStub . reset ( ) ;
} ) ;
@ -44,30 +37,37 @@ describe('requestPdfTranscript', () => {
it ( 'should throw an error if room doesnt have a v property' , async ( ) = > {
await expect ( requestPdfTranscript ( { } , 'userId' ) ) . to . be . rejectedWith ( 'improper-room-state' ) ;
} ) ;
it ( 'should not request a transcript if it was already requested' , async ( ) = > {
await requestPdfTranscript ( { v : 1 , pdfTranscriptRequested : true } , 'userId' ) ;
expect ( setStub . callCount ) . to . equal ( 0 ) ;
expect ( workOnPdfStub . callCount ) . to . equal ( 0 ) ;
expect ( queueWorkStub . callCount ) . to . equal ( 0 ) ;
it ( 'should not allow to request a transcript if it already exists' , async ( ) = > {
const result = await requestPdfTranscript ( { _id : 'roomIdxx' , v : 1 , pdfTranscriptFileId : 'afsdafadsfs' } , 'userId' ) ;
expect ( result ) . to . be . undefined ;
} ) ;
it ( 'should set pdfTranscriptRequested to true on room' , async ( ) = > {
await requestPdfTranscript ( { _id : 'roomId' , v : { } , pdfTranscriptRequested : false } , 'userId' ) ;
expect ( setStub . calledWith ( 'roomId' ) ) . to . be . true ;
it ( 'should not allow to request a transcript if it was already requested during the previous 15 seconds' , async ( ) = > {
await requestPdfTranscript ( { _id : 'roomId' , v : 1 } , 'userId' ) ;
expect ( workOnPdfStub . callCount ) . to . equal ( 0 ) ;
expect ( queueWorkStub . callCount ) . to . equal ( 1 ) ;
const result = await requestPdfTranscript ( { _id : 'roomId' , v : 1 } , 'userId' ) ;
expect ( workOnPdfStub . callCount ) . to . equal ( 0 ) ;
expect ( queueWorkStub . callCount ) . to . equal ( 1 ) ;
expect ( result ) . to . be . undefined ;
} ) ;
it ( 'should call workOnPdf if TEST_MODE is true' , async ( ) = > {
process . env . TEST_MODE = 'true' ;
await requestPdfTranscript ( { _id : 'roomId' , v : { } } , 'userId' ) ;
expect ( workOnPdfStub . getCall ( 0 ) . calledWithExactly ( { details : { rid : 'roomId' , userId : 'userId' , from : 'omnichannel-transcript' } } ) ) . to
. be . true ;
await requestPdfTranscript ( { _id : 'roomId-fasdafsdas' , v : { } } , 'userId' ) ;
expect (
workOnPdfStub
. getCall ( 0 )
. calledWithExactly ( { details : { rid : 'roomId-fasdafsdas' , userId : 'userId' , from : 'omnichannel-transcript' } } ) ,
) . to . be . true ;
expect ( queueWorkStub . calledOnce ) . to . be . false ;
} ) ;
it ( 'should queue work if TEST_MODE is not set' , async ( ) = > {
delete process . env . TEST_MODE ;
await requestPdfTranscript ( { _id : 'roomId' , v : { } } , 'userId' ) ;
await requestPdfTranscript ( { _id : 'roomId-afsdfaefzv ' , v : { } } , 'userId' ) ;
expect ( workOnPdfStub . calledOnce ) . to . be . false ;
expect (
queueWorkStub . getCall ( 0 ) . calledWithExactly ( 'work' , 'omnichannel-transcript.workOnPdf' , {
details : { rid : 'roomId' , userId : 'userId' , from : 'omnichannel-transcript' } ,
details : { rid : 'roomId-afsdfaefzv ' , userId : 'userId' , from : 'omnichannel-transcript' } ,
} ) ,
) . to . be . true ;
} ) ;