-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #470 from ruxailab/create-heuristic-e2e-test
[E2E TESTS] Generate auth utils + auth test + heuristic test
- Loading branch information
Showing
13 changed files
with
275 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,16 @@ | ||
const { defineConfig } = require("cypress"); | ||
const { defineConfig } = require('cypress') | ||
require('dotenv').config() | ||
|
||
module.exports = defineConfig({ | ||
projectId: 'xmf2jf', | ||
e2e: { | ||
setupNodeEvents(on, config) { | ||
// implement node event listeners here | ||
}, | ||
}, | ||
}); | ||
env: { | ||
// add environment variables here | ||
...process.env, | ||
url: 'http://localhost:8080', | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
const authUser = require('../fixtures/authUser.json') | ||
const url = Cypress.env('url') | ||
|
||
describe('Authentication Suite', () => { | ||
describe('Registration', () => { | ||
it('should allow a new user to register', () => { | ||
cy.visit(url + '/signup') | ||
const { email, password } = authUser | ||
cy.get('form').findByLabelText(/e-mail/i).type(email) | ||
cy.get('form').findByLabelText("Password").type(password) | ||
cy.get('form').findByLabelText("Confirm your password").type(password) | ||
cy.findByRole('button', {name: 'Sign-up'}).click() | ||
cy.wait(500) | ||
cy.contains(email) | ||
cy.deleteUser(email, password) | ||
}) | ||
it('should reject registration with invalid password', () => { | ||
cy.visit(url + '/signup') | ||
const { email, invalidPassword } = authUser | ||
cy.get('form').findByLabelText(/e-mail/i).type(email) | ||
cy.get('form').findByLabelText("Password").type(invalidPassword) | ||
cy.get('form').findByLabelText("Confirm your password").type(invalidPassword) | ||
cy.findByRole('button', {name: 'Sign-up'}).click() | ||
cy.contains('Password must be at least 6 characters') | ||
}) | ||
it('should reject registration when passwords do not match', () => { | ||
cy.visit(url + '/signup') | ||
const { email, password, invalidPassword } = authUser | ||
cy.get('form').findByLabelText(/e-mail/i).type(email) | ||
cy.get('form').findByLabelText("Password").type(password) | ||
cy.get('form').findByLabelText("Confirm your password").type(invalidPassword) | ||
cy.findByRole('button', {name: 'Sign-up'}).click() | ||
cy.contains('Different passwords') | ||
}) | ||
}) | ||
describe('Login', () => { | ||
const { email, password } = authUser | ||
beforeEach(() => { | ||
cy.signup(email, password) | ||
cy.logout() | ||
cy.visit(url + '/signin') | ||
}) | ||
afterEach(() => { | ||
cy.deleteUser(email, password) | ||
}) | ||
it('should allow a registered user to login', () => { | ||
cy.get('form').findByLabelText(/e-mail/i).type(email) | ||
cy.get('form').findByLabelText('Password').type(password) | ||
cy.findByTestId('sign-in-button').click() | ||
cy.wait(500) | ||
cy.contains(email) | ||
}) | ||
it('should reject login with incorrect password', () => { | ||
const { email, password, invalidPassword } = authUser | ||
cy.get('form').findByLabelText(/e-mail/i).type(email) | ||
cy.get('form').findByLabelText('Password').type(invalidPassword) | ||
cy.findByTestId('sign-in-button').click() | ||
cy.contains('Incorrect password') | ||
}) | ||
it('should reject login with unregistered email', () => { | ||
cy.get('form').findByLabelText(/e-mail/i).type('[email protected]') | ||
cy.get('form').findByLabelText('Password').type('noexist') | ||
cy.findByTestId('sign-in-button').click() | ||
cy.contains('Incorrect username or password') | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const heuristic = require('../fixtures/heuristic.json') | ||
const authUser = require('../fixtures/authUser.json') | ||
|
||
const url = Cypress.env('url') | ||
const { email, password } = authUser | ||
|
||
describe('Heuristic test Suite', () => { | ||
before('Signup into the app', () => { | ||
cy.deleteUser(email, password) | ||
cy.signup(email, password) | ||
cy.login(email, password) | ||
}) | ||
after('Remove user', () => { | ||
cy.deleteUser(email, password) | ||
}) | ||
describe('Create Heuristic Test', () => { | ||
it('should allow a new test to create', () => { | ||
cy.visit(url + '/testslist') | ||
cy.findByTestId('create-test-btn').click() | ||
cy.findByText('Create a blank test').click() | ||
cy.findByText('Usability Heuristic').click() | ||
|
||
const { name, description } = heuristic | ||
cy.findByLabelText(/Test name/i).type(name) | ||
cy.findByLabelText(/Test Description/i).type(description) | ||
cy.findByTestId('add-name-test-creation-btn').click() | ||
|
||
cy.contains(/Manager/i) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"email": "[email protected]", | ||
"password": "ruxailab1234", | ||
"invalidPassword": "123", | ||
"data": { | ||
"accessLevel": 1, | ||
"email" : "[email protected]", | ||
"myAnswers": {}, | ||
"myTests": {}, | ||
"notifications": [] | ||
}, | ||
"collection": "users" | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "Heuristic Test", | ||
"description": "This is a test of the heuristic test" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import { initializeApp } from 'firebase/app' | ||
import { | ||
getAuth, | ||
connectAuthEmulator, | ||
deleteUser as deleteUserAuth, | ||
signInWithEmailAndPassword, | ||
signOut, | ||
createUserWithEmailAndPassword, | ||
} from 'firebase/auth' | ||
import { | ||
getFirestore, | ||
connectFirestoreEmulator, | ||
doc, | ||
setDoc, | ||
deleteDoc, | ||
} from 'firebase/firestore' | ||
|
||
const authUser = require('../../fixtures/authUser.json') | ||
|
||
const firebaseConfig = { | ||
apiKey: Cypress.env('VUE_APP_FIREBASE_API_KEY'), | ||
authDomain: Cypress.env('VUE_APP_FIREBASE_AUTH_DOMAIN'), | ||
storageBucket: Cypress.env('VUE_APP_FIREBASE_STORAGE_BUCKET'), | ||
projectId: Cypress.env('VUE_APP_FIREBASE_PROJECT_ID'), | ||
appId: Cypress.env('VUE_APP_FIREBASE_APP_ID'), | ||
} | ||
|
||
const firebaseApp = initializeApp(firebaseConfig) | ||
const auth = getAuth(firebaseApp) | ||
const db = getFirestore(firebaseApp) | ||
if (window.Cypress) { | ||
connectAuthEmulator(auth, 'http://localhost:9099') | ||
connectFirestoreEmulator(db, 'localhost', 8081) | ||
} | ||
|
||
/** | ||
* Delete the currently logged-in user | ||
* @returns {Promise<void>} | ||
*/ | ||
export const deleteUser = async (email, password) => { | ||
try { | ||
const { user } = await signInWithEmailAndPassword(auth, email, password) | ||
const { collection } = authUser | ||
await deleteDocById(collection, user.uid) | ||
await deleteUserAuth(user) | ||
console.info(`Deleted user with ID "${user.uid}"`) | ||
} catch (err) { | ||
console.error(err) | ||
} | ||
} | ||
|
||
/** | ||
* Log in with email and password | ||
* @param email | ||
* @param password | ||
* @returns {Promise<void>} | ||
*/ | ||
export const logInWithEmailAndPassword = async (email, password) => { | ||
try { | ||
await signInWithEmailAndPassword(auth, email, password).then(() => { | ||
console.info(`Logged in as "${email}"`) | ||
}) | ||
} catch (err) { | ||
console.error(err) | ||
} | ||
} | ||
|
||
/** | ||
* Log out the currently logged-in user | ||
* @returns {Promise<void>} | ||
*/ | ||
export const logOut = async () => { | ||
try { | ||
await signOut(auth).then(() => { | ||
console.info('Logged out') | ||
}) | ||
} catch (err) { | ||
console.error(err) | ||
} | ||
} | ||
|
||
/** | ||
* Sign up with email and password | ||
* @param email | ||
* @param password | ||
* @returns {Promise<void>} | ||
*/ | ||
export const signUpWithEmailAndPassword = async (email, password) => { | ||
try { | ||
const { user } = await createUserWithEmailAndPassword(auth, email, password) | ||
console.info(`Signed up as "${email}" with user ID "${user.uid}"`) | ||
const { data, collection } = authUser | ||
await createDoc(collection, user.uid, data) | ||
} catch (err) { | ||
console.error(err) | ||
} | ||
} | ||
|
||
/** | ||
* Create a document in a collection | ||
* @param col | ||
* @param docId | ||
* @param data | ||
* @returns {Promise<void>} | ||
*/ | ||
export const createDoc = async (col, docId, data) => { | ||
try { | ||
const ref = doc(db, `${col}/${docId}`) | ||
await setDoc(ref, data) | ||
} catch (err) { | ||
console.error(err) | ||
} | ||
} | ||
|
||
/** | ||
* Delete a document by ID | ||
* @param col | ||
* @param docId | ||
* @returns {Promise<void>} | ||
*/ | ||
export const deleteDocById = async (col, docId) => { | ||
try { | ||
const ref = doc(db, `${col}/${docId}`) | ||
await deleteDoc(ref) | ||
} catch (err) { | ||
console.error(err) | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
"baseUrl": "./", | ||
"paths": { | ||
"@/*": ["src/*"] | ||
} | ||
}, | ||
"types": ["cypress", "@testing-library/cypress"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters