diff --git a/package.json b/package.json index 41daab1..d980aa8 100644 --- a/package.json +++ b/package.json @@ -12,9 +12,9 @@ "prettier:fix": "npm run prettier -- --write", "start": "NODE_ENV=production node ./server", "develop": "NODE_ENV=development node ./server", - "test": "test/run.sh", + "test": "test.sh", "versions": "npx dependency-version-checker check", - "watch": "node --no-warnings=ExperimentalWarning test/suite setup && node --test --watch --no-warnings=ExperimentalWarning; node --no-warnings=ExperimentalWarning test/suite teardown" + "watch": "test.sh watch" }, "repository": { "type": "git", @@ -43,10 +43,10 @@ "@hapi/hoek": "^11.0.4", "@hapi/inert": "^7.1.0", "@hapi/vision": "^7.0.3", - "@nictool/validate": "^0.7.1", + "@nictool/validate": "^0.7.2", "hapi-swagger": "^17.2.1", - "mysql2": "^3.9.1", + "mysql2": "^3.9.2", "qs": "^6.11.2", - "yaml": "^2.3.4" + "yaml": "^2.4.0" } } diff --git a/routes/group.test.js b/routes/group.test.js index 66c1d19..d2668be 100644 --- a/routes/group.test.js +++ b/routes/group.test.js @@ -8,7 +8,7 @@ import User from '../lib/user.js' import groupCase from './test/group.json' with { type: 'json' } import userCase from './test/user.json' with { type: 'json' } -let server, sessionCookie +let server before(async () => { server = await init() @@ -21,6 +21,8 @@ after(async () => { }) describe('group routes', () => { + let sessionCookie + it('POST /session establishes a session', async () => { const res = await server.inject({ method: 'POST', diff --git a/test/suite.js b/test.js similarity index 78% rename from test/suite.js rename to test.js index 3ca5797..6ff6df0 100644 --- a/test/suite.js +++ b/test.js @@ -2,14 +2,14 @@ import path from 'node:path' -import Group from '../lib/group.js' -import User from '../lib/user.js' -import Session from '../lib/session.js' +import Group from './lib/group.js' +import User from './lib/user.js' +import Session from './lib/session.js' -import groupCase from '../lib/test/group.json' with { type: 'json' } -import userCase from '../lib/test/user.json' with { type: 'json' } -import groupCaseR from '../routes/test/group.json' with { type: 'json' } -import userCaseR from '../routes/test/user.json' with { type: 'json' } +import groupCase from './lib/test/group.json' with { type: 'json' } +import userCase from './lib/test/user.json' with { type: 'json' } +import groupCaseR from './routes/test/group.json' with { type: 'json' } +import userCaseR from './routes/test/user.json' with { type: 'json' } switch (process.argv[2]) { case 'setup': diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..d59f011 --- /dev/null +++ b/test.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +node --no-warnings=ExperimentalWarning test.js setup + +if [ "$1" = "watch" ]; then + node --no-warnings=ExperimentalWarning --test --watch +else + node --no-warnings=ExperimentalWarning --test + # npx mocha --exit --no-warnings=ExperimentalWarning lib/*.test.js routes/*.test.js +fi + +node --no-warnings=ExperimentalWarning test.js teardown diff --git a/test/run.sh b/test/run.sh deleted file mode 100755 index 5eaf879..0000000 --- a/test/run.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -node --no-warnings=ExperimentalWarning test/suite.js setup -node --no-warnings=ExperimentalWarning --test -node --no-warnings=ExperimentalWarning test/suite.js teardown diff --git a/test/v2/group.json b/test/v2/group.json deleted file mode 100644 index 41c8429..0000000 --- a/test/v2/group.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "nt_group_id": 4096, - "parent_group_id": 0, - "name": "example.com", - "deleted": 0 -} diff --git a/test/v2/user.json b/test/v2/user.json deleted file mode 100644 index 860b489..0000000 --- a/test/v2/user.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "nt_user_id": 4096, - "nt_group_id": 4096, - "username": "unit-test", - "email": "unit-test@example.com", - "password": "What@%Fun34Security", - "first_name": "Unit", - "last_name": "Test", - "deleted": 0 -}