updating tests and memberHelper to try and make parseMemberCommand less bloated/broken (not working ATM)

This commit is contained in:
Aster Fialla
2026-02-22 21:40:42 -05:00
parent c3e7bf4433
commit be24034d48
3 changed files with 317 additions and 198 deletions

View File

@@ -12,7 +12,8 @@ cmds.set('member', {
const authorFull = `${message.author.username}#${message.author.discriminator}`
const attachmentUrl = message.attachments.size > 0 ? message.attachments.first().url : null;
const attachmentExpires = message.attachments.size > 0 ? message.attachments.first().expires_at : null;
const reply = await memberHelper.parseMemberCommand(message.author.id, authorFull, args, attachmentUrl, attachmentExpires).catch(async (e) =>{await message.reply(e.message);});
if (attachmentUrl) args.push(null, attachmentUrl, attachmentExpires);
const reply = await memberHelper.parseMemberCommand(message.author.id, authorFull, args).catch(async (e) =>{await message.reply(e.message);});
if (typeof reply === 'string') {
return await message.reply(reply);
}

View File

@@ -6,8 +6,8 @@ import {utils} from "./utils.js";
const mh = {};
// Has an empty "command" to parse the help message properly
const commandList = ['--help', 'new', 'remove', 'name', 'list', 'displayName', 'proxy', 'propic', ''];
const commandList = ['new', 'remove', 'name', 'list', 'displayName', 'proxy', 'propic'];
const newAndRemoveCommands = ['new', 'remove'];
/**
* Parses through the subcommands that come after "pf;member" and calls functions accordingly.
@@ -16,35 +16,97 @@ const commandList = ['--help', 'new', 'remove', 'name', 'list', 'displayName', '
* @param {string} authorId - The id of the message author
* @param {string} authorFull - The username and discriminator of the message author
* @param {string[]} args - The message arguments
* @param {string | null} attachmentUrl - The message attachment url.
* @param {string | null} attachmentExpiration - The message attachment expiration (if uploaded via Fluxer)
* @returns {Promise<string>} A success message.
* @returns {Promise <EmbedBuilder>} A list of 25 members as an embed.
* @returns {Promise <EmbedBuilder>} A list of member commands and descriptions.
* @returns {Promise<{EmbedBuilder, [string], string}>} A member info embed + info/errors.
* @throws {Error}
*/
mh.parseMemberCommand = async function (authorId, authorFull, args, attachmentUrl = null, attachmentExpiration = null) {
if (!args[0]) {
mh.parseMemberCommand = async function (authorId, authorFull, args) {
let memberName, command, isHelp = false;
// checks whether command is in list, otherwise assumes it's a name
// ex: pf;member, pf;member --help
if (args.length === 0 || args[0] === '--help' || 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 });
// ex: pf;member remove somePerson
if (commandList.includes(args[0]) && args[1]) {
command = args[0];
memberName = args[1];
}
// ex: pf;member somePerson propic
else if (args[1] && commandList.includes(args[1])) {
command = args[1];
memberName = args[0];
}
// ex: pf;member somePerson
else if (!commandList.includes(args[0]) && !args[1]) {
memberName = args[0];
}
// ex: pf;member remove, pf;member remove --help
if (command && (!memberName || args.includes("--help"))) {
isHelp = true;
}
const memberName = !commandList.includes(args[0]) ? args[0] : args[1];
return await mh.memberArgumentHandler(authorId, authorFull, isHelp, command, memberName, args)
}
// checks whether command is in list, otherwise assumes it's a name
mh.memberArgumentHandler = async function(authorId, authorFull, isHelp, command = null, memberName = null,args = null) {
if (!command && !memberName && !isHelp) {
throw new Error(enums.err.COMMAND_NOT_RECOGNIZED);
}
// ex: pf;member blah blah
if (!memberName && !isHelp) {
throw new Error(enums.err.NO_MEMBER);
}
// remove memberName and command from values to reduce confusion
console.log(command, memberName, isHelp, args);
let values = args.slice(2);
console.log(values);
if (isHelp) {
mh.sendHelpEnum(command);
}
else if (command === "list") {
return await mh.getAllMembersInfo(authorId, authorFull);
}
else if (command && memberName && values || newAndRemoveCommands.includes(command) && memberName) {
return await mh.memberCommandHandler(authorId, command, memberName, values);
}
else if (command && memberName) {
return await mh.sendCurrentValue(authorId, memberName, command);
}
}
mh.sendCurrentValue = async function(authorId, memberName, command) {
const member = await mh.getMemberByName(authorId, memberName).then((m) => {
if (!m) throw new Error(enums.err.NO_MEMBER);
return m;
})
});
switch (args[0]) {
if (!command) {
return mh.getMemberInfo(member);
}
switch (command) {
case 'name':
return `The name of ${member.name} is \"${member.name}\" but you probably already knew that!`;
case 'displayname':
return `The display name for ${member.name} is \"${member.displayname}\".`;
case 'proxy':
return `The proxy for ${member.name} is \"${member.proxy}\".`;
case 'propic':
return `The profile picture for ${member.name} is \"${member.propic}\".`;
}
}
mh.sendHelpEnum = function(command) {
switch (command) {
case 'new':
return enums.help.NEW;
case 'remove':
if (!args[1] || args[1] === "--help") return enums.help.REMOVE;
return await mh.removeMember(authorId, memberName).catch((e) => { throw e });
return enums.help.REMOVE;
case 'name':
return enums.help.NAME;
case 'displayname':
@@ -54,27 +116,25 @@ mh.parseMemberCommand = async function (authorId, authorFull, args, attachmentUr
case 'propic':
return enums.help.PROPIC;
case 'list':
if (args[1] && args[1] === "--help") return enums.help.LIST;
return await mh.getAllMembersInfo(authorId, authorFull).catch((e) => { throw e });
case '--help':
case '':
return mh.getMemberCommandInfo();
return enums.help.LIST;
}
switch (args[1]) {
}
mh.memberCommandHandler = async function(authorId, command, memberName, values) {
switch (command) {
case 'new':
return await mh.addNewMember(authorId, memberName, values).catch((e) => {throw e});
case 'remove':
return await mh.removeMember(authorId, memberName).catch((e) => {throw e});
case 'name':
if (!args[2]) return member.name;
return await mh.updateName(authorId, args[0], args[2]).catch((e) => { throw e});
return await mh.updateName(authorId, memberName, values[0]).catch((e) => {throw e});
case 'displayname':
if (!args[2]) return member.displayname ?? `Display name ${enums.err.NO_VALUE}`;
return await mh.updateDisplayName(authorId, args[0], args[2]).catch((e) => {throw e});
return await mh.updateDisplayName(authorId, memberName, values[0]).catch((e) => {throw e});
case 'proxy':
if (!args[2]) return member.proxy ?? `Proxy ${enums.err.NO_VALUE}`;
return await mh.updateProxy(authorId, args[0], args[2]).catch((e) => {throw e});
return await mh.updateProxy(authorId, memberName, values[0]).catch((e) => {throw e});
case 'propic':
if (!args[2] && !attachmentUrl) return member.propic ?? `Profile picture ${enums.err.NO_VALUE}`;
return await mh.updatePropic(authorId, args[0], args[2], attachmentUrl, attachmentExpiration).catch((e) => {throw e});
default:
return await mh.getMemberInfo(member);
return await mh.updatePropic(authorId, memberName, values).catch((e) => {throw e});
}
}
@@ -83,19 +143,19 @@ mh.parseMemberCommand = async function (authorId, authorFull, args, attachmentUr
*
* @async
* @param {string} authorId - The author of the message
* @param {string[]} args - The message arguments
* @param {string | null} attachmentURL - The attachment URL, if any exists
* @param {string} memberName - The member name
* @param {string[]} values - The arguments following the member name and command
* @returns {Promise<string>} A successful addition.
* @throws {Error} When the member exists, or creating a member doesn't work.
*/
mh.addNewMember = async function (authorId, args, attachmentURL = null) {
const memberName = args[1];
const displayName = args[2];
const proxy = args[3];
const propic = args[4] ?? attachmentURL;
mh.addNewMember = async function (authorId, memberName, values) {
const displayName = values[2];
const proxy = values[3];
const propic = values[4] ?? values[5];
return await mh.addFullMember(authorId, memberName, displayName, proxy, propic).then(async(response) => {
const memberInfoEmbed = await mh.getMemberInfo(response.member).catch((e) => {throw e})
const memberInfoEmbed = mh.getMemberInfo(response.member);
return {embed: memberInfoEmbed, errors: response.errors, success: `${memberName} has been added successfully.`};
}).catch(e => {
console.error(e);
@@ -155,7 +215,7 @@ mh.updateDisplayName = async function (authorId, membername, displayname) {
* @param {string} memberName - The member to update
* @param {string} proxy - The proxy to set
* @returns {Promise<string> } A successful update.
* @throws {RangeError | Error} When an empty proxy was provided, or no proxy exists.
* @throws {Error} When an empty proxy was provided, or a proxy exists.
*/
mh.updateProxy = async function (authorId, memberName, proxy) {
// Throws error if exists
@@ -170,17 +230,17 @@ mh.updateProxy = async function (authorId, memberName, proxy) {
* @async
* @param {string} authorId - The author of the message
* @param {string} memberName - The member to update
* @param {string | null} imgUrl - The message arguments
* @param {string | null} attachmentUrl - The url of the first attachment in the message
* @param {string | null} attachmentExpiry - The expiration date of the first attachment in the message (if uploaded to Fluxer)
* @param {string} values - The message arguments
* @returns {Promise<string>} A successful update.
* @throws {Error} When loading the profile picture from a URL doesn't work.
*/
mh.updatePropic = async function (authorId, memberName, imgUrl = null, attachmentUrl = null, attachmentExpiry = null) {
mh.updatePropic = async function (authorId, memberName, values) {
const imgUrl = values[0] ?? values[1];
const attachmentExpiry = values[1] ? values[2] : null;
// Throws error if invalid
await utils.checkImageFormatValidity(attachmentUrl ?? imgUrl).catch((e) => { throw e });
return await mh.updateMemberField(authorId, memberName, "propic", attachmentUrl ?? imgUrl, attachmentExpiry).catch((e) => { throw e });
return await mh.updateMemberField(authorId, memberName, "propic", imgUrl, attachmentExpiry).catch((e) => { throw e });
}
/**
@@ -326,11 +386,10 @@ mh.setExpirationWarning = function (expirationString) {
/**
* Gets the details for a member.
*
* @async
* @param {model} member - The member object
* @returns {Promise<EmbedBuilder>} The member's info.
* @returns {EmbedBuilder} The member's info.
*/
mh.getMemberInfo = async function (member) {
mh.getMemberInfo = function (member) {
return new EmbedBuilder()
.setTitle(member.name)
.setDescription(`Details for ${member.name}`)

View File

@@ -50,51 +50,55 @@ describe('MemberHelper', () => {
describe('parseMemberCommand', () => {
beforeEach(() => {
jest.spyOn(memberHelper, 'getMemberByName').mockResolvedValue(mockMember);
jest.spyOn(memberHelper, 'getMemberInfo').mockResolvedValue("member info");
jest.spyOn(memberHelper, 'addNewMember').mockResolvedValue("new member");
jest.spyOn(memberHelper, 'removeMember').mockResolvedValue("remove member");
jest.spyOn(memberHelper, 'getAllMembersInfo').mockResolvedValue("all member info");
jest.spyOn(memberHelper, 'updateName').mockResolvedValue("update name");
jest.spyOn(memberHelper, 'updateDisplayName').mockResolvedValue("update display name");
jest.spyOn(memberHelper, 'updateProxy').mockResolvedValue("update proxy");
jest.spyOn(memberHelper, 'updatePropic').mockResolvedValue("update propic");
// jest.spyOn(memberHelper, 'getMemberByName').mockResolvedValue(mockMember);
// jest.spyOn(memberHelper, 'getMemberInfo').mockResolvedValue("member info");
// jest.spyOn(memberHelper, 'addNewMember').mockResolvedValue("new member");
// jest.spyOn(memberHelper, 'removeMember').mockResolvedValue("remove member");
// jest.spyOn(memberHelper, 'getAllMembersInfo').mockResolvedValue("all member info");
// jest.spyOn(memberHelper, 'updateName').mockResolvedValue("update name");
// jest.spyOn(memberHelper, 'updateDisplayName').mockResolvedValue("update display name");
// jest.spyOn(memberHelper, 'updateProxy').mockResolvedValue("update proxy");
// jest.spyOn(memberHelper, 'updatePropic').mockResolvedValue("update propic");
jest.spyOn(memberHelper, 'getMemberCommandInfo').mockResolvedValue("member command info");
jest.spyOn(memberHelper, 'memberArgumentHandler').mockResolvedValue("handled argument");
jest.spyOn(memberHelper, 'memberCommandHandler').mockResolvedValue("called command");
jest.spyOn(memberHelper, 'sendCurrentValue').mockResolvedValue("current value");
jest.spyOn(memberHelper, 'sendHelpEnum').mockResolvedValue("help enum")
});
test.each([
[['new', 'somePerson'], attachmentUrl],
[['new', 'somePerson'], null],
])('%s calls addNewMember and returns correct values', async(args, attachmentUrl) => {
// Act
return memberHelper.parseMemberCommand(authorId, authorFull, args, attachmentUrl).then((result) => {
// Assert
expect(result).toEqual("new member");
expect(memberHelper.addNewMember).toHaveBeenCalledTimes(1);
expect(memberHelper.addNewMember).toHaveBeenCalledWith(authorId, args, attachmentUrl);
});
})
test('["remove", "somePerson"] calls removeMember with authorId and "somePerson" and returns expected result', async() => {
// Act
return memberHelper.parseMemberCommand(authorId, authorFull, ["remove", "somePerson"]).then((result) => {
// Assert
expect(result).toEqual("remove member");
expect(memberHelper.removeMember).toHaveBeenCalledTimes(1);
expect(memberHelper.removeMember).toHaveBeenCalledWith(authorId, "somePerson");
});
});
test('["list"] calls getAllMembersInfo and returns expected result', async () => {
// Act
return memberHelper.parseMemberCommand(authorId, authorFull, ["list"]).then((result) => {
// Assert
expect(result).toEqual("all member info");
expect(memberHelper.getAllMembersInfo).toHaveBeenCalledTimes(1);
expect(memberHelper.getAllMembersInfo).toHaveBeenCalledWith(authorId, authorFull);
});
});
// test.each([
// [['new', 'somePerson'], attachmentUrl],
// [['new', 'somePerson'], null],
// ])('%s calls addNewMember and returns correct values', async(args, attachmentUrl) => {
// // Act
// return memberHelper.parseMemberCommand(authorId, authorFull, args, attachmentUrl).then((result) => {
// // Assert
// expect(result).toEqual("new member");
// expect(memberHelper.addNewMember).toHaveBeenCalledTimes(1);
// expect(memberHelper.addNewMember).toHaveBeenCalledWith(authorId, args, attachmentUrl);
// });
// })
//
// test('["remove", "somePerson"] calls removeMember with authorId and "somePerson" and returns expected result', async() => {
// // Act
// return memberHelper.parseMemberCommand(authorId, authorFull, ["remove", "somePerson"]).then((result) => {
// // Assert
// expect(result).toEqual("remove member");
// expect(memberHelper.removeMember).toHaveBeenCalledTimes(1);
// expect(memberHelper.removeMember).toHaveBeenCalledWith(authorId, "somePerson");
// });
// });
//
// test('["list"] calls getAllMembersInfo and returns expected result', async () => {
// // Act
// return memberHelper.parseMemberCommand(authorId, authorFull, ["list"]).then((result) => {
// // Assert
// expect(result).toEqual("all member info");
// expect(memberHelper.getAllMembersInfo).toHaveBeenCalledTimes(1);
// expect(memberHelper.getAllMembersInfo).toHaveBeenCalledWith(authorId, authorFull);
// });
// });
//
test.each([
[['--help']],
[['']],
@@ -110,117 +114,172 @@ describe('MemberHelper', () => {
});
test.each([
[['somePerson', 'name', 'newPerson'], "updateName", "update name"],
[['somePerson', 'displayname', 'Some Person'], "updateDisplayName", "update display name"],
[['somePerson', 'proxy', '--text'], "updateProxy", "update proxy"],
])('%s calls %s returns expected result %s', async (args, method, expectedResult) => {
[[mockMember.name, '--help'], null, true],
[['new', '--help'], 'new', true],
[['remove', '--help'], 'remove', true],
[['name', '--help'], 'name', true],
[['list', '--help'], 'list', true],
[['displayname', '--help'], 'displayname', true],
[['proxy', '--help'], 'proxy', true],
[['propic', '--help'], 'propic', true],
[['new'], 'new', true],
[['remove'], 'remove', true],
[['name'], 'name', true],
[['list'], 'list', true],
[['displayname'], 'displayname', true],
[['proxy'], 'proxy', true],
[['propic'], 'propic', true],
[[mockMember.name, 'remove'], 'remove', false],
[[mockMember.name, 'remove', 'test'], 'remove', false],
[[mockMember.name, 'new'], 'new', false],
[[mockMember.name, 'new', 'test'], 'new', false],
[[mockMember.name, 'new', mockMember.displayname], 'new', false],
[[mockMember.name, 'new', mockMember.proxy], 'new', false],
[[mockMember.name, 'new', mockMember.propic], 'new', false],
[[mockMember.name, 'new', null, mockMember.propic], 'new', false],
[[mockMember.name, 'new', null, mockMember.propic, attachmentExpiry], 'new', false],
[[mockMember.name, 'name', mockMember.name], 'name', false],
[[mockMember.name, 'displayname', mockMember.displayname], 'displayname', false],
[[mockMember.name, 'proxy', mockMember.proxy], 'proxy', false],
[[mockMember.name, 'propic', mockMember.propic], 'propic', false],
[[mockMember.name, 'propic', null, mockMember.propic], 'propic', false],
[[mockMember.name, 'propic', null, mockMember.propic, attachmentExpiry], 'propic', false],
[['remove', mockMember.name], 'remove'],
[['remove', mockMember.name, 'test'], 'remove'],
[['new', mockMember.name], 'new'],
[['new', mockMember.name, mockMember.displayname], 'new'],
[['new', mockMember.name, mockMember.displayname, mockMember.proxy], 'new'],
[['new', mockMember.name, mockMember.displayname, mockMember.proxy, mockMember.propic], 'new'],
[['new', mockMember.name, null, mockMember.displayname, mockMember.proxy, mockMember.propic, attachmentExpiry], 'new'],
[['new', mockMember.name, null, mockMember.displayname, mockMember.proxy, mockMember.propic, attachmentExpiry], 'new'],
[['name', mockMember.name, mockMember.name], 'name'],
[['displayname', mockMember.name, mockMember.name, mockMember.displayname], 'displayname'],
[['proxy', mockMember.name, mockMember.name, mockMember.displayname, mockMember.proxy], 'proxy'],
[['propic', mockMember.name, mockMember.name, mockMember.displayname, mockMember.proxy, mockMember.propic], 'propic'],
[['propic', mockMember.name, null, mockMember.name, mockMember.displayname, mockMember.proxy, mockMember.propic, attachmentExpiry], 'propic'],
[['propic', mockMember.name, null, mockMember.name, mockMember.displayname, mockMember.proxy, mockMember.propic, attachmentExpiry], 'propic'],
])('%s calls memberCommandHandler with correct values', async (args, command, isHelp) => {
// Act
return memberHelper.parseMemberCommand(authorId, authorFull, args).then((result) => {
return memberHelper.parseMemberCommand(authorId, authorFull, args).then((result, command) => {
// Assert
expect(result).toEqual(expectedResult);
expect(memberHelper[method]).toHaveBeenCalledTimes(1);
expect(memberHelper[method]).toHaveBeenCalledWith(authorId, args[0], args[2]);
});
});
test.each([
[["somePerson", "propic", attachmentUrl], null, null],
[["somePerson", "propic", null], 'ono.png', attachmentExpiry],
])('%s calls updatePropic and returns expected values', async (args, attachmentUrl, attachmentExpiration) => {
// Act
return memberHelper.parseMemberCommand(authorId, authorFull, args, attachmentUrl, attachmentExpiration).then((result) => {
// Assert
expect(result).toEqual("update propic");
expect(memberHelper['updatePropic']).toHaveBeenCalledTimes(1);
expect(memberHelper['updatePropic']).toHaveBeenCalledWith(authorId, args[0], args[2], attachmentUrl, attachmentExpiration)
expect(result).toEqual("handled argument");
expect(memberHelper.memberArgumentHandler).toHaveBeenCalledTimes(1);
expect(memberHelper.memberArgumentHandler).toHaveBeenCalledWith(authorId, authorFull, isHelp, command, mockMember.name, args.slice(2));
});
})
test('any non-command returns getMemberInfo', async() => {
// Act
return memberHelper.parseMemberCommand(authorId, authorFull, ['somePerson']).then(() => {
// Assert
expect(memberHelper['getMemberInfo']).toHaveBeenCalledTimes(1);
expect(memberHelper['getMemberInfo']).toHaveBeenCalledWith(mockMember);
})
})
test.each([
[['new'], "addNewMember", enums.help.NEW],
[['new', '--help'], "addNewMember", enums.help.NEW],
[['remove'], "removeMember", enums.help.REMOVE],
[['remove', '--help'], "removeMember", enums.help.REMOVE],
[['name'], "updateName", enums.help.NAME],
[['name', '--help'], "updateName", enums.help.NAME],
[['somePerson', 'name'], "updateName", mockMember.name],
[['displayname'], "updateDisplayName", enums.help.DISPLAY_NAME],
[['displayname', '--help'], "updateDisplayName", enums.help.DISPLAY_NAME],
[['somePerson', 'displayname'], "updateDisplayName", mockMember.displayname],
[['proxy'], "updateProxy", enums.help.PROXY],
[['proxy', '--help'], "updateProxy", enums.help.PROXY],
[['somePerson', 'proxy'], "updateProxy", mockMember.proxy],
[['propic'], "updatePropic", enums.help.PROPIC],
[['propic', '--help'], "updatePropic", enums.help.PROPIC],
[['somePerson', 'propic'], "updatePropic", mockMember.propic],
[['list', '--help'], "getAllMembersInfo", enums.help.LIST],
])('%s shall not call %s and returns correct string', async (args, method, expectedResult) => {
// Act
return memberHelper.parseMemberCommand(authorId, authorFull, args).then((result) => {
// Assert
expect(result).toEqual(expectedResult);
expect(memberHelper[method]).not.toHaveBeenCalled();
});
});
test.each([
[['somePerson', 'displayname'], "updateDisplayName", "Display name"],
[['somePerson', 'proxy'], "updateProxy", "Proxy"],
[['somePerson', 'propic'], "updatePropic", "Profile picture"],
])('if value not set, %s shall not call %s and returns value error', async (args, method, expectedResult) => {
// Arrange
const mockEmptyMember = {
name: "somePerson",
displayname: null,
proxy: null,
propic: null,
}
jest.spyOn(memberHelper, 'getMemberByName').mockResolvedValue(mockEmptyMember);
// Act
return memberHelper.parseMemberCommand(authorId, authorFull, args).then((result) => {
// Assert
expect(result).toEqual(`${expectedResult} ${enums.err.NO_VALUE}`);
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();
});
});
//
// test.each([
// [['somePerson', 'name', 'newPerson'], "updateName", "update name"],
// [['somePerson', 'displayname', 'Some Person'], "updateDisplayName", "update display name"],
// [['somePerson', 'proxy', '--text'], "updateProxy", "update proxy"],
// ])('%s calls %s returns expected result %s', async (args, method, expectedResult) => {
// // Act
// return memberHelper.parseMemberCommand(authorId, authorFull, args).then((result) => {
// // Assert
// expect(result).toEqual(expectedResult);
// expect(memberHelper[method]).toHaveBeenCalledTimes(1);
// expect(memberHelper[method]).toHaveBeenCalledWith(authorId, args[0], args[2]);
// });
// });
//
// test.each([
// [["somePerson", "propic", attachmentUrl], null, null],
// [["somePerson", "propic", null], 'ono.png', attachmentExpiry],
// ])('%s calls updatePropic and returns expected values', async (args, attachmentUrl, attachmentExpiration) => {
// // Act
// return memberHelper.parseMemberCommand(authorId, authorFull, args, attachmentUrl, attachmentExpiration).then((result) => {
// // Assert
// expect(result).toEqual("update propic");
// expect(memberHelper['updatePropic']).toHaveBeenCalledTimes(1);
// expect(memberHelper['updatePropic']).toHaveBeenCalledWith(authorId, args[0], args[2], attachmentUrl, attachmentExpiration)
// });
// })
//
// test('any non-command returns getMemberInfo', async() => {
// // Act
// return memberHelper.parseMemberCommand(authorId, authorFull, ['somePerson']).then(() => {
// // Assert
// expect(memberHelper['getMemberInfo']).toHaveBeenCalledTimes(1);
// expect(memberHelper['getMemberInfo']).toHaveBeenCalledWith(mockMember);
// })
// })
//
// test.each([
// [['new'], "addNewMember", enums.help.NEW],
// [['new', '--help'], "addNewMember", enums.help.NEW],
// [['remove'], "removeMember", enums.help.REMOVE],
// [['remove', '--help'], "removeMember", enums.help.REMOVE],
// [['name'], "updateName", enums.help.NAME],
// [['name', '--help'], "updateName", enums.help.NAME],
// [['somePerson', 'name'], "updateName", mockMember.name],
// [['displayname'], "updateDisplayName", enums.help.DISPLAY_NAME],
// [['displayname', '--help'], "updateDisplayName", enums.help.DISPLAY_NAME],
// [['somePerson', 'displayname'], "updateDisplayName", mockMember.displayname],
// [['proxy'], "updateProxy", enums.help.PROXY],
// [['proxy', '--help'], "updateProxy", enums.help.PROXY],
// [['somePerson', 'proxy'], "updateProxy", mockMember.proxy],
// [['propic'], "updatePropic", enums.help.PROPIC],
// [['propic', '--help'], "updatePropic", enums.help.PROPIC],
// [['somePerson', 'propic'], "updatePropic", mockMember.propic],
// [['list', '--help'], "getAllMembersInfo", enums.help.LIST],
// ])('%s shall not call %s and returns correct string', async (args, method, expectedResult) => {
// // Act
// return memberHelper.parseMemberCommand(authorId, authorFull, args).then((result) => {
// // Assert
// expect(result).toEqual(expectedResult);
// expect(memberHelper[method]).not.toHaveBeenCalled();
// });
// });
//
// test.each([
// [['somePerson', 'displayname'], "updateDisplayName", "Display name"],
// [['somePerson', 'proxy'], "updateProxy", "Proxy"],
// [['somePerson', 'propic'], "updatePropic", "Profile picture"],
// ])('if value not set, %s shall not call %s and returns value error', async (args, method, expectedResult) => {
// // Arrange
// const mockEmptyMember = {
// name: "somePerson",
// displayname: null,
// proxy: null,
// propic: null,
// }
// jest.spyOn(memberHelper, 'getMemberByName').mockResolvedValue(mockEmptyMember);
// // Act
// return memberHelper.parseMemberCommand(authorId, authorFull, args).then((result) => {
// // Assert
// expect(result).toEqual(`${expectedResult} ${enums.err.NO_VALUE}`);
// 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', () => {