From 546043d7653e49e9f4118aa7f2a3c11660b81a43 Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Fri, 8 Mar 2024 16:30:14 -0800 Subject: [PATCH] user.test: use creds from json test case --- lib/user.test.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/user.test.js b/lib/user.test.js index 460ef63..bab699c 100644 --- a/lib/user.test.js +++ b/lib/user.test.js @@ -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 () => { @@ -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) }) }) @@ -129,8 +129,8 @@ describe('user', function () { it('accepts a valid username & password', async () => { const u = await User.authenticate({ - username: 'unit-test@example.com', - password: 'Wh@tA-Decent#P6ssw0rd', + username: `${userCase.username}@${groupCase.name}`, + password: userCase.password, }) assert.ok(u) })