-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
8 changed files
with
1,559 additions
and
717 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,8 @@ const { MongoClient, ServerApiVersion } = require('mongodb'); | |
// the mongodb server URL | ||
// const dbURL = "mongodb://localhost:27017/users"; | ||
|
||
const uri = "mongodb+srv://lionness267:[email protected]/?retryWrites=true&w=majority&appName=Cluster0"; | ||
const uri = process.env.MONGO_URI || "mongodb+srv://lionness267:[email protected]/?retryWrites=true&w=majority&appName=Cluster0"; | ||
console.log("URI: ", uri); | ||
|
||
const client = new MongoClient(uri, { | ||
serverApi: { | ||
|
@@ -88,7 +89,7 @@ const loginAccount = async (req, res) => { | |
if (exists.password === password) { | ||
req.session.username = username; | ||
req.session.save(); | ||
res.status(201).send(exists); | ||
res.status(200).send({ id: exists._id, username: exists.username }); | ||
} else { | ||
res.status(400).send('Incorrect password'); | ||
} | ||
|
@@ -103,7 +104,7 @@ const updateProfilePicture = async (req, res) => { | |
const profilePicture = req.query?.profilePicture ?? undefined; | ||
|
||
const exists = await db.collection('users').updateOne({ username: username }, { $set: { profilePicture: profilePicture } }) | ||
if (exists) { | ||
if (exists.modifiedCount > 0) { | ||
res.status(201).send('Profile picture updated') | ||
} else { | ||
res.status(400).send('User does not exist') | ||
|
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const { MongoMemoryServer } = require('mongodb-memory-server'); | ||
|
||
module.exports = async () => { | ||
const mongoServer = await MongoMemoryServer.create(); | ||
process.env.MONGO_URI = mongoServer.getUri(); | ||
|
||
// Global reference to avoid multiple instances in watch mode | ||
global.__MONGOSERVER__ = mongoServer; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = async () => { | ||
if (global.__MONGOSERVER__) { | ||
await global.__MONGOSERVER__.stop(); | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const path = require('path'); | ||
|
||
module.exports = { | ||
testEnvironment: 'node', | ||
clearMocks: true, | ||
globalSetup: path.resolve('jest-mongodb-setup.js'), | ||
globalTeardown: path.resolve('jest-mongodb-teardown.js'), | ||
}; |
Oops, something went wrong.