summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--controllers/games/gameId.js23
-rw-r--r--package-lock.json136
-rw-r--r--tests/games.spec.js4
3 files changed, 84 insertions, 79 deletions
diff --git a/controllers/games/gameId.js b/controllers/games/gameId.js
index 9487743..2bc0a5e 100644
--- a/controllers/games/gameId.js
+++ b/controllers/games/gameId.js
@@ -9,16 +9,19 @@ function makePageData(user, game) {
}
export function gameId_get(req, res) {
- const game = JSON.parse(getGame(req.params.gameId).data);
- if (game) {
- if (game.player1.id === req.session.user.id) {
- game.letters = game.player1.letters;
- delete game.player2.letters;
- } else {
- game.letters = game.player2.letters;
- delete game.player1.letters;
+ const gameData = getGame(req.params.gameId);
+ if (gameData) {
+ const game = JSON.parse(gameData.data);
+ if (game) {
+ if (game.player1.id === req.session.user.id) {
+ game.letters = game.player1.letters;
+ delete game.player2.letters;
+ } else {
+ game.letters = game.player2.letters;
+ delete game.player1.letters;
+ }
+ return res.render('game', makePageData(req.session.user, game));
}
- return res.render('game', makePageData(req.session.user, game));
- }
+ } // we got null or undefined from the getGame database request
return res.redirect('/games');
}
diff --git a/package-lock.json b/package-lock.json
index 7eb5304..9e16cff 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -554,9 +554,9 @@
}
},
"node_modules/@types/node": {
- "version": "18.11.18",
- "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.18.tgz",
- "integrity": "sha512-DHQpWGjyQKSHj3ebjFI/wRKcqQcdR+MoFBygntYOZytCqNfkd2ZC4ARDJ2DQqhjH5p85Nnd3jhUJIXrszFX/JA==",
+ "version": "18.13.0",
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-18.13.0.tgz",
+ "integrity": "sha512-gC3TazRzGoOnoKAhUx+Q0t8S9Tzs74z7m0ipwGpSqQrleP14hKxP4/JUeEQcD3W1/aIpnWl8pHowI7WokuZpXg==",
"dev": true
},
"node_modules/abbrev": {
@@ -1336,9 +1336,9 @@
}
},
"node_modules/eslint": {
- "version": "8.33.0",
- "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.33.0.tgz",
- "integrity": "sha512-WjOpFQgKK8VrCnAtl8We0SUOy/oVZ5NHykyMiagV1M9r8IFpIJX7DduK6n1mpfhlG7T1NLWm2SuD8QB7KFySaA==",
+ "version": "8.34.0",
+ "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.34.0.tgz",
+ "integrity": "sha512-1Z8iFsucw+7kSqXNZVslXS8Ioa4u2KM7GPwuKtkTFAqZ/cHMcEaR+1+Br0wLlot49cNxIiZk5wp8EAbPcYZxTg==",
"dev": true,
"dependencies": {
"@eslint/eslintrc": "^1.4.1",
@@ -2546,17 +2546,17 @@
}
},
"node_modules/minimist": {
- "version": "1.2.7",
- "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.7.tgz",
- "integrity": "sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g==",
+ "version": "1.2.8",
+ "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz",
+ "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==",
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/minipass": {
- "version": "4.0.1",
- "resolved": "https://registry.npmjs.org/minipass/-/minipass-4.0.1.tgz",
- "integrity": "sha512-V9esFpNbK0arbN3fm2sxDKqMYgIp7XtVdE4Esj+PE4Qaaxdg1wIw48ITQIOn1sc8xXSmUviVL3cyjMqPlrVkiA==",
+ "version": "4.0.3",
+ "resolved": "https://registry.npmjs.org/minipass/-/minipass-4.0.3.tgz",
+ "integrity": "sha512-OW2r4sQ0sI+z5ckEt5c1Tri4xTgZwYDxpE54eqWlQloQRoWtXjqt9udJ5Z4dSv7wK+nfFI7FRXyCpBSft+gpFw==",
"engines": {
"node": ">=8"
}
@@ -2655,9 +2655,9 @@
}
},
"node_modules/node-abi": {
- "version": "3.31.0",
- "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.31.0.tgz",
- "integrity": "sha512-eSKV6s+APenqVh8ubJyiu/YhZgxQpGP66ntzUb3lY1xB9ukSRaGnx0AIxI+IM+1+IVYC1oWobgG5L3Lt9ARykQ==",
+ "version": "3.33.0",
+ "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.33.0.tgz",
+ "integrity": "sha512-7GGVawqyHF4pfd0YFybhv/eM9JwTtPqx0mAanQ146O3FlSh3pA24zf9IRQTOsfTSqXTNzPSP5iagAJ94jjuVog==",
"dependencies": {
"semver": "^7.3.5"
},
@@ -3261,9 +3261,9 @@
}
},
"node_modules/rollup": {
- "version": "3.12.1",
- "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.12.1.tgz",
- "integrity": "sha512-t9elERrz2i4UU9z7AwISj3CQcXP39cWxgRWLdf4Tm6aKm1eYrqHIgjzXBgb67GNY1sZckTFFi0oMozh3/S++Ig==",
+ "version": "3.15.0",
+ "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.15.0.tgz",
+ "integrity": "sha512-F9hrCAhnp5/zx/7HYmftvsNBkMfLfk/dXUh73hPSM2E3CRgap65orDNJbLetoiUFwSAk6iHPLvBrZ5iHYvzqsg==",
"dev": true,
"bin": {
"rollup": "dist/bin/rollup"
@@ -3573,12 +3573,12 @@
}
},
"node_modules/strip-literal": {
- "version": "1.0.0",
- "resolved": "https://registry.npmjs.org/strip-literal/-/strip-literal-1.0.0.tgz",
- "integrity": "sha512-5o4LsH1lzBzO9UFH63AJ2ad2/S2AVx6NtjOcaz+VTT2h1RiRvbipW72z8M/lxEhcPHDBQwpDrnTF7sXy/7OwCQ==",
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/strip-literal/-/strip-literal-1.0.1.tgz",
+ "integrity": "sha512-QZTsipNpa2Ppr6v1AmJHESqJ3Uz247MUS0OjrnnZjFAvEoWqxuyFuXn2xLgMtRnijJShAa1HL0gtJyUs7u7n3Q==",
"dev": true,
"dependencies": {
- "acorn": "^8.8.1"
+ "acorn": "^8.8.2"
},
"funding": {
"url": "https://github.com/sponsors/antfu"
@@ -3745,9 +3745,9 @@
}
},
"node_modules/tinyspy": {
- "version": "1.0.2",
- "resolved": "https://registry.npmjs.org/tinyspy/-/tinyspy-1.0.2.tgz",
- "integrity": "sha512-bSGlgwLBYf7PnUsQ6WOc6SJ3pGOcd+d8AA6EUnLDDM0kWEstC1JIlSZA3UNliDXhd9ABoS7hiRBDCu+XP/sf1Q==",
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/tinyspy/-/tinyspy-1.1.1.tgz",
+ "integrity": "sha512-UVq5AXt/gQlti7oxoIg5oi/9r0WpF7DGEVwXgqWSMmyN16+e3tl5lIvTaOpJ3TAtu5xFzWccFRM4R5NaWHF+4g==",
"dev": true,
"engines": {
"node": ">=14.0.0"
@@ -3915,9 +3915,9 @@
}
},
"node_modules/validator": {
- "version": "13.7.0",
- "resolved": "https://registry.npmjs.org/validator/-/validator-13.7.0.tgz",
- "integrity": "sha512-nYXQLCBkpJ8X6ltALua9dRrZDHVYxjJ1wgskNt1lH9fzGjs3tgojGSCBjmEPwkWS1y29+DrizMTW19Pr9uB2nw==",
+ "version": "13.9.0",
+ "resolved": "https://registry.npmjs.org/validator/-/validator-13.9.0.tgz",
+ "integrity": "sha512-B+dGG8U3fdtM0/aNK4/X8CXq/EcxU2WPrPEkJGslb47qyHsxmbggTWK0yEA4qnYVNF+nxNlN88o14hIcPmSIEA==",
"engines": {
"node": ">= 0.10"
}
@@ -3931,15 +3931,15 @@
}
},
"node_modules/vite": {
- "version": "4.0.4",
- "resolved": "https://registry.npmjs.org/vite/-/vite-4.0.4.tgz",
- "integrity": "sha512-xevPU7M8FU0i/80DMR+YhgrzR5KS2ORy1B4xcX/cXLsvnUWvfHuqMmVU6N0YiJ4JWGRJJsLCgjEzKjG9/GKoSw==",
+ "version": "4.1.1",
+ "resolved": "https://registry.npmjs.org/vite/-/vite-4.1.1.tgz",
+ "integrity": "sha512-LM9WWea8vsxhr782r9ntg+bhSFS06FJgCvvB0+8hf8UWtvaiDagKYWXndjfX6kGl74keHJUcpzrQliDXZlF5yg==",
"dev": true,
"dependencies": {
- "esbuild": "^0.16.3",
- "postcss": "^8.4.20",
+ "esbuild": "^0.16.14",
+ "postcss": "^8.4.21",
"resolve": "^1.22.1",
- "rollup": "^3.7.0"
+ "rollup": "^3.10.0"
},
"bin": {
"vite": "bin/vite.js"
@@ -4460,9 +4460,9 @@
}
},
"@types/node": {
- "version": "18.11.18",
- "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.18.tgz",
- "integrity": "sha512-DHQpWGjyQKSHj3ebjFI/wRKcqQcdR+MoFBygntYOZytCqNfkd2ZC4ARDJ2DQqhjH5p85Nnd3jhUJIXrszFX/JA==",
+ "version": "18.13.0",
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-18.13.0.tgz",
+ "integrity": "sha512-gC3TazRzGoOnoKAhUx+Q0t8S9Tzs74z7m0ipwGpSqQrleP14hKxP4/JUeEQcD3W1/aIpnWl8pHowI7WokuZpXg==",
"dev": true
},
"abbrev": {
@@ -5040,9 +5040,9 @@
"dev": true
},
"eslint": {
- "version": "8.33.0",
- "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.33.0.tgz",
- "integrity": "sha512-WjOpFQgKK8VrCnAtl8We0SUOy/oVZ5NHykyMiagV1M9r8IFpIJX7DduK6n1mpfhlG7T1NLWm2SuD8QB7KFySaA==",
+ "version": "8.34.0",
+ "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.34.0.tgz",
+ "integrity": "sha512-1Z8iFsucw+7kSqXNZVslXS8Ioa4u2KM7GPwuKtkTFAqZ/cHMcEaR+1+Br0wLlot49cNxIiZk5wp8EAbPcYZxTg==",
"dev": true,
"requires": {
"@eslint/eslintrc": "^1.4.1",
@@ -5939,14 +5939,14 @@
}
},
"minimist": {
- "version": "1.2.7",
- "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.7.tgz",
- "integrity": "sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g=="
+ "version": "1.2.8",
+ "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz",
+ "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA=="
},
"minipass": {
- "version": "4.0.1",
- "resolved": "https://registry.npmjs.org/minipass/-/minipass-4.0.1.tgz",
- "integrity": "sha512-V9esFpNbK0arbN3fm2sxDKqMYgIp7XtVdE4Esj+PE4Qaaxdg1wIw48ITQIOn1sc8xXSmUviVL3cyjMqPlrVkiA=="
+ "version": "4.0.3",
+ "resolved": "https://registry.npmjs.org/minipass/-/minipass-4.0.3.tgz",
+ "integrity": "sha512-OW2r4sQ0sI+z5ckEt5c1Tri4xTgZwYDxpE54eqWlQloQRoWtXjqt9udJ5Z4dSv7wK+nfFI7FRXyCpBSft+gpFw=="
},
"minizlib": {
"version": "2.1.2",
@@ -6025,9 +6025,9 @@
"integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg=="
},
"node-abi": {
- "version": "3.31.0",
- "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.31.0.tgz",
- "integrity": "sha512-eSKV6s+APenqVh8ubJyiu/YhZgxQpGP66ntzUb3lY1xB9ukSRaGnx0AIxI+IM+1+IVYC1oWobgG5L3Lt9ARykQ==",
+ "version": "3.33.0",
+ "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.33.0.tgz",
+ "integrity": "sha512-7GGVawqyHF4pfd0YFybhv/eM9JwTtPqx0mAanQ146O3FlSh3pA24zf9IRQTOsfTSqXTNzPSP5iagAJ94jjuVog==",
"requires": {
"semver": "^7.3.5"
}
@@ -6450,9 +6450,9 @@
}
},
"rollup": {
- "version": "3.12.1",
- "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.12.1.tgz",
- "integrity": "sha512-t9elERrz2i4UU9z7AwISj3CQcXP39cWxgRWLdf4Tm6aKm1eYrqHIgjzXBgb67GNY1sZckTFFi0oMozh3/S++Ig==",
+ "version": "3.15.0",
+ "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.15.0.tgz",
+ "integrity": "sha512-F9hrCAhnp5/zx/7HYmftvsNBkMfLfk/dXUh73hPSM2E3CRgap65orDNJbLetoiUFwSAk6iHPLvBrZ5iHYvzqsg==",
"dev": true,
"requires": {
"fsevents": "~2.3.2"
@@ -6655,12 +6655,12 @@
"dev": true
},
"strip-literal": {
- "version": "1.0.0",
- "resolved": "https://registry.npmjs.org/strip-literal/-/strip-literal-1.0.0.tgz",
- "integrity": "sha512-5o4LsH1lzBzO9UFH63AJ2ad2/S2AVx6NtjOcaz+VTT2h1RiRvbipW72z8M/lxEhcPHDBQwpDrnTF7sXy/7OwCQ==",
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/strip-literal/-/strip-literal-1.0.1.tgz",
+ "integrity": "sha512-QZTsipNpa2Ppr6v1AmJHESqJ3Uz247MUS0OjrnnZjFAvEoWqxuyFuXn2xLgMtRnijJShAa1HL0gtJyUs7u7n3Q==",
"dev": true,
"requires": {
- "acorn": "^8.8.1"
+ "acorn": "^8.8.2"
}
},
"superagent": {
@@ -6790,9 +6790,9 @@
"dev": true
},
"tinyspy": {
- "version": "1.0.2",
- "resolved": "https://registry.npmjs.org/tinyspy/-/tinyspy-1.0.2.tgz",
- "integrity": "sha512-bSGlgwLBYf7PnUsQ6WOc6SJ3pGOcd+d8AA6EUnLDDM0kWEstC1JIlSZA3UNliDXhd9ABoS7hiRBDCu+XP/sf1Q==",
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/tinyspy/-/tinyspy-1.1.1.tgz",
+ "integrity": "sha512-UVq5AXt/gQlti7oxoIg5oi/9r0WpF7DGEVwXgqWSMmyN16+e3tl5lIvTaOpJ3TAtu5xFzWccFRM4R5NaWHF+4g==",
"dev": true
},
"to-regex-range": {
@@ -6917,9 +6917,9 @@
"integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA=="
},
"validator": {
- "version": "13.7.0",
- "resolved": "https://registry.npmjs.org/validator/-/validator-13.7.0.tgz",
- "integrity": "sha512-nYXQLCBkpJ8X6ltALua9dRrZDHVYxjJ1wgskNt1lH9fzGjs3tgojGSCBjmEPwkWS1y29+DrizMTW19Pr9uB2nw=="
+ "version": "13.9.0",
+ "resolved": "https://registry.npmjs.org/validator/-/validator-13.9.0.tgz",
+ "integrity": "sha512-B+dGG8U3fdtM0/aNK4/X8CXq/EcxU2WPrPEkJGslb47qyHsxmbggTWK0yEA4qnYVNF+nxNlN88o14hIcPmSIEA=="
},
"vary": {
"version": "1.1.2",
@@ -6927,16 +6927,16 @@
"integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg=="
},
"vite": {
- "version": "4.0.4",
- "resolved": "https://registry.npmjs.org/vite/-/vite-4.0.4.tgz",
- "integrity": "sha512-xevPU7M8FU0i/80DMR+YhgrzR5KS2ORy1B4xcX/cXLsvnUWvfHuqMmVU6N0YiJ4JWGRJJsLCgjEzKjG9/GKoSw==",
+ "version": "4.1.1",
+ "resolved": "https://registry.npmjs.org/vite/-/vite-4.1.1.tgz",
+ "integrity": "sha512-LM9WWea8vsxhr782r9ntg+bhSFS06FJgCvvB0+8hf8UWtvaiDagKYWXndjfX6kGl74keHJUcpzrQliDXZlF5yg==",
"dev": true,
"requires": {
- "esbuild": "^0.16.3",
+ "esbuild": "^0.16.14",
"fsevents": "~2.3.2",
- "postcss": "^8.4.20",
+ "postcss": "^8.4.21",
"resolve": "^1.22.1",
- "rollup": "^3.7.0"
+ "rollup": "^3.10.0"
}
},
"vite-node": {
diff --git a/tests/games.spec.js b/tests/games.spec.js
index 1d5333c..6ff8788 100644
--- a/tests/games.spec.js
+++ b/tests/games.spec.js
@@ -6,7 +6,8 @@ import app from '../main.js';
describe.concurrent('Games handlers tests', function() {
describe.concurrent('When not logged in', function() {
test('GET /games', async function() { await supertest(app).get('/games').expect('Content-Type', /text\/plain/).expect(302, /Redirecting to \/login$/); });
- test('GET /games/1', async function() { await supertest(app).get('/games').expect('Content-Type', /text\/plain/).expect(302, /Redirecting to \/login$/); });
+ test('GET /games/1', async function() { await supertest(app).get('/games/1').expect('Content-Type', /text\/plain/).expect(302, /Redirecting to \/login$/); });
+ test('GET /games/2', async function() { await supertest(app).get('/games/2').expect('Content-Type', /text\/plain/).expect(302, /Redirecting to \/login$/); });
});
describe.concurrent('With valid credentials', function() {
beforeEach(async function(ctx) {
@@ -19,5 +20,6 @@ describe.concurrent('Games handlers tests', function() {
});
test('GET /games', async function(ctx) { await supertest(app).get('/games').set('Cookie', ctx.cookie).expect('Content-Type', /text\/html/).expect(200, /<td><a href="\/games\/1">Alice vs Bob<\/a><\/td>/); });
test('GET /games/1', async function(ctx) { await supertest(app).get('/games/1').set('Cookie', ctx.cookie).expect('Content-Type', /text\/html/).expect(200, /<h2>Alice vs Bob<\/h2>/); });
+ test('GET /games/2', async function(ctx) { await supertest(app).get('/games/2').set('Cookie', ctx.cookie).expect('Content-Type', /text\/plain/).expect(302, /Redirecting to \/games/); });
});
});