diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml
index a8f09e99..5c00b1db 100644
--- a/.github/workflows/code-quality.yml
+++ b/.github/workflows/code-quality.yml
@@ -18,6 +18,5 @@ jobs:
- run: yarn install
- run: npx webpack
- run: yarn run lint
- continue-on-error: true # should be removed if all the issues are fixed
- run: yarn run test
- uses: codecov/codecov-action@v3
diff --git a/package.json b/package.json
index bb50b868..b1b8ef69 100644
--- a/package.json
+++ b/package.json
@@ -39,7 +39,9 @@
"grunt-postcss": "0.9.0",
"grunt-run": "^0.8.1",
"grunt-sass": "3.1.0",
+ "highcharts": "^11.2.0",
"jest": "^29.7.0",
+ "jquery": "^3.7.1",
"load-grunt-config": "4.0.1",
"load-grunt-tasks": "5.1.0",
"octokit": "^3.1.2",
diff --git a/routes/views/account/post/report.js b/routes/views/account/post/report.js
index 6f2e477d..70e01e75 100644
--- a/routes/views/account/post/report.js
+++ b/routes/views/account/post/report.js
@@ -2,13 +2,17 @@ let flash = {};
let request = require('request');
const {check, validationResult} = require('express-validator');
-function promiseRequest(url) {
+function promiseRequest(url, req) {
return new Promise(function (resolve, reject) {
- request(url, function (error, res, body) {
+ request(url, {
+ headers: {
+ 'Authorization': 'Bearer ' + req.user.data.attributes.token,
+ }
+ }, function (error, res, body) {
if (!error && res.statusCode < 300) {
resolve(body);
} else {
- reject(error);
+ reject(error || new Error('report failed with status' + res.statusCode));
}
});
});
@@ -78,7 +82,7 @@ exports = module.exports = async function (req, res) {
const userFetchRoute = process.env.API_URL+'/data/player?filter='+filter+'&fields[player]=login&page[size]='+offenders.length;
let apiUsers;
try {
- const userFetch = await promiseRequest(userFetchRoute);
+ const userFetch = await promiseRequest(userFetchRoute, req);
apiUsers = JSON.parse(userFetch);
}
catch(e){
@@ -126,7 +130,7 @@ exports = module.exports = async function (req, res) {
if (isGameReport){
const gameFetchRoute = process.env.API_URL+'/data/game?filter=id=='+req.body.game_id+'&fields[game]='; /* empty field here to fetch nothing but ID */
try {
- const gameFetch = await promiseRequest(gameFetchRoute);
+ const gameFetch = await promiseRequest(gameFetchRoute, req);
const gameData = JSON.parse(gameFetch);
}
catch(e){
diff --git a/src/frontend/js/entrypoint/clans.js b/src/frontend/js/entrypoint/clans.js
index 9ddd1faa..b1713dc2 100644
--- a/src/frontend/js/entrypoint/clans.js
+++ b/src/frontend/js/entrypoint/clans.js
@@ -1,146 +1 @@
-//Variables used across the board
-let pageNumber = 0;
-let lastPage = 5;
-let clanList = [];
-let timedOutPlayers = [];
-let currentClan = '';
-
-let clanListDivided = clanList.length / 100;
-// This decides the time filter
-let d = new Date();
-let timeFilter = 6; // 6 Months is the default value
-let minusTimeFilter = d.setMonth(d.getMonth() - timeFilter);
-let currentDate = new Date(minusTimeFilter).toISOString();
-
-
-//Names of buttons
-async function clanOneJSON() {
- //Check which category is active
- const response = await fetch(`js/app/members/getAllClans.json`);
-
- const data = await response.json();
-
- clanList = data;
-
- return await data;
-}
-
-clanOneJSON();
-
-
-//Updates the clan according to what is needed
-function clanUpdate() {
- // We convert clanList into a string to find out how many pages we have. We can find so by checking the first two digits. In other words, if we have 1349 players, then we have 13 pages. However, if we have 834, we have 8 pages (only take the first digit).
- clanListDivided = clanList.length / 100;
- lastPage = Math.floor(clanListDivided);
-
- //Deletes everything with the class clanDelete, we do it to delete all the previous clan and add the new one back in.
- let clanDelete = document.querySelectorAll('.clanDelete');
- clanDelete.forEach(clanDelete => {
- clanDelete.remove();
- });
-
- //determines the current page, whether to add or substract the missing players in case we pressed next or previous then it will add or substract players
- let clanIndex = (clanList.length - 100) - (pageNumber * 100); //- addNextPlayer;
- let next100Players = clanList.length - (pageNumber * 100);
-
- for (clanIndex; clanIndex < next100Players; clanIndex++) {
- if (clanIndex < 0) {
- clanIndex = 0;
- console.log('There are no more players left.');
- }
- // Gets the player data and inserts it into the li element
-
-
- document.getElementById('clanPlayer').insertAdjacentHTML('afterbegin', `
${clanList[clanIndex][0].leaderName}`);
- document.getElementById('clanName').insertAdjacentHTML('afterbegin', ` ${clanList[clanIndex][1].name}`);
- document.getElementById('clanTAG').insertAdjacentHTML('afterbegin', ` ${clanList[clanIndex][1].tag}`);
-
- document.getElementById('clanPopulation').insertAdjacentHTML('afterbegin', ` ${clanList[clanIndex][1].population}`);
-
- }
-}
-
-//This function triggers when the next, previous, first or last button are clicked
-let pageButton = document.querySelectorAll('.pageButton');
-
-function pageChange(newPageNumber) {
- pageNumber = newPageNumber;
- pageButton.forEach(element => element.classList.remove(`exhaustedButton`));
- if (pageNumber === 0) {
- //You see 4-7 pageButton because there are a total of 8 buttons counting the ones at the bottom of the page
- pageButton[0].classList.add('exhaustedButton');
- pageButton[2].classList.add('exhaustedButton');
- pageButton[4].classList.add('exhaustedButton');
- pageButton[6].classList.add('exhaustedButton');
- }
- if (pageNumber === lastPage) {
- pageButton[1].classList.add('exhaustedButton');
- pageButton[3].classList.add('exhaustedButton');
- pageButton[5].classList.add('exhaustedButton');
- pageButton[7].classList.add('exhaustedButton');
- }
- clanUpdate();
-}
-
-// Don't know why but the code refuses to run correctly unless it is delayed by at least 1/10 of a second/100ms. Not really an issue but idk why its doing this
-setTimeout(() => {
- clanUpdate();
-}, 1000);
-
-
-// SEARCH BAR
-
-
-//Gets called from the HTML search input form
-function pressEnter(event) {
- let inputText = event.target.value;
- // this regex grabs the current input and due to the ^, it selects whatever starts with the input, so if you type Te, Tex will show up.
- if (inputText === '') {
- document.querySelectorAll('.removeOldSearch').forEach(element => element.remove());
- } else {
- let regex = `^${inputText.toLowerCase()}`;
- let searchName = clanList.filter(element => element[1].tag.toLowerCase().match(regex));
-
- document.querySelectorAll('.removeOldSearch').forEach(element => element.remove());
- for (let player of searchName.slice(0, 5)) {
- document.querySelector('#placeMe').insertAdjacentHTML('afterend', ` ${player[1].tag} `);
- }
-
- if (event.key === 'Enter') {
-
- findPlayer(inputText);
- }
- }
- document.querySelector('#errorLog').innerText = '';
-
-}
-
-function findPlayer(userInput) {
- clanOneJSON(currentClan)
- .then(() => {
- //input from the searchbar becomes clanName and then searchClan is their index number
- let searchClan = clanList.findIndex(element => element[1].tag.toLowerCase() === userInput.toLowerCase());
- if (searchClan !== -1) {
- window.location.href = `/clans/${userInput}`;
- } else {
- throw new Error('clan couldnt be found');
- }
-
-
- document.querySelector('#errorLog').innerText = ``;
- }).catch(() => {
- document.querySelector('#errorLog').innerText = `Clan "${userInput}" couldn't be found`;
- });
-}
-
-// SEACRH AND CLEAR BUTTONS
-document.querySelector('#clearSearch').addEventListener('click', () => {
- document.querySelector('#searchResults').classList.add('appearWhenSearching');
- document.querySelector('#clearSearch').classList.add('appearWhenSearching');
- let clanDelete = document.querySelectorAll('.clanDeleteSearch');
- clanDelete.forEach(element => element.remove());
-});
-
-
-
+// noop while clan-refactoring is in progress
diff --git a/src/frontend/js/entrypoint/content-creators.js b/src/frontend/js/entrypoint/content-creators.js
index e674852d..fcb4d4c2 100644
--- a/src/frontend/js/entrypoint/content-creators.js
+++ b/src/frontend/js/entrypoint/content-creators.js
@@ -1,8 +1,8 @@
-async function getWordpress() {
- const response = await fetch('/data/content-creators.json');
- const data = await response.json();
- let insertWordpress = document.getElementById('contentCreatorWordpress');
- insertWordpress.insertAdjacentHTML('beforeend', `${data[0].content}`);
- return await data;
+async function getWordpress () {
+ const response = await fetch('/data/content-creators.json')
+ const data = await response.json()
+ const insertWordpress = document.getElementById('contentCreatorWordpress')
+ insertWordpress.insertAdjacentHTML('beforeend', `${data[0].content}`)
+ return await data
}
-getWordpress();
+getWordpress()
diff --git a/src/frontend/js/entrypoint/donation.js b/src/frontend/js/entrypoint/donation.js
index ad5f7a64..c71e9f5a 100644
--- a/src/frontend/js/entrypoint/donation.js
+++ b/src/frontend/js/entrypoint/donation.js
@@ -1,74 +1,73 @@
+import Highcharts from 'highcharts'
Highcharts.chart('container', {
- chart: {
- plotBackgroundColor: null,
- plotBorderWidth: null,
- plotShadow: true,
- backgroundColor: 'transparent',
- type: 'pie',
+ chart: {
+ plotBackgroundColor: null,
+ plotBorderWidth: null,
+ plotShadow: true,
+ backgroundColor: 'transparent',
+ type: 'pie'
- },
- credits: {
- enabled: false
- },
- exporting: {
- enabled: false
- },
- title: {
- text: 'How FAF Uses Donations',
- style: {
- color: '#ffffff',
- fontSize: '30px',
- fontFamily: 'electrolize'
- }
- },
- tooltip: {
- pointFormat: '{series.name}: {point.percentage:.1f}%'
- },
- accessibility: {
- point: {
- valueSuffix: '%'
- }
- },
- plotOptions: {
- pie: {
- allowPointSelect: false,
- cursor: 'pointer',
-
- dataLabels: {
- color: '#ffffff',
- font: '20px electrolize',
- enabled: true,
- format: '{point.name}
: {point.percentage:.1f} %',
+ },
+ credits: {
+ enabled: false
+ },
+ exporting: {
+ enabled: false
+ },
+ title: {
+ text: 'How FAF Uses Donations',
+ style: {
+ color: '#ffffff',
+ fontSize: '30px',
+ fontFamily: 'electrolize'
+ }
+ },
+ tooltip: {
+ pointFormat: '{series.name}: {point.percentage:.1f}%'
+ },
+ accessibility: {
+ enabled: false
+ },
+ plotOptions: {
+ pie: {
+ allowPointSelect: false,
+ cursor: 'pointer',
+
+ dataLabels: {
+ color: '#ffffff',
+ font: '20px electrolize',
+ enabled: true,
+ format: '{point.name}
: {point.percentage:.1f} %',
+ style: {
+ fontSize: '18px',
+ fontFamily: 'electrolize'
+ }
+ }
+ }
+ },
+ dataLabels: {
style: {
- fontSize: '18px',
- fontFamily: 'electrolize'
- },
- }
- }
- },
- dataLabels: {
- style: {
- color: '#ffffff'
- }
- },
- series: [{
- name: 'Expenses',
- colorByPoint: true,
- color: '#ffffff',
-
- data: [{
- name: 'Infrastructure Costs',
- y: 56,
- sliced: true,
- color: '#7376a8',
- selected: true
-
- }, {
- name: 'Tournament Prizes',
- y: 44,
- color: '#dadada',
- selected: true
+ color: '#ffffff'
+ }
+ },
+ series: [{
+ name: 'Expenses',
+ colorByPoint: true,
+ color: '#ffffff',
+
+ data: [{
+ name: 'Infrastructure Costs',
+ y: 56,
+ sliced: true,
+ color: '#7376a8',
+ selected: true
+
+ }, {
+ name: 'Tournament Prizes',
+ y: 44,
+ color: '#dadada',
+ selected: true
+ }]
}]
- }]
-});
+})
diff --git a/src/frontend/js/entrypoint/faf-teams.js b/src/frontend/js/entrypoint/faf-teams.js
index f47c58b4..e67bcaa3 100644
--- a/src/frontend/js/entrypoint/faf-teams.js
+++ b/src/frontend/js/entrypoint/faf-teams.js
@@ -1,27 +1,17 @@
-
-let teamSelection = document.querySelectorAll('.teamSelection');
-let teamContainer = document.querySelectorAll('.teamContainer');
-async function getWordpress() {
- const response = await fetch('/data/faf-teams.json');
- const data = await response.json();
- let insertWordpress = document.getElementById('insertWordpress');
- insertWordpress.insertAdjacentHTML('beforeend', `${data[0].content}`);
- teamSelection = document.querySelectorAll('.teamSelection');
- teamContainer = document.querySelectorAll('.teamContainer');
- return await data;
+let teamSelection = document.querySelectorAll('.teamSelection')
+let teamContainer = document.querySelectorAll('.teamContainer')
+async function getWordpress () {
+ const response = await fetch('/data/faf-teams.json')
+ const data = await response.json()
+ const insertWordpress = document.getElementById('insertWordpress')
+ insertWordpress.insertAdjacentHTML('beforeend', `${data[0].content}`)
+ teamSelection = document.querySelectorAll('.teamSelection')
+ teamContainer = document.querySelectorAll('.teamContainer')
+ return await data
}
-getWordpress();
-
-
+getWordpress()
teamSelection.forEach((team, index) => team.addEventListener('click', () => {
-
- teamSelection.forEach(item => item.style.display = 'none');
- teamContainer[index].style.display = 'grid';
-}));
-
-function returnTeam() {
- teamSelection.forEach(item => item.style.display = 'block');
- teamContainer.forEach(item => item.style.display = 'none');
-}
-
+ teamSelection.forEach(item => { item.style.display = 'none' })
+ teamContainer[index].style.display = 'grid'
+}))
diff --git a/src/frontend/js/entrypoint/getClans.js b/src/frontend/js/entrypoint/getClans.js
index f34fec5e..b1713dc2 100644
--- a/src/frontend/js/entrypoint/getClans.js
+++ b/src/frontend/js/entrypoint/getClans.js
@@ -1,72 +1 @@
-const clanName = document.getElementById('clanName');
-const clanTag = document.getElementById('clanTag');
-const clanDescription = document.getElementById('clanDescription');
-const clanCreation = document.getElementById('clanCreation');
-const clanLeader = document.getElementById('clanLeader');
-const clanMembers = document.getElementById('clanMembers');
-
-
-let leaderName = '';
-
-async function getClan() {
-
- //So here we check the tag of the clan in the url
- let url = window.location.href;
- const sliceIndicator = url.indexOf('/clans');
-// The slice has + 7 because thats the amount of characters in "/clans/" yes with two /, not one!
- let findClanTag = url.slice(sliceIndicator + 7, sliceIndicator + 10);
- let clanTag = await findClanTag.replace(/\?m|\?/gm,'');
-
- // We compare the url TAG with the TAGS available in getAllClans and find the clan leader this way
-
- // TODO: Change this hardcoded url into something with env
- const response = await fetch(`https://api.faforever.com/data/clan?include=memberships.player&filter=tag==${clanTag}`);
- const fetchData = await response.json();
-
- const leaderID = fetchData.data[0].relationships.leader.data.id;
-
- fetchData.included.forEach((element, index) => {
- if (index % 2 !== 0) {
- if (element.id === leaderID) {
- leaderName = element.attributes.login;
- }
- }
- });
-
-
- //verifies if user is a member, which allows them to leave the clan
- const clanMember = document.getElementById('iAmMember');
- const isMember = url.indexOf('?member');
- let verifyMembership = url.slice(isMember + 8);
- if (verifyMembership === 'true') {
- clanMember.style.display = 'block';
- }
- return fetchData;
-}
-setTimeout( ()=> {
- getClan()
- .then(fetchData => {
-
- const { attributes} = fetchData.data[0];
- clanName.insertAdjacentHTML('afterbegin',
- `${attributes.name}`);
- clanDescription.insertAdjacentHTML('afterbegin',
- `${attributes.description}`);
- clanTag.insertAdjacentHTML('afterbegin',
- `Welcome to "${attributes.tag}"`);
- //clanLeader.insertAdjacentHTML('afterbegin',
- // `${fetchData.data[0].attributes.id}`);
- clanCreation.insertAdjacentHTML('afterbegin',
- `Created on ${attributes.createTime.slice(0, 10)}`);
- clanLeader.insertAdjacentHTML('afterbegin',
- `Led by ${leaderName}`);
-
- for (let i = 0; i < fetchData.included.length; i++) {
- if (i % 2 !== 0) {
- clanMembers.insertAdjacentHTML('afterbegin',
- ` ${fetchData.included[i].attributes.login} `);
- }
- }
- });
-
-},750);
+// noop while clan-refactoring is in progress
diff --git a/src/frontend/js/entrypoint/leaderboards.js b/src/frontend/js/entrypoint/leaderboards.js
index 180e9f0a..ffa65390 100644
--- a/src/frontend/js/entrypoint/leaderboards.js
+++ b/src/frontend/js/entrypoint/leaderboards.js
@@ -1,64 +1,63 @@
-//Variables used across the board
-let pageNumber = 0;
-let lastPage = 5;
-let playerList = [];
-let timedOutPlayers = [];
-let currentLeaderboard = '1v1';
-const insertPlayer = document.getElementById('insertPlayer');
+// Variables used across the board
+window.pageNumber = 0
+window.lastPage = 5
+let playerList = []
+let timedOutPlayers = []
+let currentLeaderboard = '1v1'
+const insertPlayer = document.getElementById('insertPlayer')
const mainLeaderboard = document.getElementById('mainLeaderboard')
-let playerListDivided = playerList.length / 100;
+let playerListDivided = playerList.length / 100
// This decides the time filter
-let d = new Date();
-let timeFilter = 6; // 6 Months is the default value
-let minusTimeFilter = d.setMonth(d.getMonth() - timeFilter);
-let currentDate = new Date(minusTimeFilter).toISOString();
-
-
-async function leaderboardOneJSON(leaderboardFile) {
- //Check which category is active
- const response = await fetch(`leaderboards/${leaderboardFile}.json`);
- currentLeaderboard = leaderboardFile;
- const data = await response.json();
- return await data;
+let d = new Date()
+let timeFilter = 6 // 6 Months is the default value
+let minusTimeFilter = d.setMonth(d.getMonth() - timeFilter)
+let currentDate = new Date(minusTimeFilter).toISOString()
+
+async function leaderboardOneJSON (leaderboardFile) {
+ // Check which category is active
+ const response = await fetch(`leaderboards/${leaderboardFile}.json`)
+ currentLeaderboard = leaderboardFile
+ const data = await response.json()
+ return await data
}
-//Updates the leaderboard according to what is needed
-function leaderboardUpdate() {
- // We convert playerList into a string to find out how many pages we have. We can find so by dividing by a 100 and flooring the results to get an integer. In other words, if we have 1349 players, then we have 13 pages.
- playerListDivided = playerList.length / 100;
- lastPage = Math.floor(playerListDivided);
+// Updates the leaderboard according to what is needed
+function leaderboardUpdate () {
+ // We convert playerList into a string to find out how many pages we have. We can find so by dividing by a 100 and flooring the results to get an integer. In other words, if we have 1349 players, then we have 13 pages.
+ playerListDivided = playerList.length / 100
+ window.lastPage = Math.floor(playerListDivided)
- //Deletes everything with the class leaderboardDelete, we do it to delete all the previous leaderboard and add the new one back in.
- let leaderboardDelete = document.querySelectorAll('.leaderboardDelete');
- leaderboardDelete.forEach(leaderboardDelete => {
- leaderboardDelete.remove();
- });
+ // Deletes everything with the class leaderboardDelete, we do it to delete all the previous leaderboard and add the new one back in.
+ const leaderboardDelete = document.querySelectorAll('.leaderboardDelete')
+ leaderboardDelete.forEach(leaderboardDelete => {
+ leaderboardDelete.remove()
+ })
- //determines the current page, whether to add or substract the missing players in case we pressed next or previous then it will add or substract players
- let playerIndex = pageNumber * 100;
- let next100Players = (1 + pageNumber) * 100;
-
- if (next100Players > playerList.length) {
- next100Players = playerList.length
- }
+ // determines the current page, whether to add or substract the missing players in case we pressed next or previous then it will add or substract players
+ let playerIndex = window.pageNumber * 100
+ let next100Players = (1 + window.pageNumber) * 100
- // Function to add player first second and third background
- if (playerIndex === 0) {
- mainLeaderboard.classList.remove('leaderboardNoAwards');
- mainLeaderboard.classList.add('leaderboardAwards');
- } else {
- mainLeaderboard.classList.remove('leaderboardAwards');
- mainLeaderboard.classList.add('leaderboardNoAwards');
- }
+ if (next100Players > playerList.length) {
+ next100Players = playerList.length
+ }
- // Actual insertion of HTML
- for (playerIndex; playerIndex < next100Players; playerIndex++) {
- if (playerIndex < 0) {
- playerIndex = 0;
+ // Function to add player first second and third background
+ if (playerIndex === 0) {
+ mainLeaderboard.classList.remove('leaderboardNoAwards')
+ mainLeaderboard.classList.add('leaderboardAwards')
+ } else {
+ mainLeaderboard.classList.remove('leaderboardAwards')
+ mainLeaderboard.classList.add('leaderboardNoAwards')
}
- let rating = playerList[playerIndex].rating;
- let winRate = playerList[playerIndex].wonGames / playerList[playerIndex].totalgames * 100;
- insertPlayer.insertAdjacentHTML('beforebegin', `
+
+ // Actual insertion of HTML
+ for (playerIndex; playerIndex < next100Players; playerIndex++) {
+ if (playerIndex < 0) {
+ playerIndex = 0
+ }
+ const rating = playerList[playerIndex].rating
+ const winRate = playerList[playerIndex].wonGames / playerList[playerIndex].totalgames * 100
+ insertPlayer.insertAdjacentHTML('beforebegin', `
${playerIndex + 1}
@@ -75,123 +74,87 @@ function leaderboardUpdate() {
${playerList[playerIndex].totalgames}
`
- );
- }
-
-
+ )
+ }
}
-
-//This function triggers when the next, previous, first or last button are clicked
-let pageButton = document.querySelectorAll('.pageButton');
-
-function pageChange(newPageNumber) {
-
- pageNumber = newPageNumber;
- pageButton.forEach(element => element.classList.remove(`exhaustedButton`));
- if (pageNumber === 0) {
- //You see 4-7 pageButton because there are a total of 8 buttons counting the ones at the bottom of the page
- pageButton[0].classList.add('exhaustedButton');
- pageButton[2].classList.add('exhaustedButton');
- pageButton[4].classList.add('exhaustedButton');
- pageButton[6].classList.add('exhaustedButton');
- }
- if (pageNumber === lastPage) {
- pageButton[1].classList.add('exhaustedButton');
- pageButton[3].classList.add('exhaustedButton');
- pageButton[5].classList.add('exhaustedButton');
- pageButton[7].classList.add('exhaustedButton');
- }
- leaderboardUpdate();
+// This function triggers when the next, previous, first or last button are clicked
+const pageButton = document.querySelectorAll('.pageButton')
+
+window.pageChange = function (newPageNumber) {
+ window.pageNumber = newPageNumber
+ pageButton.forEach(element => element.classList.remove('exhaustedButton'))
+ if (window.pageNumber === 0) {
+ // You see 4-7 pageButton because there are a total of 8 buttons counting the ones at the bottom of the page
+ pageButton[0].classList.add('exhaustedButton')
+ pageButton[2].classList.add('exhaustedButton')
+ pageButton[4].classList.add('exhaustedButton')
+ pageButton[6].classList.add('exhaustedButton')
+ }
+ if (window.pageNumber === window.lastPage) {
+ pageButton[1].classList.add('exhaustedButton')
+ pageButton[3].classList.add('exhaustedButton')
+ pageButton[5].classList.add('exhaustedButton')
+ pageButton[7].classList.add('exhaustedButton')
+ }
+ leaderboardUpdate()
}
-//This function checks the different filters the user has chosen
+// This function checks the different filters the user has chosen
// It shows as it not being used because it is called by the HTML
-function timeCheck(timeSelected) {
-
- timeFilter = timeSelected;
- d = new Date();
- minusTimeFilter = d.setMonth(d.getMonth() - timeFilter);
- currentDate = new Date(minusTimeFilter).toISOString();
-
- //Re-insert all players that were kicked, to have a clean slate
- for (let i = 0; i < timedOutPlayers.length; i++) {
- playerList.push(timedOutPlayers[i]);
- }
- // Sort players by their rating
- playerList.sort((playerA, playerB) => playerB.rating - playerA.rating);
-
- //clean slate
- timedOutPlayers = [];
-
- //kick all the players that dont meet the time filter
- for (let i = 0; i < playerList.length; i++) {
-
- if (currentDate > playerList[i].date) {
-
- timedOutPlayers.push(playerList[i]);
- playerList.splice(i, 1);
+window.timeCheck = function (timeSelected) {
+ timeFilter = timeSelected
+ d = new Date()
+ minusTimeFilter = d.setMonth(d.getMonth() - timeFilter)
+ currentDate = new Date(minusTimeFilter).toISOString()
+
+ // Re-insert all players that were kicked, to have a clean slate
+ for (let i = 0; i < timedOutPlayers.length; i++) {
+ playerList.push(timedOutPlayers[i])
}
- }
-
-
- pageChange(0);
-}
-
-function filterLeaderboards() {
- console.log('Im in progress');
- /*
- //Re-insert all players that were kicked, to have a clean slate
- for (let i = 0; i < timedOutPlayers.length; i++) {
- playerList.push(timedOutPlayers[i]);
- }
- //Sort players
- playerList.sort((playerA, playerB) => (playerB[1].wonGames / playerB[1].totalgames * 100) - (playerA[1].wonGames / playerA[1].totalgames * 100) || playerB[1].totalgames - playerA[1].totalgames);
-
- //clean slate
- timedOutPlayers = [];
-
- //kick all the players that dont meet the time filter
-
- for (let i = 0; i < playerList.length; i++) {
-
- if (50 > playerList[i][1].totalgames) {
- timedOutPlayers.push(playerList[i]);
- playerList.splice(i, 1);
+ // Sort players by their rating
+ playerList.sort((playerA, playerB) => playerB.rating - playerA.rating)
+
+ // clean slate
+ timedOutPlayers = []
+
+ // kick all the players that dont meet the time filter
+ for (let i = 0; i < playerList.length; i++) {
+ if (currentDate > playerList[i].date) {
+ timedOutPlayers.push(playerList[i])
+ playerList.splice(i, 1)
+ }
}
- }
- pageChange(0);
- */
-
-}
+ window.pageChange(0)
+}
// This changes the current leaderboard(newLeaderboard), sets the page to 0 (pageNumber = 0) and resets the next and previous buttons.
-function changeLeaderboard(newLeaderboard) {
- leaderboardOneJSON(newLeaderboard)
- .then(data => {
- playerList = data;
- playerListDivided = playerList.length / 100;
- lastPage = Math.floor(playerListDivided);
- pageChange(0);
- });
+window.changeLeaderboard = function (newLeaderboard) {
+ leaderboardOneJSON(newLeaderboard)
+ .then(data => {
+ playerList = data
+ playerListDivided = playerList.length / 100
+ window.lastPage = Math.floor(playerListDivided)
+ window.pageChange(0)
+ })
}
-//Gets called once so it generates a leaderboard
-changeLeaderboard('1v1');
+// Gets called once so it generates a leaderboard
+window.changeLeaderboard('1v1')
-const insertSearch = document.getElementById('insertSearch');
+const insertSearch = document.getElementById('insertSearch')
// SEARCH BAR
-function findPlayer(playerName) {
- leaderboardOneJSON(currentLeaderboard)
- .then(() => {
- //input from the searchbar becomes playerName and then searchPlayer is their index number
- let searchPlayer = playerList.findIndex(element => element.label.toLowerCase() === playerName.toLowerCase());
-
- let rating = playerList[searchPlayer].rating;
- let winRate = playerList[searchPlayer].wonGames / playerList[searchPlayer].totalgames * 100;
- insertSearch.insertAdjacentHTML('beforebegin', `
+function findPlayer (playerName) {
+ leaderboardOneJSON(currentLeaderboard)
+ .then(() => {
+ // input from the searchbar becomes playerName and then searchPlayer is their index number
+ const searchPlayer = playerList.findIndex(element => element.label.toLowerCase() === playerName.toLowerCase())
+
+ const rating = playerList[searchPlayer].rating
+ const winRate = playerList[searchPlayer].wonGames / playerList[searchPlayer].totalgames * 100
+ insertSearch.insertAdjacentHTML('beforebegin', `
${searchPlayer + 1}
@@ -207,52 +170,48 @@ function findPlayer(playerName) {
${playerList[searchPlayer].totalgames}
-
`);
+
`)
-
- document.querySelector('#errorLog').innerText = ``;
- }).catch(() => {
- document.querySelector('#errorLog').innerText = `Player "${playerName}" couldn't be found in the ${currentLeaderboard} leaderboard.`;
- });
+ document.querySelector('#errorLog').innerText = ''
+ }).catch(() => {
+ document.querySelector('#errorLog').innerText = `Player "${playerName}" couldn't be found in the ${currentLeaderboard} leaderboard.`
+ })
}
-function selectPlayer(name) {
+window.selectPlayer = function (name) {
const element = document.getElementById('input')
element.value = name
- element.dispatchEvent(new KeyboardEvent('keyup', {'key': 'Enter'}));
+ element.dispatchEvent(new KeyboardEvent('keyup', { key: 'Enter' }))
}
-//Gets called from the HTML search input form
-function pressEnter(event) {
- let inputText = event.target.value;
- // this regex grabs the current input and due to the ^, it selects whatever starts with the input, so if you type te, Tex will show up.
- if (inputText === '') {
- document.querySelectorAll('.removeOldSearch').forEach(element => element.remove());
- } else {
- let regex = `^${inputText.toLowerCase()}`;
- let searchName = playerList.filter(element => element.label.toLowerCase().match(regex));
-
- document.querySelectorAll('.removeOldSearch').forEach(element => element.remove());
- for (let player of searchName.slice(0, 5)) {
- document.querySelector('#placeMe').insertAdjacentHTML('afterend', `${player.label}`);
- }
-
- if (event.key === 'Enter') {
- document.querySelector('#searchResults').classList.remove('appearWhenSearching');
- document.querySelector('#clearSearch').classList.remove('appearWhenSearching');
- findPlayer(inputText.trim());
+// Gets called from the HTML search input form
+window.pressEnter = function (event) {
+ const inputText = event.target.value
+ // this regex grabs the current input and due to the ^, it selects whatever starts with the input, so if you type te, Tex will show up.
+ if (inputText === '') {
+ document.querySelectorAll('.removeOldSearch').forEach(element => element.remove())
+ } else {
+ const regex = `^${inputText.toLowerCase()}`
+ const searchName = playerList.filter(element => element.label.toLowerCase().match(regex))
+
+ document.querySelectorAll('.removeOldSearch').forEach(element => element.remove())
+ for (const player of searchName.slice(0, 5)) {
+ document.querySelector('#placeMe').insertAdjacentHTML('afterend', `${player.label}`)
+ }
+
+ if (event.key === 'Enter') {
+ document.querySelector('#searchResults').classList.remove('appearWhenSearching')
+ document.querySelector('#clearSearch').classList.remove('appearWhenSearching')
+ findPlayer(inputText.trim())
+ }
}
- }
- document.querySelector('#errorLog').innerText = '';
-
+ document.querySelector('#errorLog').innerText = ''
}
-
// SEACRH AND CLEAR BUTTONS
document.querySelector('#clearSearch').addEventListener('click', () => {
- document.querySelector('#searchResults').classList.add('appearWhenSearching');
- document.querySelector('#clearSearch').classList.add('appearWhenSearching');
- let leaderboardDelete = document.querySelectorAll('.leaderboardDeleteSearch');
- leaderboardDelete.forEach(element => element.remove());
-});
-
+ document.querySelector('#searchResults').classList.add('appearWhenSearching')
+ document.querySelector('#clearSearch').classList.add('appearWhenSearching')
+ const leaderboardDelete = document.querySelectorAll('.leaderboardDeleteSearch')
+ leaderboardDelete.forEach(element => element.remove())
+})
diff --git a/src/frontend/js/entrypoint/navigation.js b/src/frontend/js/entrypoint/navigation.js
index ebd8c60e..d2be7868 100644
--- a/src/frontend/js/entrypoint/navigation.js
+++ b/src/frontend/js/entrypoint/navigation.js
@@ -1,150 +1,135 @@
+document.addEventListener('DOMContentLoaded', () => {
+ // JS for the main navbar menus to open on hover and close when leaving (GAME, COMMUNITY, etc). It uses mobilenav-active because it just needs the display:block
+
+ const navList = document.getElementsByClassName('navList')
+ const navAbsolute = document.querySelectorAll('.navAbsolute')
+ let stillHere = 0
+
+ for (let i = 0; i < navList.length; i++) {
+ // When you mouseover/click, menu appears
+ navList[i].addEventListener('mouseout', () => {
+ stillHere = 1
+ if (navAbsolute[i]) {
+ navAbsolute[i].classList.remove('navAbsoluteActive')
+ setTimeout(() => {
+ if (stillHere === 1) {
+ navAbsolute.forEach(list => { list.style.opacity = '0%' })
+ }
+ }, 0)
+ }
+ })
+ navList[i].addEventListener('mouseover', () => {
+ stillHere = 0
+ if (navAbsolute[i]) {
+ navAbsolute[i].classList.add('navAbsoluteActive')
+ setTimeout(() => {
+ navAbsolute[i].style.opacity = '100%'
+ }, 10)
+ }
+ })
+ // when you mouseout/leave, menu dissapears
+ }
-document.addEventListener("DOMContentLoaded", () => {
-
-
-
-
-
- //JS for the main navbar menus to open on hover and close when leaving (GAME, COMMUNITY, etc). It uses mobilenav-active because it just needs the display:block
-
- let navList = document.getElementsByClassName("navList");
- let navAbsolute = document.querySelectorAll(".navAbsolute");
- let stillHere = 0;
-
- for (let i = 0; i < navList.length; i++) {
- //When you mouseover/click, menu appears
- navList[i].addEventListener("mouseout", () => {
- stillHere = 1;
- if (navAbsolute[i]) {
- navAbsolute[i].classList.remove("navAbsoluteActive");
+ const mobileNavMenuContent = document.querySelectorAll('.mobileNavMenuContent')
+ const mobileNavElement = document.querySelectorAll('.mobileNavElement')
+ const mobileNavMenu = document.querySelectorAll('.mobileNavMenu')
+ const returnMenu = document.querySelector('#returnMenu')
+ // Random variable to determine whether same menu was clicked
+ let mobileSameElementClicked = 7
+
+ // Code that works out how the mobileNav menus are open
+ mobileNavMenu.forEach((element, index) => element.addEventListener('click', () => {
+ mobileNavMenuContent.forEach(item => { item.style.display = 'none' })
+ mobileNavMenu.forEach(item => { item.style.backgroundColor = '#262626' })
+ mobileNavElement.forEach(item => { item.style.display = 'none' })
+ returnMenu.style.display = 'none'
+
+ if (mobileSameElementClicked !== index) {
+ returnMenu.style.display = 'block'
+ mobileNavMenu[index].style.display = 'block'
+ mobileNavMenu[index].style.backgroundColor = '#3F3F3FFF'
+ mobileNavMenuContent[index].style.display = 'block'
+ mobileSameElementClicked = index
+ } else {
+ mobileSameElementClicked = 7
+ mobileNavElement.forEach(item => { item.style.display = 'block' })
+ }
+ }))
+ // Clicking the return Menu Brings us back
+ returnMenu.addEventListener('click', () => {
+ mobileNavMenuContent.forEach(item => { item.style.display = 'none' })
+ mobileNavMenu.forEach(item => { item.style.backgroundColor = '#262626' })
+ mobileNavElement.forEach(item => { item.style.display = 'block' })
+ returnMenu.style.display = 'none'
+ })
+
+ // Code that creates the transition from menu closing to menu opening
+ const mobileNavBar = document.querySelector('#mobileNavBar')
+ const mobileTransitionBar = document.querySelectorAll('.mobileTransition')
+ const openMenu = document.querySelector('#openMenu')
+ const closeMenu = document.querySelector('#closeMenu')
+ const bodyHTML = document.body
+
+ openMenu.addEventListener('click', () => {
+ mobileNavBar.style.display = 'grid'
+ mobileTransitionBar[0].style.display = 'none'
+ mobileTransitionBar[0].style.opacity = '0'
+ bodyHTML.classList.add('stopScroll')
setTimeout(() => {
- if (stillHere === 1) {
- navAbsolute.forEach(list => list.style.opacity = "0%");
- }
- }, 0);
- }
- });
- navList[i].addEventListener("mouseover", () => {
- stillHere = 0;
- if (navAbsolute[i]) {
- navAbsolute[i].classList.add("navAbsoluteActive");
+ mobileNavBar.style.opacity = '1'
+ }, 1)
+ })
+
+ closeMenu.addEventListener('click', () => {
+ mobileNavBar.style.opacity = '0'
+ mobileTransitionBar[0].style.display = 'grid'
+ bodyHTML.classList.remove('stopScroll')
setTimeout(() => {
- navAbsolute[i].style.opacity = "100%";
- }, 10);
- }
- });
- //when you mouseout/leave, menu dissapears
- }
-
- const mobileNavMenuContent = document.querySelectorAll(".mobileNavMenuContent");
- const mobileNavElement = document.querySelectorAll(".mobileNavElement");
- const mobileNavMenu = document.querySelectorAll(".mobileNavMenu");
- const returnMenu = document.querySelector('#returnMenu');
- //Random variable to determine whether same menu was clicked
- let mobileSameElementClicked = 7;
-
- //Code that works out how the mobileNav menus are open
- mobileNavMenu.forEach((element,index) => element.addEventListener('click', () => {
- mobileNavMenuContent.forEach(item => item.style.display = "none");
- mobileNavMenu.forEach(item => item.style.backgroundColor = "#262626");
- mobileNavElement.forEach(item => item.style.display = 'none');
- returnMenu.style.display = 'none';
-
- if (mobileSameElementClicked !== index) {
- returnMenu.style.display = 'block';
- mobileNavMenu[index].style.display = "block";
- mobileNavMenu[index].style.backgroundColor = "#3F3F3FFF";
- mobileNavMenuContent[index].style.display = "block";
- mobileSameElementClicked = index;
-
- } else {
- mobileSameElementClicked = 7;
- mobileNavElement.forEach(item => item.style.display = 'block');
+ mobileNavBar.style.display = 'none'
+ mobileTransitionBar[0].style.opacity = '1'
+ }, 500)
+ })
+
+ const loginList = document.getElementById('loginList')
+
+ if (loginList) {
+ const loginAbsolute = document.getElementById('loginAbsolute')
+ let stillHovering = 0
+ // when you mouse is over the login, it should appear
+ loginList.addEventListener('mouseover', () => {
+ stillHovering = 0
+
+ setTimeout(() => {
+ loginAbsolute.style.display = 'block'
+ // console.log('timeout done');
+ }, 0)
+ })
+ // When you mouseover/click, menu appears
+ // when you mouseout/leave, menu dissapears
+ loginList.addEventListener('mouseout', () => {
+ stillHovering = 1
+ setTimeout(() => {
+ if (stillHovering === 1) {
+ loginAbsolute.style.display = 'none'
+ }
+ }, 0)
+ })
}
- }));
- // Clicking the return Menu Brings us back
- returnMenu.addEventListener('click', () => {
- mobileNavMenuContent.forEach(item => item.style.display = "none");
- mobileNavMenu.forEach(item => item.style.backgroundColor = "#262626");
- mobileNavElement.forEach(item => item.style.display = 'block');
- returnMenu.style.display = 'none';
- });
-
-
- // Code that creates the transition from menu closing to menu opening
- let mobileNavBar = document.querySelector('#mobileNavBar');
- let mobileTransitionBar = document.querySelectorAll('.mobileTransition');
- let openMenu = document.querySelector('#openMenu');
- let closeMenu = document.querySelector('#closeMenu');
- let bodyHTML = document.body;
-
- openMenu.addEventListener('click', () => {
-
- mobileNavBar.style.display = "grid";
- mobileTransitionBar[0].style.display = "none";
- mobileTransitionBar[0].style.opacity = "0";
- bodyHTML.classList.add("stopScroll");
- setTimeout( () => {
- mobileNavBar.style.opacity = "1";
- }, 1);
- });
-
- closeMenu.addEventListener('click', () => {
- mobileNavBar.style.opacity = "0";
- mobileTransitionBar[0].style.display = "grid";
- bodyHTML.classList.remove("stopScroll");
- setTimeout( () => {
- mobileNavBar.style.display = "none";
- mobileTransitionBar[0].style.opacity = "1";
- }, 500);
- });
-
-
-
- let loginList = document.getElementById("loginList");
-
- if (loginList) {
- let loginAbsolute = document.getElementById("loginAbsolute");
- let stillHovering = 0;
- //when you mouse is over the login, it should appear
- loginList.addEventListener("mouseover", () => {
- stillHovering = 0;
-
- setTimeout(() => {
- loginAbsolute.style.display = "block";
- //console.log('timeout done');
- }, 0);
- });
- //When you mouseover/click, menu appears
- //when you mouseout/leave, menu dissapears
- loginList.addEventListener("mouseout", () => {
- stillHovering = 1;
- setTimeout(() => {
- if (stillHovering === 1) {
- loginAbsolute.style.display = "none";
+ // function to make highligthed text change colors/pulsate (it goes from white to gold and viceversa)
+ const highlightText = document.querySelectorAll('.highlightText')
+ let highLigthCounter = 0
+
+ function highlightPulse () {
+ if (highLigthCounter < 1) {
+ highLigthCounter++
+ highlightText.forEach(element => { element.style.transition = '1s' })
+ highlightText.forEach(element => { element.style.color = '#FFFFFF' })
+ } else {
+ highLigthCounter--
+ highlightText.forEach(element => { element.style.color = '#f7941d' })
}
- }, 0);
-
- });
- }
-
- //function to make highligthed text change colors/pulsate (it goes from white to gold and viceversa)
- let highlightText = document.querySelectorAll(".highlightText");
- let highLigthCounter = 0;
-
- function highlightPulse() {
- if (highLigthCounter < 1) {
- highLigthCounter++;
- highlightText.forEach(element => element.style.transition = "1s");
- highlightText.forEach(element => element.style.color = "#FFFFFF");
- } else {
- highLigthCounter--;
- highlightText.forEach(element => element.style.color = "#f7941d");
-
}
- }
- setInterval(highlightPulse, 2000);
-
-});
+ setInterval(highlightPulse, 2000)
+})
diff --git a/src/frontend/js/entrypoint/newshub.js b/src/frontend/js/entrypoint/newshub.js
index a586738d..7bc0a7c4 100644
--- a/src/frontend/js/entrypoint/newshub.js
+++ b/src/frontend/js/entrypoint/newshub.js
@@ -1,27 +1,26 @@
-
-async function getNewshub() {
- const response = await fetch('/data/newshub.json');
- const data = await response.json();
- return await data;
+async function getNewshub () {
+ const response = await fetch('/data/newshub.json')
+ const data = await response.json()
+ return await data
}
-async function getTournament() {
- const response = await fetch('/data/tournament-news.json');
- const data = await response.json();
- return await data;
+async function getTournament () {
+ const response = await fetch('/data/tournament-news.json')
+ const data = await response.json()
+ return await data
}
-let dataLength = 0;
-let clientSpawn = document.getElementById('clientSpawn');
-let clientContainer = document.querySelectorAll('.clientContainer');
-let clientMainFeature = document.querySelectorAll('.clientMainFeature');
-
-function createArticles() {
- getNewshub()
- .then(data => {
- dataLength = data.length;
- let fixedLinkingOrder = data.length - 1;
- for (let i = 0; i < data.length - 1; i++) {
- clientSpawn.insertAdjacentHTML('afterbegin', `
+let dataLength = 0
+const clientSpawn = document.getElementById('clientSpawn')
+const clientContainer = document.querySelectorAll('.clientContainer')
+const clientMainFeature = document.querySelectorAll('.clientMainFeature')
+
+function createArticles () {
+ getNewshub()
+ .then(data => {
+ dataLength = data.length
+ let fixedLinkingOrder = data.length - 1
+ for (let i = 0; i < data.length - 1; i++) {
+ clientSpawn.insertAdjacentHTML('afterbegin', `
@@ -29,11 +28,11 @@ function createArticles() {
-`);
+`)
- fixedLinkingOrder--;
- }
- clientMainFeature[0].insertAdjacentHTML('afterbegin', `
+ fixedLinkingOrder--
+ }
+ clientMainFeature[0].insertAdjacentHTML('afterbegin', `
@@ -43,82 +42,74 @@ function createArticles() {
-`);
- return data;
- }).then(data => {
-
- let clientImage = document.querySelectorAll('.clientImage');
- let clientTitle = document.querySelectorAll('.clientTitle');
- let clientContent = document.querySelectorAll('.clientContent');
- for (let i = 0; i < data.length - 1; i++) {
- let content = data[i + 1].content;
- clientImage[i].style.backgroundImage = `url("${data[i + 1].media}")`;
- clientTitle[i].innerHTML = `${data[i + 1].title}`;
- clientContent[i].innerHTML = `${content.substring(0, 200)}`;
- }
- let featureImage = document.querySelectorAll('.featureImage');
- let featureTitle = document.querySelectorAll('.featureTitle');
- let featureContent = document.querySelectorAll('.featureContent');
- let content = data[0].content;
- featureImage[0].style.backgroundImage = `url("${data[0].media}")`;
- featureTitle[0].innerHTML = `${data[0].title}`;
- featureContent[0].innerHTML = `${content.substring(0, 400)}`;
-
- });
+`)
+ return data
+ }).then(data => {
+ const clientImage = document.querySelectorAll('.clientImage')
+ const clientTitle = document.querySelectorAll('.clientTitle')
+ const clientContent = document.querySelectorAll('.clientContent')
+ for (let i = 0; i < data.length - 1; i++) {
+ const content = data[i + 1].content
+ clientImage[i].style.backgroundImage = `url("${data[i + 1].media}")`
+ clientTitle[i].innerHTML = `${data[i + 1].title}`
+ clientContent[i].innerHTML = `${content.substring(0, 200)}`
+ }
+ const featureImage = document.querySelectorAll('.featureImage')
+ const featureTitle = document.querySelectorAll('.featureTitle')
+ const featureContent = document.querySelectorAll('.featureContent')
+ const content = data[0].content
+ featureImage[0].style.backgroundImage = `url("${data[0].media}")`
+ featureTitle[0].innerHTML = `${data[0].title}`
+ featureContent[0].innerHTML = `${content.substring(0, 400)}`
+ })
}
-createArticles();
-let arrowRight = document.getElementById('clientArrowRigth');
-let arrowLeft = document.getElementById('clientArrowLeft');
-let newsPosition = 0;
-let newsLimit = 0;
-let spawnStyle = getComputedStyle(clientSpawn).columnGap;
-let columnGap = spawnStyle.slice(0, 2);
-
+createArticles()
+const arrowRight = document.getElementById('clientArrowRigth')
+const arrowLeft = document.getElementById('clientArrowLeft')
+let newsPosition = 0
+let newsLimit = 0
+const spawnStyle = getComputedStyle(clientSpawn).columnGap
+const columnGap = spawnStyle.slice(0, 2)
arrowRight.addEventListener('click', () => {
- let newsMove = clientContainer[0].offsetWidth;
- if (newsLimit === dataLength) {
- console.log('limit reached');
- } else {
- newsLimit++;
- newsPosition = newsPosition - newsMove;
- clientSpawn.style.transform = `translateX(${newsPosition - columnGap}px)`;
- arrowLeft.style.display = 'grid';
- }
-});
+ const newsMove = clientContainer[0].offsetWidth
+ if (newsLimit === dataLength) {
+ console.log('limit reached')
+ } else {
+ newsLimit++
+ newsPosition = newsPosition - newsMove
+ clientSpawn.style.transform = `translateX(${newsPosition - columnGap}px)`
+ arrowLeft.style.display = 'grid'
+ }
+})
arrowLeft.addEventListener('click', () => {
- let newsMove = clientContainer[0].offsetWidth;
- if (newsLimit === 0) {
- } else {
- newsLimit--;
- newsPosition = newsPosition + newsMove;
- clientSpawn.style.transform = `translateX(${newsPosition - columnGap + 10}px)`;
- }
-
-});
+ const newsMove = clientContainer[0].offsetWidth
+ if (newsLimit !== 0) {
+ newsLimit--
+ newsPosition = newsPosition + newsMove
+ clientSpawn.style.transform = `translateX(${newsPosition - columnGap + 10}px)`
+ }
+})
addEventListener('resize', () => {
- clientSpawn.style.transform = `translateX(0px)`;
- newsPosition = 0;
- newsLimit = 0;
-});
-
-let clientTournamentSpawn = document.getElementById('tournamentSpawn');
-function createTournaments() {
- getTournament()
- .then(data => {
- clientTournamentSpawn.insertAdjacentHTML('beforeend', `${data[0].content}`);
- return data;
- });
+ clientSpawn.style.transform = 'translateX(0px)'
+ newsPosition = 0
+ newsLimit = 0
+})
+
+const clientTournamentSpawn = document.getElementById('tournamentSpawn')
+function createTournaments () {
+ getTournament()
+ .then(data => {
+ clientTournamentSpawn.insertAdjacentHTML('beforeend', `${data[0].content}`)
+ return data
+ })
}
-createTournaments();
-
-
-
+createTournaments()
-let links = document.getElementsByTagName('a');
-let linksLength = links.length;
-for (let i= 0; i < linksLength; i++) {
- links[i].target = '_blank';
+const links = document.getElementsByTagName('a')
+const linksLength = links.length
+for (let i = 0; i < linksLength; i++) {
+ links[i].target = '_blank'
}
diff --git a/src/frontend/js/entrypoint/play.js b/src/frontend/js/entrypoint/play.js
index 92e6bae8..7dc5c663 100644
--- a/src/frontend/js/entrypoint/play.js
+++ b/src/frontend/js/entrypoint/play.js
@@ -1,8 +1,8 @@
-import {Octokit} from "octokit";
+import { Octokit } from 'octokit'
const githubOrg = 'faforever'
const githubRepository = 'downlords-faf-client'
-const githubFallbackUrl = 'https://github.com/FAForever/downlords-faf-client/releases/latest';
+const githubFallbackUrl = 'https://github.com/FAForever/downlords-faf-client/releases/latest'
const downloadButtonId = 'faf-client-download'
const startDownloadFile = (url) => window.location.assign(url)
@@ -10,27 +10,27 @@ const startDownloadFile = (url) => window.location.assign(url)
const openFallbackDownloadPage = () => open(githubFallbackUrl, '_blank')
const getWindowsDownloadLink = (response) => {
- let [exeAsset] = response?.data?.assets?.filter?.(function (asset) {
+ const [exeAsset] = response?.data?.assets?.filter?.(function (asset) {
return asset.name?.includes?.('.exe')
}) ?? []
if (exeAsset) {
try {
- new URL(exeAsset.browser_download_url ?? false)
-
- return exeAsset.browser_download_url
+ const url = new URL(exeAsset.browser_download_url ?? false)
+
+ return url.toString()
} catch (e) {}
}
-
+
return false
}
const onGithubResponse = (response) => {
const windowsDownloadLink = getWindowsDownloadLink(response)
-
+
if (windowsDownloadLink) {
startDownloadFile(windowsDownloadLink)
-
+
return
}
@@ -50,5 +50,5 @@ const onDownloadButtonClicked = (event) => {
const downloadButton = document.getElementById(downloadButtonId)
if (downloadButton) {
- downloadButton.addEventListener("click", onDownloadButtonClicked)
+ downloadButton.addEventListener('click', onDownloadButtonClicked)
}
diff --git a/src/frontend/js/entrypoint/report.js b/src/frontend/js/entrypoint/report.js
index 53a2e224..6dd86f26 100644
--- a/src/frontend/js/entrypoint/report.js
+++ b/src/frontend/js/entrypoint/report.js
@@ -1,46 +1,48 @@
-// load..
-const memberList = JSON.parse(reportable_members);
-const searchBar = $("#offender_0");
-addAwesompleteListener(searchBar);
+import $ from 'jquery'
+import Awesomplete from 'awesomplete'
+const memberList = JSON.parse(window.reportable_members)
+const searchBar = $('#offender_0')
+addAwesompleteListener(searchBar)
-$( "#add_offender" ).click(function() {
- addOffender();
-});
+$('#add_offender').click(function () {
+ addOffender()
+})
-function addAwesompleteListener(element ){
+function addAwesompleteListener (element) {
// Show label but insert value into the input:
- new Awesomplete(element[ 0 ], {
+ /* eslint-disable no-new */
+ new Awesomplete(element[0], {
list: memberList
- });
- element[ 0 ].addEventListener('awesomplete-select', function(e){});
- element[ 0 ].addEventListener('awesomplete-selectcomplete', function(e){
- const text = e.text;
- element.val(text);
- });
+ })
+ element[0].addEventListener('awesomplete-select', function (e) {})
+ element[0].addEventListener('awesomplete-selectcomplete', function (e) {
+ const text = e.text
+ element.val(text)
+ })
}
-function addOffender(){
- const numberOfOffenders = $(".offender_name").length;
- for (i = 0; i <= numberOfOffenders; i++){
- if (!$("#offender_"+i).length){
- const element = $("#offender_"+(i-1)).clone(false)
- element.insertAfter($("#offender_"+(i-1)));
- element.attr("id", "offender_"+i);
- element.attr("name", "offender_"+i);
- element.val("");
- addAwesompleteListener(element);
- return element;
+function addOffender () {
+ const numberOfOffenders = $('.offender_name').length
+ for (let i = 0; i <= numberOfOffenders; i++) {
+ if (!$('#offender_' + i).length) {
+ const element = $('#offender_' + (i - 1)).clone(false)
+ element.insertAfter($('#offender_' + (i - 1)))
+ element.attr('id', 'offender_' + i)
+ element.attr('name', 'offender_' + i)
+ element.val('')
+ addAwesompleteListener(element)
+ return element
}
}
}
-const offenders = JSON.parse(offenders_names);
-for (k in offenders){
- const offender = offenders[k];
- if (k == 0){
- searchBar.val(offender);
- continue;
+const offenders = JSON.parse(window.offenders_names)
+for (const k in offenders) {
+ const offender = offenders[k]
+ if (k === 0) {
+ searchBar.val(offender)
+ continue
}
- addOffender().val(offender);
+ addOffender().val(offender)
}
diff --git a/templates/views/account/report.pug b/templates/views/account/report.pug
index 540eed1d..319c76fc 100755
--- a/templates/views/account/report.pug
+++ b/templates/views/account/report.pug
@@ -106,7 +106,7 @@ block content
block js
script(type='text/javascript').
- const reportable_members = '!{JSON.stringify(reportable_members)}';
- const offenders_names = '!{JSON.stringify(offenders_names)}';
+ window.reportable_members = '!{JSON.stringify(reportable_members)}';
+ window.offenders_names = '!{JSON.stringify(offenders_names)}';
script(src=webpackAssetJS('report'))
diff --git a/templates/views/donation.pug b/templates/views/donation.pug
index e6c09001..2d42c1e7 100644
--- a/templates/views/donation.pug
+++ b/templates/views/donation.pug
@@ -27,9 +27,5 @@ block content
block js
- script(src="https://code.highcharts.com/highcharts.js")
- script(src="https://code.highcharts.com/modules/exporting.js")
- script(src="https://code.highcharts.com/modules/export-data.js")
- script(src="https://code.highcharts.com/modules/accessibility.js")
script(src=webpackAssetJS('donation'))
diff --git a/tests/LeaderboardService.test.js b/tests/LeaderboardService.test.js
index f2e792f2..465e63c5 100644
--- a/tests/LeaderboardService.test.js
+++ b/tests/LeaderboardService.test.js
@@ -1,12 +1,12 @@
-const LeaderboardService = require("../lib/LeaderboardService")
-const LeaderboardRepository = require("../lib/LeaderboardRepository")
-const NodeCache = require("node-cache")
-const {Axios} = require("axios");
+const LeaderboardService = require('../lib/LeaderboardService')
+const LeaderboardRepository = require('../lib/LeaderboardRepository')
+const NodeCache = require('node-cache')
+const { Axios } = require('axios')
-jest.mock("axios")
+jest.mock('axios')
let leaderboardService = null
-let axios = new Axios()
+const axios = new Axios()
const fakeEntry = JSON.stringify({
data: [
{
@@ -53,22 +53,22 @@ test('malformed empty response', async () => {
})
test('malformed response data missing', async () => {
- axios.get.mockImplementationOnce(() => Promise.resolve({ status: 200, data: JSON.stringify({included: []}) }))
+ axios.get.mockImplementationOnce(() => Promise.resolve({ status: 200, data: JSON.stringify({ included: [] }) }))
await expect(leaderboardService.getLeaderboard(0)).rejects.toThrowError('LeaderboardRepository::mapResponse malformed response, expected "data"')
})
test('malformed response included missing', async () => {
- axios.get.mockImplementationOnce(() => Promise.resolve({ status: 200, data: JSON.stringify({data: [{}]}) }))
+ axios.get.mockImplementationOnce(() => Promise.resolve({ status: 200, data: JSON.stringify({ data: [{}] }) }))
await expect(leaderboardService.getLeaderboard(0)).rejects.toThrowError('LeaderboardRepository::mapResponse malformed response, expected "included"')
})
test('empty response will log and not throw an error', async () => {
- const warn = jest.spyOn(console, "log").mockImplementationOnce(() => {});
- axios.get.mockImplementationOnce(() => Promise.resolve({ status: 200, data: JSON.stringify({data: []}) }))
+ const warn = jest.spyOn(console, 'log').mockImplementationOnce(() => {})
+ axios.get.mockImplementationOnce(() => Promise.resolve({ status: 200, data: JSON.stringify({ data: [] }) }))
await leaderboardService.getLeaderboard(0)
expect(warn).toBeCalledWith('[info] leaderboard empty')
-});
+})
test('response is mapped correctly', async () => {
axios.get.mockImplementationOnce(() => Promise.resolve({ status: 200, data: fakeEntry }))
@@ -80,55 +80,55 @@ test('response is mapped correctly', async () => {
expect(result[0].wonGames).toBe(30)
expect(result[0].date).toBe('2023-12-1')
expect(result[0].label).toBe('player1')
-});
+})
test('only numbers valid', async () => {
- expect.assertions(1);
-
+ expect.assertions(1)
+
try {
await leaderboardService.getLeaderboard()
} catch (e) {
expect(e.toString()).toBe('Error: LeaderboardService:getLeaderboard id must be a number')
}
-});
+})
test('timeout for cache creation throws an error', async () => {
- expect.assertions(1);
+ expect.assertions(1)
axios.get.mockImplementationOnce(() => Promise.resolve({ status: 200, data: fakeEntry }))
leaderboardService.mutexService.locked = true
leaderboardService.getLeaderboard(0).then(() => {}).catch((e) => {
expect(e.toString()).toBe('Error: MutexService timeout reached')
})
-
+
jest.runOnlyPendingTimers()
-});
+})
test('full scenario', async () => {
- const cacheSetSpy = jest.spyOn(leaderboardService.cacheService, 'set');
+ const cacheSetSpy = jest.spyOn(leaderboardService.cacheService, 'set')
const mock = axios.get.mockImplementation(() => Promise.resolve({ status: 200, data: fakeEntry }))
-
- // starting two promises simultaneously
+
+ // starting two promises simultaneously
const creatingTheCache = leaderboardService.getLeaderboard(0)
const waitingForCache = leaderboardService.getLeaderboard(0)
-
+
await Promise.all([creatingTheCache, waitingForCache])
// start another one, that will get the cache directly
await leaderboardService.getLeaderboard(0)
expect(mock.mock.calls.length).toBe(1)
- expect(cacheSetSpy).toHaveBeenCalledTimes(1);
-
+ expect(cacheSetSpy).toHaveBeenCalledTimes(1)
+
const date = new Date()
date.setSeconds(date.getSeconds() + (60 * 60) + 1)
- jest.setSystemTime(date);
-
+ jest.setSystemTime(date)
+
// start another with when the cache is stale
await leaderboardService.getLeaderboard(0)
- expect(cacheSetSpy).toHaveBeenCalledTimes(2);
+ expect(cacheSetSpy).toHaveBeenCalledTimes(2)
expect(mock.mock.calls.length).toBe(2)
- jest.setSystemTime(new Date());
+ jest.setSystemTime(new Date())
cacheSetSpy.mockReset()
-});
+})
diff --git a/tests/MutexService.test.js b/tests/MutexService.test.js
index 47d389c2..62e8d0ca 100644
--- a/tests/MutexService.test.js
+++ b/tests/MutexService.test.js
@@ -1,8 +1,8 @@
-const {AcquireTimeoutError, MutexService} = require('../lib/MutexService')
+const { AcquireTimeoutError, MutexService } = require('../lib/MutexService')
test('release will unlock the queue', async () => {
const mutexService = new MutexService()
expect(mutexService.locked).toBe(false)
-
+
await mutexService.acquire(() => {
expect(mutexService.locked).toBe(true)
})
@@ -14,12 +14,12 @@ test('call lock twice will fill the queue', async () => {
let oneCalled = false
let twoCalled = false
const mutexService = new MutexService()
- const one = mutexService.acquire(() => oneCalled = true)
- const two = mutexService.acquire(() => twoCalled = true)
+ const one = mutexService.acquire(() => { oneCalled = true })
+ const two = mutexService.acquire(() => { twoCalled = true })
expect(mutexService.queue).toHaveLength(1)
expect(mutexService.locked).toBe(true)
-
+
await one
await two
expect(oneCalled).toBe(true)
@@ -29,10 +29,10 @@ test('call lock twice will fill the queue', async () => {
})
test('lock timeout will trow an error if locked by another "process" for too long', async () => {
- expect.assertions(1);
-
+ expect.assertions(1)
+
const mutexService = new MutexService()
-
+
await mutexService.acquire(async () => {
try {
await mutexService.acquire(() => {}, 1)
@@ -40,10 +40,10 @@ test('lock timeout will trow an error if locked by another "process" for too lon
expect(e).toBeInstanceOf(AcquireTimeoutError)
}
})
-});
+})
test('lock timeout will remove it from queue', async () => {
- expect.assertions(2);
+ expect.assertions(2)
const mutexService = new MutexService()
@@ -53,9 +53,7 @@ test('lock timeout will remove it from queue', async () => {
}, 1)
} catch (e) {
expect(e).toBeInstanceOf(AcquireTimeoutError)
- expect(mutexService.queue).toHaveLength(0);
+ expect(mutexService.queue).toHaveLength(0)
}
-
})
})
-
diff --git a/tests/helpers/PassportMock.js b/tests/helpers/PassportMock.js
index da6d35a9..89005e50 100644
--- a/tests/helpers/PassportMock.js
+++ b/tests/helpers/PassportMock.js
@@ -1,13 +1,13 @@
const passport = require('passport')
const StrategyMock = require('./StrategyMock')
-module.exports = function(app, options) {
+module.exports = function (app, options) {
passport.use(new StrategyMock(options))
-
- app.get('/mock-login' ,
- passport.authenticate('mock', {failureRedirect: '/mock/login', failureFlash: true}),
+
+ app.get('/mock-login',
+ passport.authenticate('mock', { failureRedirect: '/mock/login', failureFlash: true }),
(req, res) => {
res.redirect('/')
}
)
-};
+}
diff --git a/tests/helpers/StrategyMock.js b/tests/helpers/StrategyMock.js
index e2950bf1..73b5a240 100644
--- a/tests/helpers/StrategyMock.js
+++ b/tests/helpers/StrategyMock.js
@@ -1,7 +1,7 @@
const passport = require('passport')
const util = require('util')
-function StrategyMock(options) {
+function StrategyMock (options) {
this.name = 'mock'
this.passAuthentication = options.passAuthentication ?? true
this.user = options.user || {
@@ -17,7 +17,7 @@ function StrategyMock(options) {
util.inherits(StrategyMock, passport.Strategy)
-StrategyMock.prototype.authenticate = function authenticate(req) {
+StrategyMock.prototype.authenticate = function authenticate (req) {
if (this.passAuthentication) {
return this.success(this.user)
}
diff --git a/tests/integration/IsAuthenticatedMiddleware.test.js b/tests/integration/IsAuthenticatedMiddleware.test.js
index 3a0c437a..765b4a6e 100644
--- a/tests/integration/IsAuthenticatedMiddleware.test.js
+++ b/tests/integration/IsAuthenticatedMiddleware.test.js
@@ -1,31 +1,30 @@
-const express = require('express')
+const Express = require('express')
const middlewares = require('../../routes/middleware')
-const supertestSession = require('supertest-session');
-const fafApp = require("../../fafApp");
+const supertestSession = require('supertest-session')
+const fafApp = require('../../fafApp')
let testApp = null
let testSession = null
beforeEach(() => {
- const app = new express()
+ const app = new Express()
fafApp.setup(app)
testSession = supertestSession(app)
testApp = app
})
describe('Authenticate Middleware', function () {
-
test('route is protected and redirects to "/login"', async () => {
testApp.get('/', middlewares.isAuthenticated(), () => {
fail('did not protect')
})
const res = await testSession.get('/')
-
+
expect(res.status).toBe(302)
- expect(res.headers['location']).toBe('/login')
+ expect(res.headers.location).toBe('/login')
})
-
+
test('default url after login', async () => {
testApp.get('/', middlewares.isAuthenticated(), () => {
fail('did not protect')
@@ -38,7 +37,7 @@ describe('Authenticate Middleware', function () {
await testSession.get('/')
const res = await testSession.get('/redirect-me')
expect(res.status).toBe(302)
- expect(res.headers['location']).toBe('/')
+ expect(res.headers.location).toBe('/')
})
test('custom url after login', async () => {
@@ -49,11 +48,11 @@ describe('Authenticate Middleware', function () {
testApp.get('/redirect-me', (req, res) => {
res.redirect(req.session.returnTo)
})
-
+
await testSession.get('/')
const res = await testSession.get('/redirect-me')
expect(res.status).toBe(302)
- expect(res.headers['location']).toBe('/go-here')
+ expect(res.headers.location).toBe('/go-here')
})
test('api url flag return 401', async () => {
@@ -63,7 +62,7 @@ describe('Authenticate Middleware', function () {
const res = await testSession.get('/')
expect(res.status).toBe(401)
- expect(res.body).toEqual({error: 'Unauthorized'})
+ expect(res.body).toEqual({ error: 'Unauthorized' })
})
test('identifies xhr request', async () => {
@@ -73,7 +72,7 @@ describe('Authenticate Middleware', function () {
const res = await testSession.get('/').set('X-Requested-With', 'XMLHttpRequest')
expect(res.status).toBe(401)
- expect(res.body).toEqual({error: 'Unauthorized'})
+ expect(res.body).toEqual({ error: 'Unauthorized' })
})
test('identifies json accept request', async () => {
@@ -83,6 +82,6 @@ describe('Authenticate Middleware', function () {
const res = await testSession.get('/').set('Accept', 'application/json')
expect(res.status).toBe(401)
- expect(res.body).toEqual({error: 'Unauthorized'})
+ expect(res.body).toEqual({ error: 'Unauthorized' })
})
})
diff --git a/tests/integration/NewsRouter.test.js b/tests/integration/NewsRouter.test.js
index 4c27dc88..e85244d6 100644
--- a/tests/integration/NewsRouter.test.js
+++ b/tests/integration/NewsRouter.test.js
@@ -1,38 +1,37 @@
-const express = require('express')
-const supertestSession = require("supertest-session");
+const Express = require('express')
+const supertestSession = require('supertest-session')
const fafApp = require('../../fafApp')
let testSession = null
beforeEach(() => {
- const app = new express()
+ const app = new Express()
fafApp.setup(app)
fafApp.loadRouters(app)
-
+
testSession = supertestSession(app)
})
describe('News Routes', function () {
-
test('responds to /', async () => {
- const res = await testSession.get('/news');
- expect(res.header['content-type']).toBe('text/html; charset=utf-8');
- expect(res.statusCode).toBe(200);
- expect(res.text).toContain('Welcome to the patchnotes for the 3750 patch.');
- expect(res.text).toContain('New FAF Website');
- expect(res.text).toContain('Game version 3738');
- expect(res.text).toContain('Weapon Target Checking Intervals');
- });
+ const res = await testSession.get('/news')
+ expect(res.header['content-type']).toBe('text/html; charset=utf-8')
+ expect(res.statusCode).toBe(200)
+ expect(res.text).toContain('Welcome to the patchnotes for the 3750 patch.')
+ expect(res.text).toContain('New FAF Website')
+ expect(res.text).toContain('Game version 3738')
+ expect(res.text).toContain('Weapon Target Checking Intervals')
+ })
test('responds to /:slug', async () => {
- const res = await testSession.get('/news/balance-patch-3750-is-live');
- expect(res.header['content-type']).toBe('text/html; charset=utf-8');
- expect(res.statusCode).toBe(200);
- expect(res.text).toContain('Welcome to the patchnotes for the 3750 patch.');
- });
+ const res = await testSession.get('/news/balance-patch-3750-is-live')
+ expect(res.header['content-type']).toBe('text/html; charset=utf-8')
+ expect(res.statusCode).toBe(200)
+ expect(res.text).toContain('Welcome to the patchnotes for the 3750 patch.')
+ })
test('responds to /:slug with redirect if called with old slug', async () => {
- const res = await testSession.get('/news/Balance-Patch-3750-Is-Live');
- expect(res.statusCode).toBe(301);
- expect(res.header['location']).toBe('balance-patch-3750-is-live');
- });
-});
+ const res = await testSession.get('/news/Balance-Patch-3750-Is-Live')
+ expect(res.statusCode).toBe(301)
+ expect(res.header.location).toBe('balance-patch-3750-is-live')
+ })
+})
diff --git a/tests/integration/accountRouter.test.js b/tests/integration/accountRouter.test.js
index 60d80c88..611652ed 100644
--- a/tests/integration/accountRouter.test.js
+++ b/tests/integration/accountRouter.test.js
@@ -1,10 +1,10 @@
-const express = require('express')
-const supertestSession = require("supertest-session")
+const Express = require('express')
+const supertestSession = require('supertest-session')
const fafApp = require('../../fafApp')
let testSession = null
beforeEach(() => {
- const app = new express()
+ const app = new Express()
fafApp.setup(app)
fafApp.loadRouters(app)
testSession = supertestSession(app)
@@ -18,18 +18,17 @@ describe('Account Routes', function () {
'/account/activate'
]
- test.each(publicUrls)("responds with OK to %p", (async (route) => {
+ test.each(publicUrls)('responds with OK to %p', async (route) => {
const res = await testSession.get(route)
expect(res.statusCode).toBe(200)
- }))
-
+ })
+
test('redirect old pw-reset routes', async () => {
const response = await testSession.get('/account/password/reset')
expect(response.statusCode).toBe(302)
expect(response.headers.location).toBe('/account/requestPasswordReset')
})
-
-
+
const protectedUrls = [
'/account/linkGog',
'/account/report',
@@ -42,8 +41,8 @@ describe('Account Routes', function () {
'/account/create'
]
- test.each(protectedUrls)("%p responds with redirect to login", (async (route) => {
+ test.each(protectedUrls)('%p responds with redirect to login', async (route) => {
const res = await testSession.get(route)
expect(res.statusCode).toBe(302)
- }))
+ })
})
diff --git a/tests/integration/clanRouter.test.js b/tests/integration/clanRouter.test.js
index 90ff00af..dbd4cab2 100644
--- a/tests/integration/clanRouter.test.js
+++ b/tests/integration/clanRouter.test.js
@@ -1,10 +1,10 @@
-const express = require('express')
-const supertestSession = require("supertest-session");
+const Express = require('express')
+const supertestSession = require('supertest-session')
const fafApp = require('../../fafApp')
let testSession = null
beforeEach(async () => {
- const app = new express()
+ const app = new Express()
fafApp.setup(app)
fafApp.loadRouters(app)
testSession = supertestSession(app)
@@ -13,9 +13,9 @@ beforeEach(async () => {
describe('Clan Routes', function () {
const arr = ['/clans', '/clans/everything']
- test.each(arr)("responds with 503 to %p", (async (route) => {
+ test.each(arr)('responds with 503 to %p', async (route) => {
const res = await testSession.get(route)
expect(res.statusCode).toBe(503)
- expect(res.text).toContain('Sorry commanders, we failed to build enough pgens and are now in a tech upgrade');
- }))
+ expect(res.text).toContain('Sorry commanders, we failed to build enough pgens and are now in a tech upgrade')
+ })
})
diff --git a/tests/integration/defaultRouter.test.js b/tests/integration/defaultRouter.test.js
index d0a1f926..ca2b5629 100644
--- a/tests/integration/defaultRouter.test.js
+++ b/tests/integration/defaultRouter.test.js
@@ -1,10 +1,10 @@
-const express = require('express')
-const supertestSession = require("supertest-session")
+const Express = require('express')
+const supertestSession = require('supertest-session')
const fafApp = require('../../fafApp')
let testSession = null
beforeEach(() => {
- const app = new express()
+ const app = new Express()
fafApp.setup(app)
fafApp.loadRouters(app)
testSession = supertestSession(app)
@@ -26,8 +26,8 @@ describe('Default Routes', function () {
'/play'
]
- test.each(arr)("responds with OK to %p", (async (route) => {
+ test.each(arr)('responds with OK to %p', async (route) => {
const res = await testSession.get(route)
expect(res.statusCode).toBe(200)
- }))
+ })
})
diff --git a/tests/integration/leaderboardRouter.test.js b/tests/integration/leaderboardRouter.test.js
index 1147eb7f..7815414d 100644
--- a/tests/integration/leaderboardRouter.test.js
+++ b/tests/integration/leaderboardRouter.test.js
@@ -1,19 +1,18 @@
-const express = require('express')
-const supertestSession = require("supertest-session");
+const Express = require('express')
+const supertestSession = require('supertest-session')
const fafApp = require('../../fafApp')
const passportMock = require('../helpers/PassportMock')
let testSession = null
beforeEach(() => {
- const app = new express()
+ const app = new Express()
fafApp.setup(app)
- passportMock(app, {passAuthentication: true})
+ passportMock(app, { passAuthentication: true })
fafApp.loadRouters(app)
testSession = supertestSession(app)
})
describe('Leaderboard Routes', function () {
-
test('authentication required for main page', async () => {
let response = await testSession.get('/leaderboards')
expect(response.status).toBe(302)
@@ -23,30 +22,30 @@ describe('Leaderboard Routes', function () {
response = await testSession.get('/leaderboards')
expect(response.status).toBe(200)
})
-
+
test('authentication required for datasets', async () => {
- let response = await testSession.get('/leaderboards/1v1.json')
+ const response = await testSession.get('/leaderboards/1v1.json')
expect(response.status).toBe(401)
})
test('fails with 404 on unknown leaderboard', async () => {
await testSession.get('/mock-login')
- let response = await testSession.get('/leaderboards/this-is-not-valid.json')
+ const response = await testSession.get('/leaderboards/this-is-not-valid.json')
expect(response.status).toBe(404)
- expect(response.body).toEqual({error: 'Leaderboard "this-is-not-valid" does not exist'})
+ expect(response.body).toEqual({ error: 'Leaderboard "this-is-not-valid" does not exist' })
})
const arr = [
'/leaderboards/1v1.json',
'/leaderboards/2v2.json',
'/leaderboards/4v4.json',
- '/leaderboards/global.json',
+ '/leaderboards/global.json'
]
- test.each(arr)("responds with OK to %p", (async (route) => {
+ test.each(arr)('responds with OK to %p', async (route) => {
await testSession.get('/mock-login')
-
+
const res = await testSession.get(route)
expect(res.statusCode).toBe(200)
- }))
+ })
})
diff --git a/tests/integration/markdownRouter.test.js b/tests/integration/markdownRouter.test.js
index d6174646..6458a661 100644
--- a/tests/integration/markdownRouter.test.js
+++ b/tests/integration/markdownRouter.test.js
@@ -1,10 +1,10 @@
-const express = require('express')
-const supertestSession = require("supertest-session");
+const Express = require('express')
+const supertestSession = require('supertest-session')
const fafApp = require('../../fafApp')
let testSession = null
beforeEach(() => {
- const app = new express()
+ const app = new Express()
fafApp.setup(app)
fafApp.loadRouters(app)
testSession = supertestSession(app)
@@ -12,18 +12,18 @@ beforeEach(() => {
describe('Privacy And TOS Routes', function () {
const arr = [
- '/privacy',
- '/privacy-fr',
- '/privacy-ru',
- '/tos',
- '/tos-fr',
- '/tos-ru',
- '/rules',
- '/cg'
+ '/privacy',
+ '/privacy-fr',
+ '/privacy-ru',
+ '/tos',
+ '/tos-fr',
+ '/tos-ru',
+ '/rules',
+ '/cg'
]
- test.each(arr)("responds with OK to %p", (async (route) => {
+ test.each(arr)('responds with OK to %p', async (route) => {
const res = await testSession.get(route)
expect(res.statusCode).toBe(200)
- }));
+ })
})
diff --git a/tests/setup.js b/tests/setup.js
index 3790bde5..0a417bba 100644
--- a/tests/setup.js
+++ b/tests/setup.js
@@ -1,34 +1,34 @@
-const fs = require("fs");
-const wordpressService = require("../lib/WordpressService");
-const leaderboardService = require("../lib/LeaderboardService");
+const fs = require('fs')
+const wordpressService = require('../lib/WordpressService')
+const leaderboardService = require('../lib/LeaderboardService')
beforeEach(() => {
- const newsFile = JSON.parse(fs.readFileSync('tests/integration/testData/news.json',{encoding:'utf8', flag:'r'}))
- jest.spyOn(wordpressService.prototype, 'getNews').mockResolvedValue(newsFile);
+ const newsFile = JSON.parse(fs.readFileSync('tests/integration/testData/news.json', { encoding: 'utf8', flag: 'r' }))
+ jest.spyOn(wordpressService.prototype, 'getNews').mockResolvedValue(newsFile)
- const tnFile = JSON.parse(fs.readFileSync('tests/integration/testData/tournament-news.json',{encoding:'utf8', flag:'r'}))
- jest.spyOn(wordpressService.prototype, 'getTournamentNews').mockResolvedValue(tnFile);
+ const tnFile = JSON.parse(fs.readFileSync('tests/integration/testData/tournament-news.json', { encoding: 'utf8', flag: 'r' }))
+ jest.spyOn(wordpressService.prototype, 'getTournamentNews').mockResolvedValue(tnFile)
- const ccFile = JSON.parse(fs.readFileSync('tests/integration/testData/content-creators.json',{encoding:'utf8', flag:'r'}))
- jest.spyOn(wordpressService.prototype, 'getContentCreators').mockResolvedValue(ccFile);
+ const ccFile = JSON.parse(fs.readFileSync('tests/integration/testData/content-creators.json', { encoding: 'utf8', flag: 'r' }))
+ jest.spyOn(wordpressService.prototype, 'getContentCreators').mockResolvedValue(ccFile)
- const ftFile = JSON.parse(fs.readFileSync('tests/integration/testData/faf-teams.json',{encoding:'utf8', flag:'r'}))
- jest.spyOn(wordpressService.prototype, 'getFafTeams').mockResolvedValue(ftFile);
+ const ftFile = JSON.parse(fs.readFileSync('tests/integration/testData/faf-teams.json', { encoding: 'utf8', flag: 'r' }))
+ jest.spyOn(wordpressService.prototype, 'getFafTeams').mockResolvedValue(ftFile)
+
+ const nhFile = JSON.parse(fs.readFileSync('tests/integration/testData/newshub.json', { encoding: 'utf8', flag: 'r' }))
+ jest.spyOn(wordpressService.prototype, 'getNewshub').mockResolvedValue(nhFile)
- const nhFile = JSON.parse(fs.readFileSync('tests/integration/testData/newshub.json',{encoding:'utf8', flag:'r'}))
- jest.spyOn(wordpressService.prototype, 'getNewshub').mockResolvedValue(nhFile);
-
jest.spyOn(leaderboardService.prototype, 'getLeaderboard').mockImplementation((id) => {
const mapping = {
1: 'global',
2: '1v1',
3: '2v2',
- 4: '4v4',
+ 4: '4v4'
}
if (id in mapping) {
- return JSON.parse(fs.readFileSync('tests/integration/testData/leaderboard/' + mapping[id] + '.json',{encoding:'utf8', flag:'r'}))
+ return JSON.parse(fs.readFileSync('tests/integration/testData/leaderboard/' + mapping[id] + '.json', { encoding: 'utf8', flag: 'r' }))
}
-
+
throw new Error('do we need to change the mock?')
})
})
diff --git a/yarn.lock b/yarn.lock
index d89a1f37..0ee1a76b 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -4157,6 +4157,11 @@ hexoid@^1.0.0:
resolved "https://registry.yarnpkg.com/hexoid/-/hexoid-1.0.0.tgz#ad10c6573fb907de23d9ec63a711267d9dc9bc18"
integrity sha512-QFLV0taWQOZtvIRIAdBChesmogZrtuXvVWsFHZTk2SU+anspqZ2vMnoLg7IE1+Uk16N19APic1BuF8bC8c2m5g==
+highcharts@^11.2.0:
+ version "11.2.0"
+ resolved "https://registry.yarnpkg.com/highcharts/-/highcharts-11.2.0.tgz#32ddc885b1c7a7d438df30c6d751c28991b16616"
+ integrity sha512-9i650YK7ZBA1Mgtr3avMkLVCAI45RQvYnwi+eHsdFSaBGuQN6BHoa4j4lMkSJLv0V4LISTK1z7J7G82Lzd7zwg==
+
highlight-es@^1.0.0:
version "1.0.3"
resolved "https://registry.yarnpkg.com/highlight-es/-/highlight-es-1.0.3.tgz#12abc300a27e686f6f18010134e3a5c6d2fe6930"
@@ -5194,6 +5199,11 @@ jit-grunt@0.10.0:
resolved "https://registry.yarnpkg.com/jit-grunt/-/jit-grunt-0.10.0.tgz#008c3a7fe1e96bd0d84e260ea1fa1783457f79c2"
integrity sha512-eT/f4c9wgZ3buXB7X1JY1w6uNtAV0bhrbOGf/mFmBb0CDNLUETJ/VRoydayWOI54tOoam0cz9RooVCn3QY1WoA==
+jquery@^3.7.1:
+ version "3.7.1"
+ resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.7.1.tgz#083ef98927c9a6a74d05a6af02806566d16274de"
+ integrity sha512-m4avr8yL8kmFN8psrbFFFmB/If14iN5o9nw/NgnnM+kybDJpRsAynV2BsfpTYrTRysYUdADVD7CkUUizgkpLfg==
+
js-stringify@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/js-stringify/-/js-stringify-1.0.2.tgz#1736fddfd9724f28a3682adc6230ae7e4e9679db"