Skip to content

Commit

Permalink
Added mocks to login tests
Browse files Browse the repository at this point in the history
  • Loading branch information
WishingWell13 committed May 12, 2024
1 parent 5eb7795 commit fde2854
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cypress/e2e/pages/login.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ describe('Login Page', () => {
cy.fixture('accounts').then(({ standard }) => {
const { email, password } = standard;

cy.fixture('acmAuthResponse').then(({ authAdmin }) => {
cy.intercept('POST', 'login', authAdmin).as('authAdminGood');
});

cy.fixture('acmStandardProfile').then(standardProfile => {
cy.intercept('GET', 'user', standardProfile).as('adminProfile');
});

cy.log('Logging in with email:', email);

cy.get('input[name="email"]').type(email);
cy.get('input[name="password"]').type(password);
cy.get('button').contains('Sign In').click();
Expand All @@ -22,6 +32,14 @@ describe('Login Page', () => {
cy.fixture('accounts').then(({ admin }) => {
const { email, password } = admin;

cy.fixture('acmAuthResponse').then(({ authAdmin }) => {
cy.intercept('POST', 'login', authAdmin).as('authAdminGood');
});

cy.fixture('acmAdminProfile').then(adminProfile => {
cy.intercept('GET', 'user', adminProfile).as('adminProfile');
});

cy.get('input[name="email"]').type(email);
cy.get('input[name="password"]').type(password);
cy.get('button').contains('Sign In').click();
Expand All @@ -33,6 +51,10 @@ describe('Login Page', () => {
});

it('Should fail with invalid credentials', () => {
cy.fixture('acmAuthResponseBadPassword').then(({ authAdminBad }) => {
cy.intercept('POST', 'login', authAdminBad).as('authAdminBad');
});

const [email, password] = ['[email protected]', 'abc'];

cy.get('input[name="email"]').type(email);
Expand Down
47 changes: 47 additions & 0 deletions cypress/fixtures/acmAdminProfile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"error": null,
"user": {
"uuid": "043fa366-d893-4e54-a6c9-ae8c40df6f0f",
"handle": "acmucsd",
"email": "[email protected]",
"firstName": "Barthomelow",
"lastName": "Admin",
"profilePicture": "https://acmucsd-membership-portal.s3.us-west-1.amazonaws.com/portal/profiles/043fa366-d893-4e54-a6c9-ae8c40df6f0f",
"accessType": "ADMIN",
"state": "PASSWORD_RESET",
"graduationYear": 2029,
"major": "Business Psychology",
"bio": "I am ACM Admin 💪\nHello\nI have a really long bio! \nI have a really long bio! \nI have a really long bio! \nI have a really long bio! \nI have a really long bio! yoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo",
"points": 100833,
"credits": 3127242,
"isAttendancePublic": false,
"resumes": [],
"userSocialMedia": [
{
"uuid": "02865e2c-649a-4e67-901d-f93982e11f8c",
"type": "EMAIL",
"url": "[email protected]"
},
{
"uuid": "50e96105-1185-4fc9-8c67-41bdb5d535d3",
"type": "DEVPOST",
"url": "https://devpost.com/sadf"
},
{
"uuid": "a7774068-03f7-4cc1-ac9c-73213dcf69b3",
"type": "FACEBOOK",
"url": "https://facebook.com/sdf"
},
{
"uuid": "35166c85-b1cf-4499-a58c-ba25624a5685",
"type": "TWITTER",
"url": "https://twitter.com/asdfs"
},
{
"uuid": "bb02c4fe-1969-4ea5-a481-4552c50c2096",
"type": "PORTFOLIO",
"url": "https://hi.comasdfs"
}
]
}
}
6 changes: 6 additions & 0 deletions cypress/fixtures/acmAuthResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"authAdmin": {
"error": null,
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1dWlkIjoiMDQzZmEzNjYtZDg5My00ZTU0LWE2YzktYWU4YzQwZGY2ZjBmIiwiYWRtaW4iOnRydWUsImlhdCI6MTcxNDg4ODQ3NiwiZXhwIjoxNzE2MDk4MDc2fQ.Y4jtIgFCMVlIaHM294kWNXvbGtI6yJgoqcEAwKgAG6I"
}
}
10 changes: 10 additions & 0 deletions cypress/fixtures/acmAuthResponseBadPassword.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"authAdminBad": {
"error": {
"httpCode": 403,
"name": "ForbiddenError",
"message": "Incorrect password",
"stack": "Error\n at new HttpError (/app/node_modules/routing-controllers/cjs/http-error/HttpError.js:17:22)\n at new ForbiddenError (/app/node_modules/routing-controllers/cjs/http-error/ForbiddenError.js:10:9)\n at UserAuthService.<anonymous> (/app/build/services/UserAuthService.js:158:27)\n at Generator.next (<anonymous>)\n at fulfilled (/app/build/services/UserAuthService.js:17:58)"
}
}
}
34 changes: 34 additions & 0 deletions cypress/fixtures/acmStandardProfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"error": null,
"user": {
"uuid": "8315405c-98a9-4f0f-9e8d-6b4871820e24",
"handle": "geovany",
"email": "[email protected]",
"firstName": "John",
"lastName": "Doe",
"profilePicture": null,
"accessType": "ADMIN",
"state": "PASSWORD_RESET",
"graduationYear": 2026,
"major": "Computer Engineering",
"bio": "I am a testing account.",
"points": 10,
"credits": 1000,
"isAttendancePublic": true,
"resumes": [
{
"uuid": "9b36daaa-7c91-42d4-97cc-cf2ecb58903f",
"isResumeVisible": true,
"url": "https://acmucsd-membership-portal.s3.us-west-1.amazonaws.com/portal/resumes/8315405c-98a9-4f0f-9e8d-6b4871820e24/Faris%20Ashai%20Resume.pdf",
"lastUpdated": "2023-03-10T23:29:58.568Z"
}
],
"userSocialMedia": [
{
"uuid": "6ef96ada-738b-4560-9838-0379cc114ac4",
"type": "LINKEDIN",
"url": "https://linkedin.com/in/asdf"
}
]
}
}

0 comments on commit fde2854

Please sign in to comment.