Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

refactor: add renovate, remove switch user #83

Merged
merged 4 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
72 changes: 36 additions & 36 deletions cypress/e2e/SignInWithStoredSession.cy.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
import { COOKIE_KEYS, getCurrentSession } from '@graasp/sdk';
// import { COOKIE_KEYS, getCurrentSession } from '@graasp/sdk';

import { HOME_PATH } from '../../src/config/paths';
import {
USER_SWITCH_ID,
buildMemberMenuItemId,
} from '../../src/config/selectors';
import { MOCK_SESSIONS } from '../fixtures/members';
// import { HOME_PATH } from '../../src/config/paths';
// import {
// USER_SWITCH_ID,
// buildMemberMenuItemId,
// } from '../../src/config/selectors';
// import { MOCK_SESSIONS } from '../fixtures/members';

describe('Sign In With Stored Session', () => {
it('Hide user switch if no stored sessions', () => {
cy.setUpApi();
// describe('Sign In With Stored Session', () => {
// it('Hide user switch if no stored sessions', () => {
// cy.setUpApi();

cy.visit(HOME_PATH);
cy.get(`#${USER_SWITCH_ID}`).should('not.exist');
});
// cy.visit(HOME_PATH);
// cy.get(`#${USER_SWITCH_ID}`).should('not.exist');
// });

it('Sign in with a stored user and redirect to saved url', () => {
// setup cookies
cy.setUpApi({ storedSessions: MOCK_SESSIONS });
// it('Sign in with a stored user and redirect to saved url', () => {
// // setup cookies
// cy.setUpApi({ storedSessions: MOCK_SESSIONS });

cy.visit(HOME_PATH);
cy.get(`#${USER_SWITCH_ID}`).click();
// cy.visit(HOME_PATH);
// cy.get(`#${USER_SWITCH_ID}`).click();

MOCK_SESSIONS.forEach(({ id }) => {
cy.get(`#${buildMemberMenuItemId(id)}`).should('be.visible');
});
// MOCK_SESSIONS.forEach(({ id }) => {
// cy.get(`#${buildMemberMenuItemId(id)}`).should('be.visible');
// });

// switch to first user
cy.get(`#${buildMemberMenuItemId(MOCK_SESSIONS[0].id)}`)
.click()
.then(() => {
// session cookie should be different
const currentCookie = getCurrentSession();
expect(currentCookie).to.equal(MOCK_SESSIONS[0].token);
});
cy.getCookie(COOKIE_KEYS.SESSION_KEY).should(
'have.property',
'value',
MOCK_SESSIONS[0].token,
);
});
});
// // switch to first user
// cy.get(`#${buildMemberMenuItemId(MOCK_SESSIONS[0].id)}`)
// .click()
// .then(() => {
// // session cookie should be different
// const currentCookie = getCurrentSession();
// expect(currentCookie).to.equal(MOCK_SESSIONS[0].token);
// });
// cy.getCookie(COOKIE_KEYS.SESSION_KEY).should(
// 'have.property',
// 'value',
// MOCK_SESSIONS[0].token,
// );
// });
// });
7 changes: 6 additions & 1 deletion cypress/e2e/SignUp.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ describe('Name and Email Validation', () => {
name: 'name',
email: 'email',
};
cy.intercept(API_ROUTES.buildGetInvitationRoute(invitation.id), invitation);
cy.intercept(
API_ROUTES.buildGetInvitationRoute(invitation.id),
({ reply }) => {
reply(invitation);
},
);
cy.visit(
`${SIGN_UP_PATH}${qs.stringify(
{ invitationId: invitation.id },
Expand Down
192 changes: 97 additions & 95 deletions cypress/e2e/SuccessContent.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,137 +14,139 @@ import {
} from '../../src/config/selectors';
import { MEMBERS } from '../fixtures/members';

describe('Sign In', () => {
it('Back Button', () => {
const { GRAASP, GRAASP_OTHER } = MEMBERS;
cy.visit(SIGN_IN_PATH);

cy.intercept(API_ROUTES.SIGN_IN_ROUTE, ({ reply }) => {
return reply({
statusCode: StatusCodes.NO_CONTENT,
describe('Success Content', () => {
describe('Sign In', () => {
it('Back Button', () => {
const { GRAASP, GRAASP_OTHER } = MEMBERS;
cy.visit(SIGN_IN_PATH);

cy.intercept(API_ROUTES.SIGN_IN_ROUTE, ({ reply }) => {
return reply({
statusCode: StatusCodes.NO_CONTENT,
});
});
});

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

// Signing in with a valid email
cy.signInAndCheck(GRAASP);
// Signing in with a valid email
cy.signInAndCheck(GRAASP);

cy.get(`#${SUCCESS_CONTENT_ID}`).should('be.visible');
cy.get(`#${SUCCESS_CONTENT_ID}`).should('be.visible');

cy.get(`#${BACK_BUTTON_ID}`).click();
cy.get(`#${BACK_BUTTON_ID}`).click();

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

// check if it's possible to sign in and use back button again
cy.signInAndCheck(GRAASP_OTHER);
// check if it's possible to sign in and use back button again
cy.signInAndCheck(GRAASP_OTHER);

cy.get(`#${SUCCESS_CONTENT_ID}`).should('be.visible');
cy.get(`#${SUCCESS_CONTENT_ID}`).should('be.visible');

cy.get(`#${BACK_BUTTON_ID}`).click();
cy.get(`#${BACK_BUTTON_ID}`).click();

cy.get(`#${SUCCESS_CONTENT_ID}`).should('not.exist');
cy.url().should('include', SIGN_IN_PATH);
cy.get(`#${SIGN_IN_HEADER_ID}`).should('be.visible');
// checks so email is cleared
cy.get(`#${EMAIL_SIGN_IN_FIELD_ID}`).should('be.empty');
});
cy.get(`#${SUCCESS_CONTENT_ID}`).should('not.exist');
cy.url().should('include', SIGN_IN_PATH);
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);
it('Resend email', () => {
const { GRAASP, GRAASP_OTHER } = MEMBERS;
cy.visit(SIGN_IN_PATH);

cy.intercept(API_ROUTES.SIGN_IN_ROUTE, ({ reply }) => {
return reply({
statusCode: StatusCodes.NO_CONTENT,
cy.intercept(API_ROUTES.SIGN_IN_ROUTE, ({ reply }) => {
return reply({
statusCode: StatusCodes.NO_CONTENT,
});
});
});

// Signing in with a valid email
cy.signInAndCheck(GRAASP_OTHER);
cy.get(`#${BACK_BUTTON_ID}`).click();
// Signing in with a valid email
cy.signInAndCheck(GRAASP_OTHER);
cy.get(`#${BACK_BUTTON_ID}`).click();

cy.signInAndCheck(GRAASP);
cy.signInAndCheck(GRAASP);

// checks so request body contains correct email
cy.intercept(API_ROUTES.SIGN_IN_ROUTE, ({ body }) => {
expect(body.email).to.eq(GRAASP.email);
});
// checks so request body contains correct email
cy.intercept(API_ROUTES.SIGN_IN_ROUTE, ({ body }) => {
expect(body.email).to.eq(GRAASP.email);
});

// checks resend email button is disabled after one click
cy.get(`#${RESEND_EMAIL_BUTTON_ID}`).click().should('be.disabled');
// checks resend email button is disabled after one click
cy.get(`#${RESEND_EMAIL_BUTTON_ID}`).click().should('be.disabled');
});
});
});

