@ -398,6 +398,81 @@ describe('[Incoming Integrations]', () => {
await removeIntegration ( withScript . _id , 'incoming' ) ;
} ) ;
it ( 'should send a message if the payload is a application/x-www-form-urlencoded JSON(when not set, default one) but theres no "payload" key, its just a string, the integration has a valid script' , async ( ) = > {
const payload = { test : 'test' } ;
let withScript : IIntegration | undefined ;
await updatePermission ( 'manage-incoming-integrations' , [ 'admin' ] ) ;
await request
. post ( api ( 'integrations.create' ) )
. set ( credentials )
. send ( {
type : 'webhook-incoming' ,
name : 'Incoming test with script and default content-type' ,
enabled : true ,
alias : 'test' ,
username : 'rocket.cat' ,
scriptEnabled : true ,
overrideDestinationChannelEnabled : false ,
channel : '#general' ,
script :
'const buildMessage = (obj) => {\n' +
' \n' +
' const template = `[#VALUE](${ obj.test })`;\n' +
' \n' +
' return {\n' +
' text: template\n' +
' };\n' +
' };\n' +
' \n' +
' class Script {\n' +
' process_incoming_request({ request }) {\n' +
' msg = buildMessage(request.content);\n' +
' \n' +
' return {\n' +
' content:{\n' +
' text: msg.text\n' +
' }\n' +
' };\n' +
' }\n' +
' }\n' +
' \n' ,
} )
. expect ( 'Content-Type' , 'application/json' )
. expect ( 200 )
. expect ( ( res ) = > {
expect ( res . body ) . to . have . property ( 'success' , true ) ;
expect ( res . body ) . to . have . property ( 'integration' ) . and . to . be . an ( 'object' ) ;
withScript = res . body . integration ;
} ) ;
if ( ! withScript ) {
throw new Error ( 'Integration not created' ) ;
}
await request
. post ( ` /hooks/ ${ withScript . _id } / ${ withScript . token } ` )
. send ( JSON . stringify ( payload ) )
. expect ( 200 )
. expect ( async ( ) = > {
return request
. get ( api ( 'channels.messages' ) )
. set ( credentials )
. query ( {
roomId : 'GENERAL' ,
} )
. expect ( 'Content-Type' , 'application/json' )
. expect ( 200 )
. expect ( ( res ) = > {
expect ( res . body ) . to . have . property ( 'success' , true ) ;
expect ( res . body ) . to . have . property ( 'messages' ) . and . to . be . an ( 'array' ) ;
expect ( ! ! ( res . body . messages as IMessage [ ] ) . find ( ( m ) = > m . msg === '[#VALUE](test)' ) ) . to . be . true ;
} ) ;
} ) ;
await removeIntegration ( withScript . _id , 'incoming' ) ;
} ) ;
} ) ;
describe ( '[/integrations.history]' , ( ) = > {