diff --git a/abolishDB.sh b/abolishDB.sh new file mode 100755 index 0000000..6a637af --- /dev/null +++ b/abolishDB.sh @@ -0,0 +1,3 @@ +cd databases/ +rm -rf *.db +cd .. \ No newline at end of file diff --git a/acceptance tests/menu.test.js b/acceptance tests/menu.test.js new file mode 100644 index 0000000..23f43b9 --- /dev/null +++ b/acceptance tests/menu.test.js @@ -0,0 +1,62 @@ +'use strict' + +const puppeteer = require('puppeteer') +const { configureToMatchImageSnapshot } = require('jest-image-snapshot') +const width = 800 +const height = 600 +const delayMS = 0 +const shell = require('shelljs') + +let browser +let page + +// threshold is the difference in pixels before the snapshots dont match +const toMatchImageSnapshot = configureToMatchImageSnapshot({ + customDiffConfig: { threshold: 2 }, + noColors: true, +}) +expect.extend({ toMatchImageSnapshot }) + +beforeAll( async() => { + browser = await puppeteer.launch({ headless: false, slowMo: delayMS, args: [`--window-size=${width},${height}`] }) + page = await browser.newPage() + await page.setViewport({ width, height }) +}) + +beforeEach( () => shell.exec('./abolishDB.sh')) + +afterAll( () => browser.close() ) + +describe('menu', () => { + + test('Main Menu', async done => { + + await page.goto('http://localhost:8080/login', { timeout: 30000, waitUntil: 'load' }) + await page.goto('http://localhost:8080/login', { timeout: 30000, waitUntil: 'load' }) + + await page.click('[href="/register"]') + + await page.type('input[name=user]', 'Craig') + await page.type('input[name=pass]', 'bread') + + await page.waitFor(1000) + await page.click('input[type=submit]') + await page.waitFor(1000) + + let title = await page.title() + expect(title).toBe('Log In') + + await page.type('input[name=user]', 'Craig') + await page.type('input[name=pass]', 'bread') + + await page.click('input[type=submit]') + title = await page.title() + expect(title).toBe('Main Menu') + + await page.click('button[name=Menu]') + title = await page.title() + expect(title).toBe('Main Menu') + + done() + }) +}) diff --git a/acceptance tests/users.test.js b/acceptance tests/users.test.js new file mode 100644 index 0000000..92c4cd1 --- /dev/null +++ b/acceptance tests/users.test.js @@ -0,0 +1,120 @@ +'use strict' + +const puppeteer = require('puppeteer') +const { configureToMatchImageSnapshot } = require('jest-image-snapshot') +const width = 800 +const height = 600 +const delayMS = 0 +const shell = require('shelljs') + +let browser +let page + +// threshold is the difference in pixels before the snapshots dont match +const toMatchImageSnapshot = configureToMatchImageSnapshot({ + customDiffConfig: { threshold: 2 }, + noColors: true, +}) +expect.extend({ toMatchImageSnapshot }) + +beforeAll( async() => { + browser = await puppeteer.launch({ headless: false, slowMo: delayMS, args: [`--window-size=${width},${height}`] }) + page = await browser.newPage() + await page.setViewport({ width, height }) +}) + +beforeEach( () => shell.exec('./abolishDB.sh')) + +afterAll( () => browser.close() ) + +describe('login test cases', () => { + + test('No Username', async done => { + + await page.goto('http://localhost:8080/login', { timeout: 30000, waitUntil: 'load' }) + await page.goto('http://localhost:8080/login', { timeout: 30000, waitUntil: 'load' }) + + await page.type('input[name=pass]', 'bread') + + await page.click('input[type=submit]') + + const title = await page.title() + expect(title).toBe('ERROR') + done() + }) + + test('No password', async done => { + + await page.goto('http://localhost:8080/login', { timeout: 30000, waitUntil: 'load' }) + await page.goto('http://localhost:8080/login', { timeout: 30000, waitUntil: 'load' }) + + await page.type('input[name=user]', 'bread') + + await page.click('input[type=submit]') + + const title = await page.title() + expect(title).toBe('ERROR') + done() + }) +}) + +describe('register', () => { + + test('No Username register', async done => { + shell.exec('abolishDB.sh') + await page.goto('http://localhost:8080/login', { timeout: 30000, waitUntil: 'load' }) + await page.goto('http://localhost:8080/login', { timeout: 30000, waitUntil: 'load' }) + + await page.click('[href="/register"]') + + await page.type('input[name=pass]', 'bread') + + await page.click('input[type=submit]') + + const title = await page.title() + expect(title).toBe('ERROR') + done() + }) + + test('No Password register', async done => { + + await page.goto('http://localhost:8080/login', { timeout: 30000, waitUntil: 'load' }) + await page.goto('http://localhost:8080/login', { timeout: 30000, waitUntil: 'load' }) + + await page.click('[href="/register"]') + + await page.type('input[name=user]', 'bread') + + await page.click('input[type=submit]') + + const title = await page.title() + expect(title).toBe('ERROR') + done() + }) + + test('Successful register', async done => { + + await page.goto('http://localhost:8080/login', { timeout: 30000, waitUntil: 'load' }) + await page.goto('http://localhost:8080/login', { timeout: 30000, waitUntil: 'load' }) + + await page.click('[href="/register"]') + + await page.type('input[name=user]', 'Craig') + await page.type('input[name=pass]', 'bread') + + await page.click('input[type=submit]') + + let title = await page.title() + expect(title).toBe('Log In') + + await page.type('input[name=user]', 'Craig') + await page.type('input[name=pass]', 'bread') + + await page.click('input[type=submit]') + title = await page.title() + expect(title).toBe('Main Menu') + done() + }) +}) + + diff --git a/jest-test.config.js b/jest-test.config.js index 220e31c..85c8e34 100644 --- a/jest-test.config.js +++ b/jest-test.config.js @@ -4,6 +4,7 @@ module.exports = { displayName: 'test', verbose: true, collectCoverage: true, + 'preset': 'jest-puppeteer', coverageThreshold: { global: { branches: 0, diff --git a/jest.puppeteer.config.js b/jest.puppeteer.config.js new file mode 100644 index 0000000..44e56b5 --- /dev/null +++ b/jest.puppeteer.config.js @@ -0,0 +1,13 @@ +'use strict' + +module.exports = { + server: { + command: 'node index.js', + port: 8080, + }, + launch: { + headless: false, + devtools: true, + timeout: 30000 + } +} diff --git a/modules/order.js b/modules/order.js index d03e97a..83e6607 100644 --- a/modules/order.js +++ b/modules/order.js @@ -52,9 +52,7 @@ module.exports = class Order { } async getItemInfo(data) { - console.log(data) const sql = `SELECT ID, name, type, price FROM items WHERE ID = "${data}"` - console.log(sql) const output = await this.db.all(sql) return output } diff --git a/modules/user.js b/modules/user.js index 021f176..1e3f663 100644 --- a/modules/user.js +++ b/modules/user.js @@ -2,8 +2,6 @@ 'use strict' const bcrypt = require('bcrypt-promise') -// const fs = require('fs-extra') -//const mime = require('mime-types') const sqlite = require('sqlite-async') const saltRounds = 10 diff --git a/npm-debug.log b/npm-debug.log new file mode 100644 index 0000000..64be86c --- /dev/null +++ b/npm-debug.log @@ -0,0 +1,45 @@ +0 info it worked if it ends with ok +1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'run', 'acceptance' ] +2 info using npm@3.5.2 +3 info using node@v8.10.0 +4 verbose run-script [ 'preacceptance', 'acceptance', 'postacceptance' ] +5 info lifecycle 10_auth@1.0.0~preacceptance: 10_auth@1.0.0 +6 silly lifecycle 10_auth@1.0.0~preacceptance: no script for preacceptance, continuing +7 info lifecycle 10_auth@1.0.0~acceptance: 10_auth@1.0.0 +8 verbose lifecycle 10_auth@1.0.0~acceptance: unsafe-perm in lifecycle true +9 verbose lifecycle 10_auth@1.0.0~acceptance: PATH: /usr/share/npm/bin/node-gyp-bin:/home/cc/Documents/340CT_Project/node_modules/.bin:/home/cc/.local/bin:/home/cc/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games +10 verbose lifecycle 10_auth@1.0.0~acceptance: CWD: /home/cc/Documents/340CT_Project +11 silly lifecycle 10_auth@1.0.0~acceptance: Args: [ '-c', './test.sh' ] +12 silly lifecycle 10_auth@1.0.0~acceptance: Returned: code: 1 signal: null +13 info lifecycle 10_auth@1.0.0~acceptance: Failed to exec acceptance script +14 verbose stack Error: 10_auth@1.0.0 acceptance: `./test.sh` +14 verbose stack Exit status 1 +14 verbose stack at EventEmitter. (/usr/share/npm/lib/utils/lifecycle.js:232:16) +14 verbose stack at emitTwo (events.js:126:13) +14 verbose stack at EventEmitter.emit (events.js:214:7) +14 verbose stack at ChildProcess. (/usr/share/npm/lib/utils/spawn.js:24:14) +14 verbose stack at emitTwo (events.js:126:13) +14 verbose stack at ChildProcess.emit (events.js:214:7) +14 verbose stack at maybeClose (internal/child_process.js:925:16) +14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5) +15 verbose pkgid 10_auth@1.0.0 +16 verbose cwd /home/cc/Documents/340CT_Project +17 error Linux 4.15.0-66-generic +18 error argv "/usr/bin/node" "/usr/bin/npm" "run" "acceptance" +19 error node v8.10.0 +20 error npm v3.5.2 +21 error code ELIFECYCLE +22 error 10_auth@1.0.0 acceptance: `./test.sh` +22 error Exit status 1 +23 error Failed at the 10_auth@1.0.0 acceptance script './test.sh'. +23 error Make sure you have the latest version of node.js and npm installed. +23 error If you do, this is most likely a problem with the 10_auth package, +23 error not with npm itself. +23 error Tell the author that this fails on your system: +23 error ./test.sh +23 error You can get information on how to open an issue for this project with: +23 error npm bugs 10_auth +23 error Or if that isn't available, you can get their info via: +23 error npm owner ls 10_auth +23 error There is likely additional logging output above. +24 verbose exit [ 1, true ] diff --git a/package.json b/package.json index 92f46e5..a24ffd0 100644 --- a/package.json +++ b/package.json @@ -8,16 +8,17 @@ }, "scripts": { "start": "node index.js", - "acceptance": "jest --coverage --detectOpenHandles", + "acceptance": "./test.sh", "jsdoc": "node_modules/.bin/jsdoc -c jsdoc.conf", "linter": "node_modules/.bin/eslint .", - "test": "jest --coverage --detectOpenHandles", + "test": "jest --coverage --detectOpenHandles unit tests/user.spec.js", "unit": "node_modules/.bin/jest --coverage --runInBand tests/unit/" }, "jest": { "projects": [ "/jest-test.config.js" - ] + ], + "preset": "jest-puppeteer" }, "author": "", "license": "ISC", @@ -45,12 +46,19 @@ "sqlite-async": "^1.0.12" }, "devDependencies": { + "0x": "^4.9.1", "eslint": "^5.15.2", "handlebars-validate": "^0.1.2", "http-status-codes": "^1.3.2", "jest": "^24.1.0", "jsdoc": "^3.6.3", "jsdoc-route-plugin": "^0.1.0", - "markdownlint": "^0.17.0" + "markdownlint": "^0.17.0", + "jest-image-snapshot": "^2.11.0", + "jest-puppeteer": "^4.3.0", + "puppeteer": "^1.20.0", + "puppeteer-har": "^1.1.1", + "start-server-and-test": "^1.10.6", + "supertest": "^4.0.2" } } diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..2631cca --- /dev/null +++ b/test.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +set -e +echo hello +mkdir -p screenshots +mkdir -p trace +cd databases/ +rm -rf *.db +cd .. +# [ ! -d "node_modules" ] && echo "INSTALLING MODULES" && npm install +node index.js& +node_modules/.bin/jest --runInBand --detectOpenHandles acceptance\ tests/* +read -p "Press enter to continue" +kill %1 \ No newline at end of file diff --git a/views/mainmenu.handlebars b/views/mainmenu.handlebars index 5919dbd..7e332f0 100644 --- a/views/mainmenu.handlebars +++ b/views/mainmenu.handlebars @@ -7,9 +7,9 @@

Main Menu

-

-

-

- +

+

+

+ \ No newline at end of file