Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A response include multiple 'Output' #1

Open
minoruta opened this issue Mar 22, 2017 · 0 comments
Open

A response include multiple 'Output' #1

minoruta opened this issue Mar 22, 2017 · 0 comments

Comments

@minoruta
Copy link

At first, thanks for your Asterisk's AMI Client library.
BTW, I couldn't get an expected result with;

Action: Command
Command: core show settings

due to multiple 'Output'.

My temporal workarround is;

diff --git a/lib/rawToObject.js b/lib/rawToObject.js
index 2e21fe6..a5bbc67 100644
--- a/lib/rawToObject.js
+++ b/lib/rawToObject.js
@@ -72,7 +72,10 @@ function rowReducer(resultObj, row){
     let pair = row.split(ROW_SPLITTER);
 
     if(pair.length > 1){
-        resultObj[pair[0].trim()] = pair.slice(1).join(ROW_SPLITTER).trim();
+        if (resultObj[pair[0].trim()])
+            resultObj[pair[0].trim()] += "\n" + pair.slice(1).join(ROW_SPLITTER).trim();
+        else
+            resultObj[pair[0].trim()] = pair.slice(1).join(ROW_SPLITTER).trim();
     }
     return resultObj;
 }
diff --git a/test/utilsTest.js b/test/utilsTest.js
index fb7e305..62856fc 100644
--- a/test/utilsTest.js
+++ b/test/utilsTest.js
@@ -128,6 +128,22 @@ describe('Event utils test', () => {
             });
         });
 
+        it('with a response includes mutiline \'Output\'s', () => {
+            let commandStr = [
+                    'Response: Success',
+                    'Message: Command output follows',
+                    'Output:   Version:                     14.3.0',
+                    'Output:   Build Options:               LOADABLE_MODULES, BUILD_NATIVE, OPTIONAL_API',
+                    'Output:   Maximum calls:               Not set'
+                ].join(CRLF) + CRLF.repeat(2);
+
+            assert.deepEqual(eventUtil.toObject(commandStr), {
+                Response: 'Success',
+                Message: 'Command output follows',
+                Output: 'Version:                     14.3.0\nBuild Options:               LOADABLE_MODULES, BUILD_NATIVE, OPTIONAL_API\nMaximum calls:               Not set'
+            });
+        });
+
         it('without event\'s raw string', () => {
             assert.deepEqual(eventUtil.toObject(), {});
         });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant