Skip to content

Commit

Permalink
fix: make auth work in client
Browse files Browse the repository at this point in the history
  • Loading branch information
spaenleh committed Nov 14, 2024
1 parent b741c23 commit bb840b3
Show file tree
Hide file tree
Showing 81 changed files with 1,590 additions and 1,337 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ VITE_SHOW_NOTIFICATIONS=true

VITE_UMAMI_WEBSITE_ID=<the id of your umami project>
VITE_UMAMI_HOST=http://localhost:8000

VITE_SENTRY_ENV= # some value
VITE_SENTRY_DSN= # some value

VITE_RECAPTCHA_SITE_KEY= # some value
```
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { SIGN_IN_PATH } from '../../src/config/paths';
import { LOGIN_PAGE_PATH } from '../../../src/config/paths';
import {
MAGIC_LINK_EMAIL_FIELD_ID,
REDIRECTION_CONTENT_CONTAINER_ID,
SUCCESS_CONTENT_ID,
} from '../../src/config/selectors';
import { MEMBERS } from '../fixtures/members';
} from '../../../src/config/selectors';
import { AUTH_MEMBERS } from '../../fixtures/members';

const DEFAULT_REDIRECTION_URL = Cypress.env('VITE_DEFAULT_REDIRECTION_URL');

describe('Name and Email Validation', () => {
beforeEach(() => {
cy.setUpApi();
cy.setUpApi({});
});
it('Sign In', () => {
const { GRAASP, WRONG_EMAIL } = MEMBERS;
cy.visit(SIGN_IN_PATH);
const { GRAASP, WRONG_EMAIL } = AUTH_MEMBERS;
cy.visit(LOGIN_PAGE_PATH);
// Signing in with a wrong email format
cy.signInByMailAndCheck(WRONG_EMAIL);
// Signing in with a valid email
Expand All @@ -24,7 +24,7 @@ describe('Name and Email Validation', () => {

describe('Already signed in', () => {
beforeEach(() => {
cy.setUpApi({ currentMember: MEMBERS.BOB });
cy.setUpApi({ currentMember: AUTH_MEMBERS.BOB });
});

it('Should show logged in', () => {
Expand All @@ -38,11 +38,13 @@ describe('Already signed in', () => {

describe('Sign In', () => {
beforeEach(() => {
cy.setUpApi();
cy.visit(SIGN_IN_PATH);
cy.setUpApi({});
cy.visit(LOGIN_PAGE_PATH);
});
it('Can use Enter to validate email', () => {
cy.get(`#${MAGIC_LINK_EMAIL_FIELD_ID}`).type(`${MEMBERS.BOB.email}{Enter}`);
cy.get(`#${MAGIC_LINK_EMAIL_FIELD_ID}`).type(
`${AUTH_MEMBERS.BOB.email}{Enter}`,
);
cy.get(`#${SUCCESS_CONTENT_ID}`).should('be.visible');
});
});
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import { StatusCodes } from 'http-status-codes';

import { API_ROUTES } from '@graasp/query-client';

import { SIGN_IN_PATH, SIGN_UP_PATH } from '../../src/config/paths';
import { StatusCodes } from 'http-status-codes';

import {
BACK_BUTTON_ID,
EMAIL_SIGN_IN_FIELD_ID,
RESEND_EMAIL_BUTTON_ID,
SIGN_IN_HEADER_ID,
SIGN_UP_HEADER_ID,
SUCCESS_CONTENT_ID,
} from '../../src/config/selectors';
import { MEMBERS } from '../fixtures/members';
} from '../../../src/config/selectors';
import { AUTH_MEMBERS } from '../../fixtures/members';

