Upload 4.14
This commit is contained in:
@@ -31,4 +31,17 @@ blogsRouter.delete('/:id', async (request, response) => {
|
|||||||
response.status(204).end()
|
response.status(204).end()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
blogsRouter.put('/:id', async (request, response) => {
|
||||||
|
const body = request.body
|
||||||
|
|
||||||
|
const blog = await Blog.findByIdAndUpdate(request.params.id, {
|
||||||
|
title: body.title,
|
||||||
|
author: body.author,
|
||||||
|
url: body.url,
|
||||||
|
likes: body.likes
|
||||||
|
}, { new: true })
|
||||||
|
|
||||||
|
response.status(200).json(blog)
|
||||||
|
})
|
||||||
|
|
||||||
module.exports = blogsRouter
|
module.exports = blogsRouter
|
||||||
7
part4/bloglist/requests/update_blog.rest
Normal file
7
part4/bloglist/requests/update_blog.rest
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
PUT http://localhost:3001/api/blogs/6477906c6320872422793b7a
|
||||||
|
content-type: application/json
|
||||||
|
|
||||||
|
{
|
||||||
|
"title": "Updated blog", "author": "Hans", "url": "www.andrew.eu", "likes": 5000
|
||||||
|
|
||||||
|
}
|
||||||
@@ -84,6 +84,40 @@ describe('adding blog', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('deleting blog', () => {
|
||||||
|
test('a blog can be deleted', async () => {
|
||||||
|
const blogsAtStart = await helper.blogsInDb()
|
||||||
|
const blogToDelete = blogsAtStart[0]
|
||||||
|
|
||||||
|
await api.delete(`/api/blogs/${blogToDelete.id}`).expect(204)
|
||||||
|
|
||||||
|
const blogsAtEnd = await helper.blogsInDb()
|
||||||
|
expect(blogsAtEnd).toHaveLength(helper.initialBlogs.length - 1)
|
||||||
|
const contents = blogsAtEnd.map((r) => r.title)
|
||||||
|
expect(contents).not.toContain(blogToDelete.title)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('updating blog', () => {
|
||||||
|
test('a blog can be updated', async () => {
|
||||||
|
const blogsAtStart = await helper.blogsInDb()
|
||||||
|
const blogToUpdate = blogsAtStart[0]
|
||||||
|
|
||||||
|
const newBlog = {
|
||||||
|
title: 'Updated blog',
|
||||||
|
author: blogToUpdate.author,
|
||||||
|
url: blogToUpdate.url,
|
||||||
|
likes: blogToUpdate.likes
|
||||||
|
}
|
||||||
|
|
||||||
|
await api.put(`/api/blogs/${blogToUpdate.id}`).send(newBlog).expect(200)
|
||||||
|
|
||||||
|
const blogsAtEnd = await helper.blogsInDb()
|
||||||
|
expect(blogsAtEnd).toHaveLength(helper.initialBlogs.length)
|
||||||
|
const contents = blogsAtEnd.map((r) => r.title)
|
||||||
|
expect(contents).toContain('Updated blog')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('blog id check', () => {
|
describe('blog id check', () => {
|
||||||
test('blog id is defined', async () => {
|
test('blog id is defined', async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user