Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unified auth experience for Volunteer signup/login[Staging] #167

Open
wants to merge 54 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
6a5444a
Merge pull request #139 from CodeYourFuture/feature-765-add-iam-not-s…
khmdagal Sep 21, 2023
f62249b
Merge pull request #130 from CodeYourFuture/dependabot/npm_and_yarn/w…
AL-ASHMALI Sep 21, 2023
9187734
Create fetch fucntion to get employers data from the database
khmdagal Dec 1, 2023
a641c80
Remove hard coded employers array
khmdagal Dec 1, 2023
5afb787
Create a POST request to post new employer name to the database and s…
khmdagal Dec 1, 2023
ec272aa
Add mock postNewEmployer function
khmdagal Dec 1, 2023
b70e0a9
Remove code that adding new employer name to the database
khmdagal Dec 11, 2023
1b7591e
Create sample employer data in e2e/fixture file and updated journey t…
khmdagal Jan 19, 2024
3bdcc1e
Merge pull request #151 from CodeYourFuture/feature-create-a-DB-of-em…
AL-ASHMALI Jan 30, 2024
1177ae3
Edit variable names
khmdagal Feb 6, 2024
d9205f3
Assert correct employer name so test to pass
khmdagal Feb 7, 2024
5003ef5
Revert all changes that were merged to the qa
khmdagal Feb 15, 2024
9cc7d3c
Replace Capgemini to original code Cap
khmdagal Feb 28, 2024
5a45596
Merge pull request #153 from CodeYourFuture/feature/697-move-employer…
ChidimmaOfodum Mar 4, 2024
7417398
Merge pull request #154 from CodeYourFuture/feature/697-move-employer…
khmdagal Apr 4, 2024
b542351
Merge pull request #156 from CodeYourFuture/bump-babel-traverse-to-7.…
CanaryWharf Apr 9, 2024
0257b0c
Unified auth experience for Volunteer signup/login
josamit Jun 10, 2024
f79efb7
Unified auth experience for Volunteer signup/login
josamit Jun 10, 2024
2443baf
Unified auth experience for Volunteer signup/login
josamit Jun 11, 2024
2b0851e
Unified auth experience for Volunteer signup/login
josamit Jun 11, 2024
1d74d9b
Unified auth experience for Volunteer signup/login
josamit Jun 17, 2024
04b9109
error msg displayed
ChidimmaOfodum Jul 12, 2024
d606604
updating e2e tests
ChidimmaOfodum Jul 15, 2024
aa69cde
updating lock file
ChidimmaOfodum Jul 15, 2024
82ad517
path to private key from working dir
ChidimmaOfodum Jul 15, 2024
5604ce7
path to private key from working dir
ChidimmaOfodum Jul 15, 2024
dfa1116
path to private key from working dir
ChidimmaOfodum Jul 15, 2024
5a07c6a
flake free test
ChidimmaOfodum Jul 15, 2024
e60a74e
change class to functional component
ChidimmaOfodum Jul 18, 2024
bf0ff19
reusable icon component
ChidimmaOfodum Jul 19, 2024
625ad00
node-engine revert
ChidimmaOfodum Jul 19, 2024
d05836e
adding login in beforeEach
ChidimmaOfodum Jul 30, 2024
2c4fade
Delete e2e/privatekey
ChidimmaOfodum Aug 5, 2024
530d9a3
Merge pull request #164 from josamit/cyf-twlo
ChidimmaOfodum Aug 5, 2024
11bb6c8
Unified auth experience for Volunteer signup/login
josamit Jun 10, 2024
c665c2b
Unified auth experience for Volunteer signup/login
josamit Jun 10, 2024
475d4ed
Unified auth experience for Volunteer signup/login
josamit Jun 11, 2024
dedf18b
Unified auth experience for Volunteer signup/login
josamit Jun 11, 2024
ea46975
Unified auth experience for Volunteer signup/login
josamit Jun 17, 2024
7e2ed53
error msg displayed
ChidimmaOfodum Jul 12, 2024
b61d627
updating e2e tests
ChidimmaOfodum Jul 15, 2024
5ec722a
updating lock file
ChidimmaOfodum Jul 15, 2024
f5e5cb8
path to private key from working dir
ChidimmaOfodum Jul 15, 2024
9ecdfed
flake free test
ChidimmaOfodum Jul 15, 2024
278526c
change class to functional component
ChidimmaOfodum Jul 18, 2024
a838fd4
reusable icon component
ChidimmaOfodum Jul 19, 2024
065a5b3
node-engine revert
ChidimmaOfodum Jul 19, 2024
ee4acea
adding login in beforeEach
ChidimmaOfodum Jul 30, 2024
fa165a0
rebase changes
ChidimmaOfodum Aug 5, 2024
90a23a1
Remove unnecessary setting of auth headers
josamit Aug 7, 2024
7eb71bf
eslint cleanup
ChidimmaOfodum Aug 14, 2024
3992651
Merge branch 'qa' into cyf-twlo
ChidimmaOfodum Aug 14, 2024
23c36be
eslint cleanup
ChidimmaOfodum Aug 14, 2024
4a835ec
remove token from headers
ChidimmaOfodum Sep 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion cypress.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
const webpackPreprocessor = require('@cypress/webpack-preprocessor')
const { JwtCreation } = require('@jc21/cypress-jwt-creation')
const { defineConfig } = require('cypress')

