Skip to content

Commit

Permalink
Merge branch 'refs/heads/develop' into playwright-testing
Browse files Browse the repository at this point in the history
# Conflicts:
#	.github/workflows/ishikawa-tools.yml
#	ishikawa_tools/ishikawa_tools_script.py
#	package.json
  • Loading branch information
Sergio Beltrán committed Jun 4, 2024
2 parents db89d12 + 28059d7 commit 7fcdd2a
Show file tree
Hide file tree
Showing 17 changed files with 309 additions and 15 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/ishikawa-tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
- cron: '0 0 * * *'
issues:
types: [opened, deleted, closed, reopened, labeled]
workflow_dispatch:

jobs:
generate-reports:
Expand All @@ -29,13 +30,13 @@ jobs:
USER: ${{ secrets.USER }}
PROJECT: ${{ secrets.PROJECT }}
run: |
echo "User: $USER"
echo "Project: $PROJECT"
echo "User secret length: ${#USER}"
echo "Project secret length: ${#PROJECT}" # Changed the checks for user and project to length checks (these secrets should probably be changed to variables)
echo "Token length: ${#ACCESS_TOKEN}" # This will print the length of the token to ensure it's set, without exposing it.
- name: Run report generation script
env:
TOKEN: ${{ secrets.ACCESS_TOKEN }}
TOKEN: ${{ secrets.GITHUB_TOKEN }} #This should work instead of using a personal access token
USER: ${{ secrets.USER }}
PROJECT: ${{ secrets.PROJECT }}
run: python ishikawa_tools/ishikawa_tools_script.py
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,26 @@ jobs:

- name: Test
run: npm test

- name: Comment to PR
if: failure() && github.event_name == 'pull_request'
uses: thollander/actions-comment-pull-request@v2
with:
message: "⚠️ The tests have failed, @${{ github.actor }} Please review the proposed changes."
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Send message to Discord
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
if: failure() && github.event_name == 'pull_request'
uses: Ilshidur/action-discord@master
with:
args: |
⚠️ The GitHub event `${{ github.event_name }}` has failed.
**Repository**: `${{ github.repository }}`
**Workflow**: `${{ github.workflow }}`
**Actor**: `${{ github.actor }}`
**Pull Request**: [Link](${{ github.event.pull_request.html_url }})
**Action URL**: [View Details](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
Please review the proposed changes.
11 changes: 9 additions & 2 deletions cypress.config.js
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',
},
})
67 changes: 67 additions & 0 deletions cypress/e2e/auth.spec.cy.js
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')
})
})
})
31 changes: 31 additions & 0 deletions cypress/e2e/heuristic.spec.cy.js
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)
})
})
})
13 changes: 13 additions & 0 deletions cypress/fixtures/authUser.json
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"
}
5 changes: 0 additions & 5 deletions cypress/fixtures/example.json

This file was deleted.

4 changes: 4 additions & 0 deletions cypress/fixtures/heuristic.json
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"
}
15 changes: 14 additions & 1 deletion cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,17 @@
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })

import '@testing-library/cypress/add-commands'
import { deleteUser,
logInWithEmailAndPassword,
logOut,
signUpWithEmailAndPassword }
from './commands/auth'


Cypress.Commands.add('deleteUser', deleteUser)
Cypress.Commands.add('login', logInWithEmailAndPassword)
Cypress.Commands.add('logout', logOut)
Cypress.Commands.add('signup', signUpWithEmailAndPassword)
130 changes: 130 additions & 0 deletions cypress/support/commands/auth.js
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)
}
}


5 changes: 3 additions & 2 deletions ishikawa_tools/ishikawa_tools_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ def generate_scatter_diagram_report(repo_owner, repo_name, github_token):
plt.savefig('./ishikawa_tools/output/scatter.pdf')

def main():
repo_owner = "marcgc21"
github_token = os.getenv('TOKEN')
username = os.getenv('USER')
repository_name = os.getenv('PROJECT')
Expand All @@ -169,11 +168,13 @@ def main():
print("One or more environment variables are missing.")
return

issues = fetch_issues(repo_owner, repository_name, github_token)
issues = fetch_issues(username, repository_name, github_token)
if issues is None:
print("Exiting script due to fetch issues failure.")
return

Path("./ishikawa_tools/output").mkdir(parents=True, exist_ok=True)

generate_pareto_diagram(issues)
generate_weekly_report(github_token, username, repository_name)
generate_histogram_report(username, repository_name, github_token)
Expand Down
4 changes: 4 additions & 0 deletions ishikawa_tools/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
matplotlib
pandas
requests
PyGithub
3 changes: 2 additions & 1 deletion jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"baseUrl": "./",
"paths": {
"@/*": ["src/*"]
}
},
"types": ["cypress", "@testing-library/cypress"]
}
}
Loading

0 comments on commit 7fcdd2a

Please sign in to comment.