-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
permission: create,get,put,delete,destroy
fixes #20
- Loading branch information
Showing
4 changed files
with
200 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,62 @@ | ||
import assert from 'node:assert/strict' | ||
import { describe, it, after } from 'node:test' | ||
import { describe, it, after, before } from 'node:test' | ||
|
||
import Permission from './permission.js' | ||
import User from './user.js' | ||
import permTestCase from './test/permission.json' with { type: 'json' } | ||
import userTestCase from './test/user.json' with { type: 'json' } | ||
|
||
before(async () => { | ||
await User.create(userTestCase) | ||
}) | ||
|
||
after(async () => { | ||
Permission.mysql.disconnect() | ||
await Permission.mysql.disconnect() | ||
}) | ||
|
||
describe('permission', function () { | ||
it('creates a permission', async () => { | ||
assert.ok(await Permission.create(permTestCase)) | ||
}) | ||
|
||
it('gets permission by id', async () => { | ||
const g = await Permission.get({ id: permTestCase.id }) | ||
assert.deepEqual(g[0], permTestCase) | ||
it('get: by id', async () => { | ||
assert.deepEqual(await Permission.get({ id: permTestCase.id }), permTestCase) | ||
}) | ||
|
||
it('get: by user id', async () => { | ||
assert.deepEqual(await Permission.get({ uid: permTestCase.user.id }), permTestCase) | ||
}) | ||
|
||
it('gets permission by user id', async () => { | ||
const g = await Permission.get({ uid: permTestCase.uid }) | ||
assert.deepEqual(g[0], permTestCase) | ||
it('get: by group id', async () => { | ||
assert.deepEqual(await Permission.get({ gid: permTestCase.group.id }), permTestCase) | ||
}) | ||
|
||
it('gets permission by group id', async () => { | ||
const g = await Permission.get({ uid: permTestCase.gid }) | ||
assert.deepEqual(g[0], permTestCase) | ||
it('getGroup: gets group permissions', async () => { | ||
assert.deepEqual(await Permission.getGroup({ uid: permTestCase.user.id }), permTestCase) | ||
}) | ||
|
||
it('changes a permission', async () => { | ||
assert.ok(await Permission.put({ id: permTestCase.id, name: 'Changed' })) | ||
const perms = await Permission.get({ id: permTestCase.id }) | ||
assert.deepEqual(perms[0].name, 'Changed') | ||
const perm = await Permission.get({ id: permTestCase.id }) | ||
assert.deepEqual(perm.name, 'Changed') | ||
assert.ok( | ||
await Permission.put({ id: permTestCase.id, name: 'Test Permission' }), | ||
) | ||
}) | ||
|
||
it('deletes a permission', async () => { | ||
assert.ok(await Permission.delete({ id: permTestCase.id })) | ||
let u = await Permission.get({ id: permTestCase.id }) | ||
assert.equal(u[0].deleted, true) | ||
let p = await Permission.get({ id: permTestCase.id }) | ||
assert.equal(p.deleted, true) | ||
await Permission.delete({ id: permTestCase.id }, 0) // restore | ||
u = await Permission.get({ id: permTestCase.id }) | ||
assert.equal(u[0].deleted, false) | ||
p = await Permission.get({ id: permTestCase.id }) | ||
assert.equal(p.deleted, false) | ||
}) | ||
|
||
it('destroys a permission', async () => { | ||
const r = await Permission.destroy({ id: permTestCase.id }) | ||
assert.equal(r.affectedRows, 1) | ||
const p = await Permission.get({ id: permTestCase.id }) | ||
assert.equal(p, undefined) | ||
}) | ||
}) |
Oops, something went wrong.