Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
msimerson committed Feb 16, 2024
1 parent e64c989 commit 480e141
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 34 deletions.
33 changes: 30 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ on:

env:
CI: true
DB_USER: root
DB_PASS: root

jobs:
lint:
Expand All @@ -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 }}
8 changes: 8 additions & 0 deletions html/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
Index
</head>
<body>
Hello World.
</body>
</html>
13 changes: 6 additions & 7 deletions lib/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
])
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Session {
nt_user_session: args.nt_user_session,
last_access: parseInt(Date.now() / 1000, 10),
})

return id
}

Expand Down
13 changes: 10 additions & 3 deletions lib/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
])
}
}

Expand Down
15 changes: 6 additions & 9 deletions test/.setup.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@

const group = require('../lib/group')
// const session = require('../lib/session')
const user = require('../lib/user')
const userCase = require('./fixtures/user.json')
const groupCase = require('./fixtures/group.json')

const setup = async () => {

await createTestGroup()
await createTestUser()
// await createTestSession()
Expand All @@ -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

Expand All @@ -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,
})
}
}
8 changes: 3 additions & 5 deletions test/.teardown.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@

const group = require('../lib/group')
// const session = require('../lib/session')
const user = require('../lib/user')
const userCase = require('./fixtures/user.json')
const groupCase = require('./fixtures/group.json')

const teardown = async () => {

// await destroyTestSession()
await destroyTestUser()
await destroyTestGroup()
Expand All @@ -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: ... })
}
10 changes: 5 additions & 5 deletions test/fixtures/group.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"nt_group_id": 4096,
"parent_group_id": 0,
"name": "example.com",
"deleted": false
}
"nt_group_id": 4096,
"parent_group_id": 0,
"name": "example.com",
"deleted": false
}
1 change: 0 additions & 1 deletion test/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ describe('user', function () {
)
assert.equal(r, false)
})

})

describe('authenticate', () => {
Expand Down

0 comments on commit 480e141

Please sign in to comment.