Skip to content

Commit

Permalink
user.test: use creds from json test case
Browse files Browse the repository at this point in the history
  • Loading branch information
msimerson committed Mar 9, 2024
1 parent f00011f commit 546043d
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions lib/user.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { describe, it, after, before } from 'node:test'
import User from './user.js'
import Group from './group.js'

import testCase from './test/user.json' with { type: 'json' }
import userCase from './test/user.json' with { type: 'json' }
import groupCase from './test/group.json' with { type: 'json' }

before(async () => {
Expand All @@ -26,41 +26,41 @@ function sanitize(u) {
describe('user', function () {
describe('POST', function () {
it('creates a user', async () => {
assert.ok(await User.create(testCase))
let users = await User.get({ id: testCase.id })
assert.deepEqual(users[0], sanitize(testCase))
assert.ok(await User.create(userCase))
let users = await User.get({ id: userCase.id })
assert.deepEqual(users[0], sanitize(userCase))
})
})

describe('GET', function () {
it('finds existing user by id', async () => {
const u = await User.get({ id: testCase.id })
const u = await User.get({ id: userCase.id })
// console.log(u)
assert.deepEqual(u[0], sanitize(testCase))
assert.deepEqual(u[0], sanitize(userCase))
})

it('finds existing user by username', async () => {
const u = await User.get({ username: 'unit-test' })
assert.deepEqual(u[0], sanitize(testCase))
assert.deepEqual(u[0], sanitize(userCase))
})
})

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

describe('DELETE', function () {
it('deletes a user', async () => {
assert.ok(await User.delete({ id: testCase.id }))
let u = await User.get({ id: testCase.id, deleted: true })
assert.ok(await User.delete({ id: userCase.id }))
let u = await User.get({ id: userCase.id, deleted: true })
assert.equal(u[0].deleted, true)
await User.delete({ id: testCase.id, deleted: false }) // restore
u = await User.get({ id: testCase.id })
await User.delete({ id: userCase.id, deleted: false }) // restore
u = await User.get({ id: userCase.id })
assert.equal(u[0].deleted, undefined)
})
})
Expand Down Expand Up @@ -129,8 +129,8 @@ describe('user', function () {

it('accepts a valid username & password', async () => {
const u = await User.authenticate({
username: '[email protected]',
password: 'Wh@tA-Decent#P6ssw0rd',
username: `${userCase.username}@${groupCase.name}`,
password: userCase.password,
})
assert.ok(u)
})
Expand Down

0 comments on commit 546043d

Please sign in to comment.