module.exports = defineConfig({
e2e: {
baseUrl: 'http://localhost:3000',
specPattern: 'e2e/integration/*.test.js',
supportFile: 'e2e/support/index.js'
supportFile: 'e2e/support/index.js',

setupNodeEvents(on, config) {
on(
'file:preprocessor',
webpackPreprocessor(webpackPreprocessor.defaultOptions)
)
on('task', JwtCreation(config))
return config
}
},
env: {
jwtPrivateKey: `${process.cwd()}/e2e/privatekey.txt`
},
fixturesFolder: 'e2e/fixtures',
screenshotsFolder: 'e2e/screenshots',
Expand Down
34 changes: 20 additions & 14 deletions e2e/integration/journey.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const mockServerURL = 'http://localhost:3001'
const email = 'jane.doe@morge.org'
const firstName = 'Jane'
const lastName = 'Doe'

beforeEach(() => {
cy.intercept('GET', `${mockServerURL}/cities?visibleIn=VOLUNTEER_FORM`, {
Expand All @@ -10,31 +13,39 @@ beforeEach(() => {
cy.intercept('GET', `${mockServerURL}/employers`, {
fixture: 'employers.json'
})
cy.visit('/')

cy.task('generateToken', {
claims: { email, fullName: `${firstName} ${lastName}` },
algo: 'HS256'
}).then(token => cy.login(token))
})

it('can submit a minimal form', () => {
cy.findByRole('textbox', { name: /email/i }).should('have.value', email)
cy.findByRole('textbox', { name: /first name/i }).should(
'have.value',
firstName
)
cy.findByRole('textbox', { name: /last name/i }).should(
'have.value',
lastName
)

cy.intercept('POST', `${mockServerURL}/volunteer`, req => {
req.reply({ volunteer: { _id: 'some-new-id', ...req.body } })
}).as('createVolunteer')
const initialData = {
firstName: 'Jane',
lastName: 'Doe',
email: 'jane.doe@morgue.org',
tel: '01189998819991197253',
interestedInVolunteer: 'just sounds interesting',
interestedInCYF: 'trying to do my bit',
industry: 'Education',
hearAboutCYF: 'Social media'
}

cy.findByRole('textbox', { name: /first name/i }).type(initialData.firstName)
cy.findByRole('textbox', { name: /last name/i }).type(initialData.lastName)
//email, first & last name pre-populated at login
cy.findByRole('combobox', { name: /city/i }).select('London')
cy.findByRole('combobox', {
name: /select the team you want to volunteer for/i
}).select('Education')
cy.findByRole('textbox', { name: /email/i }).type(initialData.email)
cy.findByRole('textbox', { name: /phone number/i }).type(initialData.tel)
cy.findByRole('textbox', { name: /interested in volunteering/i }).type(
initialData.interestedInVolunteer
Expand Down Expand Up @@ -93,9 +104,7 @@ it('can submit a minimal form', () => {
name: 'ReactJS'
})
})
cy.findByText(
`Welcome ${initialData.firstName} ${initialData.lastName}`
).should('exist')
cy.findByText(`Welcome ${firstName} ${lastName}`).should('exist')
cy.findByText(/thank you for submitting your application/i).should('exist')
})

Expand All @@ -104,13 +113,10 @@ it('requires employee selection', () => {
req.reply({ volunteer: { _id: 'some-new-id', ...req.body } })
}).as('createVolunteer')

cy.findByRole('textbox', { name: /first name/i }).type('Laura')
cy.findByRole('textbox', { name: /last name/i }).type('Olsen')
cy.findByRole('combobox', { name: /city/i }).select('London')
cy.findByRole('combobox', {
name: /select the team you want to volunteer for/i
}).select('5e863b833150f6001b34627d')
cy.findByRole('textbox', { name: /email/i }).type('laura.olsen@example.com')
cy.findByRole('textbox', { name: /phone number/i }).type('96838503')
cy.findByRole('textbox', { name: /interested in volunteering/i }).type('just')
cy.findByRole('textbox', { name: /interested in code your future/i }).type(
Expand Down
12 changes: 8 additions & 4 deletions e2e/integration/withCode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ beforeEach(() => {
cy.intercept('GET', `${mockServerURL}/teams`, {
fixture: 'teams.json'
})
cy.intercept('GET', `${mockServerURL}/employers`, {
fixture: 'teams.json'
})
cy.task('generateToken', {
claims: { email: 'foo@bar.org' },
algo: 'HS256'
}).then(token => cy.login(token))
})

it('shows success message', () => {
Expand All @@ -25,9 +32,6 @@ it('includes the user ID when resubmitting', () => {
cy.findByRole('textbox', { name: /first name/i }).type('Erhard')
cy.findByRole('textbox', { name: /last name/i }).type('Hennemann')
cy.findByRole('combobox', { name: /city/i }).select('London')
cy.findByRole('textbox', { name: /email/i }).type(
'erhard.hennemann@example.com'
)
cy.findByRole('combobox', {
name: /select the team you want to volunteer for/i
}).select('Education')
Expand All @@ -46,6 +50,7 @@ it('includes the user ID when resubmitting', () => {
})

it('lets you request a reminder email', () => {
// cy.login(token)
cy.intercept('POST', `${mockServerURL}/volunteer/email/verification`, {
statusCode: 200
}).as('verifyEmail')
Expand All @@ -60,7 +65,6 @@ it('lets you request a reminder email', () => {
// TODO why is this a clickable span?!
cy.findByText('here').click()
// TODO not accessible by label
cy.findByRole('textbox').type(email)
cy.findByRole('button', { name: /submit/i }).click()

cy.wait('@verifyEmail').then(({ request: { body: payload } }) => {
Expand Down
1 change: 1 addition & 0 deletions e2e/privatekey.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
JWT_SECRET
20 changes: 20 additions & 0 deletions e2e/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,23 @@
// https://on.cypress.io/custom-commands
// ***********************************************//
import '@testing-library/cypress/add-commands'
const mockServerURL = 'http://localhost:3001'

Cypress.Commands.add('login', token => {
cy.intercept('POST', `${mockServerURL}/volunteer/login`, req => {
req.reply({ token })
}).as('login')
cy.visit('/')
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(200)
cy.findByRole('textbox', { name: /email/i })
.should('be.visible')
.type('jane@codeyourfuture.io')
cy.findByRole('button', { name: /submit/i })
.should('be.visible')
.click()
cy.wait('@login')

cy.findByText(/Please check your email/i).should('exist')
cy.visit(`${Cypress.config('baseUrl')}/log-in/${token}`)
})
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"private": true,
"dependencies": {
"axios": "^1.1.2",
"jwt-decode": "^2.2.0",
"moment": "^2.23.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down Expand Up @@ -64,6 +65,8 @@
]
},
"devDependencies": {
"@cypress/webpack-preprocessor": "^6.0.2",
"@jc21/cypress-jwt-creation": "^0.0.6",
"@testing-library/cypress": "^8.0.3",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
Expand Down
15 changes: 15 additions & 0 deletions src/Components/Loading/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react'

export default ({ err, msg }) => {
if (err) {
return <p className="errors">{err}</p>
}
if (msg) {
return <p className="success">{msg}</p>
}
return (
<div className="d-flex justify-content-center mt-5 p-5">
<div className="loader" />
</div>
)
}
35 changes: 35 additions & 0 deletions src/Components/auth/EmailLogin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React, { Fragment } from 'react'

export default props => (
<Fragment>
<p className="login-p1">Welcome</p>
<form className="mt-0" onSubmit={props.handleSubmit}>
<div className="form-group-login">
<label htmlFor="email" className="lead">
Log in with email
</label>
{props.error && <p className="errors">{props.error}</p>}
<div>
<input
type="email"
id="email"
name="email"
className="form-control2"
value={props.email}
required
onChange={props.onChange}
/>
<button
disabled={props.email.trim() === ' '}
className="sign-up-btnn"
type="submit"
name="submit"
>
Submit
</button>
</div>
</div>
</form>
<p className="line1">or</p>
</Fragment>
)
28 changes: 28 additions & 0 deletions src/Components/auth/Login.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React, { useEffect, useState } from 'react'
import * as AuthService from '../../layout/AuthService'
import { useNavigate, useParams } from 'react-router-dom'

const GitHubLogIn = () => {
const navigate = useNavigate()
const params = useParams()
const { token } = params
const [error, setError] = useState(null)

useEffect(() => {
const redirectUser = async token => {
if (token) {
await AuthService.setToken(token)
navigate('/')
} else {
setError('No token provided, please make sure you have the right URL')
}
}
redirectUser(token)
}, [navigate, token])

return (
<div className="sign-in">{error && <p className="error">{error}</p>}</div>
)
}

export default GitHubLogIn
18 changes: 18 additions & 0 deletions src/Components/auth/Loginlogo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading