Skip to content

Commit

Permalink
Merge pull request #32 from Habilya/dev
Browse files Browse the repository at this point in the history
Merge from Dev 2024-12-17
  • Loading branch information
Habilya authored Dec 17, 2024
2 parents f1c7296 + 0cf9586 commit 0d2226c
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 17 deletions.
110 changes: 110 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,116 @@
.gitignore
package-lock.json

# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/

# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/

#visual studio code
*.vscode

# Visual Studio 2017 auto generated files
Generated\ Files/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

# NUNIT
*.VisualState.xml
TestResult.xml

# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c

# Benchmark Results
BenchmarkDotNet.Artifacts/

# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/

# StyleCop
StyleCopReport.xml

# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc

# Chutzpah Test files
_Chutzpah*

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb

# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap

# Visual Studio Trace Files
*.e2e

# c9 cloud editor (ide folder)
.c9/
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "wordcountingdiscordbotjs",
"version": "1.0.4",
"version": "1.0.5",
"description": "A discord bot to count how many times a specific word or a pattern was spoken",
"main": "src/index.js",
"scripts": {
"test": "jest --verbose",
"test": "jest",
"test-mon": "jest --watchAll --verbose"
},
"jest": {
Expand All @@ -25,7 +25,7 @@
"jest-when": "^3.6.0",
"jsdom": "^22.1.0",
"mongoose": "^7.6.2",
"node-html-to-image": "^4.0.0",
"node-html-to-image": "^5.0.0",
"winston": "^3.11.0",
"winston-daily-rotate-file": "^4.7.1"
}
Expand Down
3 changes: 2 additions & 1 deletion src/commands/reactions/topReactionsByUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ module.exports = {
}

// Read the templates
leaderBoardTemplator.initTemplates();
const pathToHTMLTemplates = '../../assets/templates/';
leaderBoardTemplator.initTemplates(pathToHTMLTemplates);

const generatedLadderboard_li = await leaderBoardTemplator.PrepareLeaderBoardTable(interaction, topUsersReactionsByReactionName, LEADERBOARD_DISPLAY_LIMIT);

Expand Down
8 changes: 4 additions & 4 deletions src/utils/leaderBoardTemplator.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
const fs = require("fs");
const path = require("path");

let ladderboard_template = '';
let ladderboard_li_template = '';


function initTemplates() {
function initTemplates(pathToHTMLTemplates) {
// Read the template into a variable
ladderboard_template = fs.readFileSync('./assets/templates/ladderboard_template.html');
ladderboard_li_template = fs.readFileSync('./assets/templates/ladderboard_li_template.html');
ladderboard_template = fs.readFileSync(path.join(pathToHTMLTemplates, 'ladderboard_template.html'));
ladderboard_li_template = fs.readFileSync(path.join(pathToHTMLTemplates, 'ladderboard_li_template.html'));
}

async function GetDiscordMemberByIdFromDiscordInteraction(discordInteraction, userId) {
Expand Down Expand Up @@ -49,7 +50,6 @@ async function PrepareLeaderBoardTable(discordInteraction, usersReactionsQueryRe
}

function GenerateLeaderBoardLine(avatarURL, userDisplayName, userAdditionalInformation, messageReactionCount) {

return ladderboard_li_template
.toString()
.replace('{{avatar_url}}', avatarURL)
Expand Down
2 changes: 1 addition & 1 deletion test/commands.misc.help.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('Command help.js tests', () => {
fields: [
{
name: "Ver.",
value: "1.0.4",
value: "1.0.5",
},
{
name: "Description",
Expand Down
23 changes: 15 additions & 8 deletions test/commands.reactions.topReactionsByUser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,14 @@ describe('Command topReactionsByUser.js tests', () => {

// Act (Global)
topUsersReactionsByReactionName = await dbLayer.getTopUsersReactionsByReactionName('gank', 5);
leaderBoardTemplator.initTemplates();
const pathToHTMLTemplates = './assets/templates/';
leaderBoardTemplator.initTemplates(pathToHTMLTemplates);
generatedLadderboard_li = await leaderBoardTemplator.PrepareLeaderBoardTable(message, topUsersReactionsByReactionName, 5);
});

it('Command /topReactionsByUser html Should Match', async() => {

// Arrange

// Act

// Assert
expect(generatedLadderboard_li).toBe(`<article class="leaderboard__profile">
const expected_result = `<article class="leaderboard__profile">
<img src="http://615751829300576314.jpg" class="leaderboard__picture">
<span class="leaderboard__name">nickname - 615751829300576314 (6314)</span>
<span class="leaderboard__value">6</span>
Expand All @@ -93,7 +89,18 @@ describe('Command topReactionsByUser.js tests', () => {
<img src="http://322173755470118915.jpg" class="leaderboard__picture">
<span class="leaderboard__name">username - 322173755470118915 (8915)</span>
<span class="leaderboard__value">1</span>
</article>`);
</article>`;
// Act
let actual = generatedLadderboard_li
.split("\r").join("")
.split("\n").join("");

let expected = expected_result
.split("\r").join("")
.split("\n").join("");

// Assert
expect(actual).toBe(expected);
});

});

0 comments on commit 0d2226c

Please sign in to comment.