forked from PluralFlux/PluralFlux
adjusted parsing logic to not try and call member when none exists (due to "new" command)
This commit is contained in:
@@ -28,6 +28,11 @@ mh.parseMemberCommand = async function (authorId, authorFull, args, attachmentUr
|
||||
if (!args[0]) {
|
||||
return mh.getMemberCommandInfo();
|
||||
}
|
||||
if (args[0] === "new") {
|
||||
if (!args[1] || args[1] === "--help") return enums.help.NEW;
|
||||
return await mh.addNewMember(authorId, args, attachmentUrl).catch((e) => { throw e });
|
||||
}
|
||||
|
||||
const memberName = !commandList.includes(args[0]) ? args[0] : args[1];
|
||||
|
||||
// checks whether command is in list, otherwise assumes it's a name
|
||||
@@ -37,9 +42,6 @@ mh.parseMemberCommand = async function (authorId, authorFull, args, attachmentUr
|
||||
})
|
||||
|
||||
switch (args[0]) {
|
||||
case 'new':
|
||||
if (!args[1] || args[1] === "--help") return enums.help.NEW;
|
||||
return await mh.addNewMember(authorId, args, attachmentUrl).catch((e) => { throw e });
|
||||
case 'remove':
|
||||
if (!args[1] || args[1] === "--help") return enums.help.REMOVE;
|
||||
return await mh.removeMember(authorId, memberName).catch((e) => { throw e });
|
||||
|
||||
@@ -64,7 +64,7 @@ describe('MemberHelper', () => {
|
||||
|
||||
test.each([
|
||||
[['new', 'somePerson'], attachmentUrl],
|
||||
[['new', 'somePerson'], null,]
|
||||
[['new', 'somePerson'], null],
|
||||
])('%s calls addNewMember and returns correct values', async(args, attachmentUrl) => {
|
||||
// Act
|
||||
return memberHelper.parseMemberCommand(authorId, authorFull, args, attachmentUrl).then((result) => {
|
||||
@@ -192,6 +192,35 @@ describe('MemberHelper', () => {
|
||||
expect(memberHelper[method]).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
test('["new", "someNewPerson"] shall call addNewMember and return correct results', async () => {
|
||||
// Act
|
||||
return memberHelper.parseMemberCommand(authorId, authorFull, ['new', 'someNewPerson']).then((result) => {
|
||||
// Assert
|
||||
expect(result).toEqual("new member");
|
||||
expect(memberHelper.getMemberByName).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
test('["new", "--help"] shall return help enum', async () => {
|
||||
// Act
|
||||
return memberHelper.parseMemberCommand(authorId, authorFull, ['new', '--help']).then((result) => {
|
||||
// Assert
|
||||
expect(result).toEqual(enums.help.NEW);
|
||||
expect(memberHelper.addNewMember).not.toHaveBeenCalled();
|
||||
expect(memberHelper.getMemberByName).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
test('["new"] shall return help enum', async () => {
|
||||
// Act
|
||||
return memberHelper.parseMemberCommand(authorId, authorFull, ['new']).then((result) => {
|
||||
// Assert
|
||||
expect(result).toEqual(enums.help.NEW);
|
||||
expect(memberHelper.addNewMember).not.toHaveBeenCalled();
|
||||
expect(memberHelper.getMemberByName).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
})
|
||||
|
||||
describe('addNewMember', () => {
|
||||
|
||||
Reference in New Issue
Block a user