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: ... }) +}