-
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.
Merge pull request #3 from laineveeti/bugfixing
fixed issues with test environment
- Loading branch information
Showing
13 changed files
with
169 additions
and
178 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
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -1,12 +1,38 @@ | ||
const router = require('express').Router(); | ||
const bcrypt = require('bcrypt'); | ||
const Blog = require('../models/blog'); | ||
const User = require('../models/user'); | ||
const { initialBlogs, initialUsers } = require('../tests/api/test_helper'); | ||
|
||
router.post('/reset', async (request, response) => { | ||
await Blog.deleteMany({}); | ||
await User.deleteMany({}); | ||
|
||
await Promise.all( | ||
initialUsers.map(async (user) => { | ||
const newUser = new User({ | ||
username: user.username, | ||
name: user.name, | ||
password: await bcrypt.hash(user.password, 10), | ||
}); | ||
return await newUser.save(); | ||
}) | ||
); | ||
|
||
const someUser = await User.findOne({ username: 'user1' }); | ||
|
||
const savedBlogs = await Promise.all( | ||
initialBlogs.map((blog) => { | ||
const newBlog = Blog(blog); | ||
newBlog.user = someUser._id; | ||
return newBlog.save(); | ||
}) | ||
); | ||
|
||
someUser.blogs = savedBlogs.map((blog) => blog._id); | ||
await someUser.save(); | ||
|
||
response.status(204).end(); | ||
}); | ||
|
||
module.exports = router; | ||
module.exports = router; |
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 config = { | ||
testPathIgnorePatterns: ['frontend/*'], | ||
verbose: true, | ||
forceExit: true, | ||
testEnvironment: 'node', | ||
}; | ||
|
||
module.exports = config; |
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 |
---|---|---|
@@ -1,37 +1,34 @@ | ||
{ | ||
"name": "bloglist", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"start": "NODE_ENV=production node index.js", | ||
"dev": "NODE_ENV=development nodemon index.js", | ||
"build": "cd frontend && npm run build", | ||
"render:deploy": "npm install && cd frontend && npm install && npm run build", | ||
"eslint": "eslint .", | ||
"test": "NODE_ENV=test jest --verbose --runInBand --forceExit", | ||
"start:test": "NODE_ENV=test node index.js" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"bcrypt": "^5.1.0", | ||
"cors": "^2.8.5", | ||
"dotenv": "^16.0.3", | ||
"express": "^4.18.2", | ||
"express-async-errors": "^3.1.1", | ||
"jsonwebtoken": "^9.0.0", | ||
"mongoose": "^6.8.3" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^8.32.0", | ||
"eslint-plugin-cypress": "^3.3.0", | ||
"eslint-plugin-react": "^7.34.3", | ||
"jest": "^29.3.1", | ||
"nodemon": "^2.0.20", | ||
"supertest": "^6.3.3" | ||
}, | ||
"jest": { | ||
"testEnvironment": "node" | ||
} | ||
"name": "bloglist", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"start": "NODE_ENV=production node index.js", | ||
"dev": "NODE_ENV=development nodemon index.js", | ||
"build": "cd frontend && npm run build", | ||
"render:deploy": "npm install && cd frontend && npm install && npm run build", | ||
"eslint": "eslint .", | ||
"test": "NODE_ENV=testing jest --verbose --runInBand --forceExit", | ||
"start:test": "NODE_ENV=testing node index.js" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"bcrypt": "^5.1.0", | ||
"cors": "^2.8.5", | ||
"dotenv": "^16.0.3", | ||
"express": "^4.18.2", | ||
"express-async-errors": "^3.1.1", | ||
"jsonwebtoken": "^9.0.0", | ||
"mongoose": "^6.8.3" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^8.32.0", | ||
"eslint-plugin-cypress": "^3.3.0", | ||
"eslint-plugin-react": "^7.34.3", | ||
"jest": "^29.3.1", | ||
"nodemon": "^2.0.20", | ||
"supertest": "^6.3.3" | ||
} | ||
} |
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
Oops, something went wrong.