-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
83f2d91
commit ca86511
Showing
14 changed files
with
74 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,8 @@ export async function checkExistence (collectionName, id) { | |
// Obtain a property from the database. Useful if the property is private | ||
// and thus unavailable to the client | ||
export async function getProperty (collectionName, id, path) { | ||
const doc = await mongoose.connection.db.collection(collectionName).find({ _id: id }, { [path]: 1 }, {limit: 1}).next(); | ||
const doc = await mongoose.connection.db.collection(collectionName) | ||
.find({ _id: id }, { [path]: 1 }, { limit: 1 }).next(); | ||
return get(doc, path); | ||
} | ||
|
||
|
@@ -23,54 +24,53 @@ export async function resetHabiticaDB () { | |
const groups = mongoose.connection.db.collection('groups'); | ||
const users = mongoose.connection.db.collection('users'); | ||
return mongoose.connection.dropDatabase() | ||
.then(() => { | ||
return users.countDocuments({ _id: '7bde7864-ebc5-4ee2-a4b7-1070d464cdb0' }); | ||
}).then(count => { | ||
if (count > 0) return; | ||
return users.insertOne({ | ||
_id: '7bde7864-ebc5-4ee2-a4b7-1070d464cdb0', | ||
apiToken: TAVERN_ID, | ||
auth: { | ||
local: { | ||
username: 'username', | ||
lowerCaseUsername: 'username', | ||
email: '[email protected]', | ||
hashed_password: 'hashed_password', // eslint-disable-line camelcase | ||
passwordHashMethod: 'bcrypt', | ||
}, | ||
}, | ||
.then(() => users.countDocuments({ _id: '7bde7864-ebc5-4ee2-a4b7-1070d464cdb0' })).then(count => { | ||
if (count === 0) { | ||
users.insertOne({ | ||
_id: '7bde7864-ebc5-4ee2-a4b7-1070d464cdb0', | ||
apiToken: TAVERN_ID, | ||
auth: { | ||
local: { | ||
username: 'username', | ||
lowerCaseUsername: 'username', | ||
email: '[email protected]', | ||
hashed_password: 'hashed_password', // eslint-disable-line camelcase | ||
passwordHashMethod: 'bcrypt', | ||
}, | ||
}, | ||
}); | ||
} | ||
}).then(() => groups.countDocuments({ _id: TAVERN_ID })) | ||
.then(count => { | ||
if (count === 0) { | ||
groups.insertOne({ | ||
_id: TAVERN_ID, | ||
chat: [], | ||
leader: '7bde7864-ebc5-4ee2-a4b7-1070d464cdb0', // Siena Leslie | ||
name: 'HabitRPG', | ||
type: 'guild', | ||
privacy: 'public', | ||
memberCount: 0, | ||
}); | ||
} | ||
}); | ||
}).then(() => { | ||
return groups.countDocuments({ _id: TAVERN_ID }); | ||
}).then(count => { | ||
if (count > 0) return; | ||
return groups.insertOne({ | ||
_id: TAVERN_ID, | ||
chat: [], | ||
leader: '7bde7864-ebc5-4ee2-a4b7-1070d464cdb0', // Siena Leslie | ||
name: 'HabitRPG', | ||
type: 'guild', | ||
privacy: 'public', | ||
memberCount: 0, | ||
}); | ||
}) | ||
} | ||
|
||
export async function updateDocument (collectionName, doc, update) { | ||
const collection = mongoose.connection.db.collection(collectionName); | ||
return await collection.updateOne({ _id: doc._id }, { $set: update }); | ||
return collection.updateOne({ _id: doc._id }, { $set: update }); | ||
} | ||
|
||
// Unset a property in the database. | ||
// Useful for testing. | ||
export async function unsetDocument (collectionName, doc, update) { | ||
const collection = mongoose.connection.db.collection(collectionName); | ||
return await collection.updateOne({ _id: doc._id }, { $unset: update }); | ||
return collection.updateOne({ _id: doc._id }, { $unset: update }); | ||
} | ||
|
||
export async function getDocument (collectionName, doc) { | ||
const collection = mongoose.connection.db.collection(collectionName); | ||
return await collection.findOne({ _id: doc._id }); | ||
return collection.findOne({ _id: doc._id }); | ||
} | ||
|
||
before(done => { | ||
|
@@ -80,9 +80,8 @@ before(done => { | |
.then(() => { | ||
done(); | ||
}) | ||
.catch(err => { | ||
logger.error(err); | ||
throw err; | ||
.catch(error => { | ||
throw error; | ||
}); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters