|
| 1 | +import assert from 'node:assert/strict' |
| 2 | +import { describe, it, after, before } from 'node:test' |
| 3 | + |
| 4 | +<<<<<<<< HEAD:lib/session/test/index.js |
| 5 | +import User from '../../user/index.js' |
| 6 | +import Session from '../index.js' |
| 7 | +import userCase from '../../user/test/user.json' with { type: 'json' } |
| 8 | +======== |
| 9 | +import User from '../index.js' |
| 10 | +import Session from '../session.js' |
| 11 | +import userCase from './user.json' with { type: 'json' } |
| 12 | +>>>>>>>> a2746b1 (mv ./lib/session ./lib/user/session):lib/user/test/session.js |
| 13 | + |
| 14 | +const sessionUser = { |
| 15 | + ...userCase, |
| 16 | + id: userCase.id + 100, |
| 17 | + username: `${userCase.username}-session`, |
| 18 | + email: `session-${userCase.email}`, |
| 19 | +} |
| 20 | + |
| 21 | +before(async () => { |
| 22 | + await User.create(sessionUser) |
| 23 | +}) |
| 24 | + |
| 25 | +after(async () => { |
| 26 | + await Session.delete({ uid: sessionUser.id }) |
| 27 | + await User.destroy({ id: sessionUser.id }) |
| 28 | + await User.mysql.disconnect() |
| 29 | +}) |
| 30 | + |
| 31 | +describe('session', function () { |
| 32 | + let sessionId |
| 33 | + |
| 34 | + describe('create', () => { |
| 35 | + it('creates a login session', async () => { |
| 36 | + sessionId = await Session.create({ |
| 37 | + nt_user_id: sessionUser.id, |
| 38 | + session: '3.0.0', |
| 39 | + last_access: parseInt(Date.now() / 1000, 10), |
| 40 | + }) |
| 41 | + assert.ok(sessionId) |
| 42 | + }) |
| 43 | + }) |
| 44 | + |
| 45 | + describe('get', () => { |
| 46 | + it('finds a session by id', async () => { |
| 47 | + const s = await Session.get({ id: sessionId }) |
| 48 | + assert.ok(s?.id) |
| 49 | + }) |
| 50 | + |
| 51 | + it('finds a session by nt_user_session_id', async () => { |
| 52 | + const s = await Session.get({ nt_user_session_id: sessionId }) |
| 53 | + assert.ok(s?.id) |
| 54 | + }) |
| 55 | + |
| 56 | + it('finds a session by session', async () => { |
| 57 | + const s = await Session.get({ nt_user_session: '3.0.0' }) |
| 58 | + assert.ok(s?.id) |
| 59 | + }) |
| 60 | + }) |
| 61 | + |
| 62 | + describe('delete', () => { |
| 63 | + it('deletes a session by ID', async () => { |
| 64 | + assert.ok(await Session.delete({ id: sessionId })) |
| 65 | + }) |
| 66 | + |
| 67 | + it('does not find a deleted session', async () => { |
| 68 | + assert.equal(await Session.get({ id: sessionId }), undefined) |
| 69 | + }) |
| 70 | + }) |
| 71 | +}) |
0 commit comments