describe('Success Content', () => {
describe('Sign In', () => {
it('Back Button', () => {
const { GRAASP, GRAASP_OTHER } = MEMBERS;
cy.visit(SIGN_IN_PATH);
const { GRAASP, GRAASP_OTHER } = AUTH_MEMBERS;
cy.visit('/auth/login');

cy.intercept(API_ROUTES.SIGN_IN_ROUTE, ({ reply }) => {
return reply({
Expand All @@ -35,7 +34,7 @@ describe('Success Content', () => {
cy.get(`#${BACK_BUTTON_ID}`).click();

cy.get(`#${SUCCESS_CONTENT_ID}`).should('not.exist');
cy.url().should('include', SIGN_IN_PATH);
cy.url().should('include', '/auth/login');
cy.get(`#${SIGN_IN_HEADER_ID}`).should('be.visible');
// checks so email is cleared
cy.get(`#${EMAIL_SIGN_IN_FIELD_ID}`).should('be.empty');
Expand All @@ -48,15 +47,15 @@ describe('Success Content', () => {
cy.get(`#${BACK_BUTTON_ID}`).click();

cy.get(`#${SUCCESS_CONTENT_ID}`).should('not.exist');
cy.url().should('include', SIGN_IN_PATH);
cy.url().should('include', '/auth/login');
cy.get(`#${SIGN_IN_HEADER_ID}`).should('be.visible');
// checks so email is cleared
cy.get(`#${EMAIL_SIGN_IN_FIELD_ID}`).should('be.empty');
});

it('Resend email', () => {
const { GRAASP, GRAASP_OTHER } = MEMBERS;
cy.visit(SIGN_IN_PATH);
const { GRAASP, GRAASP_OTHER } = AUTH_MEMBERS;
cy.visit('/auth/login');

cy.intercept(API_ROUTES.SIGN_IN_ROUTE, ({ reply }) => {
return reply({
Expand Down Expand Up @@ -89,8 +88,8 @@ describe('Success Content', () => {
});
});
it('Back Button', () => {
const { GRAASP, GRAASP_OTHER } = MEMBERS;
cy.visit(SIGN_UP_PATH);
const { GRAASP, GRAASP_OTHER } = AUTH_MEMBERS;
cy.visit('/auth/register');

cy.get(`#${SUCCESS_CONTENT_ID}`).should('not.exist');

Expand All @@ -102,7 +101,7 @@ describe('Success Content', () => {
cy.get(`#${BACK_BUTTON_ID}`).click();

cy.get(`#${SUCCESS_CONTENT_ID}`).should('not.exist');
cy.url().should('include', SIGN_UP_PATH);
cy.url().should('include', '/auth/register');
cy.get(`#${SIGN_UP_HEADER_ID}`).should('be.visible');

// check if it's possible to sign up and use back button again
Expand All @@ -113,13 +112,13 @@ describe('Success Content', () => {
cy.get(`#${BACK_BUTTON_ID}`).click();

cy.get(`#${SUCCESS_CONTENT_ID}`).should('not.exist');
cy.url().should('include', SIGN_UP_PATH);
cy.url().should('include', '/auth/register');
cy.get(`#${SIGN_UP_HEADER_ID}`).should('be.visible');
});

it('Resend email', () => {
const { GRAASP, GRAASP_OTHER } = MEMBERS;
cy.visit(SIGN_UP_PATH);
const { GRAASP, GRAASP_OTHER } = AUTH_MEMBERS;
cy.visit('/auth/register');

// Signing up with a valid email
cy.signUpAndCheck(GRAASP_OTHER, true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import { StatusCodes } from 'http-status-codes';

import { API_ROUTES } from '@graasp/query-client';

import { SIGN_UP_PATH } from '../../src/config/paths';
import { StatusCodes } from 'http-status-codes';

import {
EMAIL_SIGN_UP_FIELD_ID,
NAME_SIGN_UP_FIELD_ID,
SIGN_UP_BUTTON_ID,
SIGN_UP_SAVE_ACTIONS_ID,
SUCCESS_CONTENT_ID,
} from '../../src/config/selectors';
import { MEMBERS } from '../fixtures/members';
} from '../../../src/config/selectors';
import { AUTH_MEMBERS } from '../../fixtures/members';
import { checkInvitationFields, fillSignUpLayout } from './util';

describe('SignUp', () => {
describe('Must Accept All Terms To Sign Up', () => {
beforeEach(() => {
cy.visit(SIGN_UP_PATH);
cy.visit('/auth/register');
cy.intercept({ method: 'post', pathname: '/register' }, ({ reply }) => {
return reply({
statusCode: StatusCodes.NO_CONTENT,
Expand All @@ -38,8 +37,8 @@ describe('SignUp', () => {

describe('Name and Email Validation', () => {
it('Sign Up', () => {
const { GRAASP, WRONG_NAME, WRONG_EMAIL } = MEMBERS;
cy.visit(SIGN_UP_PATH);
const { GRAASP, WRONG_NAME, WRONG_EMAIL } = AUTH_MEMBERS;
cy.visit('/auth/register');
cy.intercept({ method: 'post', pathname: '/register' }, ({ reply }) => {
return reply({
statusCode: StatusCodes.NO_CONTENT,
Expand Down Expand Up @@ -70,7 +69,7 @@ describe('SignUp', () => {
);
const search = new URLSearchParams();
search.set('invitationId', invitation.id);
cy.visit(`${SIGN_UP_PATH}?${search.toString()}`);
cy.visit(`/auth/register?${search.toString()}`);
checkInvitationFields(invitation);
});

Expand All @@ -85,7 +84,7 @@ describe('SignUp', () => {
);
const search = new URLSearchParams();
search.set('invitationId', invitation.id);
cy.visit(`${SIGN_UP_PATH}?${search.toString()}`);
cy.visit(`/auth/register?${search.toString()}`);
checkInvitationFields(invitation);
});

Expand All @@ -100,14 +99,14 @@ describe('SignUp', () => {
});
const search = new URLSearchParams();
search.set('invitationId', invitation.id);
cy.visit(`${SIGN_UP_PATH}?${search.toString()}`);
cy.visit(`/auth/register?${search.toString()}`);
cy.get(`#${SIGN_UP_BUTTON_ID}`).should('be.visible');
});

it('Username can not contain special characters', () => {
const badUsername = '<<div>%^\'"';

cy.visit(SIGN_UP_PATH);
cy.visit('/auth/register');
cy.get(`#${NAME_SIGN_UP_FIELD_ID}`).clear();
cy.get(`#${NAME_SIGN_UP_FIELD_ID}`).type(badUsername);
cy.get(`#${EMAIL_SIGN_UP_FIELD_ID}`).clear();
Expand All @@ -124,10 +123,10 @@ describe('SignUp', () => {
});

describe('Defining Analytics On Sign Up', () => {
const { GRAASP } = MEMBERS;
const { GRAASP } = AUTH_MEMBERS;

beforeEach(() => {
cy.visit(SIGN_UP_PATH);
cy.visit('/auth/register');
cy.intercept({ method: 'post', pathname: '/register' }, ({ reply }) => {
return reply({
statusCode: StatusCodes.NO_CONTENT,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import { REQUEST_PASSWORD_RESET_PATH } from '../../src/config/paths';
import { REQUEST_PASSWORD_RESET_PATH } from '../../../src/config/paths';
import {
REQUEST_PASSWORD_RESET_EMAIL_FIELD_HELPER_ID,
REQUEST_PASSWORD_RESET_EMAIL_FIELD_ID,
REQUEST_PASSWORD_RESET_ERROR_MESSAGE_ID,
REQUEST_PASSWORD_RESET_SUBMIT_BUTTON_ID,
REQUEST_PASSWORD_RESET_SUCCESS_MESSAGE_ID,
} from '../../src/config/selectors';
import { MEMBERS } from '../fixtures/members';
} from '../../../src/config/selectors';
import { AUTH_MEMBERS } from '../../fixtures/members';

describe('Request password reset', () => {
it('For existing member', () => {
cy.setUpApi();
cy.setUpApi({});
cy.visit(REQUEST_PASSWORD_RESET_PATH);
// request password reset for an existing member
cy.get(`#${REQUEST_PASSWORD_RESET_EMAIL_FIELD_ID}`).type(
MEMBERS.GRAASP.email,
AUTH_MEMBERS.GRAASP.email,
);
cy.get(`#${REQUEST_PASSWORD_RESET_SUBMIT_BUTTON_ID}`).click();
cy.get(`#${REQUEST_PASSWORD_RESET_SUCCESS_MESSAGE_ID}`).should(
'be.visible',
);
});
it('For non-email', () => {
cy.setUpApi();
cy.setUpApi({});
cy.visit(REQUEST_PASSWORD_RESET_PATH);

cy.get(`#${REQUEST_PASSWORD_RESET_EMAIL_FIELD_ID}`).type(
MEMBERS.WRONG_EMAIL.email,
AUTH_MEMBERS.WRONG_EMAIL.email,
);

// click the button to trigger the validation
Expand All @@ -43,7 +43,7 @@ describe('Request password reset', () => {
cy.visit(REQUEST_PASSWORD_RESET_PATH);

cy.get(`#${REQUEST_PASSWORD_RESET_EMAIL_FIELD_ID}`).type(
MEMBERS.GRAASP.email,
AUTH_MEMBERS.GRAASP.email,
);

cy.get(`#${REQUEST_PASSWORD_RESET_SUBMIT_BUTTON_ID}`).click();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RESET_PASSWORD_PATH } from '../../src/config/paths';
import { RESET_PASSWORD_PATH } from '../../../src/config/paths';
import {
RESET_PASSWORD_BACK_TO_LOGIN_BUTTON_ID,
RESET_PASSWORD_ERROR_MESSAGE_ID,
Expand All @@ -9,14 +9,14 @@ import {
RESET_PASSWORD_SUBMIT_BUTTON_ID,
RESET_PASSWORD_SUCCESS_MESSAGE_ID,
RESET_PASSWORD_TOKEN_ERROR_ID,
} from '../../src/config/selectors';
import { MEMBERS } from '../fixtures/members';
} from '../../../src/config/selectors';
import { AUTH_MEMBERS } from '../../fixtures/members';
import { generateJWT } from './util';

describe('Reset password', () => {
describe('With valid token', () => {
it('With strong password', () => {
cy.setUpApi();
cy.setUpApi({});

// this allows to run async code in cypress
cy.wrap(null).then(async () => {
Expand All @@ -25,10 +25,10 @@ describe('Reset password', () => {
});

cy.get(`#${RESET_PASSWORD_NEW_PASSWORD_FIELD_ID}`).type(
MEMBERS.GRAASP.password,
AUTH_MEMBERS.GRAASP.password,
);
cy.get(`#${RESET_PASSWORD_NEW_PASSWORD_CONFIRMATION_FIELD_ID}`).type(
MEMBERS.GRAASP.password,
AUTH_MEMBERS.GRAASP.password,
);
cy.get(`#${RESET_PASSWORD_SUBMIT_BUTTON_ID}`).click();
cy.get(`#${RESET_PASSWORD_SUCCESS_MESSAGE_ID}`).should('be.visible');
Expand All @@ -39,7 +39,7 @@ describe('Reset password', () => {
});

it('With weak password', () => {
cy.setUpApi();
cy.setUpApi({});

// this allows to run async code in cypress
cy.wrap(null).then(async () => {
Expand All @@ -64,7 +64,7 @@ describe('Reset password', () => {
});

it('Without matching passwords', () => {
cy.setUpApi();
cy.setUpApi({});

// this allows to run async code in cypress
cy.wrap(null).then(async () => {
Expand Down Expand Up @@ -110,7 +110,7 @@ describe('Reset password', () => {

describe('Invalid token', () => {
it('Without token', () => {
cy.setUpApi();
cy.setUpApi({});
cy.visit(RESET_PASSWORD_PATH);

// a rough error message is displayed when the url does not
Expand All @@ -122,7 +122,7 @@ describe('Reset password', () => {
});

it('Not a JWT token', () => {
cy.setUpApi();
cy.setUpApi({});
cy.visit(`${RESET_PASSWORD_PATH}?t=${'1234'}`);

// a rough error message is displayed when the url does not
Expand All @@ -134,7 +134,7 @@ describe('Reset password', () => {
});

it('Expired token', () => {
cy.setUpApi();
cy.setUpApi({});

// this allows to run async code in cypress
cy.wrap(null).then(async () => {
Expand Down
Loading

0 comments on commit bb840b3

Please sign in to comment.