describe('Sign Up', () => {
it('Back Button', () => {
const { GRAASP, GRAASP_OTHER } = MEMBERS;
cy.visit(SIGN_UP_PATH);
describe('Sign Up', () => {
it('Back Button', () => {
const { GRAASP, GRAASP_OTHER } = MEMBERS;
cy.visit(SIGN_UP_PATH);

cy.intercept(API_ROUTES.SIGN_UP_ROUTE, ({ reply }) => {
return reply({
statusCode: StatusCodes.NO_CONTENT,
cy.intercept(API_ROUTES.SIGN_UP_ROUTE, ({ reply }) => {
return reply({
statusCode: StatusCodes.NO_CONTENT,
});
});
});

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

// Signing up with a valid email
cy.signUpAndCheck(GRAASP);
// Signing up with a valid email
cy.signUpAndCheck(GRAASP);

cy.get(`#${SUCCESS_CONTENT_ID}`).should('be.visible');
cy.get(`#${SUCCESS_CONTENT_ID}`).should('be.visible');

cy.get(`#${BACK_BUTTON_ID}`).click();
cy.get(`#${BACK_BUTTON_ID}`).click();

cy.get(`#${SUCCESS_CONTENT_ID}`).should('not.exist');
cy.url().should('include', SIGN_UP_PATH);
cy.get(`#${SIGN_UP_HEADER_ID}`).should('be.visible');
// checks so email is still filled
cy.get(`#${EMAIL_SIGN_UP_FIELD_ID}`).should('have.value', GRAASP.email);
cy.get(`#${SUCCESS_CONTENT_ID}`).should('not.exist');
cy.url().should('include', SIGN_UP_PATH);
cy.get(`#${SIGN_UP_HEADER_ID}`).should('be.visible');
// checks so email is still filled
cy.get(`#${EMAIL_SIGN_UP_FIELD_ID}`).should('have.value', GRAASP.email);

// check if it's possible to sign up and use back button again
cy.signUpAndCheck(GRAASP_OTHER);
// check if it's possible to sign up and use back button again
cy.signUpAndCheck(GRAASP_OTHER);

cy.get(`#${SUCCESS_CONTENT_ID}`).should('be.visible');
cy.get(`#${SUCCESS_CONTENT_ID}`).should('be.visible');

cy.get(`#${BACK_BUTTON_ID}`).click();
cy.get(`#${BACK_BUTTON_ID}`).click();

cy.get(`#${SUCCESS_CONTENT_ID}`).should('not.exist');
cy.url().should('include', SIGN_UP_PATH);
cy.get(`#${SIGN_UP_HEADER_ID}`).should('be.visible');
// checks so email is still filled
cy.get(`#${EMAIL_SIGN_UP_FIELD_ID}`).should(
'have.value',
GRAASP_OTHER.email,
);
});
cy.get(`#${SUCCESS_CONTENT_ID}`).should('not.exist');
cy.url().should('include', SIGN_UP_PATH);
cy.get(`#${SIGN_UP_HEADER_ID}`).should('be.visible');
// checks so email is still filled
cy.get(`#${EMAIL_SIGN_UP_FIELD_ID}`).should(
'have.value',
GRAASP_OTHER.email,
);
});

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

cy.intercept(API_ROUTES.SIGN_UP_ROUTE, ({ reply }) => {
return reply({
statusCode: StatusCodes.NO_CONTENT,
cy.intercept(API_ROUTES.SIGN_UP_ROUTE, ({ reply }) => {
return reply({
statusCode: StatusCodes.NO_CONTENT,
});
});
});

// Signing up with a valid email
cy.signUpAndCheck(GRAASP_OTHER);
cy.get(`#${BACK_BUTTON_ID}`).click();
// Signing up with a valid email
cy.signUpAndCheck(GRAASP_OTHER);
cy.get(`#${BACK_BUTTON_ID}`).click();

cy.signUpAndCheck(GRAASP);
cy.signUpAndCheck(GRAASP);

// checks so request body contains correct email
cy.intercept(API_ROUTES.SIGN_IN_ROUTE, ({ body }) => {
expect(body.email).to.eq(GRAASP.email);
});
// checks so request body contains correct email
cy.intercept(API_ROUTES.SIGN_IN_ROUTE, ({ body }) => {
expect(body.email).to.eq(GRAASP.email);
});

// checks resend email button is disabled after one click
cy.get(`#${RESEND_EMAIL_BUTTON_ID}`).click().should('be.disabled');
// checks resend email button is disabled after one click
cy.get(`#${RESEND_EMAIL_BUTTON_ID}`).click().should('be.disabled');
});
});
});
30 changes: 11 additions & 19 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ import { mockGetCurrentMember, mockGetMember, mockGetMembers } from './server';
declare global {
namespace Cypress {
interface Chainable {
setUpApi(args?: {
members?: Member[];
storedSessions?: { id: string; token: string; createdAt: string }[];
}): Chainable<JQuery<HTMLElement>>;
setUpApi(args?: { members?: Member[] }): Chainable<JQuery<HTMLElement>>;

checkErrorTextField(
id: string,
Expand All @@ -44,27 +41,27 @@ declare global {

signUpAndCheck(
member: Member & {
nameValid: boolean;
emailValid: boolean;
passwordValid: boolean;
nameValid?: boolean;
emailValid?: boolean;
passwordValid?: boolean;
},
): Chainable<JQuery<HTMLElement>>;

signInAndCheck(
value: Partial<Member> & {
nameValid: boolean;
emailValid: boolean;
passwordValid: boolean;
nameValid?: boolean;
emailValid?: boolean;
passwordValid?: boolean;
},
): Chainable<JQuery<HTMLElement>>;

signInPasswordMethodAndCheck(): Chainable<JQuery<HTMLElement>>;

signInPasswordAndCheck(
member: Member & {
nameValid: boolean;
emailValid: boolean;
passwordValid: boolean;
nameValid?: boolean;
emailValid?: boolean;
passwordValid?: boolean;
},
): Chainable<JQuery<HTMLElement>>;
}
Expand All @@ -73,14 +70,9 @@ declare global {

Cypress.Commands.add(
'setUpApi',
({ members = Object.values(MEMBERS), storedSessions = [] } = {}) => {
({ members = Object.values(MEMBERS) } = {}) => {
const cachedMembers = JSON.parse(JSON.stringify(members));

cy.setCookie(
COOKIE_KEYS.STORED_SESSIONS_KEY,
JSON.stringify(storedSessions),
);

mockGetMember(cachedMembers);
mockGetMembers(cachedMembers);

Expand Down
Loading