Files
PluralFlux-infra/tests/helpers/memberHelper.test.js

738 lines
40 KiB
JavaScript
Raw Normal View History

feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
const {enums} = require('../../src/enums.js');
const {utils} = require("../../src/helpers/utils.js");
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
jest.mock('@fluxerjs/core', () => jest.fn());
perf: Merge develop into main (#36) * Update dockerfile for standalone deployment (#23) * Add files via upload * Update Docker image for pluralflux service * removing unnecessary network and container name definitions --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Converting ES6 back to CJS (#25) converting back to cjs Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Fix: Further converting ES6 to CJS - Making exports named instead of default (#26) * adding to git ignore * making imports named not default to not break all my tests * adjusted setup for memberhelper test --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: add db migrations with typeORM (#28) * adding typescript packages for typeORM * add typeORM initial files * updating package scripts * updating compose.yaml to have an exposed port for the postgres * modifying setup for typeORM * update database stuff and and package.json to help generate migrations * made models and migrations in typeORM * delete unneeded database.js * made database pattern ignored by jest * remove sequelize * separate member repo from member helper * not sure why i made everything numbers in the model but it's fixed now * edited package.json script * remove unused index.ts * adjusted files to reference repository correctly and appdatasource * made appdatasource export as named * removed start-db script * added init to appdatasource in bot.js * migrations finally! * new migration matching model names I want * updating tests * removing testpathignore patterns since it seems to be unecessary? * adjusting migrations to match current schema * removed reference to secrets file * delete old migration * Revert "delete old migration" This reverts commit db1efa39a7a80d8976878856250ccaac6a753ab2. * Revert "adjusting migrations to match current schema" This reverts commit ef89a83f6a2ef0643d6ace0a3fcf9c40f4bc6dd6. * just deleted system creation since it's got nothing in it anyway * renamed memberRepository to memberRepo for consistency * added await back to parseMemberCommand call to memberArgumentHandler * changed call to memberHelper.getMembersByAuthor to memberRepo * renamed repo updateMemberValue to updateMemberField * removed throw references in repo docstrings * remove unneeded subscriber directory ref * changed createdAt and updatedAt columns to be auto-generated made member table have timezone * changed casing of isInitialized in mock for bot.js * removed % from ILike query so that it doesn't match substrings/wildcard * renamed some stray updateMemberValue in mocks -> updateMemberField --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: Add migration to migrate existing data to new member table (#29) added migration to fill new Member table with data from Members Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update message helper reference hotfix (#30) * forgot to update a reference in messageHelper to memberRepo instead of memberHelper * turned off data-source logging --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update dockerfile to run npm start (#31) fix: update dockerfile to run npm start (which runs ts-node) instead of node Co-authored-by: Aster Fialla <asterfialla@gmail.com> * added .env with examples, updated data-source to be access a docker container instead of relying on loopback * i forgot to git add data-source.ts :facepalm: * fix: changed property reference for createMember in repo (#32) fix for createMember object references (was referencing non-existent properties) Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: memberRepo methods syntax (#35) * rearranged update member field and remove member to match expected structure in typeORM * update docstring * change insert to save in memberRepo * added command in package.json --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Delete duplicate members migration (#33) * add migration to delete duplicates that currently exist in the db * added a name attribute for consistency --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Add unique index migration (#34) * add migration to delete duplicates that currently exist in the db * change model and migration to add a unique index constraint to id and name * renamed unique index name to be readable * redid model and migration to use @Unique instead of @Index * remove //Here comment --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * why wont these workflows stay up gahdamn --------- Co-authored-by: Laika Bozhko <63646916+LaikaBzko@users.noreply.github.com> Co-authored-by: Aster Fialla <asterfialla@gmail.com> Co-authored-by: laika <laika@sanya.gay>
2026-03-09 09:00:15 -04:00
jest.mock('../../src/repositories/memberRepo.js', () => {
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
return {
perf: Merge develop into main (#36) * Update dockerfile for standalone deployment (#23) * Add files via upload * Update Docker image for pluralflux service * removing unnecessary network and container name definitions --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Converting ES6 back to CJS (#25) converting back to cjs Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Fix: Further converting ES6 to CJS - Making exports named instead of default (#26) * adding to git ignore * making imports named not default to not break all my tests * adjusted setup for memberhelper test --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: add db migrations with typeORM (#28) * adding typescript packages for typeORM * add typeORM initial files * updating package scripts * updating compose.yaml to have an exposed port for the postgres * modifying setup for typeORM * update database stuff and and package.json to help generate migrations * made models and migrations in typeORM * delete unneeded database.js * made database pattern ignored by jest * remove sequelize * separate member repo from member helper * not sure why i made everything numbers in the model but it's fixed now * edited package.json script * remove unused index.ts * adjusted files to reference repository correctly and appdatasource * made appdatasource export as named * removed start-db script * added init to appdatasource in bot.js * migrations finally! * new migration matching model names I want * updating tests * removing testpathignore patterns since it seems to be unecessary? * adjusting migrations to match current schema * removed reference to secrets file * delete old migration * Revert "delete old migration" This reverts commit db1efa39a7a80d8976878856250ccaac6a753ab2. * Revert "adjusting migrations to match current schema" This reverts commit ef89a83f6a2ef0643d6ace0a3fcf9c40f4bc6dd6. * just deleted system creation since it's got nothing in it anyway * renamed memberRepository to memberRepo for consistency * added await back to parseMemberCommand call to memberArgumentHandler * changed call to memberHelper.getMembersByAuthor to memberRepo * renamed repo updateMemberValue to updateMemberField * removed throw references in repo docstrings * remove unneeded subscriber directory ref * changed createdAt and updatedAt columns to be auto-generated made member table have timezone * changed casing of isInitialized in mock for bot.js * removed % from ILike query so that it doesn't match substrings/wildcard * renamed some stray updateMemberValue in mocks -> updateMemberField --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: Add migration to migrate existing data to new member table (#29) added migration to fill new Member table with data from Members Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update message helper reference hotfix (#30) * forgot to update a reference in messageHelper to memberRepo instead of memberHelper * turned off data-source logging --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update dockerfile to run npm start (#31) fix: update dockerfile to run npm start (which runs ts-node) instead of node Co-authored-by: Aster Fialla <asterfialla@gmail.com> * added .env with examples, updated data-source to be access a docker container instead of relying on loopback * i forgot to git add data-source.ts :facepalm: * fix: changed property reference for createMember in repo (#32) fix for createMember object references (was referencing non-existent properties) Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: memberRepo methods syntax (#35) * rearranged update member field and remove member to match expected structure in typeORM * update docstring * change insert to save in memberRepo * added command in package.json --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Delete duplicate members migration (#33) * add migration to delete duplicates that currently exist in the db * added a name attribute for consistency --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Add unique index migration (#34) * add migration to delete duplicates that currently exist in the db * change model and migration to add a unique index constraint to id and name * renamed unique index name to be readable * redid model and migration to use @Unique instead of @Index * remove //Here comment --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * why wont these workflows stay up gahdamn --------- Co-authored-by: Laika Bozhko <63646916+LaikaBzko@users.noreply.github.com> Co-authored-by: Aster Fialla <asterfialla@gmail.com> Co-authored-by: laika <laika@sanya.gay>
2026-03-09 09:00:15 -04:00
memberRepo: {
getMemberByName: jest.fn().mockResolvedValue(),
getMembersByAuthor: jest.fn().mockResolvedValue(),
removeMember: jest.fn().mockResolvedValue(),
createMember: jest.fn().mockResolvedValue(),
updateMemberField: jest.fn().mockResolvedValue(),
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
}
}
});
jest.mock("../../src/helpers/utils.js", () => {
return {
utils:
{
checkImageFormatValidity: jest.fn().mockResolvedValue(),
}
}
});
const {memberHelper} = require("../../src/helpers/memberHelper.js");
perf: Merge develop into main (#36) * Update dockerfile for standalone deployment (#23) * Add files via upload * Update Docker image for pluralflux service * removing unnecessary network and container name definitions --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Converting ES6 back to CJS (#25) converting back to cjs Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Fix: Further converting ES6 to CJS - Making exports named instead of default (#26) * adding to git ignore * making imports named not default to not break all my tests * adjusted setup for memberhelper test --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: add db migrations with typeORM (#28) * adding typescript packages for typeORM * add typeORM initial files * updating package scripts * updating compose.yaml to have an exposed port for the postgres * modifying setup for typeORM * update database stuff and and package.json to help generate migrations * made models and migrations in typeORM * delete unneeded database.js * made database pattern ignored by jest * remove sequelize * separate member repo from member helper * not sure why i made everything numbers in the model but it's fixed now * edited package.json script * remove unused index.ts * adjusted files to reference repository correctly and appdatasource * made appdatasource export as named * removed start-db script * added init to appdatasource in bot.js * migrations finally! * new migration matching model names I want * updating tests * removing testpathignore patterns since it seems to be unecessary? * adjusting migrations to match current schema * removed reference to secrets file * delete old migration * Revert "delete old migration" This reverts commit db1efa39a7a80d8976878856250ccaac6a753ab2. * Revert "adjusting migrations to match current schema" This reverts commit ef89a83f6a2ef0643d6ace0a3fcf9c40f4bc6dd6. * just deleted system creation since it's got nothing in it anyway * renamed memberRepository to memberRepo for consistency * added await back to parseMemberCommand call to memberArgumentHandler * changed call to memberHelper.getMembersByAuthor to memberRepo * renamed repo updateMemberValue to updateMemberField * removed throw references in repo docstrings * remove unneeded subscriber directory ref * changed createdAt and updatedAt columns to be auto-generated made member table have timezone * changed casing of isInitialized in mock for bot.js * removed % from ILike query so that it doesn't match substrings/wildcard * renamed some stray updateMemberValue in mocks -> updateMemberField --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: Add migration to migrate existing data to new member table (#29) added migration to fill new Member table with data from Members Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update message helper reference hotfix (#30) * forgot to update a reference in messageHelper to memberRepo instead of memberHelper * turned off data-source logging --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update dockerfile to run npm start (#31) fix: update dockerfile to run npm start (which runs ts-node) instead of node Co-authored-by: Aster Fialla <asterfialla@gmail.com> * added .env with examples, updated data-source to be access a docker container instead of relying on loopback * i forgot to git add data-source.ts :facepalm: * fix: changed property reference for createMember in repo (#32) fix for createMember object references (was referencing non-existent properties) Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: memberRepo methods syntax (#35) * rearranged update member field and remove member to match expected structure in typeORM * update docstring * change insert to save in memberRepo * added command in package.json --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Delete duplicate members migration (#33) * add migration to delete duplicates that currently exist in the db * added a name attribute for consistency --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Add unique index migration (#34) * add migration to delete duplicates that currently exist in the db * change model and migration to add a unique index constraint to id and name * renamed unique index name to be readable * redid model and migration to use @Unique instead of @Index * remove //Here comment --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * why wont these workflows stay up gahdamn --------- Co-authored-by: Laika Bozhko <63646916+LaikaBzko@users.noreply.github.com> Co-authored-by: Aster Fialla <asterfialla@gmail.com> Co-authored-by: laika <laika@sanya.gay>
2026-03-09 09:00:15 -04:00
const {memberRepo} = require("../../src/repositories/memberRepo.js");
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
describe('MemberHelper', () => {
const authorId = "0001";
const authorFull = "author#0001";
const attachmentUrl = "../oya.png";
const attachmentExpiration = new Date('2026-01-01').toDateString();
const mockMember = {
name: "somePerson",
displayname: "Some Person",
proxy: "--text",
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>
2026-02-25 19:30:39 -05:00
propic: 'ono.png'
}
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
beforeEach(() => {
jest.resetModules();
jest.clearAllMocks();
})
describe('parseMemberCommand', () => {
beforeEach(() => {
2026-02-20 11:36:41 -05:00
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")
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
});
test.each([
[['--help']],
[['']],
[[]]
])('%s calls getMemberCommandInfo and returns expected result', async (args) => {
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
// Act
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>
2026-02-25 19:30:39 -05:00
const result = await memberHelper.parseMemberCommand(authorId, authorFull, args);
// Assert
expect(result).toEqual("member command info");
expect(memberHelper.getMemberCommandInfo).toHaveBeenCalledTimes(1);
expect(memberHelper.getMemberCommandInfo).toHaveBeenCalledWith();
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
});
test.each([
[[mockMember.name, '--help'], null, null, undefined, true, undefined],
[['new', '--help'], null, null, 'new', true, '--help'],
[['remove', '--help'], null, null, 'remove', true, '--help'],
[['name', '--help'], null, null, 'name', true, '--help'],
[['list', '--help'], null, null, 'list', true, '--help'],
[['name', '--help'], null, null, 'name', true, '--help'],
[['displayname', '--help'], null, null, 'displayname', true, '--help'],
[['proxy', '--help'], null, null, 'proxy', true, '--help'],
[['propic', '--help'], null, null, 'propic', true, '--help'],
[['new'], null, null, 'new', true, undefined],
[['remove'], null, null, 'remove', true, undefined],
[['name'], null, null, 'name', true, undefined],
[['list'], null, null, 'list', false, undefined],
[['displayname'], null, null, 'displayname', true, undefined],
[['proxy'], null, null, 'proxy', true, undefined],
[['propic'], null, null, 'propic', true, undefined],
[[mockMember.name, 'remove'], null, null, 'remove', false, mockMember.name],
[[mockMember.name, 'remove', 'test'], null, null, 'remove', false, mockMember.name],
[[mockMember.name, 'new'], null, null, 'new', false, mockMember.name],
[[mockMember.name, 'new', mockMember.displayname], null, null, 'new', false, mockMember.name],
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>
2026-02-25 19:30:39 -05:00
[[mockMember.name, 'new', mockMember.displayname, mockMember.proxy], null, null, 'new', false, mockMember.name],
[[mockMember.name, 'new', mockMember.displayname, mockMember.proxy, mockMember.propic], null, null, 'new', false, mockMember.name],
[[mockMember.name, 'new', mockMember.displayname, mockMember.proxy, null], mockMember.propic, null, 'new', false, mockMember.name],
[[mockMember.name, 'new', mockMember.displayname, mockMember.proxy, null], mockMember.propic, attachmentExpiration, 'new', false, mockMember.name],
[[mockMember.name, 'name', mockMember.name], null, null, 'name', false, mockMember.name],
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>
2026-02-25 19:30:39 -05:00
[[mockMember.name, 'new', '', mockMember.proxy], null, null, 'new', false, mockMember.name],
[[mockMember.name, 'new', '', '', mockMember.propic], null, null, 'new', false, mockMember.name],
[[mockMember.name, 'new', '', '', null], mockMember.propic, null, 'new', false, mockMember.name],
[[mockMember.name, 'new', '', '', null], mockMember.propic, attachmentExpiration, 'new', false, mockMember.name],
//
[[mockMember.name, 'displayname', mockMember.displayname], null, null, 'displayname', false, mockMember.name],
[[mockMember.name, 'proxy', mockMember.proxy], null, null, 'proxy', false, mockMember.name],
[[mockMember.name, 'propic', mockMember.propic], null, null, 'propic', false, mockMember.name],
[[mockMember.name, 'propic', null], mockMember.propic, null, 'propic', false, mockMember.name],
[[mockMember.name, 'propic', null], mockMember.propic, attachmentExpiration, 'propic', false, mockMember.name],
[['remove', mockMember.name], null, null, 'remove', false, mockMember.name],
[['remove', mockMember.name, 'test'], null, null, 'remove', false, mockMember.name],
[['new', mockMember.name], null, null, 'new', false, mockMember.name],
[['new', mockMember.name, mockMember.displayname], null, null, 'new', false, mockMember.name],
[['new', mockMember.name, mockMember.displayname, mockMember.proxy], null, null, 'new', false, mockMember.name],
[['new', mockMember.name, mockMember.displayname, mockMember.proxy, mockMember.propic], null, null, 'new', false, mockMember.name],
[['new', mockMember.name, undefined, mockMember.displayname, mockMember.proxy, undefined], mockMember.propic, null, 'new', false, mockMember.name],
[['new', mockMember.name, undefined, mockMember.displayname, mockMember.proxy, undefined], mockMember.propic, attachmentExpiration, 'new', false, mockMember.name],
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>
2026-02-25 19:30:39 -05:00
[['new', mockMember.name, '', mockMember.proxy], null, null, 'new', false, mockMember.name],
[['new', mockMember.name, '', '', mockMember.propic], null, null, 'new', false, mockMember.name],
[['new', mockMember.name, '', '', null], mockMember.propic, null, 'new', false, mockMember.name],
[['new', mockMember.name, '', '', null], mockMember.propic, attachmentExpiration, 'new', false, mockMember.name],
//
[['name', mockMember.name, mockMember.name], null, null, 'name', false, mockMember.name],
[['displayname', mockMember.name, mockMember.name, mockMember.displayname], null, null, 'displayname', false, mockMember.name],
[['proxy', mockMember.name, mockMember.name, mockMember.displayname, mockMember.proxy], null, null, 'proxy', false, mockMember.name],
[['propic', mockMember.name, mockMember.name, mockMember.displayname, mockMember.proxy, mockMember.propic], null, null, 'propic', false, mockMember.name],
[['propic', mockMember.name, undefined, mockMember.name, mockMember.displayname, mockMember.proxy, undefined], mockMember.propic, null, 'propic', false, mockMember.name],
[['propic', mockMember.name, undefined, mockMember.name, mockMember.displayname, mockMember.proxy, undefined], mockMember.propic, attachmentExpiration, 'propic', false, mockMember.name]
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>
2026-02-25 19:30:39 -05:00
])('%s args with attachmentURL %s and attachment expiration %s calls memberCommandHandler with correct values', async (args, attachmentUrl, attachmentExpiration, command, isHelp, memberName) => {
console.log(args, command, isHelp)
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
// Act
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>
2026-02-25 19:30:39 -05:00
const result = await memberHelper.parseMemberCommand(authorId, authorFull, args, attachmentUrl, attachmentExpiration);
// Assert
expect(result).toEqual("handled argument");
expect(memberHelper.memberArgumentHandler).toHaveBeenCalledTimes(1);
expect(memberHelper.memberArgumentHandler).toHaveBeenCalledWith(authorId, authorFull, isHelp, command, memberName, args, attachmentUrl, attachmentExpiration);
})
});
describe('memberArgumentHandler', () => {
beforeEach(() => {
jest.spyOn(memberHelper, 'memberCommandHandler').mockResolvedValue("handled command");
jest.spyOn(memberHelper, 'getAllMembersInfo').mockResolvedValue("all member info");
jest.spyOn(memberHelper, 'sendCurrentValue').mockResolvedValue("current value");
jest.spyOn(memberHelper, 'sendHelpEnum').mockReturnValue("help enum");
})
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>
2026-02-25 19:30:39 -05:00
test('when all values are null should throw command not recognized enum', async () => {
// Arrange
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>
2026-02-25 19:30:39 -05:00
await expect(memberHelper.memberArgumentHandler(authorId, authorFull, false, null, null, [])).rejects.toThrow(enums.err.COMMAND_NOT_RECOGNIZED);
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
})
2026-02-20 11:36:41 -05:00
test.each([
['new'],
['remove'],
['name'],
['displayname'],
['proxy'],
['propic'],
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>
2026-02-25 19:30:39 -05:00
])('when %s is present but other values are null, should throw no member enum', async (command) => {
// Arrange
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>
2026-02-25 19:30:39 -05:00
await expect(memberHelper.memberArgumentHandler(authorId, authorFull, false, command, null, [])).rejects.toThrow(enums.err.NO_MEMBER);
2026-02-20 11:36:41 -05:00
})
test.each([
['new'],
['remove'],
['name'],
['list'],
['displayname'],
['proxy'],
['propic'],
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>
2026-02-25 19:30:39 -05:00
])('%s calls sendHelpEnum', async (command) => {
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
// Arrange
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>
2026-02-25 19:30:39 -05:00
const result = await memberHelper.memberArgumentHandler(authorId, authorFull, true, command, mockMember.name, []);
// Assert
expect(result).toEqual("help enum");
expect(memberHelper.sendHelpEnum).toHaveBeenCalledTimes(1);
expect(memberHelper.sendHelpEnum).toHaveBeenCalledWith(command);
})
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>
2026-02-25 19:30:39 -05:00
test('list should call getAllMembersInfo', async () => {
// Arrange
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>
2026-02-25 19:30:39 -05:00
const result = await memberHelper.memberArgumentHandler(authorId, authorFull, false, 'list', mockMember.name, []);
// Assert
expect(result).toEqual("all member info");
expect(memberHelper.getAllMembersInfo).toHaveBeenCalledTimes(1);
expect(memberHelper.getAllMembersInfo).toHaveBeenCalledWith(authorId, authorFull);
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
})
test.each([
[[mockMember.name, 'remove'], null, null, 'remove'],
[[mockMember.name, 'remove', 'test'], null, null, 'remove'],
[[mockMember.name, 'new'], null, null, 'new'],
[[mockMember.name, 'new', mockMember.displayname], null, null, 'new'],
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>
2026-02-25 19:30:39 -05:00
[[mockMember.name, 'new', mockMember.displayname, mockMember.proxy], null, null, 'new'],
[[mockMember.name, 'new', mockMember.displayname, mockMember.proxy, mockMember.propic], null, null, 'new'],
[[mockMember.name, 'new', mockMember.displayname, mockMember.proxy, null], mockMember.propic, null, 'new'],
[[mockMember.name, 'new', mockMember.displayname, mockMember.proxy, null], mockMember.propic, attachmentExpiration, 'new'],
[[mockMember.name, 'name', mockMember.name], null, null, 'name'],
[[mockMember.name, 'displayname', mockMember.displayname], null, null, 'displayname'],
[[mockMember.name, 'new', mockMember.displayname], null, null, 'new'],
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>
2026-02-25 19:30:39 -05:00
[[mockMember.name, 'new', '', mockMember.proxy], null, null, 'new'],
[[mockMember.name, 'new', '', '', mockMember.propic], null, null, 'new'],
[[mockMember.name, 'new', '', '', undefined], mockMember.propic, null, 'new'],
[[mockMember.name, 'new', '', '', undefined], mockMember.propic, attachmentExpiration, 'new'],
[[mockMember.name, 'new', '', ''], mockMember.propic, null, 'new'],
[[mockMember.name, 'new', '', ''], mockMember.propic, attachmentExpiration, 'new'],
[[mockMember.name, 'proxy', mockMember.proxy], null, null, 'proxy'],
[[mockMember.name, 'propic', mockMember.propic], null, null, 'propic'],
[[mockMember.name, 'propic', undefined], mockMember.propic, null, 'propic'],
[[mockMember.name, 'propic', undefined], mockMember.propic, attachmentExpiration, 'propic'],
[[mockMember.name, 'propic'], mockMember.propic, null, 'propic'],
[[mockMember.name, 'propic'], mockMember.propic, attachmentExpiration, 'propic'],
[['remove', mockMember.name], null, null, 'remove'],
[['remove', mockMember.name, 'test'], null, null, 'remove'],
[['new', mockMember.name], null, null, 'new'],
[['new', mockMember.name, mockMember.displayname], null, null, 'new'],
[['new', mockMember.name, mockMember.displayname, mockMember.proxy], null, null, 'new'],
[['new', mockMember.name, mockMember.displayname, mockMember.proxy, mockMember.propic], null, null, 'new'],
[['new', mockMember.name, undefined, mockMember.displayname, mockMember.proxy, undefined], mockMember.propic, null, 'new'],
[['new', mockMember.name, undefined, mockMember.displayname, mockMember.proxy, undefined], mockMember.propic, attachmentExpiration, 'new'],
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>
2026-02-25 19:30:39 -05:00
[['new', mockMember.name, '', mockMember.proxy], null, null, 'new'],
[['new', mockMember.name, '', '', mockMember.propic], null, null, 'new'],
[['new', mockMember.name, '', '', undefined], mockMember.propic, null, 'new'],
[['new', mockMember.name, '', '', undefined], mockMember.propic, attachmentExpiration, 'new'],
[['new', mockMember.name, '', ''], mockMember.propic, null, 'new'],
[['new', mockMember.name, '', ''], mockMember.propic, attachmentExpiration, 'new'],
[['name', mockMember.name, mockMember.name], null, null, 'name'],
[['displayname', mockMember.name, mockMember.name, mockMember.displayname], null, null, 'displayname'],
[['proxy', mockMember.name, mockMember.name, mockMember.displayname, mockMember.proxy], null, null, 'proxy'],
[['propic', mockMember.name, mockMember.name, mockMember.displayname, mockMember.proxy, mockMember.propic], null, null, 'propic'],
[['propic', mockMember.name, undefined, mockMember.name, mockMember.displayname, mockMember.proxy, undefined], mockMember.propic, null, 'propic'],
[['propic', mockMember.name, undefined, mockMember.name, mockMember.displayname, mockMember.proxy, undefined], mockMember.propic, attachmentExpiration, 'propic']
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>
2026-02-25 19:30:39 -05:00
])('%s args with attachmentURL %s and attachment expiration %s calls memberCommandHandler', async (args, attachmentUrl, attachmentExpiration, command) => {
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
// Arrange
let values = args.slice(2);
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
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>
2026-02-25 19:30:39 -05:00
const result = await memberHelper.memberArgumentHandler(authorId, authorFull, false, command, mockMember.name, args, attachmentUrl, attachmentExpiration);
// Assert
expect(result).toEqual("handled command");
expect(memberHelper.memberCommandHandler).toHaveBeenCalledTimes(1);
expect(memberHelper.memberCommandHandler).toHaveBeenCalledWith(authorId, command, mockMember.name, values, attachmentUrl, attachmentExpiration);
})
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
test.each([
[null],
['name'],
['displayname'],
['proxy'],
['propic'],
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>
2026-02-25 19:30:39 -05:00
])('%s calls sendCurrentValue', async (command) => {
const result = await memberHelper.memberArgumentHandler(authorId, authorFull, false, command, mockMember.name, []);
// Assert
expect(result).toEqual("current value");
expect(memberHelper.sendCurrentValue).toHaveBeenCalledTimes(1);
expect(memberHelper.sendCurrentValue).toHaveBeenCalledWith(authorId, mockMember.name, command);
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
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>
2026-02-25 19:30:39 -05:00
})
});
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
describe('sendCurrentValue', () => {
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
test.each([
['name', `The name of ${mockMember.name} is \"${mockMember.name}\" but you probably already knew that!`],
['displayname', `The display name for ${mockMember.name} is \"${mockMember.displayname}\".`],
['proxy', `The proxy for ${mockMember.name} is \"${mockMember.proxy}\".`],
['propic', `The profile picture for ${mockMember.name} is \"${mockMember.propic}\".`],
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>
2026-02-25 19:30:39 -05:00
])('%s calls getMemberByName and returns value', async (command, expected) => {
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
// Arrange
perf: Merge develop into main (#36) * Update dockerfile for standalone deployment (#23) * Add files via upload * Update Docker image for pluralflux service * removing unnecessary network and container name definitions --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Converting ES6 back to CJS (#25) converting back to cjs Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Fix: Further converting ES6 to CJS - Making exports named instead of default (#26) * adding to git ignore * making imports named not default to not break all my tests * adjusted setup for memberhelper test --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: add db migrations with typeORM (#28) * adding typescript packages for typeORM * add typeORM initial files * updating package scripts * updating compose.yaml to have an exposed port for the postgres * modifying setup for typeORM * update database stuff and and package.json to help generate migrations * made models and migrations in typeORM * delete unneeded database.js * made database pattern ignored by jest * remove sequelize * separate member repo from member helper * not sure why i made everything numbers in the model but it's fixed now * edited package.json script * remove unused index.ts * adjusted files to reference repository correctly and appdatasource * made appdatasource export as named * removed start-db script * added init to appdatasource in bot.js * migrations finally! * new migration matching model names I want * updating tests * removing testpathignore patterns since it seems to be unecessary? * adjusting migrations to match current schema * removed reference to secrets file * delete old migration * Revert "delete old migration" This reverts commit db1efa39a7a80d8976878856250ccaac6a753ab2. * Revert "adjusting migrations to match current schema" This reverts commit ef89a83f6a2ef0643d6ace0a3fcf9c40f4bc6dd6. * just deleted system creation since it's got nothing in it anyway * renamed memberRepository to memberRepo for consistency * added await back to parseMemberCommand call to memberArgumentHandler * changed call to memberHelper.getMembersByAuthor to memberRepo * renamed repo updateMemberValue to updateMemberField * removed throw references in repo docstrings * remove unneeded subscriber directory ref * changed createdAt and updatedAt columns to be auto-generated made member table have timezone * changed casing of isInitialized in mock for bot.js * removed % from ILike query so that it doesn't match substrings/wildcard * renamed some stray updateMemberValue in mocks -> updateMemberField --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: Add migration to migrate existing data to new member table (#29) added migration to fill new Member table with data from Members Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update message helper reference hotfix (#30) * forgot to update a reference in messageHelper to memberRepo instead of memberHelper * turned off data-source logging --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update dockerfile to run npm start (#31) fix: update dockerfile to run npm start (which runs ts-node) instead of node Co-authored-by: Aster Fialla <asterfialla@gmail.com> * added .env with examples, updated data-source to be access a docker container instead of relying on loopback * i forgot to git add data-source.ts :facepalm: * fix: changed property reference for createMember in repo (#32) fix for createMember object references (was referencing non-existent properties) Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: memberRepo methods syntax (#35) * rearranged update member field and remove member to match expected structure in typeORM * update docstring * change insert to save in memberRepo * added command in package.json --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Delete duplicate members migration (#33) * add migration to delete duplicates that currently exist in the db * added a name attribute for consistency --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Add unique index migration (#34) * add migration to delete duplicates that currently exist in the db * change model and migration to add a unique index constraint to id and name * renamed unique index name to be readable * redid model and migration to use @Unique instead of @Index * remove //Here comment --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * why wont these workflows stay up gahdamn --------- Co-authored-by: Laika Bozhko <63646916+LaikaBzko@users.noreply.github.com> Co-authored-by: Aster Fialla <asterfialla@gmail.com> Co-authored-by: laika <laika@sanya.gay>
2026-03-09 09:00:15 -04:00
memberRepo.getMemberByName.mockResolvedValue(mockMember);
// Act
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>
2026-02-25 19:30:39 -05:00
const result = await memberHelper.sendCurrentValue(authorId, mockMember.name, command);
// Assert
expect(result).toEqual(expected);
perf: Merge develop into main (#36) * Update dockerfile for standalone deployment (#23) * Add files via upload * Update Docker image for pluralflux service * removing unnecessary network and container name definitions --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Converting ES6 back to CJS (#25) converting back to cjs Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Fix: Further converting ES6 to CJS - Making exports named instead of default (#26) * adding to git ignore * making imports named not default to not break all my tests * adjusted setup for memberhelper test --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: add db migrations with typeORM (#28) * adding typescript packages for typeORM * add typeORM initial files * updating package scripts * updating compose.yaml to have an exposed port for the postgres * modifying setup for typeORM * update database stuff and and package.json to help generate migrations * made models and migrations in typeORM * delete unneeded database.js * made database pattern ignored by jest * remove sequelize * separate member repo from member helper * not sure why i made everything numbers in the model but it's fixed now * edited package.json script * remove unused index.ts * adjusted files to reference repository correctly and appdatasource * made appdatasource export as named * removed start-db script * added init to appdatasource in bot.js * migrations finally! * new migration matching model names I want * updating tests * removing testpathignore patterns since it seems to be unecessary? * adjusting migrations to match current schema * removed reference to secrets file * delete old migration * Revert "delete old migration" This reverts commit db1efa39a7a80d8976878856250ccaac6a753ab2. * Revert "adjusting migrations to match current schema" This reverts commit ef89a83f6a2ef0643d6ace0a3fcf9c40f4bc6dd6. * just deleted system creation since it's got nothing in it anyway * renamed memberRepository to memberRepo for consistency * added await back to parseMemberCommand call to memberArgumentHandler * changed call to memberHelper.getMembersByAuthor to memberRepo * renamed repo updateMemberValue to updateMemberField * removed throw references in repo docstrings * remove unneeded subscriber directory ref * changed createdAt and updatedAt columns to be auto-generated made member table have timezone * changed casing of isInitialized in mock for bot.js * removed % from ILike query so that it doesn't match substrings/wildcard * renamed some stray updateMemberValue in mocks -> updateMemberField --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: Add migration to migrate existing data to new member table (#29) added migration to fill new Member table with data from Members Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update message helper reference hotfix (#30) * forgot to update a reference in messageHelper to memberRepo instead of memberHelper * turned off data-source logging --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update dockerfile to run npm start (#31) fix: update dockerfile to run npm start (which runs ts-node) instead of node Co-authored-by: Aster Fialla <asterfialla@gmail.com> * added .env with examples, updated data-source to be access a docker container instead of relying on loopback * i forgot to git add data-source.ts :facepalm: * fix: changed property reference for createMember in repo (#32) fix for createMember object references (was referencing non-existent properties) Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: memberRepo methods syntax (#35) * rearranged update member field and remove member to match expected structure in typeORM * update docstring * change insert to save in memberRepo * added command in package.json --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Delete duplicate members migration (#33) * add migration to delete duplicates that currently exist in the db * added a name attribute for consistency --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Add unique index migration (#34) * add migration to delete duplicates that currently exist in the db * change model and migration to add a unique index constraint to id and name * renamed unique index name to be readable * redid model and migration to use @Unique instead of @Index * remove //Here comment --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * why wont these workflows stay up gahdamn --------- Co-authored-by: Laika Bozhko <63646916+LaikaBzko@users.noreply.github.com> Co-authored-by: Aster Fialla <asterfialla@gmail.com> Co-authored-by: laika <laika@sanya.gay>
2026-03-09 09:00:15 -04:00
expect(memberRepo.getMemberByName).toHaveBeenCalledTimes(1);
expect(memberRepo.getMemberByName).toHaveBeenCalledWith(authorId, mockMember.name);
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>
2026-02-25 19:30:39 -05:00
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
})
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>
2026-02-25 19:30:39 -05:00
test('returns error if no member found', async () => {
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
// Arrange
perf: Merge develop into main (#36) * Update dockerfile for standalone deployment (#23) * Add files via upload * Update Docker image for pluralflux service * removing unnecessary network and container name definitions --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Converting ES6 back to CJS (#25) converting back to cjs Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Fix: Further converting ES6 to CJS - Making exports named instead of default (#26) * adding to git ignore * making imports named not default to not break all my tests * adjusted setup for memberhelper test --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: add db migrations with typeORM (#28) * adding typescript packages for typeORM * add typeORM initial files * updating package scripts * updating compose.yaml to have an exposed port for the postgres * modifying setup for typeORM * update database stuff and and package.json to help generate migrations * made models and migrations in typeORM * delete unneeded database.js * made database pattern ignored by jest * remove sequelize * separate member repo from member helper * not sure why i made everything numbers in the model but it's fixed now * edited package.json script * remove unused index.ts * adjusted files to reference repository correctly and appdatasource * made appdatasource export as named * removed start-db script * added init to appdatasource in bot.js * migrations finally! * new migration matching model names I want * updating tests * removing testpathignore patterns since it seems to be unecessary? * adjusting migrations to match current schema * removed reference to secrets file * delete old migration * Revert "delete old migration" This reverts commit db1efa39a7a80d8976878856250ccaac6a753ab2. * Revert "adjusting migrations to match current schema" This reverts commit ef89a83f6a2ef0643d6ace0a3fcf9c40f4bc6dd6. * just deleted system creation since it's got nothing in it anyway * renamed memberRepository to memberRepo for consistency * added await back to parseMemberCommand call to memberArgumentHandler * changed call to memberHelper.getMembersByAuthor to memberRepo * renamed repo updateMemberValue to updateMemberField * removed throw references in repo docstrings * remove unneeded subscriber directory ref * changed createdAt and updatedAt columns to be auto-generated made member table have timezone * changed casing of isInitialized in mock for bot.js * removed % from ILike query so that it doesn't match substrings/wildcard * renamed some stray updateMemberValue in mocks -> updateMemberField --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: Add migration to migrate existing data to new member table (#29) added migration to fill new Member table with data from Members Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update message helper reference hotfix (#30) * forgot to update a reference in messageHelper to memberRepo instead of memberHelper * turned off data-source logging --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update dockerfile to run npm start (#31) fix: update dockerfile to run npm start (which runs ts-node) instead of node Co-authored-by: Aster Fialla <asterfialla@gmail.com> * added .env with examples, updated data-source to be access a docker container instead of relying on loopback * i forgot to git add data-source.ts :facepalm: * fix: changed property reference for createMember in repo (#32) fix for createMember object references (was referencing non-existent properties) Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: memberRepo methods syntax (#35) * rearranged update member field and remove member to match expected structure in typeORM * update docstring * change insert to save in memberRepo * added command in package.json --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Delete duplicate members migration (#33) * add migration to delete duplicates that currently exist in the db * added a name attribute for consistency --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Add unique index migration (#34) * add migration to delete duplicates that currently exist in the db * change model and migration to add a unique index constraint to id and name * renamed unique index name to be readable * redid model and migration to use @Unique instead of @Index * remove //Here comment --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * why wont these workflows stay up gahdamn --------- Co-authored-by: Laika Bozhko <63646916+LaikaBzko@users.noreply.github.com> Co-authored-by: Aster Fialla <asterfialla@gmail.com> Co-authored-by: laika <laika@sanya.gay>
2026-03-09 09:00:15 -04:00
memberRepo.getMemberByName.mockResolvedValue(null);
// Act
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>
2026-02-25 19:30:39 -05:00
await expect(memberHelper.sendCurrentValue(authorId, mockMember.name, 'name')).rejects.toThrow(enums.err.NO_MEMBER);
// Assert
perf: Merge develop into main (#36) * Update dockerfile for standalone deployment (#23) * Add files via upload * Update Docker image for pluralflux service * removing unnecessary network and container name definitions --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Converting ES6 back to CJS (#25) converting back to cjs Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Fix: Further converting ES6 to CJS - Making exports named instead of default (#26) * adding to git ignore * making imports named not default to not break all my tests * adjusted setup for memberhelper test --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: add db migrations with typeORM (#28) * adding typescript packages for typeORM * add typeORM initial files * updating package scripts * updating compose.yaml to have an exposed port for the postgres * modifying setup for typeORM * update database stuff and and package.json to help generate migrations * made models and migrations in typeORM * delete unneeded database.js * made database pattern ignored by jest * remove sequelize * separate member repo from member helper * not sure why i made everything numbers in the model but it's fixed now * edited package.json script * remove unused index.ts * adjusted files to reference repository correctly and appdatasource * made appdatasource export as named * removed start-db script * added init to appdatasource in bot.js * migrations finally! * new migration matching model names I want * updating tests * removing testpathignore patterns since it seems to be unecessary? * adjusting migrations to match current schema * removed reference to secrets file * delete old migration * Revert "delete old migration" This reverts commit db1efa39a7a80d8976878856250ccaac6a753ab2. * Revert "adjusting migrations to match current schema" This reverts commit ef89a83f6a2ef0643d6ace0a3fcf9c40f4bc6dd6. * just deleted system creation since it's got nothing in it anyway * renamed memberRepository to memberRepo for consistency * added await back to parseMemberCommand call to memberArgumentHandler * changed call to memberHelper.getMembersByAuthor to memberRepo * renamed repo updateMemberValue to updateMemberField * removed throw references in repo docstrings * remove unneeded subscriber directory ref * changed createdAt and updatedAt columns to be auto-generated made member table have timezone * changed casing of isInitialized in mock for bot.js * removed % from ILike query so that it doesn't match substrings/wildcard * renamed some stray updateMemberValue in mocks -> updateMemberField --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: Add migration to migrate existing data to new member table (#29) added migration to fill new Member table with data from Members Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update message helper reference hotfix (#30) * forgot to update a reference in messageHelper to memberRepo instead of memberHelper * turned off data-source logging --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update dockerfile to run npm start (#31) fix: update dockerfile to run npm start (which runs ts-node) instead of node Co-authored-by: Aster Fialla <asterfialla@gmail.com> * added .env with examples, updated data-source to be access a docker container instead of relying on loopback * i forgot to git add data-source.ts :facepalm: * fix: changed property reference for createMember in repo (#32) fix for createMember object references (was referencing non-existent properties) Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: memberRepo methods syntax (#35) * rearranged update member field and remove member to match expected structure in typeORM * update docstring * change insert to save in memberRepo * added command in package.json --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Delete duplicate members migration (#33) * add migration to delete duplicates that currently exist in the db * added a name attribute for consistency --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Add unique index migration (#34) * add migration to delete duplicates that currently exist in the db * change model and migration to add a unique index constraint to id and name * renamed unique index name to be readable * redid model and migration to use @Unique instead of @Index * remove //Here comment --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * why wont these workflows stay up gahdamn --------- Co-authored-by: Laika Bozhko <63646916+LaikaBzko@users.noreply.github.com> Co-authored-by: Aster Fialla <asterfialla@gmail.com> Co-authored-by: laika <laika@sanya.gay>
2026-03-09 09:00:15 -04:00
expect(memberRepo.getMemberByName).toHaveBeenCalledTimes(1);
expect(memberRepo.getMemberByName).toHaveBeenCalledWith(authorId, mockMember.name);
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>
2026-02-25 19:30:39 -05:00
});
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
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>
2026-02-25 19:30:39 -05:00
test('calls getMemberInfo with member if no command present', async () => {
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
// Arrange
perf: Merge develop into main (#36) * Update dockerfile for standalone deployment (#23) * Add files via upload * Update Docker image for pluralflux service * removing unnecessary network and container name definitions --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Converting ES6 back to CJS (#25) converting back to cjs Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Fix: Further converting ES6 to CJS - Making exports named instead of default (#26) * adding to git ignore * making imports named not default to not break all my tests * adjusted setup for memberhelper test --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: add db migrations with typeORM (#28) * adding typescript packages for typeORM * add typeORM initial files * updating package scripts * updating compose.yaml to have an exposed port for the postgres * modifying setup for typeORM * update database stuff and and package.json to help generate migrations * made models and migrations in typeORM * delete unneeded database.js * made database pattern ignored by jest * remove sequelize * separate member repo from member helper * not sure why i made everything numbers in the model but it's fixed now * edited package.json script * remove unused index.ts * adjusted files to reference repository correctly and appdatasource * made appdatasource export as named * removed start-db script * added init to appdatasource in bot.js * migrations finally! * new migration matching model names I want * updating tests * removing testpathignore patterns since it seems to be unecessary? * adjusting migrations to match current schema * removed reference to secrets file * delete old migration * Revert "delete old migration" This reverts commit db1efa39a7a80d8976878856250ccaac6a753ab2. * Revert "adjusting migrations to match current schema" This reverts commit ef89a83f6a2ef0643d6ace0a3fcf9c40f4bc6dd6. * just deleted system creation since it's got nothing in it anyway * renamed memberRepository to memberRepo for consistency * added await back to parseMemberCommand call to memberArgumentHandler * changed call to memberHelper.getMembersByAuthor to memberRepo * renamed repo updateMemberValue to updateMemberField * removed throw references in repo docstrings * remove unneeded subscriber directory ref * changed createdAt and updatedAt columns to be auto-generated made member table have timezone * changed casing of isInitialized in mock for bot.js * removed % from ILike query so that it doesn't match substrings/wildcard * renamed some stray updateMemberValue in mocks -> updateMemberField --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: Add migration to migrate existing data to new member table (#29) added migration to fill new Member table with data from Members Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update message helper reference hotfix (#30) * forgot to update a reference in messageHelper to memberRepo instead of memberHelper * turned off data-source logging --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update dockerfile to run npm start (#31) fix: update dockerfile to run npm start (which runs ts-node) instead of node Co-authored-by: Aster Fialla <asterfialla@gmail.com> * added .env with examples, updated data-source to be access a docker container instead of relying on loopback * i forgot to git add data-source.ts :facepalm: * fix: changed property reference for createMember in repo (#32) fix for createMember object references (was referencing non-existent properties) Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: memberRepo methods syntax (#35) * rearranged update member field and remove member to match expected structure in typeORM * update docstring * change insert to save in memberRepo * added command in package.json --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Delete duplicate members migration (#33) * add migration to delete duplicates that currently exist in the db * added a name attribute for consistency --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Add unique index migration (#34) * add migration to delete duplicates that currently exist in the db * change model and migration to add a unique index constraint to id and name * renamed unique index name to be readable * redid model and migration to use @Unique instead of @Index * remove //Here comment --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * why wont these workflows stay up gahdamn --------- Co-authored-by: Laika Bozhko <63646916+LaikaBzko@users.noreply.github.com> Co-authored-by: Aster Fialla <asterfialla@gmail.com> Co-authored-by: laika <laika@sanya.gay>
2026-03-09 09:00:15 -04:00
memberRepo.getMemberByName.mockResolvedValue(mockMember);
jest.spyOn(memberHelper, 'getMemberInfo').mockResolvedValue('member info');
// Act
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>
2026-02-25 19:30:39 -05:00
const result = await memberHelper.sendCurrentValue(authorId, mockMember.name, null);
// Assert
expect(result).toEqual('member info');
expect(memberHelper.getMemberInfo).toHaveBeenCalledTimes(1);
expect(memberHelper.getMemberInfo).toHaveBeenCalledWith(mockMember);
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
})
test.each([
['displayname', `Display name ${enums.err.NO_VALUE}`],
['proxy', `Proxy ${enums.err.NO_VALUE}`],
['propic', `Propic ${enums.err.NO_VALUE}`],
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>
2026-02-25 19:30:39 -05:00
])('returns null message if no value found', async (command, expected) => {
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
// Arrange
const empty = {name: mockMember.name, displayname: null, proxy: null, propic: null}
perf: Merge develop into main (#36) * Update dockerfile for standalone deployment (#23) * Add files via upload * Update Docker image for pluralflux service * removing unnecessary network and container name definitions --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Converting ES6 back to CJS (#25) converting back to cjs Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Fix: Further converting ES6 to CJS - Making exports named instead of default (#26) * adding to git ignore * making imports named not default to not break all my tests * adjusted setup for memberhelper test --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: add db migrations with typeORM (#28) * adding typescript packages for typeORM * add typeORM initial files * updating package scripts * updating compose.yaml to have an exposed port for the postgres * modifying setup for typeORM * update database stuff and and package.json to help generate migrations * made models and migrations in typeORM * delete unneeded database.js * made database pattern ignored by jest * remove sequelize * separate member repo from member helper * not sure why i made everything numbers in the model but it's fixed now * edited package.json script * remove unused index.ts * adjusted files to reference repository correctly and appdatasource * made appdatasource export as named * removed start-db script * added init to appdatasource in bot.js * migrations finally! * new migration matching model names I want * updating tests * removing testpathignore patterns since it seems to be unecessary? * adjusting migrations to match current schema * removed reference to secrets file * delete old migration * Revert "delete old migration" This reverts commit db1efa39a7a80d8976878856250ccaac6a753ab2. * Revert "adjusting migrations to match current schema" This reverts commit ef89a83f6a2ef0643d6ace0a3fcf9c40f4bc6dd6. * just deleted system creation since it's got nothing in it anyway * renamed memberRepository to memberRepo for consistency * added await back to parseMemberCommand call to memberArgumentHandler * changed call to memberHelper.getMembersByAuthor to memberRepo * renamed repo updateMemberValue to updateMemberField * removed throw references in repo docstrings * remove unneeded subscriber directory ref * changed createdAt and updatedAt columns to be auto-generated made member table have timezone * changed casing of isInitialized in mock for bot.js * removed % from ILike query so that it doesn't match substrings/wildcard * renamed some stray updateMemberValue in mocks -> updateMemberField --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: Add migration to migrate existing data to new member table (#29) added migration to fill new Member table with data from Members Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update message helper reference hotfix (#30) * forgot to update a reference in messageHelper to memberRepo instead of memberHelper * turned off data-source logging --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update dockerfile to run npm start (#31) fix: update dockerfile to run npm start (which runs ts-node) instead of node Co-authored-by: Aster Fialla <asterfialla@gmail.com> * added .env with examples, updated data-source to be access a docker container instead of relying on loopback * i forgot to git add data-source.ts :facepalm: * fix: changed property reference for createMember in repo (#32) fix for createMember object references (was referencing non-existent properties) Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: memberRepo methods syntax (#35) * rearranged update member field and remove member to match expected structure in typeORM * update docstring * change insert to save in memberRepo * added command in package.json --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Delete duplicate members migration (#33) * add migration to delete duplicates that currently exist in the db * added a name attribute for consistency --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Add unique index migration (#34) * add migration to delete duplicates that currently exist in the db * change model and migration to add a unique index constraint to id and name * renamed unique index name to be readable * redid model and migration to use @Unique instead of @Index * remove //Here comment --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * why wont these workflows stay up gahdamn --------- Co-authored-by: Laika Bozhko <63646916+LaikaBzko@users.noreply.github.com> Co-authored-by: Aster Fialla <asterfialla@gmail.com> Co-authored-by: laika <laika@sanya.gay>
2026-03-09 09:00:15 -04:00
memberRepo.getMemberByName.mockResolvedValue(empty);
// Act
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>
2026-02-25 19:30:39 -05:00
const result = await memberHelper.sendCurrentValue(authorId, mockMember.name, command);
// Assert
expect(result).toEqual(expected);
perf: Merge develop into main (#36) * Update dockerfile for standalone deployment (#23) * Add files via upload * Update Docker image for pluralflux service * removing unnecessary network and container name definitions --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Converting ES6 back to CJS (#25) converting back to cjs Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Fix: Further converting ES6 to CJS - Making exports named instead of default (#26) * adding to git ignore * making imports named not default to not break all my tests * adjusted setup for memberhelper test --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: add db migrations with typeORM (#28) * adding typescript packages for typeORM * add typeORM initial files * updating package scripts * updating compose.yaml to have an exposed port for the postgres * modifying setup for typeORM * update database stuff and and package.json to help generate migrations * made models and migrations in typeORM * delete unneeded database.js * made database pattern ignored by jest * remove sequelize * separate member repo from member helper * not sure why i made everything numbers in the model but it's fixed now * edited package.json script * remove unused index.ts * adjusted files to reference repository correctly and appdatasource * made appdatasource export as named * removed start-db script * added init to appdatasource in bot.js * migrations finally! * new migration matching model names I want * updating tests * removing testpathignore patterns since it seems to be unecessary? * adjusting migrations to match current schema * removed reference to secrets file * delete old migration * Revert "delete old migration" This reverts commit db1efa39a7a80d8976878856250ccaac6a753ab2. * Revert "adjusting migrations to match current schema" This reverts commit ef89a83f6a2ef0643d6ace0a3fcf9c40f4bc6dd6. * just deleted system creation since it's got nothing in it anyway * renamed memberRepository to memberRepo for consistency * added await back to parseMemberCommand call to memberArgumentHandler * changed call to memberHelper.getMembersByAuthor to memberRepo * renamed repo updateMemberValue to updateMemberField * removed throw references in repo docstrings * remove unneeded subscriber directory ref * changed createdAt and updatedAt columns to be auto-generated made member table have timezone * changed casing of isInitialized in mock for bot.js * removed % from ILike query so that it doesn't match substrings/wildcard * renamed some stray updateMemberValue in mocks -> updateMemberField --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: Add migration to migrate existing data to new member table (#29) added migration to fill new Member table with data from Members Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update message helper reference hotfix (#30) * forgot to update a reference in messageHelper to memberRepo instead of memberHelper * turned off data-source logging --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update dockerfile to run npm start (#31) fix: update dockerfile to run npm start (which runs ts-node) instead of node Co-authored-by: Aster Fialla <asterfialla@gmail.com> * added .env with examples, updated data-source to be access a docker container instead of relying on loopback * i forgot to git add data-source.ts :facepalm: * fix: changed property reference for createMember in repo (#32) fix for createMember object references (was referencing non-existent properties) Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: memberRepo methods syntax (#35) * rearranged update member field and remove member to match expected structure in typeORM * update docstring * change insert to save in memberRepo * added command in package.json --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Delete duplicate members migration (#33) * add migration to delete duplicates that currently exist in the db * added a name attribute for consistency --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Add unique index migration (#34) * add migration to delete duplicates that currently exist in the db * change model and migration to add a unique index constraint to id and name * renamed unique index name to be readable * redid model and migration to use @Unique instead of @Index * remove //Here comment --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * why wont these workflows stay up gahdamn --------- Co-authored-by: Laika Bozhko <63646916+LaikaBzko@users.noreply.github.com> Co-authored-by: Aster Fialla <asterfialla@gmail.com> Co-authored-by: laika <laika@sanya.gay>
2026-03-09 09:00:15 -04:00
expect(memberRepo.getMemberByName).toHaveBeenCalledTimes(1);
expect(memberRepo.getMemberByName).toHaveBeenCalledWith(authorId, mockMember.name);
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
})
})
describe('addNewMember', () => {
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>
2026-02-25 19:30:39 -05:00
test('calls addFullMember with correct arguments', async () => {
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
// Arrange
const args = [mockMember.displayname, mockMember.proxy, mockMember.propic];
jest.spyOn(memberHelper, 'addFullMember').mockResolvedValue(mockMember);
jest.spyOn(memberHelper, 'getMemberInfo').mockResolvedValue();
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
// Act
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>
2026-02-25 19:30:39 -05:00
const result = await memberHelper.addNewMember(authorId, mockMember.name, args, attachmentUrl, attachmentExpiration);
// Assert
expect(memberHelper.addFullMember).toHaveBeenCalledTimes(1);
expect(memberHelper.addFullMember).toHaveBeenCalledWith(authorId, mockMember.name, mockMember.displayname, mockMember.proxy, mockMember.propic, attachmentExpiration);
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
})
test('calls getMemberInfo when successful and returns result', async () => {
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
// Arrange
const args = [mockMember.displayname, mockMember.proxy, mockMember.propic];
const fullMemberResponse = {member: mockMember, errors: []}
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>
2026-02-25 19:30:39 -05:00
const expected = {
embed: mockMember,
errors: [],
success: `${mockMember.name} has been added successfully.`
};
jest.spyOn(memberHelper, 'addFullMember').mockResolvedValue(fullMemberResponse);
jest.spyOn(memberHelper, 'getMemberInfo').mockReturnValue(mockMember);
//Act
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>
2026-02-25 19:30:39 -05:00
const result = await memberHelper.addNewMember(authorId, mockMember.name, args, attachmentUrl, attachmentExpiration);
// Assert
expect(result).toEqual(expected);
expect(memberHelper.getMemberInfo).toHaveBeenCalledTimes(1);
expect(memberHelper.getMemberInfo).toHaveBeenCalledWith(mockMember);
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
})
test('throws expected error when getMemberInfo throws error', async () => {
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
// Arrange
const args = [];
const memberObject = {name: args[1]}
jest.spyOn(memberHelper, 'addFullMember').mockResolvedValue(memberObject);
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>
2026-02-25 19:30:39 -05:00
jest.spyOn(memberHelper, 'getMemberInfo').mockImplementation(() => {throw new Error('getMemberInfo error')});
//Act
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>
2026-02-25 19:30:39 -05:00
await expect(memberHelper.addNewMember(authorId, mockMember.name, args)).rejects.toThrow('getMemberInfo error');
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
})
test('throws expected error when addFullMember throws error', async () => {
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
// Arrange
const args = [];
const expected = 'add full member error';
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>
2026-02-25 19:30:39 -05:00
jest.spyOn(memberHelper, 'addFullMember').mockRejectedValue(new Error(expected));
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
//Act
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>
2026-02-25 19:30:39 -05:00
await expect(memberHelper.addNewMember(authorId, mockMember.name, args)).rejects.toThrow(expected)
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
})
})
describe('updateName', () => {
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
test('call updateMemberField with correct arguments when displayname passed in correctly and returns string', async () => {
// Arrange;
jest.spyOn(memberHelper, 'updateMemberField').mockResolvedValue("Updated");
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
// Act
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>
2026-02-25 19:30:39 -05:00
const result = await memberHelper.updateName(authorId, mockMember.name, " somePerson ")
// Assert
expect(result).toEqual("Updated");
expect(memberHelper.updateMemberField).toHaveBeenCalledTimes(1);
expect(memberHelper.updateMemberField).toHaveBeenCalledWith(authorId, mockMember.name, "name", "somePerson");
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
})
test('throws error when name is blank', async () => {
// Arrange;
jest.spyOn(memberHelper, 'updateMemberField').mockResolvedValue("Updated");
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>
2026-02-25 19:30:39 -05:00
// Act & Assert
await expect(memberHelper.updateName(authorId, mockMember.name, " ")).rejects.toThrow('Name ' + enums.err.NO_VALUE);
// Assert
expect(memberHelper.updateMemberField).not.toHaveBeenCalled();
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
})
})
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
describe('updateDisplayName', () => {
test('throws error when displayname is blank', async () => {
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
// Arrange
jest.spyOn(memberHelper, 'updateMemberField').mockResolvedValue();
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>
2026-02-25 19:30:39 -05:00
// Act & Assert
await expect(memberHelper.updateDisplayName(authorId, mockMember.name, " ")).rejects.toThrow("Display name " + enums.err.NO_VALUE);
// Assert
expect(memberHelper.updateMemberField).not.toHaveBeenCalled();
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
})
test('Sends error when display name is too long', async () => {
// Arrange
const tooLongDisplayName = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
jest.spyOn(memberHelper, 'updateMemberField').mockResolvedValue();
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>
2026-02-25 19:30:39 -05:00
// Act & Assert
await expect(memberHelper.updateDisplayName(authorId, mockMember.name, tooLongDisplayName)).rejects.toThrow(enums.err.DISPLAY_NAME_TOO_LONG);
// Assert
expect(memberHelper.updateMemberField).not.toHaveBeenCalled();
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
})
test('call updateMemberField with correct arguments when displayname passed in correctly and returns string', async () => {
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
// Arrange
jest.spyOn(memberHelper, 'updateMemberField').mockResolvedValue("Updated");
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
// Act
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>
2026-02-25 19:30:39 -05:00
const result = await memberHelper.updateDisplayName(authorId, mockMember.name, " Some Person ");
// Assert
expect(result).toEqual("Updated");
expect(memberHelper.updateMemberField).toHaveBeenCalledWith(authorId, mockMember.name, "displayname", mockMember.displayname);
expect(memberHelper.updateMemberField).toHaveBeenCalledTimes(1);
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
})
})
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
describe('updateProxy', () => {
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>
2026-02-25 19:30:39 -05:00
test('calls checkIfProxyExists and updateMemberField and returns string', async () => {
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
// Arrange
jest.spyOn(memberHelper, 'checkIfProxyExists').mockResolvedValue();
jest.spyOn(memberHelper, 'updateMemberField').mockResolvedValue("Updated");
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
// Act
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>
2026-02-25 19:30:39 -05:00
const result = await memberHelper.updateProxy(authorId, mockMember.name, "--text");
// Assert
expect(result).toEqual("Updated");
expect(memberHelper.checkIfProxyExists).toHaveBeenCalledTimes(1);
expect(memberHelper.checkIfProxyExists).toHaveBeenCalledWith(authorId, mockMember.proxy);
expect(memberHelper.updateMemberField).toHaveBeenCalledTimes(1);
expect(memberHelper.updateMemberField).toHaveBeenCalledWith(authorId, mockMember.name, "proxy", mockMember.proxy);
})
})
describe('updatePropic', () => {
test.each([
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>
2026-02-25 19:30:39 -05:00
[null, attachmentUrl, undefined, attachmentUrl],
[mockMember.propic, null, undefined, mockMember.propic],
[mockMember.propic, attachmentUrl, undefined, mockMember.propic],
])('calls checkImageFormatValidity and updateMemberField and returns string', async (imgUrl, attachmentUrl, attachmentExpiration, expected) => {
// Arrange
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>
2026-02-25 19:30:39 -05:00
jest.spyOn(memberHelper, 'updateMemberField').mockResolvedValue("Updated");
utils.setExpirationWarning = jest.fn().mockReturnValue(undefined);
// Act
const result = await memberHelper.updatePropic(authorId, mockMember.name, imgUrl, attachmentUrl, attachmentExpiration);
// Assert
expect(result).toEqual("Updated");
expect(utils.checkImageFormatValidity).toHaveBeenCalledTimes(1);
expect(utils.checkImageFormatValidity).toHaveBeenCalledWith(expected);
expect(memberHelper.updateMemberField).toHaveBeenCalledTimes(1);
expect(memberHelper.updateMemberField).toHaveBeenCalledWith(authorId, mockMember.name, "propic", expected, undefined);
})
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>
2026-02-25 19:30:39 -05:00
test('calls setExpirationWarning', async() => {
// Arrange
jest.spyOn(memberHelper, 'updateMemberField').mockResolvedValue("Updated");
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>
2026-02-25 19:30:39 -05:00
utils.setExpirationWarning = jest.fn().mockReturnValue(enums.misc.ATTACHMENT_EXPIRATION_WARNING);
// Act
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>
2026-02-25 19:30:39 -05:00
const result = await memberHelper.updatePropic(authorId, mockMember.name, null, attachmentUrl, attachmentExpiration);
// Assert
expect(result).toEqual("Updated");
expect(utils.setExpirationWarning).toHaveBeenCalledTimes(1);
expect(utils.setExpirationWarning).toHaveBeenCalledWith(attachmentUrl, attachmentExpiration);
expect(memberHelper.updateMemberField).toHaveBeenCalledTimes(1);
expect(memberHelper.updateMemberField).toHaveBeenCalledWith(authorId, mockMember.name, "propic", attachmentUrl, enums.misc.ATTACHMENT_EXPIRATION_WARNING);
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
})
})
describe('addFullMember', () => {
test('calls getMemberByName', async () => {
perf: Merge develop into main (#36) * Update dockerfile for standalone deployment (#23) * Add files via upload * Update Docker image for pluralflux service * removing unnecessary network and container name definitions --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Converting ES6 back to CJS (#25) converting back to cjs Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Fix: Further converting ES6 to CJS - Making exports named instead of default (#26) * adding to git ignore * making imports named not default to not break all my tests * adjusted setup for memberhelper test --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: add db migrations with typeORM (#28) * adding typescript packages for typeORM * add typeORM initial files * updating package scripts * updating compose.yaml to have an exposed port for the postgres * modifying setup for typeORM * update database stuff and and package.json to help generate migrations * made models and migrations in typeORM * delete unneeded database.js * made database pattern ignored by jest * remove sequelize * separate member repo from member helper * not sure why i made everything numbers in the model but it's fixed now * edited package.json script * remove unused index.ts * adjusted files to reference repository correctly and appdatasource * made appdatasource export as named * removed start-db script * added init to appdatasource in bot.js * migrations finally! * new migration matching model names I want * updating tests * removing testpathignore patterns since it seems to be unecessary? * adjusting migrations to match current schema * removed reference to secrets file * delete old migration * Revert "delete old migration" This reverts commit db1efa39a7a80d8976878856250ccaac6a753ab2. * Revert "adjusting migrations to match current schema" This reverts commit ef89a83f6a2ef0643d6ace0a3fcf9c40f4bc6dd6. * just deleted system creation since it's got nothing in it anyway * renamed memberRepository to memberRepo for consistency * added await back to parseMemberCommand call to memberArgumentHandler * changed call to memberHelper.getMembersByAuthor to memberRepo * renamed repo updateMemberValue to updateMemberField * removed throw references in repo docstrings * remove unneeded subscriber directory ref * changed createdAt and updatedAt columns to be auto-generated made member table have timezone * changed casing of isInitialized in mock for bot.js * removed % from ILike query so that it doesn't match substrings/wildcard * renamed some stray updateMemberValue in mocks -> updateMemberField --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: Add migration to migrate existing data to new member table (#29) added migration to fill new Member table with data from Members Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update message helper reference hotfix (#30) * forgot to update a reference in messageHelper to memberRepo instead of memberHelper * turned off data-source logging --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update dockerfile to run npm start (#31) fix: update dockerfile to run npm start (which runs ts-node) instead of node Co-authored-by: Aster Fialla <asterfialla@gmail.com> * added .env with examples, updated data-source to be access a docker container instead of relying on loopback * i forgot to git add data-source.ts :facepalm: * fix: changed property reference for createMember in repo (#32) fix for createMember object references (was referencing non-existent properties) Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: memberRepo methods syntax (#35) * rearranged update member field and remove member to match expected structure in typeORM * update docstring * change insert to save in memberRepo * added command in package.json --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Delete duplicate members migration (#33) * add migration to delete duplicates that currently exist in the db * added a name attribute for consistency --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Add unique index migration (#34) * add migration to delete duplicates that currently exist in the db * change model and migration to add a unique index constraint to id and name * renamed unique index name to be readable * redid model and migration to use @Unique instead of @Index * remove //Here comment --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * why wont these workflows stay up gahdamn --------- Co-authored-by: Laika Bozhko <63646916+LaikaBzko@users.noreply.github.com> Co-authored-by: Aster Fialla <asterfialla@gmail.com> Co-authored-by: laika <laika@sanya.gay>
2026-03-09 09:00:15 -04:00
// Arrange
memberRepo.getMemberByName.mockResolvedValue();
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
// Act
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>
2026-02-25 19:30:39 -05:00
await memberHelper.addFullMember(authorId, mockMember.name)
// Assert
perf: Merge develop into main (#36) * Update dockerfile for standalone deployment (#23) * Add files via upload * Update Docker image for pluralflux service * removing unnecessary network and container name definitions --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Converting ES6 back to CJS (#25) converting back to cjs Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Fix: Further converting ES6 to CJS - Making exports named instead of default (#26) * adding to git ignore * making imports named not default to not break all my tests * adjusted setup for memberhelper test --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: add db migrations with typeORM (#28) * adding typescript packages for typeORM * add typeORM initial files * updating package scripts * updating compose.yaml to have an exposed port for the postgres * modifying setup for typeORM * update database stuff and and package.json to help generate migrations * made models and migrations in typeORM * delete unneeded database.js * made database pattern ignored by jest * remove sequelize * separate member repo from member helper * not sure why i made everything numbers in the model but it's fixed now * edited package.json script * remove unused index.ts * adjusted files to reference repository correctly and appdatasource * made appdatasource export as named * removed start-db script * added init to appdatasource in bot.js * migrations finally! * new migration matching model names I want * updating tests * removing testpathignore patterns since it seems to be unecessary? * adjusting migrations to match current schema * removed reference to secrets file * delete old migration * Revert "delete old migration" This reverts commit db1efa39a7a80d8976878856250ccaac6a753ab2. * Revert "adjusting migrations to match current schema" This reverts commit ef89a83f6a2ef0643d6ace0a3fcf9c40f4bc6dd6. * just deleted system creation since it's got nothing in it anyway * renamed memberRepository to memberRepo for consistency * added await back to parseMemberCommand call to memberArgumentHandler * changed call to memberHelper.getMembersByAuthor to memberRepo * renamed repo updateMemberValue to updateMemberField * removed throw references in repo docstrings * remove unneeded subscriber directory ref * changed createdAt and updatedAt columns to be auto-generated made member table have timezone * changed casing of isInitialized in mock for bot.js * removed % from ILike query so that it doesn't match substrings/wildcard * renamed some stray updateMemberValue in mocks -> updateMemberField --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: Add migration to migrate existing data to new member table (#29) added migration to fill new Member table with data from Members Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update message helper reference hotfix (#30) * forgot to update a reference in messageHelper to memberRepo instead of memberHelper * turned off data-source logging --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update dockerfile to run npm start (#31) fix: update dockerfile to run npm start (which runs ts-node) instead of node Co-authored-by: Aster Fialla <asterfialla@gmail.com> * added .env with examples, updated data-source to be access a docker container instead of relying on loopback * i forgot to git add data-source.ts :facepalm: * fix: changed property reference for createMember in repo (#32) fix for createMember object references (was referencing non-existent properties) Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: memberRepo methods syntax (#35) * rearranged update member field and remove member to match expected structure in typeORM * update docstring * change insert to save in memberRepo * added command in package.json --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Delete duplicate members migration (#33) * add migration to delete duplicates that currently exist in the db * added a name attribute for consistency --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Add unique index migration (#34) * add migration to delete duplicates that currently exist in the db * change model and migration to add a unique index constraint to id and name * renamed unique index name to be readable * redid model and migration to use @Unique instead of @Index * remove //Here comment --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * why wont these workflows stay up gahdamn --------- Co-authored-by: Laika Bozhko <63646916+LaikaBzko@users.noreply.github.com> Co-authored-by: Aster Fialla <asterfialla@gmail.com> Co-authored-by: laika <laika@sanya.gay>
2026-03-09 09:00:15 -04:00
expect(memberRepo.getMemberByName).toHaveBeenCalledWith(authorId, mockMember.name);
expect(memberRepo.getMemberByName).toHaveBeenCalledTimes(1);
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
})
test('if getMemberByName returns member, throw error', async () => {
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>
2026-02-25 19:30:39 -05:00
// Arrange
perf: Merge develop into main (#36) * Update dockerfile for standalone deployment (#23) * Add files via upload * Update Docker image for pluralflux service * removing unnecessary network and container name definitions --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Converting ES6 back to CJS (#25) converting back to cjs Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Fix: Further converting ES6 to CJS - Making exports named instead of default (#26) * adding to git ignore * making imports named not default to not break all my tests * adjusted setup for memberhelper test --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: add db migrations with typeORM (#28) * adding typescript packages for typeORM * add typeORM initial files * updating package scripts * updating compose.yaml to have an exposed port for the postgres * modifying setup for typeORM * update database stuff and and package.json to help generate migrations * made models and migrations in typeORM * delete unneeded database.js * made database pattern ignored by jest * remove sequelize * separate member repo from member helper * not sure why i made everything numbers in the model but it's fixed now * edited package.json script * remove unused index.ts * adjusted files to reference repository correctly and appdatasource * made appdatasource export as named * removed start-db script * added init to appdatasource in bot.js * migrations finally! * new migration matching model names I want * updating tests * removing testpathignore patterns since it seems to be unecessary? * adjusting migrations to match current schema * removed reference to secrets file * delete old migration * Revert "delete old migration" This reverts commit db1efa39a7a80d8976878856250ccaac6a753ab2. * Revert "adjusting migrations to match current schema" This reverts commit ef89a83f6a2ef0643d6ace0a3fcf9c40f4bc6dd6. * just deleted system creation since it's got nothing in it anyway * renamed memberRepository to memberRepo for consistency * added await back to parseMemberCommand call to memberArgumentHandler * changed call to memberHelper.getMembersByAuthor to memberRepo * renamed repo updateMemberValue to updateMemberField * removed throw references in repo docstrings * remove unneeded subscriber directory ref * changed createdAt and updatedAt columns to be auto-generated made member table have timezone * changed casing of isInitialized in mock for bot.js * removed % from ILike query so that it doesn't match substrings/wildcard * renamed some stray updateMemberValue in mocks -> updateMemberField --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: Add migration to migrate existing data to new member table (#29) added migration to fill new Member table with data from Members Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update message helper reference hotfix (#30) * forgot to update a reference in messageHelper to memberRepo instead of memberHelper * turned off data-source logging --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update dockerfile to run npm start (#31) fix: update dockerfile to run npm start (which runs ts-node) instead of node Co-authored-by: Aster Fialla <asterfialla@gmail.com> * added .env with examples, updated data-source to be access a docker container instead of relying on loopback * i forgot to git add data-source.ts :facepalm: * fix: changed property reference for createMember in repo (#32) fix for createMember object references (was referencing non-existent properties) Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: memberRepo methods syntax (#35) * rearranged update member field and remove member to match expected structure in typeORM * update docstring * change insert to save in memberRepo * added command in package.json --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Delete duplicate members migration (#33) * add migration to delete duplicates that currently exist in the db * added a name attribute for consistency --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Add unique index migration (#34) * add migration to delete duplicates that currently exist in the db * change model and migration to add a unique index constraint to id and name * renamed unique index name to be readable * redid model and migration to use @Unique instead of @Index * remove //Here comment --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * why wont these workflows stay up gahdamn --------- Co-authored-by: Laika Bozhko <63646916+LaikaBzko@users.noreply.github.com> Co-authored-by: Aster Fialla <asterfialla@gmail.com> Co-authored-by: laika <laika@sanya.gay>
2026-03-09 09:00:15 -04:00
memberRepo.getMemberByName.mockResolvedValue({name: mockMember.name});
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>
2026-02-25 19:30:39 -05:00
// Act & Assert
await expect(memberHelper.addFullMember(authorId, mockMember.name)).rejects.toThrow(`Can't add ${mockMember.name}. ${enums.err.MEMBER_EXISTS}`)
// Assert
perf: Merge develop into main (#36) * Update dockerfile for standalone deployment (#23) * Add files via upload * Update Docker image for pluralflux service * removing unnecessary network and container name definitions --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Converting ES6 back to CJS (#25) converting back to cjs Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Fix: Further converting ES6 to CJS - Making exports named instead of default (#26) * adding to git ignore * making imports named not default to not break all my tests * adjusted setup for memberhelper test --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: add db migrations with typeORM (#28) * adding typescript packages for typeORM * add typeORM initial files * updating package scripts * updating compose.yaml to have an exposed port for the postgres * modifying setup for typeORM * update database stuff and and package.json to help generate migrations * made models and migrations in typeORM * delete unneeded database.js * made database pattern ignored by jest * remove sequelize * separate member repo from member helper * not sure why i made everything numbers in the model but it's fixed now * edited package.json script * remove unused index.ts * adjusted files to reference repository correctly and appdatasource * made appdatasource export as named * removed start-db script * added init to appdatasource in bot.js * migrations finally! * new migration matching model names I want * updating tests * removing testpathignore patterns since it seems to be unecessary? * adjusting migrations to match current schema * removed reference to secrets file * delete old migration * Revert "delete old migration" This reverts commit db1efa39a7a80d8976878856250ccaac6a753ab2. * Revert "adjusting migrations to match current schema" This reverts commit ef89a83f6a2ef0643d6ace0a3fcf9c40f4bc6dd6. * just deleted system creation since it's got nothing in it anyway * renamed memberRepository to memberRepo for consistency * added await back to parseMemberCommand call to memberArgumentHandler * changed call to memberHelper.getMembersByAuthor to memberRepo * renamed repo updateMemberValue to updateMemberField * removed throw references in repo docstrings * remove unneeded subscriber directory ref * changed createdAt and updatedAt columns to be auto-generated made member table have timezone * changed casing of isInitialized in mock for bot.js * removed % from ILike query so that it doesn't match substrings/wildcard * renamed some stray updateMemberValue in mocks -> updateMemberField --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: Add migration to migrate existing data to new member table (#29) added migration to fill new Member table with data from Members Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update message helper reference hotfix (#30) * forgot to update a reference in messageHelper to memberRepo instead of memberHelper * turned off data-source logging --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update dockerfile to run npm start (#31) fix: update dockerfile to run npm start (which runs ts-node) instead of node Co-authored-by: Aster Fialla <asterfialla@gmail.com> * added .env with examples, updated data-source to be access a docker container instead of relying on loopback * i forgot to git add data-source.ts :facepalm: * fix: changed property reference for createMember in repo (#32) fix for createMember object references (was referencing non-existent properties) Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: memberRepo methods syntax (#35) * rearranged update member field and remove member to match expected structure in typeORM * update docstring * change insert to save in memberRepo * added command in package.json --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Delete duplicate members migration (#33) * add migration to delete duplicates that currently exist in the db * added a name attribute for consistency --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Add unique index migration (#34) * add migration to delete duplicates that currently exist in the db * change model and migration to add a unique index constraint to id and name * renamed unique index name to be readable * redid model and migration to use @Unique instead of @Index * remove //Here comment --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * why wont these workflows stay up gahdamn --------- Co-authored-by: Laika Bozhko <63646916+LaikaBzko@users.noreply.github.com> Co-authored-by: Aster Fialla <asterfialla@gmail.com> Co-authored-by: laika <laika@sanya.gay>
2026-03-09 09:00:15 -04:00
expect(memberRepo.createMember).not.toHaveBeenCalled();
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
})
test('if name is not filled out, throw error', async () => {
perf: Merge develop into main (#36) * Update dockerfile for standalone deployment (#23) * Add files via upload * Update Docker image for pluralflux service * removing unnecessary network and container name definitions --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Converting ES6 back to CJS (#25) converting back to cjs Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Fix: Further converting ES6 to CJS - Making exports named instead of default (#26) * adding to git ignore * making imports named not default to not break all my tests * adjusted setup for memberhelper test --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: add db migrations with typeORM (#28) * adding typescript packages for typeORM * add typeORM initial files * updating package scripts * updating compose.yaml to have an exposed port for the postgres * modifying setup for typeORM * update database stuff and and package.json to help generate migrations * made models and migrations in typeORM * delete unneeded database.js * made database pattern ignored by jest * remove sequelize * separate member repo from member helper * not sure why i made everything numbers in the model but it's fixed now * edited package.json script * remove unused index.ts * adjusted files to reference repository correctly and appdatasource * made appdatasource export as named * removed start-db script * added init to appdatasource in bot.js * migrations finally! * new migration matching model names I want * updating tests * removing testpathignore patterns since it seems to be unecessary? * adjusting migrations to match current schema * removed reference to secrets file * delete old migration * Revert "delete old migration" This reverts commit db1efa39a7a80d8976878856250ccaac6a753ab2. * Revert "adjusting migrations to match current schema" This reverts commit ef89a83f6a2ef0643d6ace0a3fcf9c40f4bc6dd6. * just deleted system creation since it's got nothing in it anyway * renamed memberRepository to memberRepo for consistency * added await back to parseMemberCommand call to memberArgumentHandler * changed call to memberHelper.getMembersByAuthor to memberRepo * renamed repo updateMemberValue to updateMemberField * removed throw references in repo docstrings * remove unneeded subscriber directory ref * changed createdAt and updatedAt columns to be auto-generated made member table have timezone * changed casing of isInitialized in mock for bot.js * removed % from ILike query so that it doesn't match substrings/wildcard * renamed some stray updateMemberValue in mocks -> updateMemberField --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: Add migration to migrate existing data to new member table (#29) added migration to fill new Member table with data from Members Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update message helper reference hotfix (#30) * forgot to update a reference in messageHelper to memberRepo instead of memberHelper * turned off data-source logging --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update dockerfile to run npm start (#31) fix: update dockerfile to run npm start (which runs ts-node) instead of node Co-authored-by: Aster Fialla <asterfialla@gmail.com> * added .env with examples, updated data-source to be access a docker container instead of relying on loopback * i forgot to git add data-source.ts :facepalm: * fix: changed property reference for createMember in repo (#32) fix for createMember object references (was referencing non-existent properties) Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: memberRepo methods syntax (#35) * rearranged update member field and remove member to match expected structure in typeORM * update docstring * change insert to save in memberRepo * added command in package.json --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Delete duplicate members migration (#33) * add migration to delete duplicates that currently exist in the db * added a name attribute for consistency --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Add unique index migration (#34) * add migration to delete duplicates that currently exist in the db * change model and migration to add a unique index constraint to id and name * renamed unique index name to be readable * redid model and migration to use @Unique instead of @Index * remove //Here comment --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * why wont these workflows stay up gahdamn --------- Co-authored-by: Laika Bozhko <63646916+LaikaBzko@users.noreply.github.com> Co-authored-by: Aster Fialla <asterfialla@gmail.com> Co-authored-by: laika <laika@sanya.gay>
2026-03-09 09:00:15 -04:00
// Arrange
memberRepo.getMemberByName.mockResolvedValue();
// Act
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>
2026-02-25 19:30:39 -05:00
await expect(memberHelper.addFullMember(authorId, " ")).rejects.toThrow(`Name ${enums.err.NO_VALUE}. ${enums.err.NAME_REQUIRED}`);
// Assert
perf: Merge develop into main (#36) * Update dockerfile for standalone deployment (#23) * Add files via upload * Update Docker image for pluralflux service * removing unnecessary network and container name definitions --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Converting ES6 back to CJS (#25) converting back to cjs Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Fix: Further converting ES6 to CJS - Making exports named instead of default (#26) * adding to git ignore * making imports named not default to not break all my tests * adjusted setup for memberhelper test --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: add db migrations with typeORM (#28) * adding typescript packages for typeORM * add typeORM initial files * updating package scripts * updating compose.yaml to have an exposed port for the postgres * modifying setup for typeORM * update database stuff and and package.json to help generate migrations * made models and migrations in typeORM * delete unneeded database.js * made database pattern ignored by jest * remove sequelize * separate member repo from member helper * not sure why i made everything numbers in the model but it's fixed now * edited package.json script * remove unused index.ts * adjusted files to reference repository correctly and appdatasource * made appdatasource export as named * removed start-db script * added init to appdatasource in bot.js * migrations finally! * new migration matching model names I want * updating tests * removing testpathignore patterns since it seems to be unecessary? * adjusting migrations to match current schema * removed reference to secrets file * delete old migration * Revert "delete old migration" This reverts commit db1efa39a7a80d8976878856250ccaac6a753ab2. * Revert "adjusting migrations to match current schema" This reverts commit ef89a83f6a2ef0643d6ace0a3fcf9c40f4bc6dd6. * just deleted system creation since it's got nothing in it anyway * renamed memberRepository to memberRepo for consistency * added await back to parseMemberCommand call to memberArgumentHandler * changed call to memberHelper.getMembersByAuthor to memberRepo * renamed repo updateMemberValue to updateMemberField * removed throw references in repo docstrings * remove unneeded subscriber directory ref * changed createdAt and updatedAt columns to be auto-generated made member table have timezone * changed casing of isInitialized in mock for bot.js * removed % from ILike query so that it doesn't match substrings/wildcard * renamed some stray updateMemberValue in mocks -> updateMemberField --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: Add migration to migrate existing data to new member table (#29) added migration to fill new Member table with data from Members Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update message helper reference hotfix (#30) * forgot to update a reference in messageHelper to memberRepo instead of memberHelper * turned off data-source logging --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update dockerfile to run npm start (#31) fix: update dockerfile to run npm start (which runs ts-node) instead of node Co-authored-by: Aster Fialla <asterfialla@gmail.com> * added .env with examples, updated data-source to be access a docker container instead of relying on loopback * i forgot to git add data-source.ts :facepalm: * fix: changed property reference for createMember in repo (#32) fix for createMember object references (was referencing non-existent properties) Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: memberRepo methods syntax (#35) * rearranged update member field and remove member to match expected structure in typeORM * update docstring * change insert to save in memberRepo * added command in package.json --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Delete duplicate members migration (#33) * add migration to delete duplicates that currently exist in the db * added a name attribute for consistency --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Add unique index migration (#34) * add migration to delete duplicates that currently exist in the db * change model and migration to add a unique index constraint to id and name * renamed unique index name to be readable * redid model and migration to use @Unique instead of @Index * remove //Here comment --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * why wont these workflows stay up gahdamn --------- Co-authored-by: Laika Bozhko <63646916+LaikaBzko@users.noreply.github.com> Co-authored-by: Aster Fialla <asterfialla@gmail.com> Co-authored-by: laika <laika@sanya.gay>
2026-03-09 09:00:15 -04:00
expect(memberRepo.createMember).not.toHaveBeenCalled();
})
perf: Merge develop into main (#36) * Update dockerfile for standalone deployment (#23) * Add files via upload * Update Docker image for pluralflux service * removing unnecessary network and container name definitions --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Converting ES6 back to CJS (#25) converting back to cjs Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Fix: Further converting ES6 to CJS - Making exports named instead of default (#26) * adding to git ignore * making imports named not default to not break all my tests * adjusted setup for memberhelper test --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: add db migrations with typeORM (#28) * adding typescript packages for typeORM * add typeORM initial files * updating package scripts * updating compose.yaml to have an exposed port for the postgres * modifying setup for typeORM * update database stuff and and package.json to help generate migrations * made models and migrations in typeORM * delete unneeded database.js * made database pattern ignored by jest * remove sequelize * separate member repo from member helper * not sure why i made everything numbers in the model but it's fixed now * edited package.json script * remove unused index.ts * adjusted files to reference repository correctly and appdatasource * made appdatasource export as named * removed start-db script * added init to appdatasource in bot.js * migrations finally! * new migration matching model names I want * updating tests * removing testpathignore patterns since it seems to be unecessary? * adjusting migrations to match current schema * removed reference to secrets file * delete old migration * Revert "delete old migration" This reverts commit db1efa39a7a80d8976878856250ccaac6a753ab2. * Revert "adjusting migrations to match current schema" This reverts commit ef89a83f6a2ef0643d6ace0a3fcf9c40f4bc6dd6. * just deleted system creation since it's got nothing in it anyway * renamed memberRepository to memberRepo for consistency * added await back to parseMemberCommand call to memberArgumentHandler * changed call to memberHelper.getMembersByAuthor to memberRepo * renamed repo updateMemberValue to updateMemberField * removed throw references in repo docstrings * remove unneeded subscriber directory ref * changed createdAt and updatedAt columns to be auto-generated made member table have timezone * changed casing of isInitialized in mock for bot.js * removed % from ILike query so that it doesn't match substrings/wildcard * renamed some stray updateMemberValue in mocks -> updateMemberField --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: Add migration to migrate existing data to new member table (#29) added migration to fill new Member table with data from Members Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update message helper reference hotfix (#30) * forgot to update a reference in messageHelper to memberRepo instead of memberHelper * turned off data-source logging --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update dockerfile to run npm start (#31) fix: update dockerfile to run npm start (which runs ts-node) instead of node Co-authored-by: Aster Fialla <asterfialla@gmail.com> * added .env with examples, updated data-source to be access a docker container instead of relying on loopback * i forgot to git add data-source.ts :facepalm: * fix: changed property reference for createMember in repo (#32) fix for createMember object references (was referencing non-existent properties) Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: memberRepo methods syntax (#35) * rearranged update member field and remove member to match expected structure in typeORM * update docstring * change insert to save in memberRepo * added command in package.json --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Delete duplicate members migration (#33) * add migration to delete duplicates that currently exist in the db * added a name attribute for consistency --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Add unique index migration (#34) * add migration to delete duplicates that currently exist in the db * change model and migration to add a unique index constraint to id and name * renamed unique index name to be readable * redid model and migration to use @Unique instead of @Index * remove //Here comment --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * why wont these workflows stay up gahdamn --------- Co-authored-by: Laika Bozhko <63646916+LaikaBzko@users.noreply.github.com> Co-authored-by: Aster Fialla <asterfialla@gmail.com> Co-authored-by: laika <laika@sanya.gay>
2026-03-09 09:00:15 -04:00
test('if displayname is over 32 characters, call memberRepo.createMember with null value', async () => {
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
// Arrange
perf: Merge develop into main (#36) * Update dockerfile for standalone deployment (#23) * Add files via upload * Update Docker image for pluralflux service * removing unnecessary network and container name definitions --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Converting ES6 back to CJS (#25) converting back to cjs Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Fix: Further converting ES6 to CJS - Making exports named instead of default (#26) * adding to git ignore * making imports named not default to not break all my tests * adjusted setup for memberhelper test --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: add db migrations with typeORM (#28) * adding typescript packages for typeORM * add typeORM initial files * updating package scripts * updating compose.yaml to have an exposed port for the postgres * modifying setup for typeORM * update database stuff and and package.json to help generate migrations * made models and migrations in typeORM * delete unneeded database.js * made database pattern ignored by jest * remove sequelize * separate member repo from member helper * not sure why i made everything numbers in the model but it's fixed now * edited package.json script * remove unused index.ts * adjusted files to reference repository correctly and appdatasource * made appdatasource export as named * removed start-db script * added init to appdatasource in bot.js * migrations finally! * new migration matching model names I want * updating tests * removing testpathignore patterns since it seems to be unecessary? * adjusting migrations to match current schema * removed reference to secrets file * delete old migration * Revert "delete old migration" This reverts commit db1efa39a7a80d8976878856250ccaac6a753ab2. * Revert "adjusting migrations to match current schema" This reverts commit ef89a83f6a2ef0643d6ace0a3fcf9c40f4bc6dd6. * just deleted system creation since it's got nothing in it anyway * renamed memberRepository to memberRepo for consistency * added await back to parseMemberCommand call to memberArgumentHandler * changed call to memberHelper.getMembersByAuthor to memberRepo * renamed repo updateMemberValue to updateMemberField * removed throw references in repo docstrings * remove unneeded subscriber directory ref * changed createdAt and updatedAt columns to be auto-generated made member table have timezone * changed casing of isInitialized in mock for bot.js * removed % from ILike query so that it doesn't match substrings/wildcard * renamed some stray updateMemberValue in mocks -> updateMemberField --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: Add migration to migrate existing data to new member table (#29) added migration to fill new Member table with data from Members Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update message helper reference hotfix (#30) * forgot to update a reference in messageHelper to memberRepo instead of memberHelper * turned off data-source logging --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update dockerfile to run npm start (#31) fix: update dockerfile to run npm start (which runs ts-node) instead of node Co-authored-by: Aster Fialla <asterfialla@gmail.com> * added .env with examples, updated data-source to be access a docker container instead of relying on loopback * i forgot to git add data-source.ts :facepalm: * fix: changed property reference for createMember in repo (#32) fix for createMember object references (was referencing non-existent properties) Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: memberRepo methods syntax (#35) * rearranged update member field and remove member to match expected structure in typeORM * update docstring * change insert to save in memberRepo * added command in package.json --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Delete duplicate members migration (#33) * add migration to delete duplicates that currently exist in the db * added a name attribute for consistency --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Add unique index migration (#34) * add migration to delete duplicates that currently exist in the db * change model and migration to add a unique index constraint to id and name * renamed unique index name to be readable * redid model and migration to use @Unique instead of @Index * remove //Here comment --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * why wont these workflows stay up gahdamn --------- Co-authored-by: Laika Bozhko <63646916+LaikaBzko@users.noreply.github.com> Co-authored-by: Aster Fialla <asterfialla@gmail.com> Co-authored-by: laika <laika@sanya.gay>
2026-03-09 09:00:15 -04:00
memberRepo.getMemberByName.mockResolvedValue();
const tooLongDisplayName = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
const expectedMemberArgs = {
name: mockMember.name,
userid: authorId,
displayname: null,
proxy: null,
propic: null
}
perf: Merge develop into main (#36) * Update dockerfile for standalone deployment (#23) * Add files via upload * Update Docker image for pluralflux service * removing unnecessary network and container name definitions --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Converting ES6 back to CJS (#25) converting back to cjs Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Fix: Further converting ES6 to CJS - Making exports named instead of default (#26) * adding to git ignore * making imports named not default to not break all my tests * adjusted setup for memberhelper test --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: add db migrations with typeORM (#28) * adding typescript packages for typeORM * add typeORM initial files * updating package scripts * updating compose.yaml to have an exposed port for the postgres * modifying setup for typeORM * update database stuff and and package.json to help generate migrations * made models and migrations in typeORM * delete unneeded database.js * made database pattern ignored by jest * remove sequelize * separate member repo from member helper * not sure why i made everything numbers in the model but it's fixed now * edited package.json script * remove unused index.ts * adjusted files to reference repository correctly and appdatasource * made appdatasource export as named * removed start-db script * added init to appdatasource in bot.js * migrations finally! * new migration matching model names I want * updating tests * removing testpathignore patterns since it seems to be unecessary? * adjusting migrations to match current schema * removed reference to secrets file * delete old migration * Revert "delete old migration" This reverts commit db1efa39a7a80d8976878856250ccaac6a753ab2. * Revert "adjusting migrations to match current schema" This reverts commit ef89a83f6a2ef0643d6ace0a3fcf9c40f4bc6dd6. * just deleted system creation since it's got nothing in it anyway * renamed memberRepository to memberRepo for consistency * added await back to parseMemberCommand call to memberArgumentHandler * changed call to memberHelper.getMembersByAuthor to memberRepo * renamed repo updateMemberValue to updateMemberField * removed throw references in repo docstrings * remove unneeded subscriber directory ref * changed createdAt and updatedAt columns to be auto-generated made member table have timezone * changed casing of isInitialized in mock for bot.js * removed % from ILike query so that it doesn't match substrings/wildcard * renamed some stray updateMemberValue in mocks -> updateMemberField --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: Add migration to migrate existing data to new member table (#29) added migration to fill new Member table with data from Members Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update message helper reference hotfix (#30) * forgot to update a reference in messageHelper to memberRepo instead of memberHelper * turned off data-source logging --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update dockerfile to run npm start (#31) fix: update dockerfile to run npm start (which runs ts-node) instead of node Co-authored-by: Aster Fialla <asterfialla@gmail.com> * added .env with examples, updated data-source to be access a docker container instead of relying on loopback * i forgot to git add data-source.ts :facepalm: * fix: changed property reference for createMember in repo (#32) fix for createMember object references (was referencing non-existent properties) Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: memberRepo methods syntax (#35) * rearranged update member field and remove member to match expected structure in typeORM * update docstring * change insert to save in memberRepo * added command in package.json --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Delete duplicate members migration (#33) * add migration to delete duplicates that currently exist in the db * added a name attribute for consistency --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Add unique index migration (#34) * add migration to delete duplicates that currently exist in the db * change model and migration to add a unique index constraint to id and name * renamed unique index name to be readable * redid model and migration to use @Unique instead of @Index * remove //Here comment --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * why wont these workflows stay up gahdamn --------- Co-authored-by: Laika Bozhko <63646916+LaikaBzko@users.noreply.github.com> Co-authored-by: Aster Fialla <asterfialla@gmail.com> Co-authored-by: laika <laika@sanya.gay>
2026-03-09 09:00:15 -04:00
memberRepo.createMember = jest.fn().mockResolvedValue(expectedMemberArgs);
const expectedReturn = {
member: expectedMemberArgs,
errors: [`Tried to set displayname to \"${tooLongDisplayName}\". ${enums.err.DISPLAY_NAME_TOO_LONG}. ${enums.err.SET_TO_NULL}`]
}
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
// Act
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>
2026-02-25 19:30:39 -05:00
const res = await memberHelper.addFullMember(authorId, mockMember.name, tooLongDisplayName, null, null);
// Assert
expect(res).toEqual(expectedReturn);
perf: Merge develop into main (#36) * Update dockerfile for standalone deployment (#23) * Add files via upload * Update Docker image for pluralflux service * removing unnecessary network and container name definitions --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Converting ES6 back to CJS (#25) converting back to cjs Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Fix: Further converting ES6 to CJS - Making exports named instead of default (#26) * adding to git ignore * making imports named not default to not break all my tests * adjusted setup for memberhelper test --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: add db migrations with typeORM (#28) * adding typescript packages for typeORM * add typeORM initial files * updating package scripts * updating compose.yaml to have an exposed port for the postgres * modifying setup for typeORM * update database stuff and and package.json to help generate migrations * made models and migrations in typeORM * delete unneeded database.js * made database pattern ignored by jest * remove sequelize * separate member repo from member helper * not sure why i made everything numbers in the model but it's fixed now * edited package.json script * remove unused index.ts * adjusted files to reference repository correctly and appdatasource * made appdatasource export as named * removed start-db script * added init to appdatasource in bot.js * migrations finally! * new migration matching model names I want * updating tests * removing testpathignore patterns since it seems to be unecessary? * adjusting migrations to match current schema * removed reference to secrets file * delete old migration * Revert "delete old migration" This reverts commit db1efa39a7a80d8976878856250ccaac6a753ab2. * Revert "adjusting migrations to match current schema" This reverts commit ef89a83f6a2ef0643d6ace0a3fcf9c40f4bc6dd6. * just deleted system creation since it's got nothing in it anyway * renamed memberRepository to memberRepo for consistency * added await back to parseMemberCommand call to memberArgumentHandler * changed call to memberHelper.getMembersByAuthor to memberRepo * renamed repo updateMemberValue to updateMemberField * removed throw references in repo docstrings * remove unneeded subscriber directory ref * changed createdAt and updatedAt columns to be auto-generated made member table have timezone * changed casing of isInitialized in mock for bot.js * removed % from ILike query so that it doesn't match substrings/wildcard * renamed some stray updateMemberValue in mocks -> updateMemberField --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: Add migration to migrate existing data to new member table (#29) added migration to fill new Member table with data from Members Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update message helper reference hotfix (#30) * forgot to update a reference in messageHelper to memberRepo instead of memberHelper * turned off data-source logging --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update dockerfile to run npm start (#31) fix: update dockerfile to run npm start (which runs ts-node) instead of node Co-authored-by: Aster Fialla <asterfialla@gmail.com> * added .env with examples, updated data-source to be access a docker container instead of relying on loopback * i forgot to git add data-source.ts :facepalm: * fix: changed property reference for createMember in repo (#32) fix for createMember object references (was referencing non-existent properties) Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: memberRepo methods syntax (#35) * rearranged update member field and remove member to match expected structure in typeORM * update docstring * change insert to save in memberRepo * added command in package.json --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Delete duplicate members migration (#33) * add migration to delete duplicates that currently exist in the db * added a name attribute for consistency --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Add unique index migration (#34) * add migration to delete duplicates that currently exist in the db * change model and migration to add a unique index constraint to id and name * renamed unique index name to be readable * redid model and migration to use @Unique instead of @Index * remove //Here comment --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * why wont these workflows stay up gahdamn --------- Co-authored-by: Laika Bozhko <63646916+LaikaBzko@users.noreply.github.com> Co-authored-by: Aster Fialla <asterfialla@gmail.com> Co-authored-by: laika <laika@sanya.gay>
2026-03-09 09:00:15 -04:00
expect(memberRepo.createMember).toHaveBeenCalledWith(expectedMemberArgs);
expect(memberRepo.createMember).toHaveBeenCalledTimes(1);
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
})
test('if proxy, call checkIfProxyExists', async () => {
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
// Arrange
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>
2026-02-25 19:30:39 -05:00
jest.spyOn(memberHelper, 'checkIfProxyExists').mockResolvedValue(true);
const expectedMemberArgs = {
name: mockMember.name,
userid: authorId,
displayname: null,
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>
2026-02-25 19:30:39 -05:00
proxy: null,
propic: null
}
perf: Merge develop into main (#36) * Update dockerfile for standalone deployment (#23) * Add files via upload * Update Docker image for pluralflux service * removing unnecessary network and container name definitions --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Converting ES6 back to CJS (#25) converting back to cjs Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Fix: Further converting ES6 to CJS - Making exports named instead of default (#26) * adding to git ignore * making imports named not default to not break all my tests * adjusted setup for memberhelper test --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: add db migrations with typeORM (#28) * adding typescript packages for typeORM * add typeORM initial files * updating package scripts * updating compose.yaml to have an exposed port for the postgres * modifying setup for typeORM * update database stuff and and package.json to help generate migrations * made models and migrations in typeORM * delete unneeded database.js * made database pattern ignored by jest * remove sequelize * separate member repo from member helper * not sure why i made everything numbers in the model but it's fixed now * edited package.json script * remove unused index.ts * adjusted files to reference repository correctly and appdatasource * made appdatasource export as named * removed start-db script * added init to appdatasource in bot.js * migrations finally! * new migration matching model names I want * updating tests * removing testpathignore patterns since it seems to be unecessary? * adjusting migrations to match current schema * removed reference to secrets file * delete old migration * Revert "delete old migration" This reverts commit db1efa39a7a80d8976878856250ccaac6a753ab2. * Revert "adjusting migrations to match current schema" This reverts commit ef89a83f6a2ef0643d6ace0a3fcf9c40f4bc6dd6. * just deleted system creation since it's got nothing in it anyway * renamed memberRepository to memberRepo for consistency * added await back to parseMemberCommand call to memberArgumentHandler * changed call to memberHelper.getMembersByAuthor to memberRepo * renamed repo updateMemberValue to updateMemberField * removed throw references in repo docstrings * remove unneeded subscriber directory ref * changed createdAt and updatedAt columns to be auto-generated made member table have timezone * changed casing of isInitialized in mock for bot.js * removed % from ILike query so that it doesn't match substrings/wildcard * renamed some stray updateMemberValue in mocks -> updateMemberField --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: Add migration to migrate existing data to new member table (#29) added migration to fill new Member table with data from Members Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update message helper reference hotfix (#30) * forgot to update a reference in messageHelper to memberRepo instead of memberHelper * turned off data-source logging --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update dockerfile to run npm start (#31) fix: update dockerfile to run npm start (which runs ts-node) instead of node Co-authored-by: Aster Fialla <asterfialla@gmail.com> * added .env with examples, updated data-source to be access a docker container instead of relying on loopback * i forgot to git add data-source.ts :facepalm: * fix: changed property reference for createMember in repo (#32) fix for createMember object references (was referencing non-existent properties) Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: memberRepo methods syntax (#35) * rearranged update member field and remove member to match expected structure in typeORM * update docstring * change insert to save in memberRepo * added command in package.json --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Delete duplicate members migration (#33) * add migration to delete duplicates that currently exist in the db * added a name attribute for consistency --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Add unique index migration (#34) * add migration to delete duplicates that currently exist in the db * change model and migration to add a unique index constraint to id and name * renamed unique index name to be readable * redid model and migration to use @Unique instead of @Index * remove //Here comment --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * why wont these workflows stay up gahdamn --------- Co-authored-by: Laika Bozhko <63646916+LaikaBzko@users.noreply.github.com> Co-authored-by: Aster Fialla <asterfialla@gmail.com> Co-authored-by: laika <laika@sanya.gay>
2026-03-09 09:00:15 -04:00
memberRepo.createMember = jest.fn().mockResolvedValue(expectedMemberArgs);
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
const expectedReturn = {member: expectedMemberArgs, errors: []}
// Act
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>
2026-02-25 19:30:39 -05:00
const res = await memberHelper.addFullMember(authorId, mockMember.name, null, mockMember.proxy)
// Assert
expect(res).toEqual(expectedReturn);
expect(memberHelper.checkIfProxyExists).toHaveBeenCalledWith(authorId, mockMember.proxy);
expect(memberHelper.checkIfProxyExists).toHaveBeenCalledTimes(1);
perf: Merge develop into main (#36) * Update dockerfile for standalone deployment (#23) * Add files via upload * Update Docker image for pluralflux service * removing unnecessary network and container name definitions --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Converting ES6 back to CJS (#25) converting back to cjs Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Fix: Further converting ES6 to CJS - Making exports named instead of default (#26) * adding to git ignore * making imports named not default to not break all my tests * adjusted setup for memberhelper test --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: add db migrations with typeORM (#28) * adding typescript packages for typeORM * add typeORM initial files * updating package scripts * updating compose.yaml to have an exposed port for the postgres * modifying setup for typeORM * update database stuff and and package.json to help generate migrations * made models and migrations in typeORM * delete unneeded database.js * made database pattern ignored by jest * remove sequelize * separate member repo from member helper * not sure why i made everything numbers in the model but it's fixed now * edited package.json script * remove unused index.ts * adjusted files to reference repository correctly and appdatasource * made appdatasource export as named * removed start-db script * added init to appdatasource in bot.js * migrations finally! * new migration matching model names I want * updating tests * removing testpathignore patterns since it seems to be unecessary? * adjusting migrations to match current schema * removed reference to secrets file * delete old migration * Revert "delete old migration" This reverts commit db1efa39a7a80d8976878856250ccaac6a753ab2. * Revert "adjusting migrations to match current schema" This reverts commit ef89a83f6a2ef0643d6ace0a3fcf9c40f4bc6dd6. * just deleted system creation since it's got nothing in it anyway * renamed memberRepository to memberRepo for consistency * added await back to parseMemberCommand call to memberArgumentHandler * changed call to memberHelper.getMembersByAuthor to memberRepo * renamed repo updateMemberValue to updateMemberField * removed throw references in repo docstrings * remove unneeded subscriber directory ref * changed createdAt and updatedAt columns to be auto-generated made member table have timezone * changed casing of isInitialized in mock for bot.js * removed % from ILike query so that it doesn't match substrings/wildcard * renamed some stray updateMemberValue in mocks -> updateMemberField --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: Add migration to migrate existing data to new member table (#29) added migration to fill new Member table with data from Members Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update message helper reference hotfix (#30) * forgot to update a reference in messageHelper to memberRepo instead of memberHelper * turned off data-source logging --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update dockerfile to run npm start (#31) fix: update dockerfile to run npm start (which runs ts-node) instead of node Co-authored-by: Aster Fialla <asterfialla@gmail.com> * added .env with examples, updated data-source to be access a docker container instead of relying on loopback * i forgot to git add data-source.ts :facepalm: * fix: changed property reference for createMember in repo (#32) fix for createMember object references (was referencing non-existent properties) Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: memberRepo methods syntax (#35) * rearranged update member field and remove member to match expected structure in typeORM * update docstring * change insert to save in memberRepo * added command in package.json --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Delete duplicate members migration (#33) * add migration to delete duplicates that currently exist in the db * added a name attribute for consistency --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Add unique index migration (#34) * add migration to delete duplicates that currently exist in the db * change model and migration to add a unique index constraint to id and name * renamed unique index name to be readable * redid model and migration to use @Unique instead of @Index * remove //Here comment --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * why wont these workflows stay up gahdamn --------- Co-authored-by: Laika Bozhko <63646916+LaikaBzko@users.noreply.github.com> Co-authored-by: Aster Fialla <asterfialla@gmail.com> Co-authored-by: laika <laika@sanya.gay>
2026-03-09 09:00:15 -04:00
expect(memberRepo.createMember).toHaveBeenCalledWith(expectedMemberArgs);
expect(memberRepo.createMember).toHaveBeenCalledTimes(1);
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
})
test('if checkProxyExists throws error, call database.member.create with null value', async () => {
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
// Arrange
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>
2026-02-25 19:30:39 -05:00
jest.spyOn(memberHelper, 'checkIfProxyExists').mockRejectedValue(new Error('error'));
const expectedMemberArgs = {
name: mockMember.name,
userid: authorId,
displayname: null,
proxy: null,
propic: null
}
perf: Merge develop into main (#36) * Update dockerfile for standalone deployment (#23) * Add files via upload * Update Docker image for pluralflux service * removing unnecessary network and container name definitions --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Converting ES6 back to CJS (#25) converting back to cjs Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Fix: Further converting ES6 to CJS - Making exports named instead of default (#26) * adding to git ignore * making imports named not default to not break all my tests * adjusted setup for memberhelper test --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: add db migrations with typeORM (#28) * adding typescript packages for typeORM * add typeORM initial files * updating package scripts * updating compose.yaml to have an exposed port for the postgres * modifying setup for typeORM * update database stuff and and package.json to help generate migrations * made models and migrations in typeORM * delete unneeded database.js * made database pattern ignored by jest * remove sequelize * separate member repo from member helper * not sure why i made everything numbers in the model but it's fixed now * edited package.json script * remove unused index.ts * adjusted files to reference repository correctly and appdatasource * made appdatasource export as named * removed start-db script * added init to appdatasource in bot.js * migrations finally! * new migration matching model names I want * updating tests * removing testpathignore patterns since it seems to be unecessary? * adjusting migrations to match current schema * removed reference to secrets file * delete old migration * Revert "delete old migration" This reverts commit db1efa39a7a80d8976878856250ccaac6a753ab2. * Revert "adjusting migrations to match current schema" This reverts commit ef89a83f6a2ef0643d6ace0a3fcf9c40f4bc6dd6. * just deleted system creation since it's got nothing in it anyway * renamed memberRepository to memberRepo for consistency * added await back to parseMemberCommand call to memberArgumentHandler * changed call to memberHelper.getMembersByAuthor to memberRepo * renamed repo updateMemberValue to updateMemberField * removed throw references in repo docstrings * remove unneeded subscriber directory ref * changed createdAt and updatedAt columns to be auto-generated made member table have timezone * changed casing of isInitialized in mock for bot.js * removed % from ILike query so that it doesn't match substrings/wildcard * renamed some stray updateMemberValue in mocks -> updateMemberField --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: Add migration to migrate existing data to new member table (#29) added migration to fill new Member table with data from Members Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update message helper reference hotfix (#30) * forgot to update a reference in messageHelper to memberRepo instead of memberHelper * turned off data-source logging --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update dockerfile to run npm start (#31) fix: update dockerfile to run npm start (which runs ts-node) instead of node Co-authored-by: Aster Fialla <asterfialla@gmail.com> * added .env with examples, updated data-source to be access a docker container instead of relying on loopback * i forgot to git add data-source.ts :facepalm: * fix: changed property reference for createMember in repo (#32) fix for createMember object references (was referencing non-existent properties) Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: memberRepo methods syntax (#35) * rearranged update member field and remove member to match expected structure in typeORM * update docstring * change insert to save in memberRepo * added command in package.json --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Delete duplicate members migration (#33) * add migration to delete duplicates that currently exist in the db * added a name attribute for consistency --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Add unique index migration (#34) * add migration to delete duplicates that currently exist in the db * change model and migration to add a unique index constraint to id and name * renamed unique index name to be readable * redid model and migration to use @Unique instead of @Index * remove //Here comment --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * why wont these workflows stay up gahdamn --------- Co-authored-by: Laika Bozhko <63646916+LaikaBzko@users.noreply.github.com> Co-authored-by: Aster Fialla <asterfialla@gmail.com> Co-authored-by: laika <laika@sanya.gay>
2026-03-09 09:00:15 -04:00
memberRepo.createMember = jest.fn().mockResolvedValue(expectedMemberArgs);
const expectedReturn = {
member: expectedMemberArgs,
errors: [`Tried to set proxy to \"${mockMember.proxy}\". error. ${enums.err.SET_TO_NULL}`]
}
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
// Act
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>
2026-02-25 19:30:39 -05:00
const res = await memberHelper.addFullMember(authorId, mockMember.name, null, mockMember.proxy, null)
// Assert
expect(res).toEqual(expectedReturn);
perf: Merge develop into main (#36) * Update dockerfile for standalone deployment (#23) * Add files via upload * Update Docker image for pluralflux service * removing unnecessary network and container name definitions --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Converting ES6 back to CJS (#25) converting back to cjs Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Fix: Further converting ES6 to CJS - Making exports named instead of default (#26) * adding to git ignore * making imports named not default to not break all my tests * adjusted setup for memberhelper test --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: add db migrations with typeORM (#28) * adding typescript packages for typeORM * add typeORM initial files * updating package scripts * updating compose.yaml to have an exposed port for the postgres * modifying setup for typeORM * update database stuff and and package.json to help generate migrations * made models and migrations in typeORM * delete unneeded database.js * made database pattern ignored by jest * remove sequelize * separate member repo from member helper * not sure why i made everything numbers in the model but it's fixed now * edited package.json script * remove unused index.ts * adjusted files to reference repository correctly and appdatasource * made appdatasource export as named * removed start-db script * added init to appdatasource in bot.js * migrations finally! * new migration matching model names I want * updating tests * removing testpathignore patterns since it seems to be unecessary? * adjusting migrations to match current schema * removed reference to secrets file * delete old migration * Revert "delete old migration" This reverts commit db1efa39a7a80d8976878856250ccaac6a753ab2. * Revert "adjusting migrations to match current schema" This reverts commit ef89a83f6a2ef0643d6ace0a3fcf9c40f4bc6dd6. * just deleted system creation since it's got nothing in it anyway * renamed memberRepository to memberRepo for consistency * added await back to parseMemberCommand call to memberArgumentHandler * changed call to memberHelper.getMembersByAuthor to memberRepo * renamed repo updateMemberValue to updateMemberField * removed throw references in repo docstrings * remove unneeded subscriber directory ref * changed createdAt and updatedAt columns to be auto-generated made member table have timezone * changed casing of isInitialized in mock for bot.js * removed % from ILike query so that it doesn't match substrings/wildcard * renamed some stray updateMemberValue in mocks -> updateMemberField --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: Add migration to migrate existing data to new member table (#29) added migration to fill new Member table with data from Members Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update message helper reference hotfix (#30) * forgot to update a reference in messageHelper to memberRepo instead of memberHelper * turned off data-source logging --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update dockerfile to run npm start (#31) fix: update dockerfile to run npm start (which runs ts-node) instead of node Co-authored-by: Aster Fialla <asterfialla@gmail.com> * added .env with examples, updated data-source to be access a docker container instead of relying on loopback * i forgot to git add data-source.ts :facepalm: * fix: changed property reference for createMember in repo (#32) fix for createMember object references (was referencing non-existent properties) Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: memberRepo methods syntax (#35) * rearranged update member field and remove member to match expected structure in typeORM * update docstring * change insert to save in memberRepo * added command in package.json --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Delete duplicate members migration (#33) * add migration to delete duplicates that currently exist in the db * added a name attribute for consistency --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Add unique index migration (#34) * add migration to delete duplicates that currently exist in the db * change model and migration to add a unique index constraint to id and name * renamed unique index name to be readable * redid model and migration to use @Unique instead of @Index * remove //Here comment --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * why wont these workflows stay up gahdamn --------- Co-authored-by: Laika Bozhko <63646916+LaikaBzko@users.noreply.github.com> Co-authored-by: Aster Fialla <asterfialla@gmail.com> Co-authored-by: laika <laika@sanya.gay>
2026-03-09 09:00:15 -04:00
expect(memberRepo.createMember).toHaveBeenCalledWith(expectedMemberArgs);
expect(memberRepo.createMember).toHaveBeenCalledTimes(1);
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
})
test('if propic, call checkImageFormatValidity', async () => {
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
// Arrange
const expectedMemberArgs = {
name: mockMember.name,
userid: authorId,
displayname: null,
proxy: null,
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>
2026-02-25 19:30:39 -05:00
propic: null
}
perf: Merge develop into main (#36) * Update dockerfile for standalone deployment (#23) * Add files via upload * Update Docker image for pluralflux service * removing unnecessary network and container name definitions --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Converting ES6 back to CJS (#25) converting back to cjs Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Fix: Further converting ES6 to CJS - Making exports named instead of default (#26) * adding to git ignore * making imports named not default to not break all my tests * adjusted setup for memberhelper test --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: add db migrations with typeORM (#28) * adding typescript packages for typeORM * add typeORM initial files * updating package scripts * updating compose.yaml to have an exposed port for the postgres * modifying setup for typeORM * update database stuff and and package.json to help generate migrations * made models and migrations in typeORM * delete unneeded database.js * made database pattern ignored by jest * remove sequelize * separate member repo from member helper * not sure why i made everything numbers in the model but it's fixed now * edited package.json script * remove unused index.ts * adjusted files to reference repository correctly and appdatasource * made appdatasource export as named * removed start-db script * added init to appdatasource in bot.js * migrations finally! * new migration matching model names I want * updating tests * removing testpathignore patterns since it seems to be unecessary? * adjusting migrations to match current schema * removed reference to secrets file * delete old migration * Revert "delete old migration" This reverts commit db1efa39a7a80d8976878856250ccaac6a753ab2. * Revert "adjusting migrations to match current schema" This reverts commit ef89a83f6a2ef0643d6ace0a3fcf9c40f4bc6dd6. * just deleted system creation since it's got nothing in it anyway * renamed memberRepository to memberRepo for consistency * added await back to parseMemberCommand call to memberArgumentHandler * changed call to memberHelper.getMembersByAuthor to memberRepo * renamed repo updateMemberValue to updateMemberField * removed throw references in repo docstrings * remove unneeded subscriber directory ref * changed createdAt and updatedAt columns to be auto-generated made member table have timezone * changed casing of isInitialized in mock for bot.js * removed % from ILike query so that it doesn't match substrings/wildcard * renamed some stray updateMemberValue in mocks -> updateMemberField --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: Add migration to migrate existing data to new member table (#29) added migration to fill new Member table with data from Members Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update message helper reference hotfix (#30) * forgot to update a reference in messageHelper to memberRepo instead of memberHelper * turned off data-source logging --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update dockerfile to run npm start (#31) fix: update dockerfile to run npm start (which runs ts-node) instead of node Co-authored-by: Aster Fialla <asterfialla@gmail.com> * added .env with examples, updated data-source to be access a docker container instead of relying on loopback * i forgot to git add data-source.ts :facepalm: * fix: changed property reference for createMember in repo (#32) fix for createMember object references (was referencing non-existent properties) Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: memberRepo methods syntax (#35) * rearranged update member field and remove member to match expected structure in typeORM * update docstring * change insert to save in memberRepo * added command in package.json --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Delete duplicate members migration (#33) * add migration to delete duplicates that currently exist in the db * added a name attribute for consistency --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Add unique index migration (#34) * add migration to delete duplicates that currently exist in the db * change model and migration to add a unique index constraint to id and name * renamed unique index name to be readable * redid model and migration to use @Unique instead of @Index * remove //Here comment --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * why wont these workflows stay up gahdamn --------- Co-authored-by: Laika Bozhko <63646916+LaikaBzko@users.noreply.github.com> Co-authored-by: Aster Fialla <asterfialla@gmail.com> Co-authored-by: laika <laika@sanya.gay>
2026-03-09 09:00:15 -04:00
utils.setExpirationWarning = jest.fn().mockReturnValue();
memberRepo.createMember = jest.fn().mockResolvedValue(expectedMemberArgs);
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
const expectedReturn = {member: expectedMemberArgs, errors: []}
// Act
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>
2026-02-25 19:30:39 -05:00
const res = await memberHelper.addFullMember(authorId, mockMember.name, null, null, mockMember.propic);
// Assert
expect(res).toEqual(expectedReturn);
expect(utils.checkImageFormatValidity).toHaveBeenCalledWith(mockMember.propic);
expect(utils.checkImageFormatValidity).toHaveBeenCalledTimes(1);
perf: Merge develop into main (#36) * Update dockerfile for standalone deployment (#23) * Add files via upload * Update Docker image for pluralflux service * removing unnecessary network and container name definitions --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Converting ES6 back to CJS (#25) converting back to cjs Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Fix: Further converting ES6 to CJS - Making exports named instead of default (#26) * adding to git ignore * making imports named not default to not break all my tests * adjusted setup for memberhelper test --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: add db migrations with typeORM (#28) * adding typescript packages for typeORM * add typeORM initial files * updating package scripts * updating compose.yaml to have an exposed port for the postgres * modifying setup for typeORM * update database stuff and and package.json to help generate migrations * made models and migrations in typeORM * delete unneeded database.js * made database pattern ignored by jest * remove sequelize * separate member repo from member helper * not sure why i made everything numbers in the model but it's fixed now * edited package.json script * remove unused index.ts * adjusted files to reference repository correctly and appdatasource * made appdatasource export as named * removed start-db script * added init to appdatasource in bot.js * migrations finally! * new migration matching model names I want * updating tests * removing testpathignore patterns since it seems to be unecessary? * adjusting migrations to match current schema * removed reference to secrets file * delete old migration * Revert "delete old migration" This reverts commit db1efa39a7a80d8976878856250ccaac6a753ab2. * Revert "adjusting migrations to match current schema" This reverts commit ef89a83f6a2ef0643d6ace0a3fcf9c40f4bc6dd6. * just deleted system creation since it's got nothing in it anyway * renamed memberRepository to memberRepo for consistency * added await back to parseMemberCommand call to memberArgumentHandler * changed call to memberHelper.getMembersByAuthor to memberRepo * renamed repo updateMemberValue to updateMemberField * removed throw references in repo docstrings * remove unneeded subscriber directory ref * changed createdAt and updatedAt columns to be auto-generated made member table have timezone * changed casing of isInitialized in mock for bot.js * removed % from ILike query so that it doesn't match substrings/wildcard * renamed some stray updateMemberValue in mocks -> updateMemberField --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: Add migration to migrate existing data to new member table (#29) added migration to fill new Member table with data from Members Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update message helper reference hotfix (#30) * forgot to update a reference in messageHelper to memberRepo instead of memberHelper * turned off data-source logging --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update dockerfile to run npm start (#31) fix: update dockerfile to run npm start (which runs ts-node) instead of node Co-authored-by: Aster Fialla <asterfialla@gmail.com> * added .env with examples, updated data-source to be access a docker container instead of relying on loopback * i forgot to git add data-source.ts :facepalm: * fix: changed property reference for createMember in repo (#32) fix for createMember object references (was referencing non-existent properties) Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: memberRepo methods syntax (#35) * rearranged update member field and remove member to match expected structure in typeORM * update docstring * change insert to save in memberRepo * added command in package.json --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Delete duplicate members migration (#33) * add migration to delete duplicates that currently exist in the db * added a name attribute for consistency --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Add unique index migration (#34) * add migration to delete duplicates that currently exist in the db * change model and migration to add a unique index constraint to id and name * renamed unique index name to be readable * redid model and migration to use @Unique instead of @Index * remove //Here comment --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * why wont these workflows stay up gahdamn --------- Co-authored-by: Laika Bozhko <63646916+LaikaBzko@users.noreply.github.com> Co-authored-by: Aster Fialla <asterfialla@gmail.com> Co-authored-by: laika <laika@sanya.gay>
2026-03-09 09:00:15 -04:00
expect(memberRepo.createMember).toHaveBeenCalledWith(expectedMemberArgs);
expect(memberRepo.createMember).toHaveBeenCalledTimes(1);
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
})
test('if checkImageFormatValidity throws error, call database.member.create with null value', async () => {
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
// Arrange
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>
2026-02-25 19:30:39 -05:00
utils.checkImageFormatValidity = jest.fn().mockRejectedValue(new Error("error"));
const expectedMemberArgs = {
name: mockMember.name,
userid: authorId,
displayname: null,
proxy: null,
propic: null
}
perf: Merge develop into main (#36) * Update dockerfile for standalone deployment (#23) * Add files via upload * Update Docker image for pluralflux service * removing unnecessary network and container name definitions --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Converting ES6 back to CJS (#25) converting back to cjs Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Fix: Further converting ES6 to CJS - Making exports named instead of default (#26) * adding to git ignore * making imports named not default to not break all my tests * adjusted setup for memberhelper test --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: add db migrations with typeORM (#28) * adding typescript packages for typeORM * add typeORM initial files * updating package scripts * updating compose.yaml to have an exposed port for the postgres * modifying setup for typeORM * update database stuff and and package.json to help generate migrations * made models and migrations in typeORM * delete unneeded database.js * made database pattern ignored by jest * remove sequelize * separate member repo from member helper * not sure why i made everything numbers in the model but it's fixed now * edited package.json script * remove unused index.ts * adjusted files to reference repository correctly and appdatasource * made appdatasource export as named * removed start-db script * added init to appdatasource in bot.js * migrations finally! * new migration matching model names I want * updating tests * removing testpathignore patterns since it seems to be unecessary? * adjusting migrations to match current schema * removed reference to secrets file * delete old migration * Revert "delete old migration" This reverts commit db1efa39a7a80d8976878856250ccaac6a753ab2. * Revert "adjusting migrations to match current schema" This reverts commit ef89a83f6a2ef0643d6ace0a3fcf9c40f4bc6dd6. * just deleted system creation since it's got nothing in it anyway * renamed memberRepository to memberRepo for consistency * added await back to parseMemberCommand call to memberArgumentHandler * changed call to memberHelper.getMembersByAuthor to memberRepo * renamed repo updateMemberValue to updateMemberField * removed throw references in repo docstrings * remove unneeded subscriber directory ref * changed createdAt and updatedAt columns to be auto-generated made member table have timezone * changed casing of isInitialized in mock for bot.js * removed % from ILike query so that it doesn't match substrings/wildcard * renamed some stray updateMemberValue in mocks -> updateMemberField --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: Add migration to migrate existing data to new member table (#29) added migration to fill new Member table with data from Members Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update message helper reference hotfix (#30) * forgot to update a reference in messageHelper to memberRepo instead of memberHelper * turned off data-source logging --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update dockerfile to run npm start (#31) fix: update dockerfile to run npm start (which runs ts-node) instead of node Co-authored-by: Aster Fialla <asterfialla@gmail.com> * added .env with examples, updated data-source to be access a docker container instead of relying on loopback * i forgot to git add data-source.ts :facepalm: * fix: changed property reference for createMember in repo (#32) fix for createMember object references (was referencing non-existent properties) Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: memberRepo methods syntax (#35) * rearranged update member field and remove member to match expected structure in typeORM * update docstring * change insert to save in memberRepo * added command in package.json --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Delete duplicate members migration (#33) * add migration to delete duplicates that currently exist in the db * added a name attribute for consistency --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Add unique index migration (#34) * add migration to delete duplicates that currently exist in the db * change model and migration to add a unique index constraint to id and name * renamed unique index name to be readable * redid model and migration to use @Unique instead of @Index * remove //Here comment --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * why wont these workflows stay up gahdamn --------- Co-authored-by: Laika Bozhko <63646916+LaikaBzko@users.noreply.github.com> Co-authored-by: Aster Fialla <asterfialla@gmail.com> Co-authored-by: laika <laika@sanya.gay>
2026-03-09 09:00:15 -04:00
memberRepo.createMember = jest.fn().mockResolvedValue(expectedMemberArgs);
const expectedReturn = {
member: expectedMemberArgs,
errors: [`Tried to set profile picture to \"${mockMember.propic}\". error. ${enums.err.SET_TO_NULL}`]
}
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
// Act
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>
2026-02-25 19:30:39 -05:00
const res = await memberHelper.addFullMember(authorId, mockMember.name, null, null, mockMember.propic);
// Assert
expect(res).toEqual(expectedReturn);
perf: Merge develop into main (#36) * Update dockerfile for standalone deployment (#23) * Add files via upload * Update Docker image for pluralflux service * removing unnecessary network and container name definitions --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Converting ES6 back to CJS (#25) converting back to cjs Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Fix: Further converting ES6 to CJS - Making exports named instead of default (#26) * adding to git ignore * making imports named not default to not break all my tests * adjusted setup for memberhelper test --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: add db migrations with typeORM (#28) * adding typescript packages for typeORM * add typeORM initial files * updating package scripts * updating compose.yaml to have an exposed port for the postgres * modifying setup for typeORM * update database stuff and and package.json to help generate migrations * made models and migrations in typeORM * delete unneeded database.js * made database pattern ignored by jest * remove sequelize * separate member repo from member helper * not sure why i made everything numbers in the model but it's fixed now * edited package.json script * remove unused index.ts * adjusted files to reference repository correctly and appdatasource * made appdatasource export as named * removed start-db script * added init to appdatasource in bot.js * migrations finally! * new migration matching model names I want * updating tests * removing testpathignore patterns since it seems to be unecessary? * adjusting migrations to match current schema * removed reference to secrets file * delete old migration * Revert "delete old migration" This reverts commit db1efa39a7a80d8976878856250ccaac6a753ab2. * Revert "adjusting migrations to match current schema" This reverts commit ef89a83f6a2ef0643d6ace0a3fcf9c40f4bc6dd6. * just deleted system creation since it's got nothing in it anyway * renamed memberRepository to memberRepo for consistency * added await back to parseMemberCommand call to memberArgumentHandler * changed call to memberHelper.getMembersByAuthor to memberRepo * renamed repo updateMemberValue to updateMemberField * removed throw references in repo docstrings * remove unneeded subscriber directory ref * changed createdAt and updatedAt columns to be auto-generated made member table have timezone * changed casing of isInitialized in mock for bot.js * removed % from ILike query so that it doesn't match substrings/wildcard * renamed some stray updateMemberValue in mocks -> updateMemberField --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: Add migration to migrate existing data to new member table (#29) added migration to fill new Member table with data from Members Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update message helper reference hotfix (#30) * forgot to update a reference in messageHelper to memberRepo instead of memberHelper * turned off data-source logging --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update dockerfile to run npm start (#31) fix: update dockerfile to run npm start (which runs ts-node) instead of node Co-authored-by: Aster Fialla <asterfialla@gmail.com> * added .env with examples, updated data-source to be access a docker container instead of relying on loopback * i forgot to git add data-source.ts :facepalm: * fix: changed property reference for createMember in repo (#32) fix for createMember object references (was referencing non-existent properties) Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: memberRepo methods syntax (#35) * rearranged update member field and remove member to match expected structure in typeORM * update docstring * change insert to save in memberRepo * added command in package.json --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Delete duplicate members migration (#33) * add migration to delete duplicates that currently exist in the db * added a name attribute for consistency --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Add unique index migration (#34) * add migration to delete duplicates that currently exist in the db * change model and migration to add a unique index constraint to id and name * renamed unique index name to be readable * redid model and migration to use @Unique instead of @Index * remove //Here comment --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * why wont these workflows stay up gahdamn --------- Co-authored-by: Laika Bozhko <63646916+LaikaBzko@users.noreply.github.com> Co-authored-by: Aster Fialla <asterfialla@gmail.com> Co-authored-by: laika <laika@sanya.gay>
2026-03-09 09:00:15 -04:00
expect(memberRepo.createMember).toHaveBeenCalledWith(expectedMemberArgs);
expect(memberRepo.createMember).toHaveBeenCalledTimes(1);
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>
2026-02-25 19:30:39 -05:00
})
test('calls setExpirationWarning if attachmentExpiration exists', async () => {
// Arrange
utils.checkImageFormatValidity = jest.fn().mockResolvedValue(true);
perf: Merge develop into main (#36) * Update dockerfile for standalone deployment (#23) * Add files via upload * Update Docker image for pluralflux service * removing unnecessary network and container name definitions --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Converting ES6 back to CJS (#25) converting back to cjs Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Fix: Further converting ES6 to CJS - Making exports named instead of default (#26) * adding to git ignore * making imports named not default to not break all my tests * adjusted setup for memberhelper test --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: add db migrations with typeORM (#28) * adding typescript packages for typeORM * add typeORM initial files * updating package scripts * updating compose.yaml to have an exposed port for the postgres * modifying setup for typeORM * update database stuff and and package.json to help generate migrations * made models and migrations in typeORM * delete unneeded database.js * made database pattern ignored by jest * remove sequelize * separate member repo from member helper * not sure why i made everything numbers in the model but it's fixed now * edited package.json script * remove unused index.ts * adjusted files to reference repository correctly and appdatasource * made appdatasource export as named * removed start-db script * added init to appdatasource in bot.js * migrations finally! * new migration matching model names I want * updating tests * removing testpathignore patterns since it seems to be unecessary? * adjusting migrations to match current schema * removed reference to secrets file * delete old migration * Revert "delete old migration" This reverts commit db1efa39a7a80d8976878856250ccaac6a753ab2. * Revert "adjusting migrations to match current schema" This reverts commit ef89a83f6a2ef0643d6ace0a3fcf9c40f4bc6dd6. * just deleted system creation since it's got nothing in it anyway * renamed memberRepository to memberRepo for consistency * added await back to parseMemberCommand call to memberArgumentHandler * changed call to memberHelper.getMembersByAuthor to memberRepo * renamed repo updateMemberValue to updateMemberField * removed throw references in repo docstrings * remove unneeded subscriber directory ref * changed createdAt and updatedAt columns to be auto-generated made member table have timezone * changed casing of isInitialized in mock for bot.js * removed % from ILike query so that it doesn't match substrings/wildcard * renamed some stray updateMemberValue in mocks -> updateMemberField --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: Add migration to migrate existing data to new member table (#29) added migration to fill new Member table with data from Members Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update message helper reference hotfix (#30) * forgot to update a reference in messageHelper to memberRepo instead of memberHelper * turned off data-source logging --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update dockerfile to run npm start (#31) fix: update dockerfile to run npm start (which runs ts-node) instead of node Co-authored-by: Aster Fialla <asterfialla@gmail.com> * added .env with examples, updated data-source to be access a docker container instead of relying on loopback * i forgot to git add data-source.ts :facepalm: * fix: changed property reference for createMember in repo (#32) fix for createMember object references (was referencing non-existent properties) Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: memberRepo methods syntax (#35) * rearranged update member field and remove member to match expected structure in typeORM * update docstring * change insert to save in memberRepo * added command in package.json --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Delete duplicate members migration (#33) * add migration to delete duplicates that currently exist in the db * added a name attribute for consistency --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Add unique index migration (#34) * add migration to delete duplicates that currently exist in the db * change model and migration to add a unique index constraint to id and name * renamed unique index name to be readable * redid model and migration to use @Unique instead of @Index * remove //Here comment --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * why wont these workflows stay up gahdamn --------- Co-authored-by: Laika Bozhko <63646916+LaikaBzko@users.noreply.github.com> Co-authored-by: Aster Fialla <asterfialla@gmail.com> Co-authored-by: laika <laika@sanya.gay>
2026-03-09 09:00:15 -04:00
utils.setExpirationWarning = jest.fn().mockReturnValue(`${enums.misc.ATTACHMENT_EXPIRATION_WARNING}`);
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>
2026-02-25 19:30:39 -05:00
// Act
await memberHelper.addFullMember(authorId, mockMember.name, null, null, mockMember.propic, attachmentExpiration)
// Assert
perf: Merge develop into main (#36) * Update dockerfile for standalone deployment (#23) * Add files via upload * Update Docker image for pluralflux service * removing unnecessary network and container name definitions --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Converting ES6 back to CJS (#25) converting back to cjs Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Fix: Further converting ES6 to CJS - Making exports named instead of default (#26) * adding to git ignore * making imports named not default to not break all my tests * adjusted setup for memberhelper test --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: add db migrations with typeORM (#28) * adding typescript packages for typeORM * add typeORM initial files * updating package scripts * updating compose.yaml to have an exposed port for the postgres * modifying setup for typeORM * update database stuff and and package.json to help generate migrations * made models and migrations in typeORM * delete unneeded database.js * made database pattern ignored by jest * remove sequelize * separate member repo from member helper * not sure why i made everything numbers in the model but it's fixed now * edited package.json script * remove unused index.ts * adjusted files to reference repository correctly and appdatasource * made appdatasource export as named * removed start-db script * added init to appdatasource in bot.js * migrations finally! * new migration matching model names I want * updating tests * removing testpathignore patterns since it seems to be unecessary? * adjusting migrations to match current schema * removed reference to secrets file * delete old migration * Revert "delete old migration" This reverts commit db1efa39a7a80d8976878856250ccaac6a753ab2. * Revert "adjusting migrations to match current schema" This reverts commit ef89a83f6a2ef0643d6ace0a3fcf9c40f4bc6dd6. * just deleted system creation since it's got nothing in it anyway * renamed memberRepository to memberRepo for consistency * added await back to parseMemberCommand call to memberArgumentHandler * changed call to memberHelper.getMembersByAuthor to memberRepo * renamed repo updateMemberValue to updateMemberField * removed throw references in repo docstrings * remove unneeded subscriber directory ref * changed createdAt and updatedAt columns to be auto-generated made member table have timezone * changed casing of isInitialized in mock for bot.js * removed % from ILike query so that it doesn't match substrings/wildcard * renamed some stray updateMemberValue in mocks -> updateMemberField --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: Add migration to migrate existing data to new member table (#29) added migration to fill new Member table with data from Members Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update message helper reference hotfix (#30) * forgot to update a reference in messageHelper to memberRepo instead of memberHelper * turned off data-source logging --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update dockerfile to run npm start (#31) fix: update dockerfile to run npm start (which runs ts-node) instead of node Co-authored-by: Aster Fialla <asterfialla@gmail.com> * added .env with examples, updated data-source to be access a docker container instead of relying on loopback * i forgot to git add data-source.ts :facepalm: * fix: changed property reference for createMember in repo (#32) fix for createMember object references (was referencing non-existent properties) Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: memberRepo methods syntax (#35) * rearranged update member field and remove member to match expected structure in typeORM * update docstring * change insert to save in memberRepo * added command in package.json --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Delete duplicate members migration (#33) * add migration to delete duplicates that currently exist in the db * added a name attribute for consistency --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Add unique index migration (#34) * add migration to delete duplicates that currently exist in the db * change model and migration to add a unique index constraint to id and name * renamed unique index name to be readable * redid model and migration to use @Unique instead of @Index * remove //Here comment --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * why wont these workflows stay up gahdamn --------- Co-authored-by: Laika Bozhko <63646916+LaikaBzko@users.noreply.github.com> Co-authored-by: Aster Fialla <asterfialla@gmail.com> Co-authored-by: laika <laika@sanya.gay>
2026-03-09 09:00:15 -04:00
expect(utils.setExpirationWarning).toHaveBeenCalledTimes(1);
expect(utils.setExpirationWarning).toHaveBeenCalledWith(mockMember.propic, attachmentExpiration);
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
})
test('if all values are valid, call database.members.create', async () => {
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
// Arrange
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>
2026-02-25 19:30:39 -05:00
jest.spyOn(memberHelper, 'checkIfProxyExists').mockResolvedValue(false);
const expectedMemberArgs = {
name: mockMember.name,
userid: authorId,
displayname: mockMember.displayname,
proxy: mockMember.proxy,
propic: mockMember.propic
}
perf: Merge develop into main (#36) * Update dockerfile for standalone deployment (#23) * Add files via upload * Update Docker image for pluralflux service * removing unnecessary network and container name definitions --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Converting ES6 back to CJS (#25) converting back to cjs Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Fix: Further converting ES6 to CJS - Making exports named instead of default (#26) * adding to git ignore * making imports named not default to not break all my tests * adjusted setup for memberhelper test --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: add db migrations with typeORM (#28) * adding typescript packages for typeORM * add typeORM initial files * updating package scripts * updating compose.yaml to have an exposed port for the postgres * modifying setup for typeORM * update database stuff and and package.json to help generate migrations * made models and migrations in typeORM * delete unneeded database.js * made database pattern ignored by jest * remove sequelize * separate member repo from member helper * not sure why i made everything numbers in the model but it's fixed now * edited package.json script * remove unused index.ts * adjusted files to reference repository correctly and appdatasource * made appdatasource export as named * removed start-db script * added init to appdatasource in bot.js * migrations finally! * new migration matching model names I want * updating tests * removing testpathignore patterns since it seems to be unecessary? * adjusting migrations to match current schema * removed reference to secrets file * delete old migration * Revert "delete old migration" This reverts commit db1efa39a7a80d8976878856250ccaac6a753ab2. * Revert "adjusting migrations to match current schema" This reverts commit ef89a83f6a2ef0643d6ace0a3fcf9c40f4bc6dd6. * just deleted system creation since it's got nothing in it anyway * renamed memberRepository to memberRepo for consistency * added await back to parseMemberCommand call to memberArgumentHandler * changed call to memberHelper.getMembersByAuthor to memberRepo * renamed repo updateMemberValue to updateMemberField * removed throw references in repo docstrings * remove unneeded subscriber directory ref * changed createdAt and updatedAt columns to be auto-generated made member table have timezone * changed casing of isInitialized in mock for bot.js * removed % from ILike query so that it doesn't match substrings/wildcard * renamed some stray updateMemberValue in mocks -> updateMemberField --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: Add migration to migrate existing data to new member table (#29) added migration to fill new Member table with data from Members Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update message helper reference hotfix (#30) * forgot to update a reference in messageHelper to memberRepo instead of memberHelper * turned off data-source logging --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update dockerfile to run npm start (#31) fix: update dockerfile to run npm start (which runs ts-node) instead of node Co-authored-by: Aster Fialla <asterfialla@gmail.com> * added .env with examples, updated data-source to be access a docker container instead of relying on loopback * i forgot to git add data-source.ts :facepalm: * fix: changed property reference for createMember in repo (#32) fix for createMember object references (was referencing non-existent properties) Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: memberRepo methods syntax (#35) * rearranged update member field and remove member to match expected structure in typeORM * update docstring * change insert to save in memberRepo * added command in package.json --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Delete duplicate members migration (#33) * add migration to delete duplicates that currently exist in the db * added a name attribute for consistency --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Add unique index migration (#34) * add migration to delete duplicates that currently exist in the db * change model and migration to add a unique index constraint to id and name * renamed unique index name to be readable * redid model and migration to use @Unique instead of @Index * remove //Here comment --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * why wont these workflows stay up gahdamn --------- Co-authored-by: Laika Bozhko <63646916+LaikaBzko@users.noreply.github.com> Co-authored-by: Aster Fialla <asterfialla@gmail.com> Co-authored-by: laika <laika@sanya.gay>
2026-03-09 09:00:15 -04:00
memberRepo.createMember = jest.fn().mockResolvedValue(expectedMemberArgs);
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>
2026-02-25 19:30:39 -05:00
utils.checkImageFormatValidity = jest.fn().mockResolvedValue(true);
perf: Merge develop into main (#36) * Update dockerfile for standalone deployment (#23) * Add files via upload * Update Docker image for pluralflux service * removing unnecessary network and container name definitions --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Converting ES6 back to CJS (#25) converting back to cjs Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Fix: Further converting ES6 to CJS - Making exports named instead of default (#26) * adding to git ignore * making imports named not default to not break all my tests * adjusted setup for memberhelper test --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: add db migrations with typeORM (#28) * adding typescript packages for typeORM * add typeORM initial files * updating package scripts * updating compose.yaml to have an exposed port for the postgres * modifying setup for typeORM * update database stuff and and package.json to help generate migrations * made models and migrations in typeORM * delete unneeded database.js * made database pattern ignored by jest * remove sequelize * separate member repo from member helper * not sure why i made everything numbers in the model but it's fixed now * edited package.json script * remove unused index.ts * adjusted files to reference repository correctly and appdatasource * made appdatasource export as named * removed start-db script * added init to appdatasource in bot.js * migrations finally! * new migration matching model names I want * updating tests * removing testpathignore patterns since it seems to be unecessary? * adjusting migrations to match current schema * removed reference to secrets file * delete old migration * Revert "delete old migration" This reverts commit db1efa39a7a80d8976878856250ccaac6a753ab2. * Revert "adjusting migrations to match current schema" This reverts commit ef89a83f6a2ef0643d6ace0a3fcf9c40f4bc6dd6. * just deleted system creation since it's got nothing in it anyway * renamed memberRepository to memberRepo for consistency * added await back to parseMemberCommand call to memberArgumentHandler * changed call to memberHelper.getMembersByAuthor to memberRepo * renamed repo updateMemberValue to updateMemberField * removed throw references in repo docstrings * remove unneeded subscriber directory ref * changed createdAt and updatedAt columns to be auto-generated made member table have timezone * changed casing of isInitialized in mock for bot.js * removed % from ILike query so that it doesn't match substrings/wildcard * renamed some stray updateMemberValue in mocks -> updateMemberField --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: Add migration to migrate existing data to new member table (#29) added migration to fill new Member table with data from Members Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update message helper reference hotfix (#30) * forgot to update a reference in messageHelper to memberRepo instead of memberHelper * turned off data-source logging --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update dockerfile to run npm start (#31) fix: update dockerfile to run npm start (which runs ts-node) instead of node Co-authored-by: Aster Fialla <asterfialla@gmail.com> * added .env with examples, updated data-source to be access a docker container instead of relying on loopback * i forgot to git add data-source.ts :facepalm: * fix: changed property reference for createMember in repo (#32) fix for createMember object references (was referencing non-existent properties) Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: memberRepo methods syntax (#35) * rearranged update member field and remove member to match expected structure in typeORM * update docstring * change insert to save in memberRepo * added command in package.json --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Delete duplicate members migration (#33) * add migration to delete duplicates that currently exist in the db * added a name attribute for consistency --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Add unique index migration (#34) * add migration to delete duplicates that currently exist in the db * change model and migration to add a unique index constraint to id and name * renamed unique index name to be readable * redid model and migration to use @Unique instead of @Index * remove //Here comment --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * why wont these workflows stay up gahdamn --------- Co-authored-by: Laika Bozhko <63646916+LaikaBzko@users.noreply.github.com> Co-authored-by: Aster Fialla <asterfialla@gmail.com> Co-authored-by: laika <laika@sanya.gay>
2026-03-09 09:00:15 -04:00
utils.setExpirationWarning = jest.fn().mockReturnValue();
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
const expectedReturn = {member: expectedMemberArgs, errors: []}
// Act
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>
2026-02-25 19:30:39 -05:00
const res = await memberHelper.addFullMember(authorId, mockMember.name, mockMember.displayname, mockMember.proxy, mockMember.propic);
// Assert
expect(res).toEqual(expectedReturn);
perf: Merge develop into main (#36) * Update dockerfile for standalone deployment (#23) * Add files via upload * Update Docker image for pluralflux service * removing unnecessary network and container name definitions --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Converting ES6 back to CJS (#25) converting back to cjs Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Fix: Further converting ES6 to CJS - Making exports named instead of default (#26) * adding to git ignore * making imports named not default to not break all my tests * adjusted setup for memberhelper test --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: add db migrations with typeORM (#28) * adding typescript packages for typeORM * add typeORM initial files * updating package scripts * updating compose.yaml to have an exposed port for the postgres * modifying setup for typeORM * update database stuff and and package.json to help generate migrations * made models and migrations in typeORM * delete unneeded database.js * made database pattern ignored by jest * remove sequelize * separate member repo from member helper * not sure why i made everything numbers in the model but it's fixed now * edited package.json script * remove unused index.ts * adjusted files to reference repository correctly and appdatasource * made appdatasource export as named * removed start-db script * added init to appdatasource in bot.js * migrations finally! * new migration matching model names I want * updating tests * removing testpathignore patterns since it seems to be unecessary? * adjusting migrations to match current schema * removed reference to secrets file * delete old migration * Revert "delete old migration" This reverts commit db1efa39a7a80d8976878856250ccaac6a753ab2. * Revert "adjusting migrations to match current schema" This reverts commit ef89a83f6a2ef0643d6ace0a3fcf9c40f4bc6dd6. * just deleted system creation since it's got nothing in it anyway * renamed memberRepository to memberRepo for consistency * added await back to parseMemberCommand call to memberArgumentHandler * changed call to memberHelper.getMembersByAuthor to memberRepo * renamed repo updateMemberValue to updateMemberField * removed throw references in repo docstrings * remove unneeded subscriber directory ref * changed createdAt and updatedAt columns to be auto-generated made member table have timezone * changed casing of isInitialized in mock for bot.js * removed % from ILike query so that it doesn't match substrings/wildcard * renamed some stray updateMemberValue in mocks -> updateMemberField --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: Add migration to migrate existing data to new member table (#29) added migration to fill new Member table with data from Members Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update message helper reference hotfix (#30) * forgot to update a reference in messageHelper to memberRepo instead of memberHelper * turned off data-source logging --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update dockerfile to run npm start (#31) fix: update dockerfile to run npm start (which runs ts-node) instead of node Co-authored-by: Aster Fialla <asterfialla@gmail.com> * added .env with examples, updated data-source to be access a docker container instead of relying on loopback * i forgot to git add data-source.ts :facepalm: * fix: changed property reference for createMember in repo (#32) fix for createMember object references (was referencing non-existent properties) Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: memberRepo methods syntax (#35) * rearranged update member field and remove member to match expected structure in typeORM * update docstring * change insert to save in memberRepo * added command in package.json --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Delete duplicate members migration (#33) * add migration to delete duplicates that currently exist in the db * added a name attribute for consistency --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Add unique index migration (#34) * add migration to delete duplicates that currently exist in the db * change model and migration to add a unique index constraint to id and name * renamed unique index name to be readable * redid model and migration to use @Unique instead of @Index * remove //Here comment --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * why wont these workflows stay up gahdamn --------- Co-authored-by: Laika Bozhko <63646916+LaikaBzko@users.noreply.github.com> Co-authored-by: Aster Fialla <asterfialla@gmail.com> Co-authored-by: laika <laika@sanya.gay>
2026-03-09 09:00:15 -04:00
expect(memberRepo.createMember).toHaveBeenCalledWith(expectedMemberArgs);
expect(memberRepo.createMember).toHaveBeenCalledTimes(1);
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
})
})
describe('updateMemberField', () => {
beforeEach(() => {
perf: Merge develop into main (#36) * Update dockerfile for standalone deployment (#23) * Add files via upload * Update Docker image for pluralflux service * removing unnecessary network and container name definitions --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Converting ES6 back to CJS (#25) converting back to cjs Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Fix: Further converting ES6 to CJS - Making exports named instead of default (#26) * adding to git ignore * making imports named not default to not break all my tests * adjusted setup for memberhelper test --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: add db migrations with typeORM (#28) * adding typescript packages for typeORM * add typeORM initial files * updating package scripts * updating compose.yaml to have an exposed port for the postgres * modifying setup for typeORM * update database stuff and and package.json to help generate migrations * made models and migrations in typeORM * delete unneeded database.js * made database pattern ignored by jest * remove sequelize * separate member repo from member helper * not sure why i made everything numbers in the model but it's fixed now * edited package.json script * remove unused index.ts * adjusted files to reference repository correctly and appdatasource * made appdatasource export as named * removed start-db script * added init to appdatasource in bot.js * migrations finally! * new migration matching model names I want * updating tests * removing testpathignore patterns since it seems to be unecessary? * adjusting migrations to match current schema * removed reference to secrets file * delete old migration * Revert "delete old migration" This reverts commit db1efa39a7a80d8976878856250ccaac6a753ab2. * Revert "adjusting migrations to match current schema" This reverts commit ef89a83f6a2ef0643d6ace0a3fcf9c40f4bc6dd6. * just deleted system creation since it's got nothing in it anyway * renamed memberRepository to memberRepo for consistency * added await back to parseMemberCommand call to memberArgumentHandler * changed call to memberHelper.getMembersByAuthor to memberRepo * renamed repo updateMemberValue to updateMemberField * removed throw references in repo docstrings * remove unneeded subscriber directory ref * changed createdAt and updatedAt columns to be auto-generated made member table have timezone * changed casing of isInitialized in mock for bot.js * removed % from ILike query so that it doesn't match substrings/wildcard * renamed some stray updateMemberValue in mocks -> updateMemberField --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: Add migration to migrate existing data to new member table (#29) added migration to fill new Member table with data from Members Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update message helper reference hotfix (#30) * forgot to update a reference in messageHelper to memberRepo instead of memberHelper * turned off data-source logging --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update dockerfile to run npm start (#31) fix: update dockerfile to run npm start (which runs ts-node) instead of node Co-authored-by: Aster Fialla <asterfialla@gmail.com> * added .env with examples, updated data-source to be access a docker container instead of relying on loopback * i forgot to git add data-source.ts :facepalm: * fix: changed property reference for createMember in repo (#32) fix for createMember object references (was referencing non-existent properties) Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: memberRepo methods syntax (#35) * rearranged update member field and remove member to match expected structure in typeORM * update docstring * change insert to save in memberRepo * added command in package.json --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Delete duplicate members migration (#33) * add migration to delete duplicates that currently exist in the db * added a name attribute for consistency --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Add unique index migration (#34) * add migration to delete duplicates that currently exist in the db * change model and migration to add a unique index constraint to id and name * renamed unique index name to be readable * redid model and migration to use @Unique instead of @Index * remove //Here comment --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * why wont these workflows stay up gahdamn --------- Co-authored-by: Laika Bozhko <63646916+LaikaBzko@users.noreply.github.com> Co-authored-by: Aster Fialla <asterfialla@gmail.com> Co-authored-by: laika <laika@sanya.gay>
2026-03-09 09:00:15 -04:00
utils.setExpirationWarning = jest.fn().mockReturnValue(`warning`);
memberRepo.updateMemberField = jest.fn().mockResolvedValue([1]);
})
test.each([
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>
2026-02-25 19:30:39 -05:00
['name', mockMember.name, undefined, `Updated name for ${mockMember.name} to ${mockMember.name}.`],
['displayname', mockMember.displayname, undefined, `Updated displayname for ${mockMember.name} to ${mockMember.displayname}.`],
['proxy', mockMember.proxy, undefined, `Updated proxy for ${mockMember.name} to ${mockMember.proxy}.`],
['propic', mockMember.propic, undefined, `Updated propic for ${mockMember.name} to ${mockMember.propic}.`],
['propic', mockMember.propic,
'warning', `Updated propic for ${mockMember.name} to ${mockMember.propic}. warning.`]
])('calls database.members.update with correct column and value and return string', async (columnName, value, attachmentExpiration, expected) => {
// Act
const res = await memberHelper.updateMemberField(authorId, mockMember.name, columnName, value, attachmentExpiration)
// Assert
expect(res).toEqual(expected);
perf: Merge develop into main (#36) * Update dockerfile for standalone deployment (#23) * Add files via upload * Update Docker image for pluralflux service * removing unnecessary network and container name definitions --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Converting ES6 back to CJS (#25) converting back to cjs Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Fix: Further converting ES6 to CJS - Making exports named instead of default (#26) * adding to git ignore * making imports named not default to not break all my tests * adjusted setup for memberhelper test --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: add db migrations with typeORM (#28) * adding typescript packages for typeORM * add typeORM initial files * updating package scripts * updating compose.yaml to have an exposed port for the postgres * modifying setup for typeORM * update database stuff and and package.json to help generate migrations * made models and migrations in typeORM * delete unneeded database.js * made database pattern ignored by jest * remove sequelize * separate member repo from member helper * not sure why i made everything numbers in the model but it's fixed now * edited package.json script * remove unused index.ts * adjusted files to reference repository correctly and appdatasource * made appdatasource export as named * removed start-db script * added init to appdatasource in bot.js * migrations finally! * new migration matching model names I want * updating tests * removing testpathignore patterns since it seems to be unecessary? * adjusting migrations to match current schema * removed reference to secrets file * delete old migration * Revert "delete old migration" This reverts commit db1efa39a7a80d8976878856250ccaac6a753ab2. * Revert "adjusting migrations to match current schema" This reverts commit ef89a83f6a2ef0643d6ace0a3fcf9c40f4bc6dd6. * just deleted system creation since it's got nothing in it anyway * renamed memberRepository to memberRepo for consistency * added await back to parseMemberCommand call to memberArgumentHandler * changed call to memberHelper.getMembersByAuthor to memberRepo * renamed repo updateMemberValue to updateMemberField * removed throw references in repo docstrings * remove unneeded subscriber directory ref * changed createdAt and updatedAt columns to be auto-generated made member table have timezone * changed casing of isInitialized in mock for bot.js * removed % from ILike query so that it doesn't match substrings/wildcard * renamed some stray updateMemberValue in mocks -> updateMemberField --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: Add migration to migrate existing data to new member table (#29) added migration to fill new Member table with data from Members Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update message helper reference hotfix (#30) * forgot to update a reference in messageHelper to memberRepo instead of memberHelper * turned off data-source logging --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update dockerfile to run npm start (#31) fix: update dockerfile to run npm start (which runs ts-node) instead of node Co-authored-by: Aster Fialla <asterfialla@gmail.com> * added .env with examples, updated data-source to be access a docker container instead of relying on loopback * i forgot to git add data-source.ts :facepalm: * fix: changed property reference for createMember in repo (#32) fix for createMember object references (was referencing non-existent properties) Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: memberRepo methods syntax (#35) * rearranged update member field and remove member to match expected structure in typeORM * update docstring * change insert to save in memberRepo * added command in package.json --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Delete duplicate members migration (#33) * add migration to delete duplicates that currently exist in the db * added a name attribute for consistency --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Add unique index migration (#34) * add migration to delete duplicates that currently exist in the db * change model and migration to add a unique index constraint to id and name * renamed unique index name to be readable * redid model and migration to use @Unique instead of @Index * remove //Here comment --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * why wont these workflows stay up gahdamn --------- Co-authored-by: Laika Bozhko <63646916+LaikaBzko@users.noreply.github.com> Co-authored-by: Aster Fialla <asterfialla@gmail.com> Co-authored-by: laika <laika@sanya.gay>
2026-03-09 09:00:15 -04:00
expect(memberRepo.updateMemberField).toHaveBeenCalledTimes(1);
expect(memberRepo.updateMemberField).toHaveBeenCalledWith(authorId, mockMember.name, columnName, value)
})
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>
2026-02-25 19:30:39 -05:00
test('if database.members.update returns 0 rows changed, throw error', async () => {
// Arrange
perf: Merge develop into main (#36) * Update dockerfile for standalone deployment (#23) * Add files via upload * Update Docker image for pluralflux service * removing unnecessary network and container name definitions --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Converting ES6 back to CJS (#25) converting back to cjs Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Fix: Further converting ES6 to CJS - Making exports named instead of default (#26) * adding to git ignore * making imports named not default to not break all my tests * adjusted setup for memberhelper test --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: add db migrations with typeORM (#28) * adding typescript packages for typeORM * add typeORM initial files * updating package scripts * updating compose.yaml to have an exposed port for the postgres * modifying setup for typeORM * update database stuff and and package.json to help generate migrations * made models and migrations in typeORM * delete unneeded database.js * made database pattern ignored by jest * remove sequelize * separate member repo from member helper * not sure why i made everything numbers in the model but it's fixed now * edited package.json script * remove unused index.ts * adjusted files to reference repository correctly and appdatasource * made appdatasource export as named * removed start-db script * added init to appdatasource in bot.js * migrations finally! * new migration matching model names I want * updating tests * removing testpathignore patterns since it seems to be unecessary? * adjusting migrations to match current schema * removed reference to secrets file * delete old migration * Revert "delete old migration" This reverts commit db1efa39a7a80d8976878856250ccaac6a753ab2. * Revert "adjusting migrations to match current schema" This reverts commit ef89a83f6a2ef0643d6ace0a3fcf9c40f4bc6dd6. * just deleted system creation since it's got nothing in it anyway * renamed memberRepository to memberRepo for consistency * added await back to parseMemberCommand call to memberArgumentHandler * changed call to memberHelper.getMembersByAuthor to memberRepo * renamed repo updateMemberValue to updateMemberField * removed throw references in repo docstrings * remove unneeded subscriber directory ref * changed createdAt and updatedAt columns to be auto-generated made member table have timezone * changed casing of isInitialized in mock for bot.js * removed % from ILike query so that it doesn't match substrings/wildcard * renamed some stray updateMemberValue in mocks -> updateMemberField --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: Add migration to migrate existing data to new member table (#29) added migration to fill new Member table with data from Members Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update message helper reference hotfix (#30) * forgot to update a reference in messageHelper to memberRepo instead of memberHelper * turned off data-source logging --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update dockerfile to run npm start (#31) fix: update dockerfile to run npm start (which runs ts-node) instead of node Co-authored-by: Aster Fialla <asterfialla@gmail.com> * added .env with examples, updated data-source to be access a docker container instead of relying on loopback * i forgot to git add data-source.ts :facepalm: * fix: changed property reference for createMember in repo (#32) fix for createMember object references (was referencing non-existent properties) Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: memberRepo methods syntax (#35) * rearranged update member field and remove member to match expected structure in typeORM * update docstring * change insert to save in memberRepo * added command in package.json --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Delete duplicate members migration (#33) * add migration to delete duplicates that currently exist in the db * added a name attribute for consistency --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Add unique index migration (#34) * add migration to delete duplicates that currently exist in the db * change model and migration to add a unique index constraint to id and name * renamed unique index name to be readable * redid model and migration to use @Unique instead of @Index * remove //Here comment --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * why wont these workflows stay up gahdamn --------- Co-authored-by: Laika Bozhko <63646916+LaikaBzko@users.noreply.github.com> Co-authored-by: Aster Fialla <asterfialla@gmail.com> Co-authored-by: laika <laika@sanya.gay>
2026-03-09 09:00:15 -04:00
memberRepo.updateMemberField = jest.fn().mockResolvedValue(0);
// Act
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>
2026-02-25 19:30:39 -05:00
await expect(memberHelper.updateMemberField(authorId, mockMember.name, "displayname", mockMember.displayname)).rejects.toThrow(`Can't update ${mockMember.name}. ${enums.err.NO_MEMBER}.`);
})
})
describe('checkIfProxyExists', () => {
beforeEach(() => {
perf: Merge develop into main (#36) * Update dockerfile for standalone deployment (#23) * Add files via upload * Update Docker image for pluralflux service * removing unnecessary network and container name definitions --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Converting ES6 back to CJS (#25) converting back to cjs Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Fix: Further converting ES6 to CJS - Making exports named instead of default (#26) * adding to git ignore * making imports named not default to not break all my tests * adjusted setup for memberhelper test --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: add db migrations with typeORM (#28) * adding typescript packages for typeORM * add typeORM initial files * updating package scripts * updating compose.yaml to have an exposed port for the postgres * modifying setup for typeORM * update database stuff and and package.json to help generate migrations * made models and migrations in typeORM * delete unneeded database.js * made database pattern ignored by jest * remove sequelize * separate member repo from member helper * not sure why i made everything numbers in the model but it's fixed now * edited package.json script * remove unused index.ts * adjusted files to reference repository correctly and appdatasource * made appdatasource export as named * removed start-db script * added init to appdatasource in bot.js * migrations finally! * new migration matching model names I want * updating tests * removing testpathignore patterns since it seems to be unecessary? * adjusting migrations to match current schema * removed reference to secrets file * delete old migration * Revert "delete old migration" This reverts commit db1efa39a7a80d8976878856250ccaac6a753ab2. * Revert "adjusting migrations to match current schema" This reverts commit ef89a83f6a2ef0643d6ace0a3fcf9c40f4bc6dd6. * just deleted system creation since it's got nothing in it anyway * renamed memberRepository to memberRepo for consistency * added await back to parseMemberCommand call to memberArgumentHandler * changed call to memberHelper.getMembersByAuthor to memberRepo * renamed repo updateMemberValue to updateMemberField * removed throw references in repo docstrings * remove unneeded subscriber directory ref * changed createdAt and updatedAt columns to be auto-generated made member table have timezone * changed casing of isInitialized in mock for bot.js * removed % from ILike query so that it doesn't match substrings/wildcard * renamed some stray updateMemberValue in mocks -> updateMemberField --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: Add migration to migrate existing data to new member table (#29) added migration to fill new Member table with data from Members Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update message helper reference hotfix (#30) * forgot to update a reference in messageHelper to memberRepo instead of memberHelper * turned off data-source logging --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update dockerfile to run npm start (#31) fix: update dockerfile to run npm start (which runs ts-node) instead of node Co-authored-by: Aster Fialla <asterfialla@gmail.com> * added .env with examples, updated data-source to be access a docker container instead of relying on loopback * i forgot to git add data-source.ts :facepalm: * fix: changed property reference for createMember in repo (#32) fix for createMember object references (was referencing non-existent properties) Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: memberRepo methods syntax (#35) * rearranged update member field and remove member to match expected structure in typeORM * update docstring * change insert to save in memberRepo * added command in package.json --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Delete duplicate members migration (#33) * add migration to delete duplicates that currently exist in the db * added a name attribute for consistency --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Add unique index migration (#34) * add migration to delete duplicates that currently exist in the db * change model and migration to add a unique index constraint to id and name * renamed unique index name to be readable * redid model and migration to use @Unique instead of @Index * remove //Here comment --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * why wont these workflows stay up gahdamn --------- Co-authored-by: Laika Bozhko <63646916+LaikaBzko@users.noreply.github.com> Co-authored-by: Aster Fialla <asterfialla@gmail.com> Co-authored-by: laika <laika@sanya.gay>
2026-03-09 09:00:15 -04:00
memberRepo.getMembersByAuthor.mockResolvedValue([mockMember]);
})
test.each([
['!text'],
['! text'],
['⭐text'],
['⭐ text'],
['⭐ text ⭐'],
['--text--'],
['!text ?'],
['SP: text'],
['text --SP'],
])('%s should call getMembersByAuthor and return false', async (proxy) => {
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>
2026-02-25 19:30:39 -05:00
// Act
const res = await memberHelper.checkIfProxyExists(authorId, proxy)
// Assert
expect(res).toEqual(false)
perf: Merge develop into main (#36) * Update dockerfile for standalone deployment (#23) * Add files via upload * Update Docker image for pluralflux service * removing unnecessary network and container name definitions --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Converting ES6 back to CJS (#25) converting back to cjs Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Fix: Further converting ES6 to CJS - Making exports named instead of default (#26) * adding to git ignore * making imports named not default to not break all my tests * adjusted setup for memberhelper test --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: add db migrations with typeORM (#28) * adding typescript packages for typeORM * add typeORM initial files * updating package scripts * updating compose.yaml to have an exposed port for the postgres * modifying setup for typeORM * update database stuff and and package.json to help generate migrations * made models and migrations in typeORM * delete unneeded database.js * made database pattern ignored by jest * remove sequelize * separate member repo from member helper * not sure why i made everything numbers in the model but it's fixed now * edited package.json script * remove unused index.ts * adjusted files to reference repository correctly and appdatasource * made appdatasource export as named * removed start-db script * added init to appdatasource in bot.js * migrations finally! * new migration matching model names I want * updating tests * removing testpathignore patterns since it seems to be unecessary? * adjusting migrations to match current schema * removed reference to secrets file * delete old migration * Revert "delete old migration" This reverts commit db1efa39a7a80d8976878856250ccaac6a753ab2. * Revert "adjusting migrations to match current schema" This reverts commit ef89a83f6a2ef0643d6ace0a3fcf9c40f4bc6dd6. * just deleted system creation since it's got nothing in it anyway * renamed memberRepository to memberRepo for consistency * added await back to parseMemberCommand call to memberArgumentHandler * changed call to memberHelper.getMembersByAuthor to memberRepo * renamed repo updateMemberValue to updateMemberField * removed throw references in repo docstrings * remove unneeded subscriber directory ref * changed createdAt and updatedAt columns to be auto-generated made member table have timezone * changed casing of isInitialized in mock for bot.js * removed % from ILike query so that it doesn't match substrings/wildcard * renamed some stray updateMemberValue in mocks -> updateMemberField --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: Add migration to migrate existing data to new member table (#29) added migration to fill new Member table with data from Members Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update message helper reference hotfix (#30) * forgot to update a reference in messageHelper to memberRepo instead of memberHelper * turned off data-source logging --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update dockerfile to run npm start (#31) fix: update dockerfile to run npm start (which runs ts-node) instead of node Co-authored-by: Aster Fialla <asterfialla@gmail.com> * added .env with examples, updated data-source to be access a docker container instead of relying on loopback * i forgot to git add data-source.ts :facepalm: * fix: changed property reference for createMember in repo (#32) fix for createMember object references (was referencing non-existent properties) Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: memberRepo methods syntax (#35) * rearranged update member field and remove member to match expected structure in typeORM * update docstring * change insert to save in memberRepo * added command in package.json --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Delete duplicate members migration (#33) * add migration to delete duplicates that currently exist in the db * added a name attribute for consistency --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Add unique index migration (#34) * add migration to delete duplicates that currently exist in the db * change model and migration to add a unique index constraint to id and name * renamed unique index name to be readable * redid model and migration to use @Unique instead of @Index * remove //Here comment --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * why wont these workflows stay up gahdamn --------- Co-authored-by: Laika Bozhko <63646916+LaikaBzko@users.noreply.github.com> Co-authored-by: Aster Fialla <asterfialla@gmail.com> Co-authored-by: laika <laika@sanya.gay>
2026-03-09 09:00:15 -04:00
expect(memberRepo.getMembersByAuthor).toHaveBeenCalledTimes(1);
expect(memberRepo.getMembersByAuthor).toHaveBeenCalledWith(authorId);
})
test.each([
['--', enums.err.NO_TEXT_FOR_PROXY, false],
[' ', enums.err.NO_TEXT_FOR_PROXY, false],
['text', enums.err.NO_PROXY_WRAPPER, false],
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>
2026-02-25 19:30:39 -05:00
])('%s returns correct error and does not call getMemberByAuthor', async (proxy, error, shouldCall) => {
// Act & Assert
await expect(memberHelper.checkIfProxyExists(authorId, proxy)).rejects.toThrow(error);
perf: Merge develop into main (#36) * Update dockerfile for standalone deployment (#23) * Add files via upload * Update Docker image for pluralflux service * removing unnecessary network and container name definitions --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Converting ES6 back to CJS (#25) converting back to cjs Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Fix: Further converting ES6 to CJS - Making exports named instead of default (#26) * adding to git ignore * making imports named not default to not break all my tests * adjusted setup for memberhelper test --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: add db migrations with typeORM (#28) * adding typescript packages for typeORM * add typeORM initial files * updating package scripts * updating compose.yaml to have an exposed port for the postgres * modifying setup for typeORM * update database stuff and and package.json to help generate migrations * made models and migrations in typeORM * delete unneeded database.js * made database pattern ignored by jest * remove sequelize * separate member repo from member helper * not sure why i made everything numbers in the model but it's fixed now * edited package.json script * remove unused index.ts * adjusted files to reference repository correctly and appdatasource * made appdatasource export as named * removed start-db script * added init to appdatasource in bot.js * migrations finally! * new migration matching model names I want * updating tests * removing testpathignore patterns since it seems to be unecessary? * adjusting migrations to match current schema * removed reference to secrets file * delete old migration * Revert "delete old migration" This reverts commit db1efa39a7a80d8976878856250ccaac6a753ab2. * Revert "adjusting migrations to match current schema" This reverts commit ef89a83f6a2ef0643d6ace0a3fcf9c40f4bc6dd6. * just deleted system creation since it's got nothing in it anyway * renamed memberRepository to memberRepo for consistency * added await back to parseMemberCommand call to memberArgumentHandler * changed call to memberHelper.getMembersByAuthor to memberRepo * renamed repo updateMemberValue to updateMemberField * removed throw references in repo docstrings * remove unneeded subscriber directory ref * changed createdAt and updatedAt columns to be auto-generated made member table have timezone * changed casing of isInitialized in mock for bot.js * removed % from ILike query so that it doesn't match substrings/wildcard * renamed some stray updateMemberValue in mocks -> updateMemberField --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: Add migration to migrate existing data to new member table (#29) added migration to fill new Member table with data from Members Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update message helper reference hotfix (#30) * forgot to update a reference in messageHelper to memberRepo instead of memberHelper * turned off data-source logging --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update dockerfile to run npm start (#31) fix: update dockerfile to run npm start (which runs ts-node) instead of node Co-authored-by: Aster Fialla <asterfialla@gmail.com> * added .env with examples, updated data-source to be access a docker container instead of relying on loopback * i forgot to git add data-source.ts :facepalm: * fix: changed property reference for createMember in repo (#32) fix for createMember object references (was referencing non-existent properties) Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: memberRepo methods syntax (#35) * rearranged update member field and remove member to match expected structure in typeORM * update docstring * change insert to save in memberRepo * added command in package.json --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Delete duplicate members migration (#33) * add migration to delete duplicates that currently exist in the db * added a name attribute for consistency --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Add unique index migration (#34) * add migration to delete duplicates that currently exist in the db * change model and migration to add a unique index constraint to id and name * renamed unique index name to be readable * redid model and migration to use @Unique instead of @Index * remove //Here comment --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * why wont these workflows stay up gahdamn --------- Co-authored-by: Laika Bozhko <63646916+LaikaBzko@users.noreply.github.com> Co-authored-by: Aster Fialla <asterfialla@gmail.com> Co-authored-by: laika <laika@sanya.gay>
2026-03-09 09:00:15 -04:00
expect(memberRepo.getMembersByAuthor).not.toHaveBeenCalled();
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>
2026-02-25 19:30:39 -05:00
})
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>
2026-02-25 19:30:39 -05:00
test('--text returns correct error and calls getMemberByAuthor', async () => {
await expect(memberHelper.checkIfProxyExists(authorId, "--text")).rejects.toThrow(enums.err.PROXY_EXISTS);
perf: Merge develop into main (#36) * Update dockerfile for standalone deployment (#23) * Add files via upload * Update Docker image for pluralflux service * removing unnecessary network and container name definitions --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Converting ES6 back to CJS (#25) converting back to cjs Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Fix: Further converting ES6 to CJS - Making exports named instead of default (#26) * adding to git ignore * making imports named not default to not break all my tests * adjusted setup for memberhelper test --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: add db migrations with typeORM (#28) * adding typescript packages for typeORM * add typeORM initial files * updating package scripts * updating compose.yaml to have an exposed port for the postgres * modifying setup for typeORM * update database stuff and and package.json to help generate migrations * made models and migrations in typeORM * delete unneeded database.js * made database pattern ignored by jest * remove sequelize * separate member repo from member helper * not sure why i made everything numbers in the model but it's fixed now * edited package.json script * remove unused index.ts * adjusted files to reference repository correctly and appdatasource * made appdatasource export as named * removed start-db script * added init to appdatasource in bot.js * migrations finally! * new migration matching model names I want * updating tests * removing testpathignore patterns since it seems to be unecessary? * adjusting migrations to match current schema * removed reference to secrets file * delete old migration * Revert "delete old migration" This reverts commit db1efa39a7a80d8976878856250ccaac6a753ab2. * Revert "adjusting migrations to match current schema" This reverts commit ef89a83f6a2ef0643d6ace0a3fcf9c40f4bc6dd6. * just deleted system creation since it's got nothing in it anyway * renamed memberRepository to memberRepo for consistency * added await back to parseMemberCommand call to memberArgumentHandler * changed call to memberHelper.getMembersByAuthor to memberRepo * renamed repo updateMemberValue to updateMemberField * removed throw references in repo docstrings * remove unneeded subscriber directory ref * changed createdAt and updatedAt columns to be auto-generated made member table have timezone * changed casing of isInitialized in mock for bot.js * removed % from ILike query so that it doesn't match substrings/wildcard * renamed some stray updateMemberValue in mocks -> updateMemberField --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * feat: Add migration to migrate existing data to new member table (#29) added migration to fill new Member table with data from Members Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update message helper reference hotfix (#30) * forgot to update a reference in messageHelper to memberRepo instead of memberHelper * turned off data-source logging --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: update dockerfile to run npm start (#31) fix: update dockerfile to run npm start (which runs ts-node) instead of node Co-authored-by: Aster Fialla <asterfialla@gmail.com> * added .env with examples, updated data-source to be access a docker container instead of relying on loopback * i forgot to git add data-source.ts :facepalm: * fix: changed property reference for createMember in repo (#32) fix for createMember object references (was referencing non-existent properties) Co-authored-by: Aster Fialla <asterfialla@gmail.com> * fix: memberRepo methods syntax (#35) * rearranged update member field and remove member to match expected structure in typeORM * update docstring * change insert to save in memberRepo * added command in package.json --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Delete duplicate members migration (#33) * add migration to delete duplicates that currently exist in the db * added a name attribute for consistency --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * Add unique index migration (#34) * add migration to delete duplicates that currently exist in the db * change model and migration to add a unique index constraint to id and name * renamed unique index name to be readable * redid model and migration to use @Unique instead of @Index * remove //Here comment --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com> * why wont these workflows stay up gahdamn --------- Co-authored-by: Laika Bozhko <63646916+LaikaBzko@users.noreply.github.com> Co-authored-by: Aster Fialla <asterfialla@gmail.com> Co-authored-by: laika <laika@sanya.gay>
2026-03-09 09:00:15 -04:00
expect(memberRepo.getMembersByAuthor).toHaveBeenCalledTimes(1);
expect(memberRepo.getMembersByAuthor).toHaveBeenCalledWith(authorId);
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>
2026-02-25 19:30:39 -05:00
})
})
feat: add tests and other such features (#3) * converted import syntax to ES modules removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * converted import syntax to commonJS removed unused methods * got test sort of working (jest set up is not crashing but also not mocking correctly) * adjusted beforeeach/beforeall so more pass * more correct test setup * more correct dockerfile and compose.yaml * Revert "converted import syntax to commonJS" This reverts commit 5ab0d62b * updated jest to sort of work with es6 * separating out enum return from method return * mostly working except for the weirdest error * nevermind it wasn't actually working, gonna move on for now * added babel to convert es modules to cjs * finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) * setup fixed more * added error handling parseMemberCommand test * renamed db to database more tests and fixing logic for memberhelper * upgraded fluxer.js * moved import to helpers folder * moved import to helpers folder * more tests for member helper * think i fixed weird error with webhook sending error when a user has no members * simplified sendMessageAsAttachment * added return to addFullMember so that addNewMember can reference it properly in strings * test setup for messagehelper and webhookhelper * readded line i shouldn't have removed in sendMessageAsMember * fixed test and logic * added test for memberHelper * updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly * added tests for parseProxyTags and updated logic * added "return" so tests dont terminate on failure and deleted env.jest * finished tests for messageHelper! * more cases for messageHelper just in case * updating docstring for messageHelper parseProxyTags * more tests for webhookhelper * deleted extra file added during merge * removed confusing brackets from enum docs * finally mocking correctly * adding more cases to messageHelper tests * updating enums * removed error response when proxy is sent without content * , updated tests for webhookHelper and removed error response when proxy is sent without content * added debounce to count guilds properly * added todo note * added tests for updateDisplayName * edited help message trigger for updatePropic * update message helper test to include space case * update bot to suppress errors from API * fixed bug for import not sending help text, added help text if you type a unrecognized command * updated to be enum * updated member helper and tests * edit enums, tweak import content command * removed unnecessary await and console.log * made it easier to make a member * added nicer error listing to importHelper * updated documentation * Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests --------- Co-authored-by: Aster Fialla <asterfialla@gmail.com>
2026-02-19 21:45:10 -05:00
afterEach(() => {
// restore the spy created with spyOn
jest.restoreAllMocks();
});
})