Răsfoiți Sursa

Merge branch 'feat/create-endpoint-growi-register' into feat/create-modal-after-typing-growi-register

zahmis 5 ani în urmă
părinte
comite
33913f8deb

+ 31 - 3
packages/slack/src/utils/slash-command-parser.test.ts

@@ -12,7 +12,7 @@ describe('parse SlashCommand', () => {
   describe('without growiCommandType', () => {
     test('throws InvalidGrowiCommandError', () => {
       // setup
-      const slashCommandText = '/growi';
+      const slashCommandText = '';
       const slashCommand = new SlashCommandMock(slashCommandText);
 
       // when/then
@@ -24,7 +24,7 @@ describe('parse SlashCommand', () => {
 
   test('returns a GrowiCommand instance with empty growiCommandArgs', () => {
     // setup
-    const slashCommandText = '/growi search';
+    const slashCommandText = 'search';
     const slashCommand = new SlashCommandMock(slashCommandText);
 
     // when
@@ -36,9 +36,37 @@ describe('parse SlashCommand', () => {
     expect(result.growiCommandArgs).toStrictEqual([]);
   });
 
+  test('returns a GrowiCommand instance with space growiCommandType', () => {
+    // setup
+    const slashCommandText = '   search   ';
+    const slashCommand = new SlashCommandMock(slashCommandText);
+
+    // when
+    const result = parse(slashCommand);
+
+    // then
+    expect(result.text).toBe(slashCommandText);
+    expect(result.growiCommandType).toBe('search');
+    expect(result.growiCommandArgs).toStrictEqual([]);
+  });
+
+  test('returns a GrowiCommand instance with space growiCommandArgs', () => {
+    // setup
+    const slashCommandText = '   search hoge   ';
+    const slashCommand = new SlashCommandMock(slashCommandText);
+
+    // when
+    const result = parse(slashCommand);
+
+    // then
+    expect(result.text).toBe(slashCommandText);
+    expect(result.growiCommandType).toBe('search');
+    expect(result.growiCommandArgs).toStrictEqual(['hoge']);
+  });
+
   test('returns a GrowiCommand instance', () => {
     // setup
-    const slashCommandText = '/growi search keyword1 keyword2';
+    const slashCommandText = 'search keyword1 keyword2';
     const slashCommand = new SlashCommandMock(slashCommandText);
 
     // when

+ 4 - 2
packages/slack/src/utils/slash-command-parser.ts

@@ -2,8 +2,10 @@ import { GrowiCommand } from '../interfaces/growi-command';
 import { InvalidGrowiCommandError } from '../models/errors';
 
 export const parse = (slashCommand:{[key:string]:string}): GrowiCommand => {
-  const splitted = slashCommand.text.split(' ');
-  if (splitted.length < 1) {
+  const trimmedText = slashCommand.text.trim();
+  const splitted = trimmedText.split(' ');
+
+  if (splitted[0] === '') {
     throw new InvalidGrowiCommandError('The SlashCommand.text does not specify GrowiCommand type');
   }
 

+ 1 - 0
packages/slackbot-proxy/.env.development

@@ -3,3 +3,4 @@ TYPEORM_HOST=mysql
 TYPEORM_DATABASE=growi-slackbot-proxy
 TYPEORM_USERNAME=growi-slackbot-proxy
 TYPEORM_PASSWORD=YrkUi7rCW46Z2N6EXSFUBwaQTUR8biCU
+