Skip to content

Commit

Permalink
partial user, group, & session
Browse files Browse the repository at this point in the history
  • Loading branch information
msimerson committed Feb 22, 2024
1 parent 99908d7 commit e4608ce
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
10 changes: 10 additions & 0 deletions routes/base.js
Original file line number Diff line number Diff line change
@@ -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
// }
40 changes: 40 additions & 0 deletions test/.setup.js
Original file line number Diff line number Diff line change
@@ -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,
})
}
28 changes: 28 additions & 0 deletions test/.teardown.js
Original file line number Diff line number Diff line change
@@ -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: ... })
}

0 comments on commit e4608ce

Please sign in to comment.