├── .gitignore ├── app ├── services │ └── UserService.js ├── views │ └── UserView.js └── models │ └── user.js ├── package.json ├── README.md └── test ├── views └── UserView.test.js ├── models └── user.test.js └── services └── UserService.test.js /.gitignore: -------------------------------------------------------------------------------- 1 | **/node_modules -------------------------------------------------------------------------------- /app/services/UserService.js: -------------------------------------------------------------------------------- 1 | const User = require('./../models/user') 2 | 3 | class UserService { 4 | static create(id, username, name){ 5 | return new User(id, username, name, "Sin Bio") 6 | } 7 | static getInfo(user){ 8 | return Object.values(user) 9 | } 10 | 11 | static updateUserUsername(user, username){ 12 | user.setUsername = username 13 | } 14 | 15 | static getAllUsernames(users){ 16 | const usersUsernames = users.map( user => user.username) 17 | return usersUsernames 18 | } 19 | } 20 | 21 | module.exports = UserService -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "twitter_launchx", 3 | "version": "1.0.0", 4 | "description": "Sprint 1: Agregar modelos", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "node ./node_modules/jest/bin/jest" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/RodolfoBaume/twitter_LaunchX.git" 12 | }, 13 | "author": "RodolfoBaume", 14 | "license": "ISC", 15 | "bugs": { 16 | "url": "https://github.com/RodolfoBaume/twitter_LaunchX/issues" 17 | }, 18 | "homepage": "https://github.com/RodolfoBaume/twitter_LaunchX#readme", 19 | "devDependencies": { 20 | "jest": "^27.5.1" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/views/UserView.js: -------------------------------------------------------------------------------- 1 | const UserService = require('./../services/UserService') 2 | 3 | class UserView { 4 | static createUser(payload){ 5 | if(payload === null){ 6 | console.log("Error NULL") 7 | return {error: "payload no existe."} // Sprint 3 Requerimiento 1 8 | } else if(typeof payload.username === 'string' && typeof payload.name === 'string' && typeof payload.id === "number") { 9 | return UserService.create(payload.id, payload.username, payload.name) // Sprint 3 Requerimiento 4 10 | } else { 11 | return {error: "Error, necesitan tener un valor válido."} // Sprint 3 Requerimiento 3 12 | } 13 | } 14 | } 15 | 16 | module.exports = UserView -------------------------------------------------------------------------------- /app/models/user.js: -------------------------------------------------------------------------------- 1 | class User { 2 | constructor(id, username, name, bio, dateCreated, lastUpdated){ 3 | this.id = id 4 | this.username = username 5 | this.name = name 6 | this.bio = bio 7 | this.dateCreated = new Date() 8 | this.lastUpdated = new Date() 9 | } 10 | get getUsername(){ 11 | return this.username 12 | } 13 | get getBio(){ 14 | return this.bio 15 | } 16 | get getDateCreated(){ 17 | return this.dateCreated 18 | } 19 | get getLastUpdated(){ 20 | return this.lastUpdated 21 | } 22 | 23 | set setUsername(newUsername){ 24 | this.username = newUsername 25 | } 26 | set setBio(newBio){ 27 | this.bio = newBio 28 | } 29 | } 30 | 31 | module.exports = User -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Twitter LaunchX 2 | 3 | 4 | [![](https://mermaid.ink/img/pako:eNptUstugzAQ_BXLJ6qSH0C5tE0PlXqLyImLizepJbAjPxpFKf9eP2vA-IDXM8PuzmofuBcUcIP7gSh1YOQiydhxZI9HUKtAogD4sEHPjC7fxt6cjLBES-SLiSVAiYY3Cfa7ymgr6_ZKS-ICuo3VqqeC-uBnsQEfcpkN9jPXWrNqVo3DLcWl6pUJJ7DXnNv_7nYuOIL8YX0cxnq2kUSPQHjS91oxWqM02hrNCrtjG2fOrRPMYOONuLz_jTtFTrRM8TIMSae8UEV-yjZSg8nNicFt24pjChuOqK7kPghCc3Jc4xHkSBi1q-f_6bD-BrsxuLEhhTMxg-5wxycrDa7eKdNC4kZLAzUmRovjnffpHTRxgQM4_QFOJOoO)](https://mermaid-js.github.io/mermaid-live-editor/edit#pako:eNptUstugzAQ_BXLJ6qSH0C5tE0PlXqLyImLizepJbAjPxpFKf9eP2vA-IDXM8PuzmofuBcUcIP7gSh1YOQiydhxZI9HUKtAogD4sEHPjC7fxt6cjLBES-SLiSVAiYY3Cfa7ymgr6_ZKS-ICuo3VqqeC-uBnsQEfcpkN9jPXWrNqVo3DLcWl6pUJJ7DXnNv_7nYuOIL8YX0cxnq2kUSPQHjS91oxWqM02hrNCrtjG2fOrRPMYOONuLz_jTtFTrRM8TIMSae8UEV-yjZSg8nNicFt24pjChuOqK7kPghCc3Jc4xHkSBi1q-f_6bD-BrsxuLEhhTMxg-5wxycrDa7eKdNC4kZLAzUmRovjnffpHTRxgQM4_QFOJOoO) 5 | 6 | -------------------------------------------------------------------------------- /test/views/UserView.test.js: -------------------------------------------------------------------------------- 1 | const UserView = require('./../../app/views/UserView') 2 | 3 | describe("Tests for UserView", () => { 4 | 5 | test("1) Return an error object when try to create a new user with an null payload", () => { 6 | const payload = null 7 | const result = UserView.createUser(payload) 8 | // https://jestjs.io/docs/using-matchers#strings 9 | expect(result.error).toMatch(/payload no existe/) 10 | }) 11 | 12 | test("2) Return an error object when try to create a new user with a payload with invalid properties", () => { 13 | const payload = {username: null, name: 12, id: "id"} 14 | const result = UserView.createUser(payload) 15 | expect(result.error).toMatch(/necesitan tener un valor válido/) 16 | }) 17 | 18 | test("3) Return an error object when try to create a new user with a payload with missing properties", () => { 19 | const payload = {username: "Username"} 20 | const result = UserView.createUser(payload) 21 | expect(result.error).toMatch(/necesitan tener un valor válido/) 22 | }) 23 | 24 | test("4) Create a user by a given valid payload", () => { 25 | const payload = {username: "username", id: 1, name: "name"} 26 | const result = UserView.createUser(payload) 27 | expect(result.name).toBe("name") 28 | expect(result.username).toBe("username") 29 | expect(result.id).toBe(1) 30 | }) 31 | 32 | }) -------------------------------------------------------------------------------- /test/models/user.test.js: -------------------------------------------------------------------------------- 1 | const User = require('./../../app/models/user') 2 | 3 | describe("Unit Test for User class",()=> { 4 | test('Create an User object', () => { 5 | //Aquí invocas el código que vas a usar en tu app 6 | const user = new User(1, "RodolfoBaume", "Rodolfo", "Bio") 7 | 8 | // Aquí validas los resultados de ese código 9 | // Esta es una comparación que va a igualar el valor de la izquierda con el valor de la derecha (valor esperado) 10 | expect(user.id).toBe(1) 11 | expect(user.username).toBe("RodolfoBaume") 12 | expect(user.name).toBe("Rodolfo") 13 | expect(user.bio).toBe("Bio") 14 | expect(user.dateCreated).not.toBeUndefined() // verifica que el valor no sea undefine 15 | expect(user.lastUpdated).not.toBeUndefined() 16 | }); 17 | test('Add getters',() => { 18 | const user = new User(1, "RodolfoBaume", "Rodolfo", "Bio") 19 | expect(user.getUsername).toBe("RodolfoBaume") 20 | expect(user.getBio).toBe("Bio") 21 | expect(user.dateCreated).not.toBeUndefined() // verifica que el valor no sea undefine 22 | expect(user.lastUpdated).not.toBeUndefined() 23 | }); 24 | test('Add setters',() => { 25 | const user = new User(1, "RodolfoBaume", "Rodolfo", "Bio") 26 | user.setUsername = "Baume" 27 | expect(user.username).toBe("Baume") 28 | 29 | user.setBio="New bio" 30 | expect(user.bio).toBe("New bio") 31 | }) 32 | }) -------------------------------------------------------------------------------- /test/services/UserService.test.js: -------------------------------------------------------------------------------- 1 | const UserService = require('./../../app/services/UserService') 2 | 3 | describe("Test for UserService",() => { 4 | 5 | test("1. Create a new user using the UserService", () => { 6 | const user = UserService.create(1, "rbaume", "Rodolfo") 7 | expect(user.username).toBe("rbaume") 8 | expect(user.name).toBe("Rodolfo") 9 | expect(user.id).toBe(1) 10 | expect(user.bio).not.toBeUndefined() 11 | }) 12 | 13 | test("2. Get all user data in a list", () => { 14 | const user = UserService.create(1, "rbaume", "Rodolfo") 15 | const userInfoInList = UserService.getInfo(user) 16 | 17 | expect(userInfoInList[0]).toBe(1) 18 | expect(userInfoInList[1]).toBe("rbaume") 19 | expect(userInfoInList[2]).toBe("Rodolfo") 20 | expect(userInfoInList[3]).toBe("Sin Bio") 21 | }) 22 | 23 | test("3) Update username", () => { 24 | const user = UserService.create(1, "RodolfoBaume", "Rodolfo") 25 | UserService.updateUserUsername(user, "rbaume") 26 | expect(user.username).toBe("rbaume") 27 | }) 28 | 29 | test("4) Givel all of users give me the list of usernames", () => { 30 | const user1 = UserService.create(1, "RodolfoBaume1", "Rodolfo") 31 | const user2 = UserService.create(1, "RodolfoBaume2", "Rodolfo") 32 | const user3 = UserService.create(1, "RodolfoBaume3", "Rodolfo") 33 | const usernames = UserService.getAllUsernames([user1, user2, user3]) 34 | expect(usernames).toContain("RodolfoBaume1") 35 | expect(usernames).toContain("RodolfoBaume2") 36 | expect(usernames).toContain("RodolfoBaume3") 37 | }) 38 | }) --------------------------------------------------------------------------------