Skip to content

Commit

Permalink
user.put: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
msimerson committed Feb 26, 2024
1 parent 25e1078 commit 88d6943
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/group.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('group', function () {
assert.ok(await group.put({ id: 4096, name: 'example.com' }))
})

it('delete a group', async () => {
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)
Expand Down
20 changes: 9 additions & 11 deletions lib/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,15 @@ class User {
}
}

// async get_perms(user_id) {
// return await Mysql.execute(
// `
// SELECT ${getPermFields()} FROM nt_perm
// WHERE deleted=0
// AND nt_user_id = ?`,
// [user_id],
// )
// }
async get_perms(user_id) {
return await Mysql.execute(
`
SELECT ${getPermFields()} FROM nt_perm
WHERE deleted=0
AND nt_user_id=?`,
[user_id],
)
}

Check warning on line 148 in lib/user.js

View check run for this annotation

Codecov / codecov/patch

lib/user.js#L141-L148

Added lines #L141 - L148 were not covered by tests

generateSalt(length = 16) {
const chars = Array.from({ length: 87 }, (_, i) =>
Expand Down Expand Up @@ -194,7 +194,6 @@ class User {
module.exports = new User()
module.exports._mysql = Mysql

/*
function getPermFields() {
return (
`nt_perm.` +
Expand Down Expand Up @@ -226,4 +225,3 @@ function getPermFields() {
].join(`, nt_perm.`)
)
}
*/
13 changes: 10 additions & 3 deletions lib/user.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ after(async () => {
})

describe('user', function () {
describe('get', function () {
describe('GET', function () {
it('finds existing user by id', async () => {
const u = await user.get({ id: 4096 })
// console.log(u)
Expand Down Expand Up @@ -36,11 +36,18 @@ describe('user', function () {
// deleted: 0,
})
})
})

describe('PUT', function () {
it.todo('modifies existing user', async () => {
//
assert.ok(await user.put({ id: 4096, first_name: 'Untie' }))
let users = await user.get({ id: 4096 })
assert.equal(users[0].first_name, 'Untie')
await user.put({ id: 4096, first_name: 'Unit' })
})
})

describe('DELETE', function () {
it('deletes a user', async () => {
assert.ok(await user.delete({ id: 4096 }))
let u = await user.getAdmin({ id: 4096 })
Expand All @@ -53,7 +60,7 @@ describe('user', function () {

describe('get_perms', function () {
it.skip('gets user permissions', async () => {
const p = await user.get_perms(242)
const p = await user.get_perms(4096)
assert.deepEqual(p[0], {
group_create: 1,
group_delete: 1,
Expand Down

0 comments on commit 88d6943

Please sign in to comment.