forked from PluralFlux/PluralFlux
Compare commits
150 Commits
df80eca0ec
...
refactor-a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
db8f2c59de | ||
|
|
dd21ed564b | ||
|
|
d226238e14 | ||
|
|
5050f98e8f | ||
|
|
dad80bd385 | ||
|
|
545136bec7 | ||
|
|
b02937a660 | ||
|
|
6d82a067a1 | ||
|
|
1d9d9600e5 | ||
|
|
c7d5f8a341 | ||
|
|
15d2f7d79d | ||
|
|
ba2274e5be | ||
|
|
de674281f9 | ||
|
|
102d694240 | ||
|
|
fb878222dd | ||
|
|
a1e007448f | ||
|
|
efefcb69f4 | ||
|
|
ad783ae6b7 | ||
|
|
664295e4a5 | ||
|
|
ded5910a7c | ||
|
|
cdf5c6e537 | ||
|
|
34cb8f3cdb | ||
|
|
8d946ce921 | ||
|
|
8919fce34f | ||
|
|
15a040d1d1 | ||
|
|
6470b223f6 | ||
|
|
5d8ff9c6c6 | ||
|
|
2bf218683a | ||
|
|
8b8cdd6d12 | ||
|
|
5a91a529b1 | ||
|
|
b36a3ae236 | ||
|
|
c19614b6a1 | ||
|
|
b4e4e5a951 | ||
|
|
5ba5435d46 | ||
|
|
fc58c47b03 | ||
|
|
a0f62763af | ||
|
|
8318d715ad | ||
|
|
971638bfe3 | ||
|
|
123aabf650 | ||
|
|
3c7dfcb72b | ||
|
|
9059c63747 | ||
|
|
6937d7b694 | ||
|
|
e31d9c2881 | ||
|
|
654338f88e | ||
|
|
2a2de70b46 | ||
|
|
7dfc949b63 | ||
|
|
bb99ee7ef1 | ||
|
|
088eaaa654 | ||
|
|
a2746a25f9 | ||
|
|
daf23b2f5d | ||
|
|
813e893afb | ||
|
|
10c145a02d | ||
|
|
6638756a9a | ||
|
|
df60ec489b | ||
|
|
79f0f19733 | ||
|
|
91e98f2434 | ||
|
|
c752ee2bf2 | ||
|
|
bfb5bf9cbb | ||
|
|
a2bd7b755c | ||
|
|
0f65db2d42 | ||
|
|
da79db856a | ||
|
|
50c41990ed | ||
|
|
1d27db960c | ||
|
|
264c3e19fd | ||
|
|
0a1652f243 | ||
|
|
580a0cb42e | ||
|
|
71c8736a38 | ||
|
|
d9530a2ccf | ||
|
|
72ec047f48 | ||
|
|
be24034d48 | ||
|
|
c3e7bf4433 | ||
|
|
7dae9f52b1 | ||
|
|
630ce7888c | ||
|
|
b88b9252be | ||
|
|
79cfc1563d | ||
|
|
fa4ca779ee | ||
|
|
eb7340faf7 | ||
|
|
d4adbc028a | ||
|
|
57336b4e58 | ||
|
|
71803fd10c | ||
|
|
cc8cb6e925 | ||
|
|
a797e9e06d | ||
|
|
4146591c90 | ||
|
|
0bca359b7f | ||
|
|
932fc9c967 | ||
|
|
cd01473121 | ||
|
|
c133ee2c42 | ||
|
|
f055518b1f | ||
|
|
3ed24458e0 | ||
|
|
a30d408c02 | ||
|
|
e9052624d4 | ||
|
|
4d3db8c001 | ||
|
|
eb6c60618b | ||
|
|
b64ba6e787 | ||
|
|
d640322392 | ||
|
|
b1a29fd3ff | ||
|
|
e7198230a7 | ||
|
|
fad6d42ee2 | ||
|
|
c4c6ad0fdd | ||
|
|
1e2724bbfb | ||
|
|
849acf7275 | ||
|
|
7a3b8c1994 | ||
|
|
2e0a8adec5 | ||
|
|
7aeae1837f | ||
|
|
6eb9fef376 | ||
|
|
9dab429d0d | ||
|
|
f9199f8477 | ||
|
|
a7cd4e96f0 | ||
|
|
21efbccfd7 | ||
|
|
873959a5f4 | ||
|
|
d33c3213f3 | ||
|
|
75c4c548d8 | ||
|
|
9d5493e8ab | ||
|
|
fc1c463696 | ||
|
|
1bba8099e9 | ||
|
|
acd9ce7c3e | ||
|
|
da9a3d2c8a | ||
|
|
274f1ead15 | ||
|
|
223292c2d3 | ||
|
|
400e40a405 | ||
|
|
152bc8873d | ||
|
|
e16694ac2d | ||
|
|
f0ac02e86d | ||
|
|
5c01f2e284 | ||
|
|
da5a250445 | ||
|
|
23a57b3e99 | ||
|
|
1bf6c8c1f2 | ||
|
|
fe00f66104 | ||
|
|
15703c24cd | ||
|
|
3dbbe7df50 | ||
|
|
31eb4262dd | ||
|
|
c645bb0aea | ||
|
|
0b7f549bdf | ||
|
|
bfc633a755 | ||
|
|
01e620a935 | ||
|
|
a4804c2ea7 | ||
|
|
164ff7d8b6 | ||
|
|
5e3b3f33d3 | ||
|
|
4fcb53482c | ||
|
|
ba9552b4aa | ||
|
|
35b454bc80 | ||
|
|
321fe7f0a9 | ||
|
|
0a4bfa59ad | ||
|
|
79d98c3618 | ||
|
|
a44e2745c5 | ||
|
|
5ab0d62bdb | ||
|
|
876f9486ad | ||
|
|
5e28cdfd01 | ||
|
|
5a39610547 | ||
|
|
a3caa2dc42 |
@@ -44,10 +44,7 @@ helperEnums.help = {
|
||||
}
|
||||
|
||||
helperEnums.misc = {
|
||||
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/"
|
||||
|
||||
ATTACHMENT_SENT_BY: "Attachment sent by:"
|
||||
}
|
||||
|
||||
export const enums = helperEnums;
|
||||
@@ -283,8 +283,8 @@ mh.updatePropic = async function (authorId, memberName, values, attachmentUrl =
|
||||
const imgUrl = values ?? attachmentUrl;
|
||||
// Throws error if invalid
|
||||
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) {
|
||||
try {
|
||||
isValidPropic = await utils.checkImageFormatValidity(propic);
|
||||
|
||||
}
|
||||
catch(e) {
|
||||
errors.push(`Tried to set profile picture to \"${propic}\". ${e.message}. ${enums.err.SET_TO_NULL}`);
|
||||
isValidPropic = false;
|
||||
}
|
||||
}
|
||||
const expirationWarning = utils.setExpirationWarning(propic, attachmentExpiration);
|
||||
if (expirationWarning) {
|
||||
errors.push(expirationWarning);
|
||||
if (isValidPropic && attachmentExpiration) {
|
||||
errors.push(mh.setExpirationWarning(attachmentExpiration));
|
||||
}
|
||||
const member = await database.members.create({
|
||||
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} columnName - The column name to update.
|
||||
* @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.
|
||||
* @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}, {
|
||||
where: {
|
||||
name: {[Op.iLike]: memberName},
|
||||
@@ -408,7 +414,21 @@ mh.updateMemberField = async function (authorId, memberName, columnName, value,
|
||||
if (res[0] === 0) {
|
||||
throw new Error(`Can't update ${memberName}. ${enums.err.NO_MEMBER}.`);
|
||||
} 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`
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,24 +34,4 @@ u.checkImageFormatValidity = async function (imageUrl) {
|
||||
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;
|
||||
|
||||
@@ -39,7 +39,7 @@ describe('MemberHelper', () => {
|
||||
name: "somePerson",
|
||||
displayname: "Some Person",
|
||||
proxy: "--text",
|
||||
propic: 'ono.png'
|
||||
propic: attachmentUrl
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -446,13 +446,14 @@ describe('MemberHelper', () => {
|
||||
|
||||
describe('updatePropic', () => {
|
||||
test.each([
|
||||
[null, attachmentUrl, undefined, attachmentUrl],
|
||||
[mockMember.propic, null, undefined, mockMember.propic],
|
||||
[mockMember.propic, attachmentUrl, undefined, mockMember.propic],
|
||||
[null, attachmentUrl, null, attachmentUrl],
|
||||
[mockMember.propic, null, null, mockMember.propic],
|
||||
[mockMember.propic, attachmentUrl, null, attachmentUrl],
|
||||
[null, attachmentUrl, attachmentExpiration, attachmentUrl]
|
||||
])('calls checkImageFormatValidity and updateMemberField and returns string', async (imgUrl, attachmentUrl, attachmentExpiration, expected) => {
|
||||
// Arrange
|
||||
|
||||
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
|
||||
@@ -460,21 +461,7 @@ describe('MemberHelper', () => {
|
||||
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);
|
||||
})
|
||||
|
||||
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);
|
||||
expect(memberHelper.updateMemberField).toHaveBeenCalledWith(authorId, mockMember.name, "propic", expected, attachmentExpiration);
|
||||
})
|
||||
})
|
||||
|
||||
@@ -625,17 +612,6 @@ describe('MemberHelper', () => {
|
||||
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 () => {
|
||||
// Arrange
|
||||
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([
|
||||
['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) => {
|
||||
['name', mockMember.name, null, `Updated name for ${mockMember.name} to ${mockMember.name}`],
|
||||
['displayname', mockMember.displayname, null, `Updated name for ${mockMember.name} to ${mockMember.displayname}`],
|
||||
['proxy', mockMember.proxy, null, `Updated name for ${mockMember.name} to ${mockMember.proxy}`],
|
||||
['propic', mockMember.propic, null, `Updated name for ${mockMember.name} to ${mockMember.propic}`],
|
||||
['propic', mockMember.propic, attachmentExpiration, `Updated name for ${mockMember.name} to ${mockMember.propic} warning}`]
|
||||
])('calls database.members.update with correct column and value and return string', async (columnName, value, attachmentExpiration) => {
|
||||
// Act
|
||||
const res = await memberHelper.updateMemberField(authorId, mockMember.name, columnName, value, attachmentExpiration)
|
||||
await memberHelper.updateMemberField(authorId, mockMember.name, columnName, value, attachmentExpiration)
|
||||
// Assert
|
||||
expect(res).toEqual(expected);
|
||||
expect(database.members.update).toHaveBeenCalledTimes(1);
|
||||
expect(database.members.update).toHaveBeenCalledWith({[columnName]: value}, {
|
||||
where: {
|
||||
|
||||
@@ -5,7 +5,6 @@ const {utils} = require("../../src/helpers/utils.js");
|
||||
describe('utils', () => {
|
||||
|
||||
const attachmentUrl = 'oya.png';
|
||||
const expirationString = new Date("2026-01-01").toDateString();
|
||||
let blob;
|
||||
|
||||
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(() => {
|
||||
// restore the spy created with spyOn
|
||||
jest.restoreAllMocks();
|
||||
|
||||
Reference in New Issue
Block a user