Skip to content

Instantly share code, notes, and snippets.

View PierreCavalet's full-sized avatar

Pierre Cavalet PierreCavalet

  • Kaliop Interactive Media
  • Montpellier, France
View GitHub Profile
@PierreCavalet
PierreCavalet / passport.md
Created December 10, 2018 07:25
Authentification avec Passport.js

Authentification avec Passport.js

Passport.js est un middleware permettant de gérer l'authentification. Il s'intègre très bien avec Express.js. L'authentification est le processus de vérification qu'un utilisateur est bien celui qu'il prétend être.

Notre système d'authentification utilisera un JSON web token.

Comprendre ce qu'est un JSON web token (JWT)

Un JWT permet à un utilisateur de certifier certaines informations. Il est composé de 3 parties:

describe('Login', () => {
it('Should log the user from home page', () => {
cy.visit('https://workshop-cypress-kaliop.netlify.app/')
cy.get('[data-cy="login-link"]').click()
cy.url().should('eq', 'https://workshop-cypress-kaliop.netlify.app/login')
cy.get('[data-cy="login-gif"]').should('exist')
cy.get('[data-cy="email-input"]').type('myemail@email.com')
cy.get('[data-cy="password-input"]').type('*secretPassword*')
@PierreCavalet
PierreCavalet / homepage.spec.js
Last active May 6, 2020 08:44
with goTo command
describe('Homepage', () => {
it('Checks if everything is in the page', () => {
cy.goTo('home')
cy.get('[data-cy="home-title"]').should('exist')
cy.get('[data-cy="home-gif"]').should('exist')
})
})
const router = require('../services/router')
Cypress.Commands.add('goTo', (routeName) => {
cy.visit(router.resolve(routeName))
})
const routes = {
home: 'https://workshop-cypress-kaliop.netlify.app/',
login: 'https://workshop-cypress-kaliop.netlify.app/login',
signup: 'https://workshop-cypress-kaliop.netlify.app/signup',
}
const router = {
resolve: (name) => routes[name],
}
describe('Signup', () => {
it('Should signup the user', () => {
cy.visit(`https://workshop-cypress-kaliop.netlify.app/signup`)
cy.get(`[data-cy="signup-gif"]`).should('exist')
cy.get('[data-cy="firstname-input"]').type('Jordan')
cy.get('[data-cy="lastname-input"]').type('Jordan')
cy.get('[data-cy="email-input"]').type('myemail@email.com')
cy.get('[data-cy="password-input"]').type('*secretPassword*')
cy.get('[data-cy="submit-button"]').click()
const axios = require('axios')
module.exports = (on, config) => {
on('task', {
getCode() {
return axios
.get('https://us-central1-random-d85ea.cloudfunctions.net/codeWorkshop')
.then((response) => response.data.code)
},
})
describe('Homepage', () => {
it('Checks if everything is in the page', () => {
cy.visit('https://workshop-cypress-kaliop.netlify.app/')
cy.get('[data-cy="home-title"]').should('exist')
cy.get('[data-cy="home-gif"]').should('exist')
})
})
@PierreCavalet
PierreCavalet / decode.js
Last active December 5, 2019 10:13
decode
function decode(score) {
const decodedInformation = [
{ name: 'The user has not read the article', value: score & 8 },
{ name: 'The user has tags that match the article tags', value: score & 4 },
{ name: 'The article is flagged important', value: score & 2 }
]
decodedInformation.forEach(info => {
// value is either 0 or the number used with the '&' operator.
// we transform it to a boolean, 0 => false, anything else => true.
{
"took": 29,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 3,