Skip to content

Commit

Permalink
test(group): use the test case
Browse files Browse the repository at this point in the history
  • Loading branch information
msimerson committed Feb 26, 2024
1 parent 575a7fc commit 8a271d7
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 23 deletions.
5 changes: 4 additions & 1 deletion lib/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ class Group {

async get(args) {
return await Mysql.select(
`SELECT nt_group_id AS id, name FROM nt_group WHERE`,
`SELECT nt_group_id AS id
, parent_group_id AS parent_gid
, name
FROM nt_group WHERE`,
Util.mapToDbColumn(args, groupDbMap),
)
}
Expand Down
40 changes: 23 additions & 17 deletions lib/group.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,51 @@ const assert = require('node:assert/strict')
const { describe, it, after } = require('node:test')

const group = require('./group')
const groupTestCase = require('../test/v3/group')

after(async () => {
group._mysql.disconnect()
})

describe('group', function () {
it('gets group by id', async () => {
const g = await group.get({ id: 4096 })
const g = await group.get({ id: groupTestCase.id })
assert.deepEqual(g[0], {
id: 4096,
name: 'example.com',
id: groupTestCase.id,
name: groupTestCase.name,
parent_gid: 0,
})
})

it('gets group by name', async () => {
const u = await group.get({ name: 'example.com' })
assert.deepEqual(u[0], {
id: 4096,
name: 'example.com',
const g = await group.get({ name: groupTestCase.name })
assert.deepEqual(g[0], {
id: groupTestCase.id,
name: groupTestCase.name,
parent_gid: 0,
})
})

it('changes a group', async () => {
assert.ok(await group.put({ id: 4096, name: 'example.net' }))
assert.deepEqual(await group.get({ id: 4096 }), [
assert.ok(await group.put({ id: groupTestCase.id, name: 'example.net' }))
assert.deepEqual(await group.get({ id: groupTestCase.id }), [
{
id: 4096,
id: groupTestCase.id,
name: 'example.net',
parent_gid: 0,
},
])
assert.ok(await group.put({ id: 4096, name: 'example.com' }))
assert.ok(
await group.put({ id: groupTestCase.id, name: groupTestCase.name }),
)
})

it('deletes a group', async () => {
assert.ok(await group.delete({ id: 4096 }))
let u = await group.getAdmin({ id: 4096 })
assert.equal(u[0].deleted, 1)
await group.delete({ id: 4096 }, 0) // restore
u = await group.getAdmin({ id: 4096 })
assert.equal(u[0].deleted, 0)
assert.ok(await group.delete({ id: groupTestCase.id }))
let g = await group.getAdmin({ id: groupTestCase.id })
assert.equal(g[0].deleted, 1)
await group.delete({ id: groupTestCase.id }, 0) // restore
g = await group.getAdmin({ id: groupTestCase.id })
assert.equal(g[0].deleted, 0)
})
})
2 changes: 1 addition & 1 deletion lib/permission.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,4 @@ function getPermFields() {
'usable_ns',
].join(`, nt_perm.`)
)
}
}
4 changes: 3 additions & 1 deletion lib/permission.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ describe('permission', function () {
assert.ok(await permission.put({ id: permTestCase.id, name: 'Changed' }))
const perms = await permission.get({ id: permTestCase.id })
assert.deepEqual(perms[0].name, 'Changed')
assert.ok(await permission.put({ id: permTestCase.id, name: 'Test Permission' }))
assert.ok(
await permission.put({ id: permTestCase.id, name: 'Test Permission' }),
)
})

it('deletes a permission', async () => {
Expand Down
6 changes: 3 additions & 3 deletions test/v3/permission.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": 4095,
"uid": 4095,
"gid": 4095,
"id": 4096,
"uid": 4096,
"gid": 4096,
"inherit": true,
"name": "Test Permission",
"group_write": false,
Expand Down

0 comments on commit 8a271d7

Please sign in to comment.