Skip to content

Commit

Permalink
solution 4.9*: Pruebas de lista de blogs, paso 2
Browse files Browse the repository at this point in the history
  • Loading branch information
patchamama committed Sep 10, 2023
1 parent f4361d4 commit 6b99032
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 16 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

Answers to [openfullstack.com](https://fullstackopen.com) course exercises from the University of Helsinki

## Exercises
# Exercises

### a. Structure of backend application, introduction to testing
## a. Structure of backend application, introduction to testing

- [Exercises 4.1.-4.2.](https://fullstackopen.com/en/part4/structure_of_backend_application_introduction_to_testing#exercises-4-1-4-2)
_Details solutions: [4.1](https://github.com/patchamama/fullstackopen-part4-bloglist/commit/01104c7798ad53f35ee73994826f5cc3602b9b3e) | [4.2](https://github.com/patchamama/fullstackopen-part4-bloglist/commit/7c913309759236084783f4bdfdec443c5b9e19d5)_
Expand All @@ -20,10 +20,13 @@ _The exercise 4.7 was done with [lodash library](https://github.com/patchamama/f
npm test
```

### b. Testing the backend
## b. Testing the backend

### c. User administration
- [Exercises 4.8.-4.12.](https://fullstackopen.com/es/part4/probando_el_backend#ejercicios-4-8-4-12)
_Details solutions: [4.8](https://github.com/patchamama/fullstackopen-part4-bloglist/commit/f4361d4a4973e98d2368596056f9257e1487565d) | [4.9]() | [4.10]() | [4.11]() | [4.12]()_

### d. Token authentication
## c. User administration

## Deploy
## d. Token authentication

# Deploy
15 changes: 6 additions & 9 deletions controllers/blogs.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
const blogsRouter = require('express').Router()
const Blog = require('../models/blog')

blogsRouter.get('/', (request, response) => {
Blog.find({}).then((blogs) => {
response.json(blogs)
})
blogsRouter.get('/', async (request, response) => {
const blogs = await Blog.find({})
response.json(blogs)
})

blogsRouter.post('/', (request, response) => {
blogsRouter.post('/', async (request, response) => {
const blog = new Blog(request.body)

blog.save().then((result) => {
response.status(201).json(result)
})
const result = blog.save()
response.status(201).json(result)
})

module.exports = blogsRouter
5 changes: 4 additions & 1 deletion models/blog.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
const mongoose = require('mongoose')

const blogSchema = new mongoose.Schema({
title: String,
title: {
type: String,
required: true,
},
author: String,
url: String,
likes: Number,
Expand Down
21 changes: 21 additions & 0 deletions tests/note_api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,27 @@ test('unknown endpoint in api url', async () => {
expect(response.body.error).toBe('unknown endpoint')
})

test('unique identifier property of the blog posts is named id,', async () => {
const response = await api.get('/api/blogs')
const contents = response.body[0]
// console.log(contents)
expect(contents.id).toBeDefined()
})

// test('blog without title is not added', async () => {
// const newBlog = {
// author: 'A. Pacheco',
// url: 'https://unlibroenmimochila.blogspot.com/2017/12/fugas-o-la-ansiedad-de-sentirse-vivo.html',
// likes: 4,
// }

// await api.post('/api/blogs').send(newBlog).expect(400)

// const response = await api.get('/api/blogs')

// expect(response.body).toHaveLength(initialBlogs.length)
// })

afterAll(async () => {
await mongoose.connection.close()
})

0 comments on commit 6b99032

Please sign in to comment.