diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7f2241a..0f7d7b7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,8 +2,8 @@ image: node:10.0.0 stages: - build - - code-testing - - acceptance-testing + - quality-check + - testing install-dependencies: stage: build @@ -14,13 +14,13 @@ install-dependencies: - node_modules/ linting: - stage: code-testing + stage: quality-check script: - npm install - npm run linter unit-testing: - stage: acceptance-testing + stage: testing script: - npm install - apt-get update @@ -28,7 +28,7 @@ unit-testing: - npm run test code-coverage: - stage: acceptance-testing + stage: testing script: - npm install - apt-get update @@ -36,7 +36,7 @@ code-coverage: - npm run coverage acceptance-tests: - stage: acceptance-testing + stage: testing script: - npm install --only=dev - apt-get update diff --git a/acceptance tests/admin.test.js b/acceptance tests/admin.test.js index e3f3aab..ad607b5 100644 --- a/acceptance tests/admin.test.js +++ b/acceptance tests/admin.test.js @@ -5,7 +5,7 @@ const puppeteer = require('puppeteer') const { configureToMatchImageSnapshot } = require('jest-image-snapshot') const width = 800 const height = 600 -const delayMS = 10 +const delayMS = 100 const shell = require('shelljs') let browser @@ -32,6 +32,8 @@ describe('menu', () => { test('Main Menu', async done => { + jest.setTimeout(30000) + await page.goto('http://localhost:8080/login', { timeout: 30000, waitUntil: 'load' }) await page.goto('http://localhost:8080/login', { timeout: 30000, waitUntil: 'load' }) diff --git a/acceptance tests/staff.test.js b/acceptance tests/staff.test.js new file mode 100644 index 0000000..a8dc669 --- /dev/null +++ b/acceptance tests/staff.test.js @@ -0,0 +1,60 @@ +/* eslint-disable max-len */ +'use strict' + +const puppeteer = require('puppeteer') +const { configureToMatchImageSnapshot } = require('jest-image-snapshot') +const width = 800 +const height = 600 +const delayMS = 100 +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: true, slowMo: delayMS, args: [`--window-size=${width},${height}`, '--no-sandbox'] }) + page = await browser.newPage() + await page.setViewport({ width, height }) +}) + +beforeEach( () => shell.exec('./abolishDB.sh')) + +afterAll( () => browser.close() ) + +describe('menu', () => { + + test('Main Menu', async done => { + + jest.setTimeout(30000) + + 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.select('select[name=auth]', 'Kitchen') + await page.type('input[name=user]', 'Craig') + await page.type('input[name=pass]', 'bread') + + await page.click('input[type=submit]') + + await page.type('input[name=user]', 'Craig') + await page.type('input[name=pass]', 'bread') + + await page.click('input[type=submit]') + + await page.click('button[name=Order]') + const title = await page.title() + expect(title).toBe('Main Menu') + + done() + + }) +}) diff --git a/modules/pdf.js b/modules/pdf.js index 8133271..969cb50 100644 --- a/modules/pdf.js +++ b/modules/pdf.js @@ -28,14 +28,10 @@ module.exports = class Order { keywords: 'Menu, Restaurant, Price,', creator: 'User'}) doc.addPage() - //doc.setFontSize(22) - //doc.text(20, 20, 'This is a title') - //doc.setFontSize(16) - //doc.text(20, 30, 'This is some normal sized text underneath.') const fileName = `testFile${new Date().getSeconds()}.pdf` // eslint-disable-next-line handle-callback-err fs.writeFile(fileName, doc.output(), (err, data) => { - console.log(`${fileName } was created! great success!`) + console.log(`${fileName} was created! great success!`) }) } } diff --git a/routes/menu.js b/routes/menu.js index 9c0d99c..e911ad3 100644 --- a/routes/menu.js +++ b/routes/menu.js @@ -92,6 +92,7 @@ router.get('/menu', async ctx => { router.post('/menu', async ctx => { try { const body = ctx.request.body + console.log(body) const pdf = new PDF() pdf.createPDF(body) ctx.redirect('/menu') diff --git a/routes/user.js b/routes/user.js index e4c5da5..b97d873 100644 --- a/routes/user.js +++ b/routes/user.js @@ -35,6 +35,7 @@ router.post('/register', koaBody, async ctx => { try { // extract the data from the request const body = ctx.request.body + console.log(body) // call the functions in the module const user = await new User(dbUsers) await user.register(body.user, body.pass, body.auth) diff --git a/views/register.handlebars b/views/register.handlebars index ae77efb..9c229dd 100644 --- a/views/register.handlebars +++ b/views/register.handlebars @@ -16,7 +16,7 @@

Username: