From e4608ce68ccb4d954446c0cfd9ee3646d0b08ab6 Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Wed, 14 Feb 2024 22:14:25 -0800 Subject: [PATCH] partial user, group, & session --- routes/base.js | 10 ++++++++++ test/.setup.js | 40 ++++++++++++++++++++++++++++++++++++++++ test/.teardown.js | 28 ++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 routes/base.js create mode 100644 test/.setup.js create mode 100644 test/.teardown.js diff --git a/routes/base.js b/routes/base.js new file mode 100644 index 0000000..6bc8175 --- /dev/null +++ b/routes/base.js @@ -0,0 +1,10 @@ +// exports.meta = { +// api: { +// version: require('../package.json').version, +// } +// } + +// exports.asInt = function (i) { +// if (parseInt(i, 10)) return parseInt(i, 10) +// return +// } diff --git a/test/.setup.js b/test/.setup.js new file mode 100644 index 0000000..cb2c262 --- /dev/null +++ b/test/.setup.js @@ -0,0 +1,40 @@ +const group = require('../lib/group') +// const session = require('../lib/session') +const user = require('../lib/user') +const userCase = require('./fixtures/user.json') +const groupCase = require('./fixtures/group.json') + +const setup = async () => { + await createTestGroup() + await createTestUser() + // await createTestSession() + await user._mysql.disconnect() + await group._mysql.disconnect() + process.exit(1) +} + +setup() + +async function createTestGroup() { + let g = group.read({ nt_group_id: groupCase.nt_group_id }) + if (g.length === 1) return + + await group.create(groupCase) +} + +async function createTestUser() { + let u = await user.read({ nt_user_id: userCase.nt_user_id }) + if (u.length === 1) return + + const instance = JSON.parse(JSON.stringify(userCase)) + instance.password = 'Wh@tA-Decent#P6ssw0rd' + + await user.create(instance) +} + +async function createTestSession() { + this.sessionId = await session.create({ + nt_user_id: userCase.nt_user_id, + nt_user_session: 12345, + }) +} diff --git a/test/.teardown.js b/test/.teardown.js new file mode 100644 index 0000000..37dbfd7 --- /dev/null +++ b/test/.teardown.js @@ -0,0 +1,28 @@ +const group = require('../lib/group') +// const session = require('../lib/session') +const user = require('../lib/user') +const userCase = require('./fixtures/user.json') +const groupCase = require('./fixtures/group.json') + +const teardown = async () => { + // await destroyTestSession() + await destroyTestUser() + await destroyTestGroup() + await user._mysql.disconnect() + await group._mysql.disconnect() + process.exit(1) +} + +teardown() + +async function destroyTestGroup() { + await group.destroy({ nt_group_id: groupCase.nt_group_id }) +} + +async function destroyTestUser() { + await user.destroy({ nt_user_id: userCase.nt_user_id }) +} + +async function destroyTestSession() { + // await session.destroy({ nt_user_id: ... }) +}