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

[#21] [#8] As a user, I can login with an email and password #35

Open
wants to merge 25 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
13e34ac
[#25] Initial
liamstevens111 Feb 16, 2023
7e7c360
[#21] Base and Auth adapter for sending request, only includes login …
liamstevens111 Feb 16, 2023
e720450
[#21] Add UserToken helper module abstraction that uses LocalStorage …
liamstevens111 Feb 16, 2023
cc04cf4
[#21] Add test code for making request and storing token on client si…
liamstevens111 Feb 16, 2023
7df8a9c
[#21] Move base URL from auth adapter to base adapter as common for e…
liamstevens111 Feb 17, 2023
9a62f4f
[#21] Fix padding and add value prop to Input element. Make button ty…
liamstevens111 Feb 17, 2023
b5647ac
[#21] Allow form to send user/password to API for token. Use Form onS…
liamstevens111 Feb 17, 2023
9ff4294
[#21] Add form error handling WIP
liamstevens111 Feb 17, 2023
2e00ee5
Cleanup
liamstevens111 Feb 17, 2023
58e583c
[#21] Change form error state from map of key/values to just a list d…
liamstevens111 Feb 20, 2023
0019700
[#21] Update package lock since pinning versions
liamstevens111 Feb 21, 2023
dcca881
[#21] Use nock for mocking API response WIP
liamstevens111 Feb 22, 2023
bf4386f
[#21] Add tests for valid and invalid credientials
liamstevens111 Feb 22, 2023
e3231ce
[#21] Add env example file
liamstevens111 Feb 22, 2023
ba6f301
[#21] Add tests for LocalStorage and authAdapter
liamstevens111 Feb 23, 2023
8d9c7e7
[#21] Add cypress tests
liamstevens111 Feb 23, 2023
1385ce6
[#21] Commented out the two cypress tests failing on CI/CD for login …
liamstevens111 Feb 23, 2023
9d0540f
[#21] Change baseAdapter request function argument name from param to…
liamstevens111 Mar 1, 2023
61d68f0
[#21] Add generic server error to translations
liamstevens111 Mar 1, 2023
9538bf5
[#21] Attempt to fix Netflix deploy on links not working
liamstevens111 Mar 1, 2023
34943f6
[#21] Attempt to fix Netflix deploy on links not working
liamstevens111 Mar 1, 2023
fb04b03
[#21] Add artifact upload to test workflow for cypress failures
liamstevens111 Mar 3, 2023
bee4a87
[#21] Add artifact upload for failed cypress tests
liamstevens111 Mar 7, 2023
9929fd1
[#21] Remove redundant class and javascript curcly braces for props
liamstevens111 Mar 8, 2023
71150ac
[#21] Fix artifact upload in workflow and add env variables to ensure…
liamstevens111 Mar 8, 2023
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
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
REACT_APP_DEFAULT_LANGUAGE=en
REACT_APP_API_ENDPOINT=
REACT_APP_API_CLIENT_ID=
REACT_APP_API_CLIENT_SECRET=
13 changes: 13 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ name: Test

on: pull_request

env:
REACT_APP_API_ENDPOINT: ${{ secrets.API_ENDPOINT }}
REACT_APP_API_CLIENT_ID: ${{ secrets.API_CLIENT_ID }}
REACT_APP_API_CLIENT_SECRET: ${{ secrets.API_CLIENT_SECRET }}

jobs:
test:
name: Run linters and tests
Expand Down Expand Up @@ -33,6 +38,14 @@ jobs:
- name: Run integration tests
run: npm run cypress

- name: Upload any cypress failures
uses: actions/upload-artifact@v3
if: failure()
with:
name: cypress-output
path: cypress/videos
retention-days: 5

- name: Merge code coverage reports
run: npm run test:merge-coverage

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

# misc
.DS_Store
.env
.env.local
.env.development.local
.env.test.local
Expand Down
1 change: 1 addition & 0 deletions cypress/fixtures/Authentication/invalid-credentials.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "errors": [{ "detail": "Your email or password is incorrect. Please try again.", "code": "invalid_email_or_password" }] }
13 changes: 13 additions & 0 deletions cypress/fixtures/Authentication/valid-credentials.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"data": {
"id": "18422",
"type": "token",
"attributes": {
"access_token": "3XwBqiXrM-xhHCc-0QCKsOuE0Xp9AYdYTiZwTSqo4M4",
"token_type": "Bearer",
"expires_in": 7200,
"refresh_token": "QOiwCsTV7Wn4mO56Kz-4rj8nGCWfVMcIwSbKo4yicEk",
"created_at": 1677124678
}
}
}
72 changes: 72 additions & 0 deletions cypress/integration/Authentication/login.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
describe('User Authentication', () => {
context('upon navigation to /login', () => {
it('displays login page', () => {
cy.visit('/login');

cy.findByTestId('login-header').should('be.visible');
});
});

// TODO: The below test fail on CI/CD with the use of Intercept

context('given valid credentials', () => {
it('redirects to the home page', () => {
cy.intercept('POST', '/oauth/token/', {
statusCode: 200,
fixture: 'Authentication/valid-credentials.json',
});

cy.visit('/login');

cy.get('input[name=email]').type('[email protected]');
cy.get('input[name=password]').type('12345678');
cy.get('button[type="submit"]').click();

cy.location().should((location) => {
expect(location.pathname).to.eq('/');
});
});
});

context('given NO credentials entered', () => {
it('shows field validation errors', () => {
cy.visit('/login');

cy.get('button[type="submit"]').click();

cy.get('.errors').should('be.visible');

cy.get('.errors').within(() => {
cy.contains('Email has invalid format');
cy.contains('Password should be at least');
});
});
});

// TODO: The below test fail on CI/CD with the use of Intercept

context('given INVALID credentials', () => {
it('shows login error', () => {
cy.intercept('POST', '/oauth/token/', {
statusCode: 400,
fixture: 'Authentication/invalid-credentials.json',
});

cy.visit('/login');

cy.get('input[name=email]').type('[email protected]');
cy.get('input[name=password]').type('password123');
cy.get('button[type="submit"]').click();

cy.location().should((location) => {
expect(location.pathname).to.eq('/login');
});

cy.get('.errors').should('be.visible');

cy.get('.errors').within(() => {
cy.findByText('Your email or password is incorrect. Please try again.').should('exist');
});
});
});
});
9 changes: 0 additions & 9 deletions cypress/integration/UserAuthentication/login.spec.ts

This file was deleted.

141 changes: 141 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,19 @@
"danger": "10.9.0",
"danger-plugin-istanbul-coverage": "1.6.2",
"eslint": "8.11.0",
"jest-localstorage-mock": "2.4.26",
"nock": "13.3.0",
"postcss": "8.4.21",
"postcss-import": "14.1.0",
"prettier": "2.6.0",
"prettier-plugin-tailwindcss": "0.2.3",
"start-server-and-test": "1.14.0",
"stylelint": "14.6.0",
"tailwindcss": "3.2.6",
"typescript": "4.6.2"
},
"jest": {
"resetMocks": false,
"collectCoverageFrom": [
"src/**/*.{js,jsx,ts,tsx}",
"!src/**/*.d.ts"
Expand Down
1 change: 1 addition & 0 deletions public/_redirects
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* /index.html 200
7 changes: 5 additions & 2 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{
"login": {
"sign_in": "Sign in",
"sign-in": "Sign in",
"email": "Email",
"password": "Password",
"forgot_password": "Forgot?"
"forgot-password": "Forgot?",
"invalid-email": "Email has invalid format",
"invalid-password": "Password should be at least {{passwordMinLength}}",
"generic-server-error": "There was a problem receiving a response from the server"
}
}
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const App = (): JSX.Element => {

return (
<div>
<main className="flex flex-col p-0 m-0 h-screen items-center justify-center">{appRoutes}</main>
<main className="m-0 flex h-screen flex-col items-center justify-center p-0">{appRoutes}</main>
</div>
);
};
Expand Down
Loading