From 480e14183588e13015615cde10c377d8df6304f3 Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Fri, 16 Feb 2024 14:26:05 -0800 Subject: [PATCH] lint --- .github/workflows/ci.yml | 33 ++++++++++++++++++++++++++++++--- html/index.html | 8 ++++++++ lib/group.js | 13 ++++++------- lib/session.js | 2 +- lib/user.js | 13 ++++++++++--- test/.setup.js | 15 ++++++--------- test/.teardown.js | 8 +++----- test/fixtures/group.json | 10 +++++----- test/user.js | 1 - 9 files changed, 69 insertions(+), 34 deletions(-) create mode 100644 html/index.html diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b7a7e2a..3052885 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,6 +6,8 @@ on: env: CI: true + DB_USER: root + DB_PASS: root jobs: lint: @@ -16,6 +18,31 @@ jobs: secrets: inherit test: - needs: lint - uses: NicTool/.github/.github/workflows/test.yml@main - secrets: inherit + needs: lint get-lts + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + node-version: ${{ fromJson(needs.get-lts.outputs.active) }} + fail-fast: false + steps: + - name: Start MySQL + run: | + sudo service mysql start + mysql -e 'CREATE DATABASE nictool;' -u${{ env.DB_USER }} -p${{ env.DB_PASS }} + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + name: Node ${{ matrix.node-version }} on ${{ matrix.os }} + with: + node-version: ${{ matrix.node-version }} + - run: npm install + - run: npm test + + get-lts: + runs-on: ubuntu-latest + steps: + - id: get + uses: msimerson/node-lts-versions@v1 + outputs: + lts: ${{ steps.get.outputs.lts }} + active: ${{ steps.get.outputs.active }} diff --git a/html/index.html b/html/index.html new file mode 100644 index 0000000..73b58c9 --- /dev/null +++ b/html/index.html @@ -0,0 +1,8 @@ + + + Index + + + Hello World. + + diff --git a/lib/group.js b/lib/group.js index b7adc7e..4bc2e7e 100644 --- a/lib/group.js +++ b/lib/group.js @@ -10,7 +10,7 @@ class Group { const { error } = validate.group.validate(args) if (error) console.error(error) - const g = await this.read({nt_group_id: args.nt_group_id}) + const g = await this.read({ nt_group_id: args.nt_group_id }) if (g.length) { // console.log(g) return g[0].nt_group_id @@ -21,17 +21,16 @@ class Group { } async read(args) { - return await mysql.select( - `SELECT * FROM nt_group WHERE`, - args, - ) + return await mysql.select(`SELECT * FROM nt_group WHERE`, args) } async destroy(args) { - const g = await this.read({nt_group_id: args.nt_group_id}) + const g = await this.read({ nt_group_id: args.nt_group_id }) // console.log(g) if (g.length === 1) { - await mysql.execute(`DELETE FROM nt_group WHERE nt_group_id=?`, [ g[0].nt_group_id ]) + await mysql.execute(`DELETE FROM nt_group WHERE nt_group_id=?`, [ + g[0].nt_group_id, + ]) } } } diff --git a/lib/session.js b/lib/session.js index e5fc251..190ac49 100644 --- a/lib/session.js +++ b/lib/session.js @@ -20,7 +20,7 @@ class Session { nt_user_session: args.nt_user_session, last_access: parseInt(Date.now() / 1000, 10), }) - + return id } diff --git a/lib/user.js b/lib/user.js index e40c13c..c2ce2ce 100644 --- a/lib/user.js +++ b/lib/user.js @@ -65,13 +65,20 @@ class User { } async delete(args) { - + const u = await this.read({ nt_user_id: args.nt_user_id }) + if (u.length === 1) { + await mysql.execute(`UPDATE nt_user SET deleted=1 WHERE nt_user_id=?`, [ + u[0].nt_user_id, + ]) + } } async destroy(args) { - const u = await this.read({nt_user_id: args.nt_user_id}) + const u = await this.read({ nt_user_id: args.nt_user_id }) if (u.length === 1) { - await mysql.execute(`DELETE FROM nt_user WHERE nt_user_id=?`, [ u[0].nt_user_id ]) + await mysql.execute(`DELETE FROM nt_user WHERE nt_user_id=?`, [ + u[0].nt_user_id, + ]) } } diff --git a/test/.setup.js b/test/.setup.js index 035a9e9..cb2c262 100644 --- a/test/.setup.js +++ b/test/.setup.js @@ -1,4 +1,3 @@ - const group = require('../lib/group') // const session = require('../lib/session') const user = require('../lib/user') @@ -6,7 +5,6 @@ const userCase = require('./fixtures/user.json') const groupCase = require('./fixtures/group.json') const setup = async () => { - await createTestGroup() await createTestUser() // await createTestSession() @@ -17,14 +15,14 @@ const setup = async () => { setup() -async function createTestGroup () { - let g = group.read({ nt_group_id: groupCase.nt_group_id }) - if (g.length === 1) return +async function createTestGroup() { + let g = group.read({ nt_group_id: groupCase.nt_group_id }) + if (g.length === 1) return await group.create(groupCase) } -async function createTestUser () { +async function createTestUser() { let u = await user.read({ nt_user_id: userCase.nt_user_id }) if (u.length === 1) return @@ -34,10 +32,9 @@ async function createTestUser () { await user.create(instance) } -async function createTestSession () { - +async function createTestSession() { this.sessionId = await session.create({ nt_user_id: userCase.nt_user_id, nt_user_session: 12345, }) -} \ No newline at end of file +} diff --git a/test/.teardown.js b/test/.teardown.js index 7899e58..37dbfd7 100644 --- a/test/.teardown.js +++ b/test/.teardown.js @@ -1,4 +1,3 @@ - const group = require('../lib/group') // const session = require('../lib/session') const user = require('../lib/user') @@ -6,7 +5,6 @@ const userCase = require('./fixtures/user.json') const groupCase = require('./fixtures/group.json') const teardown = async () => { - // await destroyTestSession() await destroyTestUser() await destroyTestGroup() @@ -17,14 +15,14 @@ const teardown = async () => { teardown() -async function destroyTestGroup () { +async function destroyTestGroup() { await group.destroy({ nt_group_id: groupCase.nt_group_id }) } -async function destroyTestUser () { +async function destroyTestUser() { await user.destroy({ nt_user_id: userCase.nt_user_id }) } -async function destroyTestSession () { +async function destroyTestSession() { // await session.destroy({ nt_user_id: ... }) } diff --git a/test/fixtures/group.json b/test/fixtures/group.json index 9822531..1b684d5 100644 --- a/test/fixtures/group.json +++ b/test/fixtures/group.json @@ -1,6 +1,6 @@ { - "nt_group_id": 4096, - "parent_group_id": 0, - "name": "example.com", - "deleted": false -} \ No newline at end of file + "nt_group_id": 4096, + "parent_group_id": 0, + "name": "example.com", + "deleted": false +} diff --git a/test/user.js b/test/user.js index 1215699..2e7f7f6 100644 --- a/test/user.js +++ b/test/user.js @@ -127,7 +127,6 @@ describe('user', function () { ) assert.equal(r, false) }) - }) describe('authenticate', () => {