forked from Laboratoria/BOG001-social-network
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creación de test unitarios historia 1 70% Stmts
- Loading branch information
Showing
8 changed files
with
116 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const auth = { | ||
createUserWithEmailAndPassword: (email, password) => { | ||
const emailChar = /[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$/; | ||
const passChar = /^.{6,}$/; | ||
return new Promise ((resolve, reject) => { | ||
const user = { | ||
email: email, | ||
password: password | ||
}; | ||
if (emailChar.test(email) && passChar.test(password)) { | ||
user.email; | ||
user.password; | ||
} else { | ||
reject('error'); | ||
}; | ||
|
||
resolve(`nuevo usuario ${user.email}, ${user.password}`); | ||
}) | ||
}, | ||
signInWithEmailAndPassword: (email, password) => { | ||
return new Promise ((resolve, reject) => { | ||
resolve(`usuario ${email}, ${password}`); | ||
reject('error') | ||
}) | ||
}, | ||
sendPasswordResetEmail: (email) => { | ||
return new Promise ((resolve, reject) => { | ||
resolve(email); | ||
reject('error'); | ||
}) | ||
}, | ||
signOut: () => { | ||
return new Promise ((resolve, reject) => { | ||
resolve(); | ||
reject('error'); | ||
}) | ||
} | ||
} | ||
|
||
export default jest.fn(() => { | ||
return auth; | ||
}) |
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
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
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 |
---|---|---|
@@ -1,8 +1,61 @@ | ||
// importamos la funcion que vamos a testear | ||
import { signUp, logIn, logInGoogle, recoverPass, signOut } from "../src/lib/index"; | ||
// importamos la funciones firebase.auth que vamos a testear | ||
import authmock from '../_mocks_/mock_auth.js'; | ||
|
||
describe('myFunction', () => { | ||
import { | ||
signUp, logIn, logInGoogle, recoverPass, signOut, | ||
} from '../src/lib/firebaseAuth.js'; | ||
|
||
global.auth = authmock(); | ||
|
||
describe('signUp', () => { | ||
it('debería ser una función', () => { | ||
expect(typeof signUp).toBe('function'); | ||
}); | ||
|
||
it('debería retornar [email protected] , contraseña1234', async () => { | ||
const newUser = await signUp('[email protected]', 'contraseña1234'); | ||
expect(newUser).toBe('nuevo usuario [email protected], contraseña1234'); | ||
}); | ||
|
||
it('debería retornar error;', async () => { | ||
const newUser = await signUp('email@emailcom', 'contraseña123'); | ||
expect(newUser).toBe('error'); | ||
}); | ||
|
||
it('debería retornar error;', async () => { | ||
const newUser = await signUp('[email protected]', 'abc'); | ||
expect(newUser).toBe('error'); | ||
}); | ||
}); | ||
|
||
describe('logIn', () => { | ||
it('debería ser una función', () => { | ||
expect(typeof myFunction).toBe('function'); | ||
expect(typeof logIn).toBe('function'); | ||
}); | ||
it('debería retornar [email protected] , contraseña1234', async () => { | ||
const user = await logIn('[email protected]', 'contraseña1234'); | ||
console.log(user); | ||
expect(user).toBe('usuario [email protected], contraseña1234'); | ||
}); | ||
}); | ||
|
||
describe('recoverPass', () => { | ||
it('debería ser una función', () => { | ||
expect(typeof recoverPass).toBe('function'); | ||
}); | ||
it('debería retornar Hemos enviado un email a [email protected] para cambiar la contraseña', async () => { | ||
const message = document.createElement('p'); | ||
const recover = await recoverPass(message, '[email protected]'); | ||
expect(recover).toBe('Hemos enviado un email a [email protected] para cambiar la contraseña'); | ||
}); | ||
}); | ||
|
||
describe('signOut', () => { | ||
it('debería ser una función', () => { | ||
expect(typeof signOut).toBe('function'); | ||
}); | ||
it('debería retornar Hemos enviado un email a [email protected] para cambiar la contraseña', async () => { | ||
const outUser = await signOut(); | ||
expect(outUser).toBe(undefined); | ||
}); | ||
}); |