*.js: test for testing result creation

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
Vincent Batts 2023-09-29 10:34:45 -04:00
parent cb0e40ed11
commit b41568337b
Signed by: vbatts
GPG key ID: E30EFAA812C6E5ED
4 changed files with 72 additions and 42 deletions

1
app.js
View file

@ -97,7 +97,6 @@ app.get('/asset/frontend.js', (req, res) => {
}) })
app.get('/newSession', (req, res) => { app.get('/newSession', (req, res) => {
// XXX
log.info(req.session) log.info(req.session)
req.session.regenerate() req.session.regenerate()
log.info(req.session) log.info(req.session)

View file

@ -26,4 +26,31 @@ describe('GET /getNextAnimal', () => {
}) })
}) })
describe('POST /recordButtonClick', () => {
const bodyData = JSON.stringify({
animal: 'SlartyBartFast',
button: 'is critter',
session: 'dang',
difference: 1234,
time: new Date()
})
it('should respond with 200 status', async () => {
const response = await request(app)
.post('/recordButtonClick')
.send(bodyData)
.set('Content-Type', 'application/json')
.set('Accept', 'application/json')
expect(response.statusCode).toBe(200)
// expect(response.body.message).toBe('Hello, World!');
})
it('have a result', async () => {
const response = await request(app)
.get('/results')
expect(response.statusCode).toBe(200)
//console.log(response.body)
expect(response.body.count.SlartyBartFast['is critter']).toBe(1)
expect(response.body.avgTimes.SlartyBartFast.total).toBe(1234)
})
})
// vim:set sts=2 sw=2 et: // vim:set sts=2 sw=2 et:

View file

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8" />
<title>Is this a Critter?</title> <title>Is this a Critter?</title>
</head> </head>
<body> <body>
@ -19,7 +19,11 @@
</div> </div>
<div id="footer"> <div id="footer">
© 2023. All rights reserved. <a href="mailto:isacritter@hashbangbash.com">isacritter</a>; <a href="https://paypal.me/vbatts/1" target="_blank">keep isacritter alive</a> © 2023. All rights reserved.
<a href="mailto:isacritter@hashbangbash.com">isacritter</a>;
<a href="https://paypal.me/vbatts/1" target="_blank"
>keep isacritter alive</a
>
</div> </div>
<script src="/asset/frontend.js"></script> <script src="/asset/frontend.js"></script>
<style type="text/css"> <style type="text/css">
@ -44,4 +48,3 @@
</style> </style>
</body> </body>
</html> </html>

View file

@ -6,6 +6,7 @@
"scripts": { "scripts": {
"test": "./node_modules/.bin/jest", "test": "./node_modules/.bin/jest",
"lint": "./node_modules/.bin/standard --ignore *.test.js .", "lint": "./node_modules/.bin/standard --ignore *.test.js .",
"fix": "./node_modules/.bin/standard --ignore *.test.js --fix .",
"start": "node server.js", "start": "node server.js",
"act": "act -W ./.gitea/workflows/" "act": "act -W ./.gitea/workflows/"
}, },