diff --git a/cypress/e2e/pages/auth/login.cy.ts b/cypress/e2e/pages/auth/login.cy.ts deleted file mode 100644 index 42273090..00000000 --- a/cypress/e2e/pages/auth/login.cy.ts +++ /dev/null @@ -1,53 +0,0 @@ -/// - -describe('Login Page', () => { - beforeEach(() => { - cy.visit('/login'); - }); - - it('Login succeeds with valid member credentials', () => { - cy.fixture('accounts').then(({ standard }) => { - const { username, password } = standard; - - cy.get('input[name="email"]').type(username); - cy.get('input[name="password"]').type(password); - cy.get('button').contains('Sign In').click(); - - cy.location('pathname').should('equal', '/'); - }); - }); - - it('Login succeeds with valid admin credentials', () => { - cy.fixture('accounts').then(({ admin }) => { - const { username, password } = admin; - - cy.get('input[name="email"]').type(username); - cy.get('input[name="password"]').type(password); - cy.get('button').contains('Sign In').click(); - - cy.location('pathname').should('equal', '/'); - }); - }); - - it('Login fails with missing username', () => { - cy.fixture('accounts').then(({ standard }) => { - const { password } = standard; - - cy.get('input[name="password"]').type(password); - cy.get('button').contains('Sign In').click(); - - cy.location('pathname').should('equal', '/login'); - cy.get('Required').should('not.exist'); - }); - }); - - it('Link to Forgot Password Functions Correctly', () => { - cy.get('a').contains('Forgot your password?').click(); - cy.location('pathname').should('equal', '/forgot-password'); - }); - - it('Link to Register Functions Correctly', () => { - cy.get('a').contains('Sign Up').click(); - cy.location('pathname').should('equal', '/register'); - }); -}); diff --git a/cypress/e2e/pages/forgot-password.cy.ts b/cypress/e2e/pages/forgot-password.cy.ts new file mode 100644 index 00000000..87d0be72 --- /dev/null +++ b/cypress/e2e/pages/forgot-password.cy.ts @@ -0,0 +1,30 @@ +/// + +describe('Forgot Password Page', () => { + beforeEach(() => { + cy.visit('/forgot-password'); + }); + + it('Should fail with missing email', () => { + cy.contains('button', 'Submit').click(); + cy.contains('p', 'Required').should('exist'); + }); + + it('Should fail with unknown email', () => { + const email = 'test@ucsd.edu'; + cy.get('input[name="email"]').type(email); + cy.contains('button', 'Submit').click(); + + cy.get('.Toastify').contains('There is no account associated with that email').should('exist'); + }); + + it('Should succeed with valid email', () => { + cy.fixture('accounts').then(({ standard }) => { + const { email } = standard; + cy.get('input[name="email"]').type(email); + cy.contains('button', 'Submit').click(); + + cy.get('.Toastify').contains('Success').should('exist'); + }); + }); +}); diff --git a/cypress/e2e/pages/login.cy.ts b/cypress/e2e/pages/login.cy.ts new file mode 100644 index 00000000..f4ca6df5 --- /dev/null +++ b/cypress/e2e/pages/login.cy.ts @@ -0,0 +1,79 @@ +/// + +describe('Login Page', () => { + beforeEach(() => { + cy.visit('/login'); + }); + + it('Should succeed with valid member login', () => { + cy.fixture('accounts').then(({ standard }) => { + const { email, password } = standard; + + cy.get('input[name="email"]').type(email); + cy.get('input[name="password"]').type(password); + cy.get('button').contains('Sign In').click(); + + cy.location('pathname').should('equal', '/'); + cy.getCookie('ACCESS_TOKEN').should('exist'); + }); + }); + + it('Should succeed with valid admin login', () => { + cy.fixture('accounts').then(({ admin }) => { + const { email, password } = admin; + + cy.get('input[name="email"]').type(email); + cy.get('input[name="password"]').type(password); + cy.get('button').contains('Sign In').click(); + + cy.location('pathname').should('equal', '/'); + cy.getCookie('ACCESS_TOKEN').should('exist'); + cy.getCookie('USER').should('exist'); + }); + }); + + it('Should fail with invalid credentials', () => { + const [email, password] = ['abc123@xyz.com', 'abc']; + + cy.get('input[name="email"]').type(email); + cy.get('input[name="password"]').type(password); + cy.get('button').contains('Sign In').click(); + + cy.get('.Toastify').contains('Unable to login').should('exist'); + cy.location('pathname').should('equal', '/login'); + }); + + it('Should fail with missing username', () => { + cy.fixture('accounts').then(({ standard }) => { + const { password } = standard; + + cy.get('input[name="password"]').type(password); + cy.get('button').contains('Sign In').click(); + + cy.location('pathname').should('equal', '/login'); + cy.get('p').contains('Required').should('exist'); + }); + }); + + it('Should fail with missing password', () => { + cy.fixture('accounts').then(({ standard }) => { + const { email } = standard; + + cy.get('input[name="email"]').type(email); + cy.get('button').contains('Sign In').click(); + + cy.location('pathname').should('equal', '/login'); + cy.get('p').get('Required').should('exist'); + }); + }); + + it('Should link to forgot password page', () => { + cy.get('a').contains('Forgot your password?').click(); + cy.location('pathname').should('equal', '/forgot-password'); + }); + + it('Should link to account register page', () => { + cy.get('a').contains('Sign Up').click(); + cy.location('pathname').should('equal', '/register'); + }); +}); diff --git a/cypress/e2e/pages/register.cy.ts b/cypress/e2e/pages/register.cy.ts new file mode 100644 index 00000000..deb559c2 --- /dev/null +++ b/cypress/e2e/pages/register.cy.ts @@ -0,0 +1,7 @@ +/// + +describe('Register Page', () => { + beforeEach(() => { + cy.visit('/register'); + }); +}); diff --git a/cypress/fixtures/accounts.json b/cypress/fixtures/accounts.json index 6f9bf9c6..ff6d630e 100644 --- a/cypress/fixtures/accounts.json +++ b/cypress/fixtures/accounts.json @@ -1,10 +1,10 @@ { "admin": { - "username": "acm@ucsd.edu", + "email": "acm@ucsd.edu", "password": "password" }, "standard": { - "username": "acm_standard@ucsd.edu", + "email": "acm_standard@ucsd.edu", "password": "password" } } diff --git a/package.json b/package.json index 8d8409f2..b0bf253c 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,6 @@ "axios": "^1.6.0", "axios-middleware": "^0.3.1", "cookies-next": "^2.1.1", - "cypress": "^13.2.0", "ics": "^3.7.2", "luxon": "^3.3.0", "next": "^13.2.5-canary.30", @@ -49,13 +48,14 @@ "validator": "^13.9.0" }, "devDependencies": { - "@types/totp-generator": "^0.0.5", "@types/lodash": "^4.14.191", "@types/luxon": "^3.3.0", "@types/node": "18.8.1", "@types/react": "18.0.21", + "@types/totp-generator": "^0.0.5", "@types/validator": "^13.7.14", "@typescript-eslint/eslint-plugin": "^5.40.1", + "cypress": "13.6.2", "eslint": "8.24.0", "eslint-config-airbnb": "^19.0.4", "eslint-config-airbnb-typescript": "^17.0.0", diff --git a/yarn.lock b/yarn.lock index 48d3105c..7412bc1e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2686,10 +2686,10 @@ csstype@^3.0.2, csstype@^3.1.2: resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.1.2.tgz#1d4bf9d572f11c14031f0436e1c10bc1f571f50b" integrity sha512-I7K1Uu0MBPzaFKg4nI5Q7Vs2t+3gWWW648spaF+Rg7pI9ds18Ugn+lvg4SHczUdKlHI5LWBXyqfS8+DufyBsgQ== -cypress@^13.2.0: - version "13.2.0" - resolved "https://registry.yarnpkg.com/cypress/-/cypress-13.2.0.tgz#10f73d06a0764764ffbb903a31e96e2118dcfc1d" - integrity sha512-AvDQxBydE771GTq0TR4ZUBvv9m9ffXuB/ueEtpDF/6gOcvFR96amgwSJP16Yhqw6VhmwqspT5nAGzoxxB+D89g== +cypress@13.6.2: + version "13.6.2" + resolved "https://registry.yarnpkg.com/cypress/-/cypress-13.6.2.tgz#c70df09db0a45063298b3cecba2fa21109768e08" + integrity sha512-TW3bGdPU4BrfvMQYv1z3oMqj71YI4AlgJgnrycicmPZAXtvywVFZW9DAToshO65D97rCWfG/kqMFsYB6Kp91gQ== dependencies: "@cypress/request" "^3.0.0" "@cypress/xvfb" "^1.2.4"