Skip to content
This repository has been archived by the owner on Dec 10, 2022. It is now read-only.

Commit

Permalink
Support commands defined or supplied in any case (fixes #3)
Browse files Browse the repository at this point in the history
  • Loading branch information
tdmalone committed Aug 25, 2018
1 parent 36da8a2 commit 39bb344
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ const extractCommand = ( message, commands ) => {
let firstLocation = Number.MAX_SAFE_INTEGER,
firstCommand;

const messageInLowerCase = message.toLowerCase();

for ( const command of commands ) {
const location = message.indexOf( command );
const location = messageInLowerCase.indexOf( command.toLowerCase() );
if ( -1 !== location && location < firstLocation ) {
firstLocation = location;
firstCommand = command;
Expand Down
26 changes: 24 additions & 2 deletions tests/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ describe( 'extractCommand', () => {
const commands = [
'test-command',
'something-else',
'another-command'
'another-command',
'UPPERCASE-COMMAND',
'Mixed-Case-Command'
];

it( 'returns a valid command from a message containing only that command', () => {
Expand Down Expand Up @@ -57,7 +59,27 @@ describe( 'extractCommand', () => {
expect( helpers.extractCommand( message, commands ) ).toBeFalse();
});

});
it( 'supports a command given in uppercase', () => {
const message = '<@U12345678> TEST-COMMAND';
expect( helpers.extractCommand( message, commands ) ).toEqual( 'test-command' );
});

it( 'supports a command given in mixed case', () => {
const message = '<@U12345678> Test-Command';
expect( helpers.extractCommand( message, commands ) ).toEqual( 'test-command' );
});

it( 'supports a command defined in uppercase', () => {
const message = '<@U12345678> uppercase-command';
expect( helpers.extractCommand( message, commands ) ).toEqual( 'UPPERCASE-COMMAND' );
});

it( 'supports a command defined in mixed case', () => {
const message = '<@U12345678> mixed-case-command';
expect( helpers.extractCommand( message, commands ) ).toEqual( 'Mixed-Case-Command' );
});

}); // ExtractCommand.

describe( 'extractPlusMinusEventData', () => {

Expand Down

0 comments on commit 39bb344

Please sign in to comment.