150 Commits

Author SHA1 Message Date
Aster Fialla
db8f2c59de adjusted importHelper to properly test throwing of aggregate error 2026-02-24 22:29:03 -05:00
Aster Fialla
dd21ed564b changed getAllMembersInfo map to say index not name as it actually gets the index of a member and then the member object 2026-02-24 21:26:42 -05:00
Aster Fialla
d226238e14 adjusted tests to properly use mockRejectedValue for async rejections 2026-02-24 21:08:04 -05:00
Aster Fialla
5050f98e8f pushes e.message instead of full error object to errors array in importHelper 2026-02-24 20:38:39 -05:00
Aster Fialla
dad80bd385 reversed check for valid proxy (was returning valid if the proxy existed and invalid if it didn't) 2026-02-24 20:38:39 -05:00
Aster Fialla
545136bec7 added default case to memberCommandHandler to throw error if command is not recognized 2026-02-24 20:38:39 -05:00
Aster Fialla
b02937a660 getAllMembersInfo checks for fields.length 2026-02-24 20:38:39 -05:00
Aster Fialla
6d82a067a1 Got rid of unnecessary check for empty message from user (Fluxer doesn't allow this to happen)
Removed export of token
2026-02-24 20:38:37 -05:00
Aster Fialla
1d9d9600e5 replaced "pk;" with "pf;" in test 2026-02-24 20:08:52 -05:00
Aster Fialla
c7d5f8a341 made importHelper mock throw error instead of "resolve" error 2026-02-24 20:05:29 -05:00
Aster Fialla
15d2f7d79d updated console.error message in database.js 2026-02-24 20:02:32 -05:00
Aster Fialla
ba2274e5be changed commands.js to not have user interaction within the catch 2026-02-24 20:02:11 -05:00
Aster Fialla
de674281f9 make memberCommand exit when error occurs with parseMemberCommand 2026-02-24 19:54:10 -05:00
Aster Fialla
102d694240 Simplify getWebhook to use .find() instead of foreach logic 2026-02-24 19:52:29 -05:00
Aster Fialla
fb878222dd removed unnecessary try/catch from utils 2026-02-24 19:49:59 -05:00
Aster Fialla
a1e007448f changed utils to check for 10MB size not 1MB 2026-02-24 19:47:46 -05:00
Aster Fialla
efefcb69f4 added the remaining webhook tests 2026-02-24 18:58:45 -05:00
Aster Fialla
ad783ae6b7 added dash to commands.js and test to pass 2026-02-24 18:48:59 -05:00
Aster Fialla
664295e4a5 refactored database to not use then/catch 2026-02-24 18:12:43 -05:00
Aster Fialla
ded5910a7c removed jest-fetch-mock since it turns out I was just manually mocking it anyway 2026-02-24 18:06:13 -05:00
Aster Fialla
cdf5c6e537 tested utils checkImageFormatValidity 2026-02-24 18:04:15 -05:00
Aster Fialla
34cb8f3cdb converted utils.js to not use then/catch 2026-02-24 16:58:56 -05:00
Aster Fialla
8d946ce921 put console.error in commands 2026-02-24 16:58:39 -05:00
Aster Fialla
8919fce34f removed console.log from import helper 2026-02-24 16:56:03 -05:00
Aster Fialla
15a040d1d1 forgot to switch over some tests in bot.test and commands.test 2026-02-24 16:55:51 -05:00
Aster Fialla
6470b223f6 fixed typo in webhookHelper 2026-02-24 16:41:00 -05:00
Aster Fialla
5d8ff9c6c6 one more test in commands.js, and removed console.error 2026-02-24 16:22:38 -05:00
Aster Fialla
2bf218683a edited bot to have top level main function 2026-02-24 16:18:40 -05:00
Aster Fialla
8b8cdd6d12 fixed set up for commands tests 2026-02-24 15:57:33 -05:00
Aster Fialla
5a91a529b1 removing then/catch from messageHelper.test.js 2026-02-24 15:47:30 -05:00
Aster Fialla
b36a3ae236 refactoring memberHelper.js and tests to not use then/catch 2026-02-24 15:43:43 -05:00
Aster Fialla
c19614b6a1 refactoring commands.js and tests to not use then/catch 2026-02-24 14:50:46 -05:00
Aster Fialla
b4e4e5a951 refactoring bot and tests to not use then/catch 2026-02-24 14:13:48 -05:00
Aster Fialla
5ba5435d46 changed docstring 2026-02-24 13:56:46 -05:00
Aster Fialla
fc58c47b03 refactor webhookHelper and tests to not use then/catch 2026-02-24 13:56:37 -05:00
Aster Fialla
a0f62763af Merge branch 'main' of https://github.com/pieartsy/PluralFlux into refactor-async-await
# Conflicts:
#	src/helpers/importHelper.js
#	tests/helpers/importHelper.test.js
2026-02-24 12:43:52 -05:00
Aster Fialla
8318d715ad added enum 2026-02-24 12:39:42 -05:00
Aster Fialla
971638bfe3 refactored async/await for import helper to not also use then/catch 2026-02-24 12:39:37 -05:00
Aster Fialla
123aabf650 documentation: adjusted docstrings 2026-02-24 10:37:02 -05:00
Aster Fialla
3c7dfcb72b update enums 2026-02-23 15:55:01 -05:00
Aster Fialla
9059c63747 mostly finished command tests 2026-02-23 15:54:45 -05:00
Aster Fialla
6937d7b694 made import error not a PDF again 2026-02-23 15:51:12 -05:00
Aster Fialla
e31d9c2881 removed now-unneeded .toJSON() for embeds 2026-02-23 15:20:39 -05:00
Aster Fialla
654338f88e removed duplicate text from importHelper 2026-02-23 15:11:10 -05:00
Aster Fialla
2a2de70b46 starting commands tests 2026-02-23 15:10:57 -05:00
Aster Fialla
7dfc949b63 separated out commands to be more easily testable and added functionality for aliases 2026-02-23 15:10:48 -05:00
Aster Fialla
bb99ee7ef1 structure for utils test edited a bit 2026-02-23 13:38:38 -05:00
Aster Fialla
088eaaa654 package.lock 2026-02-23 13:36:58 -05:00
Aster Fialla
a2746a25f9 updated enums 2026-02-23 13:36:40 -05:00
Aster Fialla
daf23b2f5d adding import tests 2026-02-23 13:36:31 -05:00
Aster Fialla
813e893afb more accurate framework for utils tests 2026-02-23 12:30:40 -05:00
Aster Fialla
10c145a02d imported env files better 2026-02-23 12:27:25 -05:00
Aster Fialla
6638756a9a replaced reference to [text] in proxy command instructions so it's clearer in contrast to the instructions to type without brackets 2026-02-23 12:01:07 -05:00
Aster Fialla
df60ec489b updated package.json 2026-02-23 11:56:35 -05:00
Aster Fialla
79f0f19733 adjusted bot.test mock 2026-02-23 11:50:50 -05:00
Aster Fialla
91e98f2434 fixed bug with memberHelper not processing attached URL 2026-02-23 11:35:01 -05:00
Aster Fialla
c752ee2bf2 Revert "adding debounce" cus it's not working
This reverts commit 1d27db960c.

# Conflicts:
#	src/bot.js
2026-02-23 11:19:26 -05:00
Aster Fialla
bfb5bf9cbb testing bot login, added invoke for login 2026-02-23 10:47:02 -05:00
Aster Fialla
a2bd7b755c testing bot.js handleMessageCreate 2026-02-23 10:38:04 -05:00
Aster Fialla
0f65db2d42 add frameworks for other tests 2026-02-23 09:00:48 -05:00
Aster Fialla
da79db856a removed unneeded imports from messageHelper tests 2026-02-23 08:59:56 -05:00
Aster Fialla
50c41990ed removed unused argument from bot call to sendMessageAsMember 2026-02-23 08:59:32 -05:00
Aster Fialla
1d27db960c adding debounce 2026-02-23 08:47:27 -05:00
Aster Fialla
264c3e19fd removing some unused imports in messageHelper 2026-02-23 08:44:50 -05:00
Aster Fialla
0a1652f243 updated docstrings 2026-02-23 08:02:30 -05:00
Aster Fialla
580a0cb42e renaming test interpolation to be less silly 2026-02-23 07:53:03 -05:00
Aster Fialla
71c8736a38 added to docstring 2026-02-23 00:18:57 -05:00
Aster Fialla
d9530a2ccf structure and test revamp for memberHelper 2026-02-23 00:18:14 -05:00
Aster Fialla
72ec047f48 test frame for utils 2026-02-22 21:40:53 -05:00
Aster Fialla
be24034d48 updating tests and memberHelper to try and make parseMemberCommand less bloated/broken (not working ATM) 2026-02-22 21:40:42 -05:00
Aster Fialla
c3e7bf4433 updated enums 2026-02-22 18:48:52 -05:00
Aster Fialla
7dae9f52b1 fixed call to getMemberInfo to not include authorId 2026-02-22 18:32:47 -05:00
Aster Fialla
630ce7888c adjusted parsing logic to not try and call member when none exists (due to "new" command) 2026-02-22 18:06:18 -05:00
Aster Fialla
b88b9252be forgot to import enums into utils 2026-02-22 17:09:02 -05:00
Aster Fialla
79cfc1563d add license 2026-02-22 12:03:44 -05:00
Aster Fialla
fa4ca779ee accidental error with memberHelper not allowing pf;member fixed 2026-02-22 11:52:51 -05:00
Aster Fialla
eb7340faf7 finished relevant tests for memberHelper 2026-02-22 11:24:57 -05:00
Aster Fialla
d4adbc028a typo not importing utils right 2026-02-22 09:54:01 -05:00
Aster Fialla
57336b4e58 added to enums 2026-02-21 23:05:59 -05:00
Aster Fialla
71803fd10c made utils file 2026-02-21 23:05:15 -05:00
Aster Fialla
cc8cb6e925 write more tests for addNewMember 2026-02-21 23:05:01 -05:00
Aster Fialla
a797e9e06d write more tests for parseMemberCommand 2026-02-21 21:37:57 -05:00
Aster Fialla
4146591c90 figured out issue (was missing return value) 2026-02-21 20:09:39 -05:00
Aster Fialla
0bca359b7f trying to get refactored memberhelper to pass tests -_- 2026-02-20 11:28:28 -05:00
Aster Fialla
932fc9c967 update getMemberCommandInfo 2026-02-20 11:03:50 -05:00
Aster Fialla
cd01473121 update enums 2026-02-20 11:00:57 -05:00
Aster Fialla
c133ee2c42 refactored memberHelper 2026-02-20 11:00:21 -05:00
Aster Fialla
f055518b1f Merge branch 'main' into add-tests
# Conflicts:
#	README.md
2026-02-20 10:02:13 -05:00
Aster Fialla
3ed24458e0 Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests 2026-02-19 21:44:07 -05:00
Aster Fialla
a30d408c02 Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests 2026-02-19 21:41:59 -05:00
Aster Fialla
e9052624d4 Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests 2026-02-19 21:41:29 -05:00
Aster Fialla
4d3db8c001 updated documentation 2026-02-19 21:38:10 -05:00
Aster Fialla
eb6c60618b added nicer error listing to importHelper 2026-02-19 21:38:03 -05:00
Aster Fialla
b64ba6e787 made it easier to make a member 2026-02-19 21:36:19 -05:00
Aster Fialla
d640322392 removed unnecessary await and console.log 2026-02-19 20:32:35 -05:00
Aster Fialla
b1a29fd3ff edit enums, tweak import content command 2026-02-19 20:30:55 -05:00
Aster Fialla
e7198230a7 updated member helper and tests 2026-02-19 20:08:26 -05:00
Aster Fialla
fad6d42ee2 updated to be enum 2026-02-19 19:32:37 -05:00
Aster Fialla
c4c6ad0fdd fixed bug for import not sending help text, added help text if you type a unrecognized command 2026-02-19 19:31:56 -05:00
Aster Fialla
1e2724bbfb update bot to suppress errors from API 2026-02-19 19:13:54 -05:00
Aster Fialla
849acf7275 update message helper test to include space case 2026-02-19 18:54:35 -05:00
Aster Fialla
7a3b8c1994 edited help message trigger for updatePropic 2026-02-19 01:45:43 -05:00
Aster Fialla
2e0a8adec5 added tests for updateDisplayName 2026-02-19 01:31:38 -05:00
Aster Fialla
7aeae1837f added todo note 2026-02-19 00:59:57 -05:00
Aster Fialla
6eb9fef376 added debounce to count guilds properly 2026-02-19 00:52:06 -05:00
Aster Fialla
9dab429d0d , updated tests for webhookHelper and removed error response when proxy is sent without content 2026-02-19 00:51:33 -05:00
Aster Fialla
f9199f8477 removed error response when proxy is sent without content 2026-02-19 00:48:57 -05:00
Aster Fialla
a7cd4e96f0 updating enums 2026-02-19 00:20:53 -05:00
Aster Fialla
21efbccfd7 adding more cases to messageHelper tests 2026-02-19 00:20:46 -05:00
Aster Fialla
873959a5f4 finally mocking correctly 2026-02-18 21:24:41 -05:00
Aster Fialla
d33c3213f3 removed confusing brackets from enum docs 2026-02-18 21:20:56 -05:00
Aster Fialla
75c4c548d8 deleted extra file added during merge 2026-02-18 21:13:25 -05:00
Aster Fialla
9d5493e8ab Merge remote-tracking branch 'origin/add-tests' into add-tests
# Conflicts:
#	src/bot.js
#	src/commands.js
#	src/database.js
#	src/helpers/importHelper.js
#	src/helpers/memberHelper.js
#	src/helpers/messageHelper.js
#	src/helpers/webhookHelper.js
2026-02-18 21:03:44 -05:00
Aster Fialla
fc1c463696 more tests for webhookhelper 2026-02-18 17:14:04 -05:00
Aster Fialla
1bba8099e9 updating docstring for messageHelper parseProxyTags 2026-02-18 16:29:08 -05:00
Aster Fialla
acd9ce7c3e more cases for messageHelper just in case 2026-02-18 16:28:35 -05:00
Aster Fialla
da9a3d2c8a finished tests for messageHelper! 2026-02-18 12:37:39 -05:00
Aster Fialla
274f1ead15 added "return" so tests dont terminate on failure and deleted env.jest 2026-02-18 12:11:55 -05:00
Aster Fialla
223292c2d3 added tests for parseProxyTags and updated logic 2026-02-18 10:17:08 -05:00
Aster Fialla
400e40a405 updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly 2026-02-18 09:19:44 -05:00
Aster Fialla
152bc8873d added test for memberHelper 2026-02-18 09:16:26 -05:00
Aster Fialla
e16694ac2d fixed test and logic 2026-02-18 08:47:37 -05:00
Aster Fialla
f0ac02e86d readded line i shouldn't have removed in sendMessageAsMember 2026-02-18 00:33:05 -05:00
Aster Fialla
5c01f2e284 test setup for messagehelper and webhookhelper 2026-02-18 00:28:18 -05:00
Aster Fialla
da5a250445 added return to addFullMember so that addNewMember can reference it properly in strings 2026-02-18 00:27:51 -05:00
Aster Fialla
23a57b3e99 simplified sendMessageAsAttachment 2026-02-18 00:26:51 -05:00
Aster Fialla
1bf6c8c1f2 think i fixed weird error with webhook sending error when a user has no members 2026-02-18 00:25:41 -05:00
Aster Fialla
fe00f66104 more tests for member helper 2026-02-17 23:03:45 -05:00
Aster Fialla
15703c24cd moved import to helpers folder 2026-02-17 23:03:19 -05:00
Aster Fialla
3dbbe7df50 moved import to helpers folder 2026-02-17 23:03:08 -05:00
Aster Fialla
31eb4262dd upgraded fluxer.js 2026-02-17 22:23:55 -05:00
Aster Fialla
c645bb0aea renamed db to database
more tests and fixing logic for memberhelper
2026-02-17 22:23:47 -05:00
Aster Fialla
0b7f549bdf added error handling parseMemberCommand test 2026-02-17 21:21:07 -05:00
Aster Fialla
bfc633a755 setup fixed more 2026-02-17 20:52:22 -05:00
Aster Fialla
01e620a935 finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach()) 2026-02-17 20:49:19 -05:00
Aster Fialla
a4804c2ea7 added babel to convert es modules to cjs 2026-02-17 20:48:44 -05:00
Aster Fialla
164ff7d8b6 nevermind it wasn't actually working, gonna move on for now 2026-02-17 19:58:56 -05:00
Aster Fialla
5e3b3f33d3 mostly working except for the weirdest error 2026-02-17 19:38:50 -05:00
Aster Fialla
4fcb53482c separating out enum return from method return 2026-02-17 19:36:14 -05:00
Aster Fialla
ba9552b4aa updated jest to sort of work with es6 2026-02-17 17:38:06 -05:00
Aster Fialla
35b454bc80 Revert "converted import syntax to commonJS"
This reverts commit 5ab0d62b
2026-02-17 17:25:18 -05:00
Aster Fialla
321fe7f0a9 more correct dockerfile and compose.yaml 2026-02-17 17:16:48 -05:00
Aster Fialla
0a4bfa59ad more correct test setup 2026-02-17 17:16:10 -05:00
Aster Fialla
79d98c3618 adjusted beforeeach/beforeall so more pass 2026-02-17 17:16:10 -05:00
Aster Fialla
a44e2745c5 got test sort of working (jest set up is not crashing but also not mocking correctly) 2026-02-17 17:16:10 -05:00
Aster Fialla
5ab0d62bdb converted import syntax to commonJS
removed unused methods
2026-02-17 17:16:09 -05:00
Aster Fialla
876f9486ad more correct test setup 2026-02-17 07:14:47 -05:00
Aster Fialla
5e28cdfd01 adjusted beforeeach/beforeall so more pass 2026-02-17 07:11:22 -05:00
Aster Fialla
5a39610547 got test sort of working (jest set up is not crashing but also not mocking correctly) 2026-02-16 18:46:33 -05:00
Aster Fialla
a3caa2dc42 converted import syntax to ES modules
removed unused methods
2026-02-16 18:46:32 -05:00
9 changed files with 65 additions and 197 deletions

View File

@@ -1,45 +0,0 @@
name: nodeJS remote worker
on:
push:
branches: ["develop"]
pull_request:
branches: ["develop"]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker BuildX
uses: docker/setup-buildx-action@v3
- name: login to gitea registry
uses: docker/login-action@v3
with:
registry: ${{ gitea.server_url }}
username: ${{ gitea.actor }}
password: ${{ secrets.GITEA }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
engineering.sanya.gay/pluralflux/pluralflux:latest
- name: Deploy bot
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
port: 22
script: |
cd /root/pluralflux-dev/PluralFlux
docker compose up -d

View File

@@ -1,46 +0,0 @@
name: nodeJS remote worker
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker BuildX
uses: docker/setup-buildx-action@v3
- name: login to gitea registry
uses: docker/login-action@v3
with:
registry: ${{ gitea.server_url }}
username: ${{ gitea.actor }}
password: ${{ secrets.GITEA }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
engineering.sanya.gay/pluralflux/pluralflux:latest
- name: Deploy bot
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: 22
script: |
cd /root/pluralflux-prod/PluralFlux
docker compose up -d

View File

@@ -1,15 +1,17 @@
services: services:
main: main:
image: engineering.sanya.gay/pluralflux/pluralflux-dev build: .
container_name: pluralflux container_name: pluralflux
restart: unless-stopped restart: unless-stopped
networks: networks:
- pluralflux-net - pluralflux-net
env_file: "secrets.env"
postgres: postgres:
image: postgres:latest image: postgres:latest
container_name: pluralflux-postgres container_name: pluralflux-postgres
env_file: "secrets.env" environment:
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_pwd
secrets:
- postgres_pwd
volumes: volumes:
- pgdata:/var/lib/postgresql - pgdata:/var/lib/postgresql
ports: ports:
@@ -21,7 +23,13 @@ services:
container_name: pluralflux-pgadmin container_name: pluralflux-pgadmin
ports: ports:
- "5050:80" - "5050:80"
env_file: "secrets.env" environment:
PGADMIN_DEFAULT_EMAIL: code@asterfialla.com
PGADMIN_DEFAULT_PASSWORD_FILE: /run/secrets/postgres_pwd
PGADMIN_CONFIG_SERVER_MODE: 'False'
PGADMIN_CONFIG_MASTER_PASSWORD_REQUIRED: 'False'
secrets:
- postgres_pwd
depends_on: depends_on:
- postgres - postgres
networks: networks:
@@ -32,4 +40,7 @@ networks:
volumes: volumes:
pgdata: pgdata:
secrets:
secrets:
postgres_pwd:
file: ./secrets/postgres-password.txt

View File

@@ -1,6 +0,0 @@
FLUXER_BOT_TOKEN=<your bot token here>
POSTGRES_PASSWORD=<your postgres password here>
PGADMIN_DEFAULT_EMAIL: <default postgres admin login>
PGADMIN_DEFAULT_PASSWORD: <your postgres password here>
PGADMIN_CONFIG_SERVER_MODE: 'False'
PGADMIN_CONFIG_MASTER_PASSWORD_REQUIRED: 'False'

View File

@@ -44,10 +44,7 @@ helperEnums.help = {
} }
helperEnums.misc = { helperEnums.misc = {
ATTACHMENT_SENT_BY: "Attachment sent by:", ATTACHMENT_SENT_BY: "Attachment sent by:"
ATTACHMENT_EXPIRATION_WARNING: "**NOTE:** Because this profile picture is hosted on Fluxer, it will expire. To avoid this, upload the picture to another website like <https://imgbb.com/> and link to it directly.",
FLUXER_ATTACHMENT_URL: "https://fluxerusercontent.com/attachments/"
} }
export const enums = helperEnums; export const enums = helperEnums;

View File

@@ -283,8 +283,8 @@ mh.updatePropic = async function (authorId, memberName, values, attachmentUrl =
const imgUrl = values ?? attachmentUrl; const imgUrl = values ?? attachmentUrl;
// Throws error if invalid // Throws error if invalid
await utils.checkImageFormatValidity(imgUrl); await utils.checkImageFormatValidity(imgUrl);
const expirationWarning = utils.setExpirationWarning(imgUrl, attachmentExpiration);
return await mh.updateMemberField(authorId, memberName, "propic", imgUrl, expirationWarning); return await mh.updateMemberField(authorId, memberName, "propic", imgUrl, attachmentExpiration);
} }
/** /**
@@ -369,15 +369,15 @@ mh.addFullMember = async function (authorId, memberName, displayName = null, pro
if (propic && propic.length > 0) { if (propic && propic.length > 0) {
try { try {
isValidPropic = await utils.checkImageFormatValidity(propic); isValidPropic = await utils.checkImageFormatValidity(propic);
} }
catch(e) { catch(e) {
errors.push(`Tried to set profile picture to \"${propic}\". ${e.message}. ${enums.err.SET_TO_NULL}`); errors.push(`Tried to set profile picture to \"${propic}\". ${e.message}. ${enums.err.SET_TO_NULL}`);
isValidPropic = false; isValidPropic = false;
} }
} }
const expirationWarning = utils.setExpirationWarning(propic, attachmentExpiration); if (isValidPropic && attachmentExpiration) {
if (expirationWarning) { errors.push(mh.setExpirationWarning(attachmentExpiration));
errors.push(expirationWarning);
} }
const member = await database.members.create({ const member = await database.members.create({
name: memberName, userid: authorId, displayname: isValidDisplayName ? displayName : null, proxy: isValidProxy ? proxy : null, propic: isValidPropic ? propic : null name: memberName, userid: authorId, displayname: isValidDisplayName ? displayName : null, proxy: isValidProxy ? proxy : null, propic: isValidPropic ? propic : null
@@ -394,11 +394,17 @@ mh.addFullMember = async function (authorId, memberName, displayName = null, pro
* @param {string} memberName - The member to update * @param {string} memberName - The member to update
* @param {string} columnName - The column name to update. * @param {string} columnName - The column name to update.
* @param {string} value - The value to update to. * @param {string} value - The value to update to.
* @param {string | null} [expirationWarning] - The attachment expiration warning (if any) * @param {string | null} [attachmentExpiration] - The attachment expiration date (if any)
* @returns {Promise<string>} A successful update. * @returns {Promise<string>} A successful update.
* @throws {Error} When no member row was updated. * @throws {Error} When no member row was updated.
*/ */
mh.updateMemberField = async function (authorId, memberName, columnName, value, expirationWarning = null) { mh.updateMemberField = async function (authorId, memberName, columnName, value, attachmentExpiration = null) {
let fluxerPropicWarning;
// indicates that an attachment was uploaded on Fluxer directly
if (columnName === "propic" && attachmentExpiration) {
fluxerPropicWarning = mh.setExpirationWarning(value);
}
const res = await database.members.update({[columnName]: value}, { const res = await database.members.update({[columnName]: value}, {
where: { where: {
name: {[Op.iLike]: memberName}, name: {[Op.iLike]: memberName},
@@ -408,7 +414,21 @@ mh.updateMemberField = async function (authorId, memberName, columnName, value,
if (res[0] === 0) { if (res[0] === 0) {
throw new Error(`Can't update ${memberName}. ${enums.err.NO_MEMBER}.`); throw new Error(`Can't update ${memberName}. ${enums.err.NO_MEMBER}.`);
} else { } else {
return `Updated ${columnName} for ${memberName} to ${value}${expirationWarning ? `. ${expirationWarning}.` : '.'}`; return `Updated ${columnName} for ${memberName} to ${value}${fluxerPropicWarning ?? ''}.`;
}
}
/**
* Sets the warning for an expiration date.
*
* @param {string} expirationString - An expiration date string.
* @returns {string} A description of the expiration, interpolating the expiration string.
*/
mh.setExpirationWarning = function (expirationString) {
let expirationDate = new Date(expirationString);
if (!isNaN(expirationDate.valueOf())) {
expirationDate = expirationDate.toDateString();
return `\n**NOTE:** Because this profile picture was uploaded via Fluxer, it will currently expire on *${expirationDate}*. To avoid this, upload the picture to another website like <https://imgbb.com/> and link to it directly`
} }
} }

View File

@@ -34,24 +34,4 @@ u.checkImageFormatValidity = async function (imageUrl) {
return true; return true;
} }
/**
* Sets the warning that a Fluxer-uploaded image will expire.
*
* @param {string | null} [imgUrl] - An image URL.
* @param {string | null} [expirationString] - An expiration date string.
* @returns {string | null} A description of the expiration, or null.
*/
u.setExpirationWarning = function (imgUrl = null, expirationString = null) {
if (imgUrl && imgUrl.startsWith(enums.misc.FLUXER_ATTACHMENT_URL)) {
return enums.misc.ATTACHMENT_EXPIRATION_WARNING;
}
else if (expirationString) {
let expirationDate = new Date(expirationString);
if (!isNaN(expirationDate.valueOf())) {
return `${enums.misc.ATTACHMENT_EXPIRATION_WARNING}. Expiration date: *${expirationString}*.`;
}
}
return null;
}
export const utils = u; export const utils = u;

View File

@@ -39,7 +39,7 @@ describe('MemberHelper', () => {
name: "somePerson", name: "somePerson",
displayname: "Some Person", displayname: "Some Person",
proxy: "--text", proxy: "--text",
propic: 'ono.png' propic: attachmentUrl
} }
beforeEach(() => { beforeEach(() => {
@@ -446,13 +446,14 @@ describe('MemberHelper', () => {
describe('updatePropic', () => { describe('updatePropic', () => {
test.each([ test.each([
[null, attachmentUrl, undefined, attachmentUrl], [null, attachmentUrl, null, attachmentUrl],
[mockMember.propic, null, undefined, mockMember.propic], [mockMember.propic, null, null, mockMember.propic],
[mockMember.propic, attachmentUrl, undefined, mockMember.propic], [mockMember.propic, attachmentUrl, null, attachmentUrl],
[null, attachmentUrl, attachmentExpiration, attachmentUrl]
])('calls checkImageFormatValidity and updateMemberField and returns string', async (imgUrl, attachmentUrl, attachmentExpiration, expected) => { ])('calls checkImageFormatValidity and updateMemberField and returns string', async (imgUrl, attachmentUrl, attachmentExpiration, expected) => {
// Arrange // Arrange
jest.spyOn(memberHelper, 'updateMemberField').mockResolvedValue("Updated"); jest.spyOn(memberHelper, 'updateMemberField').mockResolvedValue("Updated");
utils.setExpirationWarning = jest.fn().mockReturnValue(undefined);
// Act // Act
const result = await memberHelper.updatePropic(authorId, mockMember.name, imgUrl, attachmentUrl, attachmentExpiration); const result = await memberHelper.updatePropic(authorId, mockMember.name, imgUrl, attachmentUrl, attachmentExpiration);
// Assert // Assert
@@ -460,21 +461,7 @@ describe('MemberHelper', () => {
expect(utils.checkImageFormatValidity).toHaveBeenCalledTimes(1); expect(utils.checkImageFormatValidity).toHaveBeenCalledTimes(1);
expect(utils.checkImageFormatValidity).toHaveBeenCalledWith(expected); expect(utils.checkImageFormatValidity).toHaveBeenCalledWith(expected);
expect(memberHelper.updateMemberField).toHaveBeenCalledTimes(1); expect(memberHelper.updateMemberField).toHaveBeenCalledTimes(1);
expect(memberHelper.updateMemberField).toHaveBeenCalledWith(authorId, mockMember.name, "propic", expected, undefined); expect(memberHelper.updateMemberField).toHaveBeenCalledWith(authorId, mockMember.name, "propic", expected, attachmentExpiration);
})
test('calls setExpirationWarning', async() => {
// Arrange
jest.spyOn(memberHelper, 'updateMemberField').mockResolvedValue("Updated");
utils.setExpirationWarning = jest.fn().mockReturnValue(enums.misc.ATTACHMENT_EXPIRATION_WARNING);
// Act
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);
}) })
}) })
@@ -625,17 +612,6 @@ describe('MemberHelper', () => {
expect(database.members.create).toHaveBeenCalledTimes(1); expect(database.members.create).toHaveBeenCalledTimes(1);
}) })
test('calls setExpirationWarning if attachmentExpiration exists', async () => {
// Arrange
utils.checkImageFormatValidity = jest.fn().mockResolvedValue(true);
jest.spyOn(memberHelper, 'setExpirationWarning').mockReturnValue(`${enums.misc.ATTACHMENT_EXPIRATION_WARNING}`);
// Act
await memberHelper.addFullMember(authorId, mockMember.name, null, null, mockMember.propic, attachmentExpiration)
// Assert
expect(memberHelper.setExpirationWarning).toHaveBeenCalledTimes(1);
expect(memberHelper.setExpirationWarning).toHaveBeenCalledWith(mockMember.propic, attachmentExpiration);
})
test('if all values are valid, call database.members.create', async () => { test('if all values are valid, call database.members.create', async () => {
// Arrange // Arrange
jest.spyOn(memberHelper, 'checkIfProxyExists').mockResolvedValue(false); jest.spyOn(memberHelper, 'checkIfProxyExists').mockResolvedValue(false);
@@ -668,18 +644,22 @@ describe('MemberHelper', () => {
}; };
}) })
test('calls setExpirationWarning if attachmentExpiration', async () => {
await memberHelper.updateMemberField(authorId, mockMember.name, "propic", mockMember.propic, attachmentExpiration)
expect(memberHelper.setExpirationWarning).toHaveBeenCalledTimes(1);
expect(memberHelper.setExpirationWarning).toHaveBeenCalledWith(mockMember.propic);
})
test.each([ test.each([
['name', mockMember.name, undefined, `Updated name for ${mockMember.name} to ${mockMember.name}.`], ['name', mockMember.name, null, `Updated name for ${mockMember.name} to ${mockMember.name}`],
['displayname', mockMember.displayname, undefined, `Updated displayname for ${mockMember.name} to ${mockMember.displayname}.`], ['displayname', mockMember.displayname, null, `Updated name for ${mockMember.name} to ${mockMember.displayname}`],
['proxy', mockMember.proxy, undefined, `Updated proxy for ${mockMember.name} to ${mockMember.proxy}.`], ['proxy', mockMember.proxy, null, `Updated name for ${mockMember.name} to ${mockMember.proxy}`],
['propic', mockMember.propic, undefined, `Updated propic for ${mockMember.name} to ${mockMember.propic}.`], ['propic', mockMember.propic, null, `Updated name for ${mockMember.name} to ${mockMember.propic}`],
['propic', mockMember.propic, ['propic', mockMember.propic, attachmentExpiration, `Updated name for ${mockMember.name} to ${mockMember.propic} warning}`]
'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) => {
])('calls database.members.update with correct column and value and return string', async (columnName, value, attachmentExpiration, expected) => {
// Act // Act
const res = await memberHelper.updateMemberField(authorId, mockMember.name, columnName, value, attachmentExpiration) await memberHelper.updateMemberField(authorId, mockMember.name, columnName, value, attachmentExpiration)
// Assert // Assert
expect(res).toEqual(expected);
expect(database.members.update).toHaveBeenCalledTimes(1); expect(database.members.update).toHaveBeenCalledTimes(1);
expect(database.members.update).toHaveBeenCalledWith({[columnName]: value}, { expect(database.members.update).toHaveBeenCalledWith({[columnName]: value}, {
where: { where: {

View File

@@ -5,7 +5,6 @@ const {utils} = require("../../src/helpers/utils.js");
describe('utils', () => { describe('utils', () => {
const attachmentUrl = 'oya.png'; const attachmentUrl = 'oya.png';
const expirationString = new Date("2026-01-01").toDateString();
let blob; let blob;
beforeEach(() => { beforeEach(() => {
@@ -61,28 +60,6 @@ describe('utils', () => {
}) })
}) })
describe('setExpirationWarning', () => {
test('sets warning if image Url starts with Fluxer host', () => {
// Act
const result = utils.setExpirationWarning(`${enums.misc.FLUXER_ATTACHMENT_URL}${attachmentUrl}`);
// Assert
expect(result).toEqual(enums.misc.ATTACHMENT_EXPIRATION_WARNING);
})
test('sets warning if expiration string exists', () => {
const result = utils.setExpirationWarning(null, expirationString);
// Assert
expect(result).toEqual(`${enums.misc.ATTACHMENT_EXPIRATION_WARNING}. Expiration date: *${expirationString}*.`);
})
test('returns null if img url does not start iwth fluxer host and no expiration', () => {
// Act
const result = utils.setExpirationWarning(attachmentUrl);
// Assert
expect(result).toBeNull();
})
})
afterEach(() => { afterEach(() => {
// restore the spy created with spyOn // restore the spy created with spyOn
jest.restoreAllMocks(); jest.restoreAllMocks();