-
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.
solution 4.8: Pruebas de lista de blogs, paso 1
- Loading branch information
1 parent
82fc7cd
commit f4361d4
Showing
8 changed files
with
88 additions
and
21 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
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
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,59 @@ | ||
const mongoose = require('mongoose') | ||
const supertest = require('supertest') | ||
const app = require('../app') | ||
const api = supertest(app) | ||
const Blog = require('../models/blog') | ||
const initialBlogs = [ | ||
{ | ||
title: 'Cinco ecuaciones que cambiaron el mundo', | ||
author: 'A. Pacheco', | ||
url: 'https://unlibroenmimochila.blogspot.com/2018/02/cinco-ecuaciones-que-cambiaron-el-mundo.html', | ||
likes: 2, | ||
}, | ||
{ | ||
title: 'El tortuoso camino de la justicia transicional', | ||
author: 'Rafael Rojas', | ||
url: 'https://www.librosdelcrepusculo.com.mx/2023/09/el-tortuoso-camino-de-la-justicia.html', | ||
likes: 1, | ||
}, | ||
] | ||
beforeEach(async () => { | ||
await Blog.deleteMany({}) | ||
let blogObject = new Blog(initialBlogs[0]) | ||
await blogObject.save() | ||
blogObject = new Blog(initialBlogs[1]) | ||
await blogObject.save() | ||
}) | ||
|
||
test('notes are returned as json', async () => { | ||
await api | ||
.get('/api/blogs') | ||
.expect(200) | ||
.expect('Content-Type', /application\/json/) | ||
}, 100000) | ||
|
||
test('all notes are returned', async () => { | ||
const response = await api.get('/api/blogs') | ||
// console.log(response.body) | ||
expect(response.body).toHaveLength(initialBlogs.length) | ||
}) | ||
|
||
test('a specific note is within the returned notes', async () => { | ||
const response = await api.get('/api/blogs') | ||
// console.log(response.body[0]) | ||
|
||
const contents = response.body.map((r) => r.title) | ||
// console.log(contents) | ||
expect(contents).toContain('El tortuoso camino de la justicia transicional') | ||
}) | ||
|
||
test('unknown endpoint in api url', async () => { | ||
const response = await api.get('/api/blogs-url-dont-exist') | ||
// console.log(response.body) | ||
|
||
expect(response.body.error).toBe('unknown endpoint') | ||
}) | ||
|
||
afterAll(async () => { | ||
await mongoose.connection.close() | ||
}) |
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,3 @@ | ||
module.exports = () => { | ||
process.exit(0) | ||
} |
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