mirror of
https://github.com/Permissionless-Software-Foundation/x402-base-facilitator.git
synced 2026-09-21 16:52:01 -07:00
Adding admin delete test case
This commit is contained in:
+29
-1
@@ -20,9 +20,16 @@ describe('Users', () => {
|
||||
password: 'pass2'
|
||||
}
|
||||
const testUser = await testUtils.createUser(userObj)
|
||||
console.log(`testUser: ${JSON.stringify(testUser, null, 2)}`)
|
||||
|
||||
context.user2 = testUser.user
|
||||
context.token2 = testUser.token
|
||||
context.id2 = testUser.user._id
|
||||
|
||||
// Get the JWT used to log in as the admin 'system' user.
|
||||
const adminJWT = await testUtils.getAdminJWT()
|
||||
console.log(`adminJWT: ${adminJWT}`)
|
||||
context.adminJWT = adminJWT
|
||||
})
|
||||
|
||||
describe('POST /users', () => {
|
||||
@@ -476,7 +483,7 @@ describe('Users', () => {
|
||||
}
|
||||
})
|
||||
|
||||
it('should delete user', async () => {
|
||||
it('should delete own user', async () => {
|
||||
const {
|
||||
user: { _id },
|
||||
token
|
||||
@@ -498,5 +505,26 @@ describe('Users', () => {
|
||||
|
||||
assert.equal(result.body.success, true)
|
||||
})
|
||||
|
||||
it('should delete other account when admin', async () => {
|
||||
const id = context.id2
|
||||
const adminJWT = context.adminJWT
|
||||
|
||||
const options = {
|
||||
method: 'DELETE',
|
||||
uri: `${LOCALHOST}/users/${id}`,
|
||||
resolveWithFullResponse: true,
|
||||
json: true,
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${adminJWT}`
|
||||
}
|
||||
}
|
||||
|
||||
const result = await rp(options)
|
||||
console.log(`result: ${util.inspect(result.body)}`)
|
||||
|
||||
assert.equal(result.body.success, true)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
+20
-1
@@ -1,5 +1,6 @@
|
||||
const mongoose = require('mongoose')
|
||||
const rp = require('request-promise')
|
||||
const config = require('../config')
|
||||
|
||||
const LOCALHOST = 'http://localhost:5000'
|
||||
|
||||
@@ -128,10 +129,28 @@ async function loginAdminUser () {
|
||||
}
|
||||
}
|
||||
|
||||
// Retrieve the admin user JWT token from the JSON file it's saved at.
|
||||
async function getAdminJWT () {
|
||||
try {
|
||||
// process.env.KOA_ENV = process.env.KOA_ENV || 'dev'
|
||||
// console.log(`env: ${process.env.KOA_ENV}`)
|
||||
|
||||
const FILENAME = `../config/system-user-test.json`
|
||||
const adminUserData = require(FILENAME)
|
||||
// console.log(`adminUserData: ${JSON.stringify(adminUserData, null, 2)}`)
|
||||
|
||||
return adminUserData.token
|
||||
} catch (err) {
|
||||
console.error('Error in test/utils.js/getAdminJWT()')
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
cleanDb,
|
||||
authUser,
|
||||
createUser,
|
||||
loginTestUser,
|
||||
loginAdminUser
|
||||
loginAdminUser,
|
||||
getAdminJWT
|
||||
}
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
const mongoose = require('mongoose')
|
||||
|
||||
const config = require('../config')
|
||||
|
||||
// Connect to the Mongo Database.
|
||||
mongoose.Promise = global.Promise
|
||||
mongoose.connect(config.database, () => {
|
||||
// mongoose.connection.db.dropDatabase()
|
||||
})
|
||||
|
||||
console.log(`config: ${JSON.stringify(config, null, 2)}`)
|
||||
|
||||
/*
|
||||
// Wipe the DB.
|
||||
function cleanDb () {
|
||||
for (const collection in mongoose.connection.collections) {
|
||||
if (mongoose.connection.collections.hasOwnProperty(collection)) {
|
||||
mongoose.connection.collections[collection].remove()
|
||||
}
|
||||
}
|
||||
console.log(`Database wiped.`)
|
||||
}
|
||||
cleanDb()
|
||||
*/
|
||||
|
||||
mongoose.connection.close()
|
||||
|
||||
console.log(`
|
||||
Here's how to wipe the db:
|
||||
1. mongo
|
||||
2. use p2pvps-server-dev
|
||||
3. db.dropDatabase()
|
||||
4. exit
|
||||
`)
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
Here's how to wipe the db:
|
||||
1. mongo
|
||||
2. use koa-server-dev
|
||||
3. db.dropDatabase()
|
||||
4. exit
|
||||
Reference in New Issue
Block a user