diff --git a/Gruntfile.js b/Gruntfile.js index 747fb360..ef46fabc 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -23,6 +23,7 @@ module.exports = function(grunt) { grunt.registerTask('prod', [ 'sass:dist', 'concat:js', - 'uglify:dist' + 'uglify:dist', + 'copy' ]); }; diff --git a/grunt/concurrent.js b/grunt/concurrent.js index 4f0b4a7d..c83f66da 100644 --- a/grunt/concurrent.js +++ b/grunt/concurrent.js @@ -1,6 +1,6 @@ module.exports = { dev: { - tasks: ['nodemon', 'concat', 'watch'], + tasks: ['nodemon', 'concat', 'watch', 'copy'], options: { logConcurrentOutput: true } diff --git a/grunt/copy.js b/grunt/copy.js new file mode 100644 index 00000000..c19015d4 --- /dev/null +++ b/grunt/copy.js @@ -0,0 +1,24 @@ +module.exports = { + js: { + files:[ + { + expand: true, + cwd: 'node_modules/simple-datatables/dist', + src: 'module.js', + dest: 'public/js/', + rename: function(dest, src) { + return dest + 'simple-datatables.js' + } + }, + { + expand: true, + cwd: 'node_modules/simple-datatables/dist', + src: 'style.css', + dest: 'public/styles/css/', + rename: function(dest, src) { + return dest + 'simple-datatables.css' + } + } + ] + } +} diff --git a/lib/clan/ClanRepository.js b/lib/clan/ClanRepository.js index a02de8cc..da78469b 100644 --- a/lib/clan/ClanRepository.js +++ b/lib/clan/ClanRepository.js @@ -124,7 +124,7 @@ class ClanRepository { updateTime: clanRaw.updateTime, founder: null, leader: null, - memberships: [], + memberships: {}, } let members = {}; diff --git a/lib/clan/ClanService.js b/lib/clan/ClanService.js index 50bd6bfc..d96ebcc3 100644 --- a/lib/clan/ClanService.js +++ b/lib/clan/ClanService.js @@ -1,5 +1,5 @@ const {MutexService} = require("../MutexService"); -const clanTTL = 60 * 60 +const clanTTL = 60 * 5 class ClanService { constructor(cacheService, clanRepository, lockTimeout = 3000) { @@ -14,7 +14,7 @@ class ClanService { } async getClan(id) { - return await this.clanRepository.fetchClan(id) + return this.clanRepository.fetchClan(id) } async getAll() { diff --git a/package.json b/package.json index 70591b1d..e2e611a1 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "express": "^4.18.1", "express-session": "^1.17.3", "express-validator": "7.0.1", + "grunt-contrib-copy": "^1.0.0", "moment": "^2.29.4", "node-cache": "^5.1.2", "node-fetch": "^2.6.7", @@ -21,6 +22,7 @@ "request": "2.88.2", "session-file-store": "^1.5.0", "showdown": "^2.1.0", + "simple-datatables": "^8.0.1", "supertest-session": "^5.0.1", "url-slug": "^4.0.1" }, diff --git a/public/js/app/clan.js b/public/js/app/clan.js index 5e5e8e01..e6475474 100644 --- a/public/js/app/clan.js +++ b/public/js/app/clan.js @@ -1,5 +1,5 @@ -(async() => { - new window.simpleDatatables.DataTable("#clan-members", { +import('/js/simple-datatables.js').then(({DataTable}) => { + new DataTable("#clan-members", { perPageSelect: null }) -})() +}) diff --git a/public/js/app/clans.js b/public/js/app/clans.js index 3e5fca52..b26faa96 100644 --- a/public/js/app/clans.js +++ b/public/js/app/clans.js @@ -1,4 +1,4 @@ -(async() => { +import('/js/simple-datatables.js').then(({DataTable}) => { fetch('/data/clans.json') .then(response => response.json()) .then(data => { @@ -6,7 +6,7 @@ return } - window.datatable = new window.simpleDatatables.DataTable("#clan-table", { + window.datatable = new DataTable("#clan-table", { perPageSelect: null, data: { headings: [ @@ -30,7 +30,8 @@ .catch((err) => { console.log(err, 'loading clans failed') }) -})() +}) + diff --git a/public/styles/site/clans.sass b/public/styles/site/clans.sass index e180a160..7cd0594f 100644 --- a/public/styles/site/clans.sass +++ b/public/styles/site/clans.sass @@ -33,195 +33,3 @@ tbody td text-align: left -// Background of the whole thing -.clanBackground - padding: 7.5vw 11vw - background-image: url("/../../images/fafbgpattern0.5.jpg") - ul - list-style: none - li - padding: 0.5em 0 - -// This is the searchbar input form -input - margin: 1em 1em 2px 1em - background-color: variables.$background-tertiary - color: variables.$color-active - font-size: var(--paragraph-font-size) - border: 0.5em solid variables.$background-secondary - border-radius: 10px - z-index: 2 - position: relative - - - -// The main box with all the names, tags, ranks, etc. -.mainClanContainer - @include mixins.gridMainContainer - padding: 0 - p - padding: 0.2em - -.clanContainer - font-family: variables.$family-paragraph - padding: 0em - .clanItem - - ul - font-size: var(--paragraph-font-size) - padding: 1em 0 - font-weight: 700 - - // ACTUAL LISTS - // There is a double li element here because the js creates a li parent element and then puts another li child element (which the child is all the names you see like ANZ and so on) - li - list-style: none - font-weight: normal - padding: 0em 0 - li - font-size: var(--paragraph-font-size) - padding: 1em 0 - -.clanBorder - border: 1px solid variables.$color-active - padding: 0px - background-color: variables.$background-primary - -// Change background colors on items in the leaderboard -.clanItem - li:nth-child(odd) - background-color: mix(variables.$background-tertiary, variables.$background-primary, 25%) - li:nth-child(even) - background-color: variables.$background-secondary - -// First page last page, etc -.clanButton - padding: 1em 0.25em - display: inline-block - place-items: start - font-family: variables.$family-paragraph - font-size: var(--paragraph-font-size) - letter-spacing: 0em - ul - padding: 0.5em - font-weight: 900 - li - - display: inline-block - padding: 0.6em 1em - border: 0.05em solid variables.$color-inactive - background-color: variables.$background-tertiary - cursor: pointer - transition: 0.4s - &:hover - border: 0.05em solid variables.$color-active - filter: brightness(2) - .exhaustedButton - border: 0.05em solid variables.$color-inactive - background-color: variables.$background-secondary - color: variables.$color-inactive-plus - pointer-events: none - cursor: default - -#searchResults - margin: 1em 0 0 0 -.appearWhenSearching - display: none -.centerYourself - display: grid - justify-items: center - position: relative - -.searchBar - ul - background-color: variables.$background-secondary - color: variables.$color-inactive - font-size: calc(var(--paragraph-font-size) * 0.9) - border-radius: 0 0 10px 10px - text-align: left - li - padding: 0.5em 1em - -.clearButton - li - cursor: pointer - margin: 1em 1em 0 1em - border-radius: 10px - background-color: variables.$background-tertiary - color: variables.$color-inactive - transition: 0.4s - &:hover - background-color: variables.$color-inactive-plus - color: variables.$color-active - .fa-trash-alt - padding: 0.5em - -@media (max-width: 800px) - .clanFilter - font-size: 10px - .clanContainer - ul - font-size: 10px - padding: 1em 0 0 0 - - li - text-overflow: ellipsis - font-size: 10px - padding: 1em 0 - - .clearButton - left: 90% - top: 68% - .clanBackground - padding: 1vw - .clanButton - padding: 1vw - font-size: var(--paragraph-font-size) - ul - li - padding: 0.65em - .clanDelete - font-size: 10px - - -@media (max-width: 1600px) - .clanContainer - ul - font-size: 14px - li - font-size: 14px - .clanFilter - font-size: 14px - - - -// Below are classes that depend -.clanManagement - @include mixins.gridMainContainer - padding: 0vw 15vw - margin: 1em 0 - .clanManagementItem - padding: 1.5em 0 - display: inline-block - justify-self: center - align-self: center - - //clan Description - textarea - width: 40vw - - .clanManagementTable - padding: 1.5em - display: inline-block - justify-self: center - align-self: center - th - padding: 4em - -@media (max-width: 800px) - .clanManagement - padding: 5px -.bigButton - font-size: 1.25em - - diff --git a/routes/views/clanRouter.js b/routes/views/clanRouter.js index cfc23816..5459df13 100644 --- a/routes/views/clanRouter.js +++ b/routes/views/clanRouter.js @@ -2,6 +2,16 @@ const express = require('express') const router = express.Router() const middlewares = require('../middleware') +router.get('/', middlewares.isAuthenticated(), (req, res) => res.render('clans/clans')) +router.get('/view/:id', middlewares.isAuthenticated(), async (req, res) => { + const clanId = parseInt(req.params.id || null) + if (!clanId) { + return res.redirect('/clans') + } + + return res.render('clans/clan', {clan: await req.services.clanService.getClan(clanId)}) +}) + // router.get('/create', middlewares.isAuthenticated(), require('./clans/get/create')) // router.get('/manage', middlewares.isAuthenticated(), require('./clans/get/manage')) // router.get('/accept_invite', middlewares.isAuthenticated(), require('./clans/get/accept_invite')) @@ -14,7 +24,6 @@ const middlewares = require('../middleware') // router.post('/leave', middlewares.isAuthenticated(), require('./clans/post/leave')) // router.post('/join', middlewares.isAuthenticated(), require('./clans/post/join')) -router.get('/', middlewares.isAuthenticated(), (req, res) => res.render('clans/clans')) -router.get('/view/:id', middlewares.isAuthenticated(), require('./clans/get/clan')) router.get('*', (req, res) => res.status(503).render('errors/503-known-issue')); + module.exports = router diff --git a/templates/views/clans/clan.pug b/templates/views/clans/clan.pug index 59ac92f1..e20c94b2 100644 --- a/templates/views/clans/clan.pug +++ b/templates/views/clans/clan.pug @@ -1,14 +1,11 @@ extends ../../layouts/default -block bannerMixin block head - link(rel='stylesheet' href='https://cdn.jsdelivr.net/npm/simple-datatables@latest/dist/style.css') + link(rel='stylesheet' href='/styles/css/simple-datatables.css') block content - #clan-view a(href="/clans") <- OVERVIEW

-
.gridMainContainer .column4 table#clan-info @@ -48,5 +45,4 @@ block content td #{member.name} td #{member.joinedAt} block js - script( src="https://cdn.jsdelivr.net/npm/simple-datatables@latest") - script( src="../../js/app/clan.js") + script( src="../../js/app/clan.js" type="module") diff --git a/templates/views/clans/clans.pug b/templates/views/clans/clans.pug index 00a7a511..dd5c6783 100644 --- a/templates/views/clans/clans.pug +++ b/templates/views/clans/clans.pug @@ -1,15 +1,9 @@ extends ../../layouts/default -include ../../mixins/new-flash-messages -block bannerMixin block head - link(rel='stylesheet' href='https://cdn.jsdelivr.net/npm/simple-datatables@latest/dist/style.css') + link(rel='stylesheet' href='/styles/css/simple-datatables.css') block content h1 Clans table#clan-table - block js - - script( src="https://cdn.jsdelivr.net/npm/simple-datatables@latest") - script( src="../../js/app/clans.js") - + script( src="../../js/app/clans.js" type="module") diff --git a/tests/integration/clanRouter.test.js b/tests/integration/clanRouter.test.js index 90ff00af..5079a7f4 100644 --- a/tests/integration/clanRouter.test.js +++ b/tests/integration/clanRouter.test.js @@ -1,21 +1,65 @@ const express = require('express') const supertestSession = require("supertest-session"); const fafApp = require('../../fafApp') +const passportMock = require("../helpers/PassportMock"); let testSession = null beforeEach(async () => { const app = new express() fafApp.setup(app) + passportMock(app, {passAuthentication: true}) fafApp.loadRouters(app) testSession = supertestSession(app) }) describe('Clan Routes', function () { - const arr = ['/clans', '/clans/everything'] - test.each(arr)("responds with 503 to %p", (async (route) => { - const res = await testSession.get(route) + test('clan list is protected', async () => { + let response = await testSession.get('/clans') + expect(response.statusCode).toBe(302) + expect(response.headers.location).toBe('/login') + + await testSession.get('/mock-login') + + response = await testSession.get('/clans') + expect(response.statusCode).toBe(200) + expect(response.text).toContain('Clans'); + }) + + test('clan list can be accessed with user', async () => { + const response = await testSession.get('/clans') + expect(response.statusCode).toBe(302) + expect(response.headers.location).toBe('/login') + }) + + test('clan view is protected', async () => { + let response = await testSession.get('/clans/view/1') + expect(response.statusCode).toBe(302) + expect(response.headers.location).toBe('/login') + + await testSession.get('/mock-login') + + response = await testSession.get('/clans/view/148') + expect(response.statusCode).toBe(200) + expect(response.text).toContain('STS-Clan'); + }) + + test('clan view redirects on shitty id', async () => { + await testSession.get('/mock-login') + let response = await testSession.get('/clans/view/not-a-number') + expect(response.statusCode).toBe(302) + expect(response.headers.location).toBe('/clans') + }) + + test('game-client clan view link is redirected', async () => { + const response = await testSession.get('/clan/1') + expect(response.statusCode).toBe(302) + expect(response.headers.location).toBe('/clans/view/1') + }) + + test("responds with 503 to other clan routes", async () => { + const res = await testSession.get('/clans/everything-else') expect(res.statusCode).toBe(503) expect(res.text).toContain('Sorry commanders, we failed to build enough pgens and are now in a tech upgrade'); - })) + }) }) diff --git a/tests/integration/testData/clan-http.json b/tests/integration/testData/clan-http.json new file mode 100644 index 00000000..35d18287 --- /dev/null +++ b/tests/integration/testData/clan-http.json @@ -0,0 +1 @@ +{"data":{"type":"clan","id":"148","attributes":{"createTime":"2014-04-22T14:52:03Z","description":"This is the old GPG-Net STS-Clan. all german people can join :) \n\n","name":"STS-Clan","requiresInvitation":true,"tag":"STS","tagColor":null,"updateTime":"2014-04-22T14:52:03Z","websiteUrl":"http://localhost:8096/clan/148"},"relationships":{"founder":{"data":{"type":"player","id":"33328"}},"leader":{"data":{"type":"player","id":"33328"}},"memberships":{"data":[{"type":"clanMembership","id":"6782"},{"type":"clanMembership","id":"6783"},{"type":"clanMembership","id":"6784"},{"type":"clanMembership","id":"6785"},{"type":"clanMembership","id":"6786"},{"type":"clanMembership","id":"6787"},{"type":"clanMembership","id":"6788"},{"type":"clanMembership","id":"6789"}]}}},"included":[{"type":"clanMembership","id":"6789","attributes":{"createTime":"2014-05-27T20:23:33Z","updateTime":"2017-05-15T17:48:35Z"},"relationships":{"clan":{"data":{"type":"clan","id":"148"}},"player":{"data":{"type":"player","id":"102475"}}}},{"type":"player","id":"102475","attributes":{"createTime":"2014-05-27T20:56:05Z","login":"DragoonTT","updateTime":"2023-10-21T21:18:37Z","userAgent":null},"relationships":{"avatarAssignments":{"data":[]},"bans":{"data":[]},"clanMembership":{"data":{"type":"clanMembership","id":"6789"}},"names":{"data":[]},"userNotes":{"data":[]}}},{"type":"clanMembership","id":"6782","attributes":{"createTime":"2014-04-22T14:52:03Z","updateTime":"2017-05-15T17:48:35Z"},"relationships":{"clan":{"data":{"type":"clan","id":"148"}},"player":{"data":{"type":"player","id":"33328"}}}},{"type":"player","id":"33328","attributes":{"createTime":"2012-10-06T18:03:04Z","login":"MVN050","updateTime":"2023-10-21T21:18:37Z","userAgent":"faf-client"},"relationships":{"avatarAssignments":{"data":[]},"bans":{"data":[]},"clanMembership":{"data":{"type":"clanMembership","id":"6782"}},"names":{"data":[]},"userNotes":{"data":[]}}},{"type":"clanMembership","id":"6783","attributes":{"createTime":"2014-04-23T20:25:28Z","updateTime":"2017-05-15T17:48:35Z"},"relationships":{"clan":{"data":{"type":"clan","id":"148"}},"player":{"data":{"type":"player","id":"2719"}}}},{"type":"player","id":"2719","attributes":{"createTime":"2012-07-05T12:22:02Z","login":"Bubble678","updateTime":"2023-10-21T21:18:37Z","userAgent":"downlords-faf-client"},"relationships":{"avatarAssignments":{"data":[]},"bans":{"data":[]},"clanMembership":{"data":{"type":"clanMembership","id":"6783"}},"names":{"data":[{"type":"nameRecord","id":"19886"}]},"userNotes":{"data":[]}}},{"type":"clanMembership","id":"6784","attributes":{"createTime":"2014-04-23T20:28:35Z","updateTime":"2017-05-15T17:48:35Z"},"relationships":{"clan":{"data":{"type":"clan","id":"148"}},"player":{"data":{"type":"player","id":"2722"}}}},{"type":"player","id":"2722","attributes":{"createTime":"2012-07-05T12:13:24Z","login":"GeneralMajor","updateTime":"2023-10-21T21:18:37Z","userAgent":null},"relationships":{"avatarAssignments":{"data":[]},"bans":{"data":[]},"clanMembership":{"data":{"type":"clanMembership","id":"6784"}},"names":{"data":[{"type":"nameRecord","id":"4341"},{"type":"nameRecord","id":"4467"}]},"userNotes":{"data":[]}}},{"type":"clanMembership","id":"6785","attributes":{"createTime":"2014-04-27T14:02:01Z","updateTime":"2017-05-15T17:48:35Z"},"relationships":{"clan":{"data":{"type":"clan","id":"148"}},"player":{"data":{"type":"player","id":"79436"}}}},{"type":"player","id":"79436","attributes":{"createTime":"2013-11-15T18:39:17Z","login":"PWD_Lux","updateTime":"2023-10-21T21:18:37Z","userAgent":null},"relationships":{"avatarAssignments":{"data":[]},"bans":{"data":[]},"clanMembership":{"data":{"type":"clanMembership","id":"6785"}},"names":{"data":[]},"userNotes":{"data":[]}}},{"type":"clanMembership","id":"6786","attributes":{"createTime":"2014-04-28T19:57:43Z","updateTime":"2017-05-15T17:48:35Z"},"relationships":{"clan":{"data":{"type":"clan","id":"148"}},"player":{"data":{"type":"player","id":"33228"}}}},{"type":"player","id":"33228","attributes":{"createTime":"2012-10-06T18:02:58Z","login":"Totalschaden","updateTime":"2023-10-21T21:18:37Z","userAgent":"downlords-faf-client"},"relationships":{"avatarAssignments":{"data":[]},"bans":{"data":[]},"clanMembership":{"data":{"type":"clanMembership","id":"6786"}},"names":{"data":[{"type":"nameRecord","id":"1248"},{"type":"nameRecord","id":"1530"},{"type":"nameRecord","id":"1818"}]},"userNotes":{"data":[]}}},{"type":"clanMembership","id":"6787","attributes":{"createTime":"2014-05-06T17:04:19Z","updateTime":"2017-05-15T17:48:35Z"},"relationships":{"clan":{"data":{"type":"clan","id":"148"}},"player":{"data":{"type":"player","id":"98228"}}}},{"type":"player","id":"98228","attributes":{"createTime":"2014-04-19T19:45:30Z","login":"Cmd_Matrix","updateTime":"2023-10-21T21:18:37Z","userAgent":"downlords-faf-client"},"relationships":{"avatarAssignments":{"data":[]},"bans":{"data":[]},"clanMembership":{"data":{"type":"clanMembership","id":"6787"}},"names":{"data":[]},"userNotes":{"data":[]}}},{"type":"clanMembership","id":"6788","attributes":{"createTime":"2014-05-11T12:58:54Z","updateTime":"2017-05-15T17:48:35Z"},"relationships":{"clan":{"data":{"type":"clan","id":"148"}},"player":{"data":{"type":"player","id":"56082"}}}},{"type":"player","id":"56082","attributes":{"createTime":"2014-05-05T19:20:03Z","login":"Fleischie","updateTime":"2023-10-21T21:18:37Z","userAgent":null},"relationships":{"avatarAssignments":{"data":[]},"bans":{"data":[]},"clanMembership":{"data":{"type":"clanMembership","id":"6788"}},"names":{"data":[]},"userNotes":{"data":[]}}}]} \ No newline at end of file diff --git a/tests/integration/testData/clan.json b/tests/integration/testData/clan.json index 35d18287..9bac2a91 100644 --- a/tests/integration/testData/clan.json +++ b/tests/integration/testData/clan.json @@ -1 +1 @@ -{"data":{"type":"clan","id":"148","attributes":{"createTime":"2014-04-22T14:52:03Z","description":"This is the old GPG-Net STS-Clan. all german people can join :) \n\n","name":"STS-Clan","requiresInvitation":true,"tag":"STS","tagColor":null,"updateTime":"2014-04-22T14:52:03Z","websiteUrl":"http://localhost:8096/clan/148"},"relationships":{"founder":{"data":{"type":"player","id":"33328"}},"leader":{"data":{"type":"player","id":"33328"}},"memberships":{"data":[{"type":"clanMembership","id":"6782"},{"type":"clanMembership","id":"6783"},{"type":"clanMembership","id":"6784"},{"type":"clanMembership","id":"6785"},{"type":"clanMembership","id":"6786"},{"type":"clanMembership","id":"6787"},{"type":"clanMembership","id":"6788"},{"type":"clanMembership","id":"6789"}]}}},"included":[{"type":"clanMembership","id":"6789","attributes":{"createTime":"2014-05-27T20:23:33Z","updateTime":"2017-05-15T17:48:35Z"},"relationships":{"clan":{"data":{"type":"clan","id":"148"}},"player":{"data":{"type":"player","id":"102475"}}}},{"type":"player","id":"102475","attributes":{"createTime":"2014-05-27T20:56:05Z","login":"DragoonTT","updateTime":"2023-10-21T21:18:37Z","userAgent":null},"relationships":{"avatarAssignments":{"data":[]},"bans":{"data":[]},"clanMembership":{"data":{"type":"clanMembership","id":"6789"}},"names":{"data":[]},"userNotes":{"data":[]}}},{"type":"clanMembership","id":"6782","attributes":{"createTime":"2014-04-22T14:52:03Z","updateTime":"2017-05-15T17:48:35Z"},"relationships":{"clan":{"data":{"type":"clan","id":"148"}},"player":{"data":{"type":"player","id":"33328"}}}},{"type":"player","id":"33328","attributes":{"createTime":"2012-10-06T18:03:04Z","login":"MVN050","updateTime":"2023-10-21T21:18:37Z","userAgent":"faf-client"},"relationships":{"avatarAssignments":{"data":[]},"bans":{"data":[]},"clanMembership":{"data":{"type":"clanMembership","id":"6782"}},"names":{"data":[]},"userNotes":{"data":[]}}},{"type":"clanMembership","id":"6783","attributes":{"createTime":"2014-04-23T20:25:28Z","updateTime":"2017-05-15T17:48:35Z"},"relationships":{"clan":{"data":{"type":"clan","id":"148"}},"player":{"data":{"type":"player","id":"2719"}}}},{"type":"player","id":"2719","attributes":{"createTime":"2012-07-05T12:22:02Z","login":"Bubble678","updateTime":"2023-10-21T21:18:37Z","userAgent":"downlords-faf-client"},"relationships":{"avatarAssignments":{"data":[]},"bans":{"data":[]},"clanMembership":{"data":{"type":"clanMembership","id":"6783"}},"names":{"data":[{"type":"nameRecord","id":"19886"}]},"userNotes":{"data":[]}}},{"type":"clanMembership","id":"6784","attributes":{"createTime":"2014-04-23T20:28:35Z","updateTime":"2017-05-15T17:48:35Z"},"relationships":{"clan":{"data":{"type":"clan","id":"148"}},"player":{"data":{"type":"player","id":"2722"}}}},{"type":"player","id":"2722","attributes":{"createTime":"2012-07-05T12:13:24Z","login":"GeneralMajor","updateTime":"2023-10-21T21:18:37Z","userAgent":null},"relationships":{"avatarAssignments":{"data":[]},"bans":{"data":[]},"clanMembership":{"data":{"type":"clanMembership","id":"6784"}},"names":{"data":[{"type":"nameRecord","id":"4341"},{"type":"nameRecord","id":"4467"}]},"userNotes":{"data":[]}}},{"type":"clanMembership","id":"6785","attributes":{"createTime":"2014-04-27T14:02:01Z","updateTime":"2017-05-15T17:48:35Z"},"relationships":{"clan":{"data":{"type":"clan","id":"148"}},"player":{"data":{"type":"player","id":"79436"}}}},{"type":"player","id":"79436","attributes":{"createTime":"2013-11-15T18:39:17Z","login":"PWD_Lux","updateTime":"2023-10-21T21:18:37Z","userAgent":null},"relationships":{"avatarAssignments":{"data":[]},"bans":{"data":[]},"clanMembership":{"data":{"type":"clanMembership","id":"6785"}},"names":{"data":[]},"userNotes":{"data":[]}}},{"type":"clanMembership","id":"6786","attributes":{"createTime":"2014-04-28T19:57:43Z","updateTime":"2017-05-15T17:48:35Z"},"relationships":{"clan":{"data":{"type":"clan","id":"148"}},"player":{"data":{"type":"player","id":"33228"}}}},{"type":"player","id":"33228","attributes":{"createTime":"2012-10-06T18:02:58Z","login":"Totalschaden","updateTime":"2023-10-21T21:18:37Z","userAgent":"downlords-faf-client"},"relationships":{"avatarAssignments":{"data":[]},"bans":{"data":[]},"clanMembership":{"data":{"type":"clanMembership","id":"6786"}},"names":{"data":[{"type":"nameRecord","id":"1248"},{"type":"nameRecord","id":"1530"},{"type":"nameRecord","id":"1818"}]},"userNotes":{"data":[]}}},{"type":"clanMembership","id":"6787","attributes":{"createTime":"2014-05-06T17:04:19Z","updateTime":"2017-05-15T17:48:35Z"},"relationships":{"clan":{"data":{"type":"clan","id":"148"}},"player":{"data":{"type":"player","id":"98228"}}}},{"type":"player","id":"98228","attributes":{"createTime":"2014-04-19T19:45:30Z","login":"Cmd_Matrix","updateTime":"2023-10-21T21:18:37Z","userAgent":"downlords-faf-client"},"relationships":{"avatarAssignments":{"data":[]},"bans":{"data":[]},"clanMembership":{"data":{"type":"clanMembership","id":"6787"}},"names":{"data":[]},"userNotes":{"data":[]}}},{"type":"clanMembership","id":"6788","attributes":{"createTime":"2014-05-11T12:58:54Z","updateTime":"2017-05-15T17:48:35Z"},"relationships":{"clan":{"data":{"type":"clan","id":"148"}},"player":{"data":{"type":"player","id":"56082"}}}},{"type":"player","id":"56082","attributes":{"createTime":"2014-05-05T19:20:03Z","login":"Fleischie","updateTime":"2023-10-21T21:18:37Z","userAgent":null},"relationships":{"avatarAssignments":{"data":[]},"bans":{"data":[]},"clanMembership":{"data":{"type":"clanMembership","id":"6788"}},"names":{"data":[]},"userNotes":{"data":[]}}}]} \ No newline at end of file +{"id":"148","name":"STS-Clan","tag":"STS","description":"This is the old GPG-Net STS-Clan. all german people can join :) \n\n","createTime":"2014-04-22T14:52:03Z","requiresInvitation":true,"tagColor":null,"updateTime":"2014-04-22T14:52:03Z","founder":{"id":"33328","membershipId":"6782","joinedAt":"2014-04-22T14:52:03Z","name":"MVN050"},"leader":{"id":"33328","membershipId":"6782","joinedAt":"2014-04-22T14:52:03Z","name":"MVN050"},"memberships":{"2719":{"id":"2719","membershipId":"6783","joinedAt":"2014-04-23T20:25:28Z","name":"Bubble678"},"2722":{"id":"2722","membershipId":"6784","joinedAt":"2014-04-23T20:28:35Z","name":"GeneralMajor"},"33228":{"id":"33228","membershipId":"6786","joinedAt":"2014-04-28T19:57:43Z","name":"Totalschaden"},"33328":{"id":"33328","membershipId":"6782","joinedAt":"2014-04-22T14:52:03Z","name":"MVN050"},"56082":{"id":"56082","membershipId":"6788","joinedAt":"2014-05-11T12:58:54Z","name":"Fleischie"},"79436":{"id":"79436","membershipId":"6785","joinedAt":"2014-04-27T14:02:01Z","name":"PWD_Lux"},"98228":{"id":"98228","membershipId":"6787","joinedAt":"2014-05-06T17:04:19Z","name":"Cmd_Matrix"},"102475":{"id":"102475","membershipId":"6789","joinedAt":"2014-05-27T20:23:33Z","name":"DragoonTT"}}} \ No newline at end of file diff --git a/tests/setup.js b/tests/setup.js index 3790bde5..3f649710 100644 --- a/tests/setup.js +++ b/tests/setup.js @@ -1,6 +1,7 @@ const fs = require("fs"); const wordpressService = require("../lib/WordpressService"); const leaderboardService = require("../lib/LeaderboardService"); +const clanService = require("../lib/clan/ClanService"); beforeEach(() => { const newsFile = JSON.parse(fs.readFileSync('tests/integration/testData/news.json',{encoding:'utf8', flag:'r'})) jest.spyOn(wordpressService.prototype, 'getNews').mockResolvedValue(newsFile); @@ -31,6 +32,10 @@ beforeEach(() => { throw new Error('do we need to change the mock?') }) + + jest.spyOn(clanService.prototype, 'getClan').mockImplementation((id) => { + return JSON.parse(fs.readFileSync('tests/integration/testData/clan.json',{encoding:'utf8', flag:'r'})) + }) }) afterEach(() => { diff --git a/yarn.lock b/yarn.lock index b8fea215..b44ae9f7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1449,7 +1449,7 @@ caseless@~0.12.0: resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc" integrity sha512-4tYFyifaFfGacoiObjJegolkwSU4xQNGbVgUiNYVUxbQ2x2lUsFvY4hVgVzGiIe6WLOPqycWXA40l+PWsxthUw== -chalk@^1.0.0: +chalk@^1.0.0, chalk@^1.1.1: version "1.1.3" resolved "https://registry.yarnpkg.com/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98" integrity sha512-U3lRVLMSlsCfjqYPbLyVv11M9CPW4I728d6TCKMAOJueEeB9/8o+eSsMnxPJD+Q+K909sdESg7C+tIkoH6on1A== @@ -1938,6 +1938,11 @@ dateformat@~4.6.2: resolved "https://registry.yarnpkg.com/dateformat/-/dateformat-4.6.3.tgz#556fa6497e5217fedb78821424f8a1c22fa3f4b5" integrity sha512-2P0p0pFGzHS5EMnhdxQi7aJN+iMheud0UhG4dlE1DLAlvL8JHjJJTX/CSm4JXwV0Ka5nGk3zC5mcb5bUQUxxMA== +dayjs@^1.11.10: + version "1.11.10" + resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.11.10.tgz#68acea85317a6e164457d6d6947564029a6a16a0" + integrity sha512-vjAczensTgRcqDERK0SR2XMwsF/tSvnvlv6VcF2GIhg6Sx4yOIt/irsr1RDJsKiIyBzJDpCoXiWWq28MqH2cnQ== + debug@2.6.9, debug@^2.2.0, debug@^2.3.3: version "2.6.9" resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f" @@ -2109,6 +2114,11 @@ dezalgo@^1.0.4: asap "^2.0.0" wrappy "1" +diff-dom@^5.1.2: + version "5.1.2" + resolved "https://registry.yarnpkg.com/diff-dom/-/diff-dom-5.1.2.tgz#951627784bc45e32999f0c97cd42e4cf8c35791f" + integrity sha512-ayOX+pBYzyLdt7iXFd+8jvWzhrcWk+9gQqYk7Zz8/0hpIsqSbtk6MNbtds+Ox6B8ONsdtIcfPmk3NXPdgb3+xQ== + diff-sequences@^29.6.3: version "29.6.3" resolved "https://registry.yarnpkg.com/diff-sequences/-/diff-sequences-29.6.3.tgz#4deaf894d11407c51efc8418012f9e70b84ea921" @@ -2560,6 +2570,11 @@ figures@^3.0.0: dependencies: escape-string-regexp "^1.0.5" +file-sync-cmp@^0.1.0: + version "0.1.1" + resolved "https://registry.yarnpkg.com/file-sync-cmp/-/file-sync-cmp-0.1.1.tgz#a5e7a8ffbfa493b43b923bbd4ca89a53b63b612b" + integrity sha512-0k45oWBokCqh2MOexeYKpyqmGKG+8mQ2Wd8iawx+uWd/weWJQAZ6SoPybagdCI4xFisag8iAR77WPm4h3pTfxA== + file-uri-to-path@1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz#553a7b8446ff6f684359c445f1e37a05dacc33dd" @@ -3042,6 +3057,14 @@ grunt-contrib-concat@^2.1.0: chalk "^4.1.2" source-map "^0.5.3" +grunt-contrib-copy@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/grunt-contrib-copy/-/grunt-contrib-copy-1.0.0.tgz#7060c6581e904b8ab0d00f076e0a8f6e3e7c3573" + integrity sha512-gFRFUB0ZbLcjKb67Magz1yOHGBkyU6uL29hiEW1tdQ9gQt72NuMKIy/kS6dsCbV0cZ0maNCb0s6y+uT1FKU7jA== + dependencies: + chalk "^1.1.1" + file-sync-cmp "^0.1.0" + grunt-contrib-jshint@^3.2.0: version "3.2.0" resolved "https://registry.yarnpkg.com/grunt-contrib-jshint/-/grunt-contrib-jshint-3.2.0.tgz#d97c125ce6dafef1b0cc766cd87201ae0fb7b408" @@ -6382,6 +6405,14 @@ signal-exit@^3.0.0, signal-exit@^3.0.2, signal-exit@^3.0.3, signal-exit@^3.0.7: resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.7.tgz#a9a1767f8af84155114eaabd73f99273c8f59ad9" integrity sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ== +simple-datatables@^8.0.1: + version "8.0.1" + resolved "https://registry.yarnpkg.com/simple-datatables/-/simple-datatables-8.0.1.tgz#9e1dd25bcdf30782aee14f6f138c8e3f97bbbc2f" + integrity sha512-1l9N7yacy4pECoOw/khm/n7XtEcpgoh5znJ1diqern1fwRqgOCgdI7keW9LCeV5es2M4K+db3qWjaWHbcFUh0Q== + dependencies: + dayjs "^1.11.10" + diff-dom "^5.1.2" + sisteransi@^1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/sisteransi/-/sisteransi-1.0.5.tgz#134d681297756437cc05ca01370d3a7a571075ed"