forked from PluralFlux/PluralFlux
refactor: Removing then/catch from async/await calls (#22)
* refactored async/await for import helper to not also use then/catch * added enum * refactor webhookHelper and tests to not use then/catch * changed docstring * refactoring bot and tests to not use then/catch * refactoring commands.js and tests to not use then/catch * refactoring memberHelper.js and tests to not use then/catch * removing then/catch from messageHelper.test.js * fixed set up for commands tests * edited bot to have top level main function * one more test in commands.js, and removed console.error * fixed typo in webhookHelper * forgot to switch over some tests in bot.test and commands.test * removed console.log from import helper * put console.error in commands * converted utils.js to not use then/catch * tested utils checkImageFormatValidity * removed jest-fetch-mock since it turns out I was just manually mocking it anyway * refactored database to not use then/catch * added dash to commands.js and test to pass * added the remaining webhook tests * changed utils to check for 10MB size not 1MB * removed unnecessary try/catch from utils * Simplify getWebhook to use .find() instead of foreach logic * make memberCommand exit when error occurs with parseMemberCommand * changed commands.js to not have user interaction within the catch * updated console.error message in database.js * made importHelper mock throw error instead of "resolve" error * replaced "pk;" with "pf;" in test * Got rid of unnecessary check for empty message from user (Fluxer doesn't allow this to happen) Removed export of token * getAllMembersInfo checks for fields.length * added default case to memberCommandHandler to throw error if command is not recognized * reversed check for valid proxy (was returning valid if the proxy existed and invalid if it didn't) * pushes e.message instead of full error object to errors array in importHelper * adjusted tests to properly use mockRejectedValue for async rejections * changed getAllMembersInfo map to say `index` not `name` as it actually gets the index of a member and then the member object * adjusted importHelper to properly test throwing of aggregate error * revamped setting of expiration warning (moved to utils and changed logic, wrote tests) --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
This commit is contained in:
@@ -3,9 +3,11 @@ env.config();
|
||||
|
||||
|
||||
jest.mock('../../src/helpers/memberHelper.js', () => {
|
||||
return {memberHelper: {
|
||||
getMembersByAuthor: jest.fn()
|
||||
}}
|
||||
return {
|
||||
memberHelper: {
|
||||
getMembersByAuthor: jest.fn()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const {memberHelper} = require("../../src/helpers/memberHelper.js");
|
||||
@@ -20,11 +22,11 @@ describe('messageHelper', () => {
|
||||
|
||||
describe('parseCommandArgs', () => {
|
||||
test.each([
|
||||
['pk;member', ['']],
|
||||
['pk;member add somePerson "Some Person"', ['add', 'somePerson', 'Some Person']],
|
||||
['pk;member add \"Some Person\"', ['add', 'Some Person']],
|
||||
['pk;member add somePerson \'Some Person\'', ['add', 'somePerson', 'Some Person']],
|
||||
['pk;member add somePerson \"\'Some\' Person\"', ['add', 'somePerson', 'Some Person']],
|
||||
['pf;member', ['']],
|
||||
['pf;member add somePerson "Some Person"', ['add', 'somePerson', 'Some Person']],
|
||||
['pf;member add \"Some Person\"', ['add', 'Some Person']],
|
||||
['pf;member add somePerson \'Some Person\'', ['add', 'somePerson', 'Some Person']],
|
||||
['pf;member add somePerson \"\'Some\' Person\"', ['add', 'somePerson', 'Some Person']],
|
||||
])('%s returns correct arguments', (content, expected) => {
|
||||
// Arrange
|
||||
const command = "member";
|
||||
@@ -72,17 +74,16 @@ describe('messageHelper', () => {
|
||||
['2', 'hello', null, undefined],
|
||||
['2', '--hello', null, undefined],
|
||||
['2', 'hello', attachmentUrl, undefined],
|
||||
['2', '--hello', attachmentUrl,undefined],
|
||||
['2', '--hello', attachmentUrl, undefined],
|
||||
['3', 'hello', null, {}],
|
||||
['3', '--hello', null, {}],
|
||||
['3', 'hello', attachmentUrl, {}],
|
||||
['3', '--hello', attachmentUrl,{}],
|
||||
])('ID %s with string %s returns correct proxy', async(specificAuthorId, content, attachmentUrl, expected) => {
|
||||
['3', '--hello', attachmentUrl, {}],
|
||||
])('ID %s with string %s returns correct proxy', async (specificAuthorId, content, attachmentUrl, expected) => {
|
||||
// Act
|
||||
return messageHelper.parseProxyTags(specificAuthorId, content, attachmentUrl).then((res) => {
|
||||
// Assert
|
||||
expect(res).toEqual(expected);
|
||||
})
|
||||
const res = await messageHelper.parseProxyTags(specificAuthorId, content, attachmentUrl);
|
||||
// Assert
|
||||
expect(res).toEqual(expected);
|
||||
});
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user