Skip to content

Commit

Permalink
add more proves b00tc4mp#182
Browse files Browse the repository at this point in the history
  • Loading branch information
JCEXCELSIOR committed Nov 19, 2024
1 parent 166c6d1 commit d4cc456
Show file tree
Hide file tree
Showing 37 changed files with 331 additions and 258 deletions.
4 changes: 2 additions & 2 deletions staff/josue-cano/unsocial/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ db.connect(process.env.MONGO_URL_TEST).then(() => {

return logic
.authenticateUser(username, password)
.then((userId) =>
jwt.sign({ sub: userId, }, process.env.JWT_SECRET, { expiresIn: "1h" })
.then(({userId, role}) =>
jwt.sign({ sub: userId, role }, process.env.JWT_SECRET, { expiresIn: "1h" })
)
.then((token) => res.json(token));
})
Expand Down
5 changes: 4 additions & 1 deletion staff/josue-cano/unsocial/api/logic/authenticateUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ export default (username, password) => {
.then(user => {
if (!user) throw new CredentialsError('wrong credentials')

return user._id.toString()
return{
userId: user._id.toString(),
role: user.role
}
})
}
47 changes: 47 additions & 0 deletions staff/josue-cano/unsocial/api/logic/deletePost.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import 'dotenv/config'

import * as chai from 'chai'
import chaiAsPromised from 'chai-as-promised';

chai.use(chaiAsPromised)
const { expect } = chai

import db, { User, Post } from 'dat'
import { errors } from "../../com/index.js"

const { SystemError, NotFoundError, OwnershipError} = errors

import deletePost from './deletePost.js';

//describe es para indicar de que traba la prueba
describe('deletePost', () => {
before (() => db.connect(process.env.MONGO_URL_TEST))
//antes de cada prueba
beforeEach(() => Promise.all([User.deleteMany(), Post.deleteMany()]))
//la prueba efectiva borrar post
it('succes delete post', () => {
const user = new User({ name: 'Coco Loco', email: '[email protected]', username: 'cocoloco', password: '123123123' })
const post = new Post({ author: user.id, image: 'https://www.image.com', text: 'hello world' })

//guarda el usuario en la base de datos
user.save()
//ahora si guarda me guardas el post
.then(() => post.save())
// si se gurda el post lo borro
.then(()=> {
deletePost(user.id, post.id)
//si se borra lo buscas
.then(() => Post.findById(post.id))
//evaluo el post
.then(post => {
expect(post).to.be.null

}
)
})

})


})

5 changes: 3 additions & 2 deletions staff/josue-cano/unsocial/api/logic/getPosts.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ export default userId => {
User.findById(userId).lean(),
Post.find().populate('author', 'username').sort({ date: -1 }).lean()
])
.catch(error => { throw new SystemError(error.message) })
.catch(error => { console.log(error)
throw new SystemError(error.message) })
.then(([user, posts]) => {
if (!user) throw new NotFoundError('user not found')

console.log(posts)
posts.forEach(post => {
post.id = post._id.toString()
delete post._id
Expand Down
4 changes: 2 additions & 2 deletions staff/josue-cano/unsocial/app/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { useState } from 'react'

import { Login, Register, Post, CreatePost } from './view'

import Header from './components/functional/Header'
import Footer from './components/functional/Footer'
import Header from './view/components/Header'
import Footer from './view/components/Footer'

import logic from './logic'

Expand Down

This file was deleted.

This file was deleted.

59 changes: 0 additions & 59 deletions staff/josue-cano/unsocial/app/src/components/functional/Header.jsx

This file was deleted.

99 changes: 0 additions & 99 deletions staff/josue-cano/unsocial/app/src/components/functional/Post.jsx

This file was deleted.

2 changes: 1 addition & 1 deletion staff/josue-cano/unsocial/app/src/view/CreatePost.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logic from '../logic'

import { Label, Input, Button, Form, Field } from '../components/library'
import { Label, Input, Button, Form, Field } from './library'

import './CreatePost.css'

Expand Down
2 changes: 1 addition & 1 deletion staff/josue-cano/unsocial/app/src/view/Login.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import './Login.css'

import { PasswordInput, Input, Button, Form, Field, Label } from '../components/library'
import { PasswordInput, Input, Button, Form, Field, Label } from './library'

import logic from '../logic'

Expand Down
2 changes: 1 addition & 1 deletion staff/josue-cano/unsocial/app/src/view/Post.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState, useEffect } from 'react'

import { Post } from '../components/functional'
import { Post } from './components'

import logic from '../logic'

Expand Down
2 changes: 1 addition & 1 deletion staff/josue-cano/unsocial/app/src/view/Register.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import './Register.css'

import { PasswordInput, Input, Button, Form, Field, Label } from '../components/library'
import { PasswordInput, Input, Button, Form, Field, Label } from './library'

import logic from '../logic'

Expand Down
Loading

0 comments on commit d4cc456

Please sign in to comment.