Skip to content

Commit

Permalink
code formatting and linting
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderGi committed Jan 6, 2024
1 parent 56999d6 commit 23d3f9c
Show file tree
Hide file tree
Showing 82 changed files with 15,367 additions and 13,591 deletions.
8 changes: 4 additions & 4 deletions .badges/lines-of-code.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# http://editorconfig.org
root = true

[*]
charset = utf-8
insert_final_newline = true
trim_trailing_whitespace = true
max_line_length = 100

[{*.js,*.json,*.yml}]
indent_size = 4
indent_style = space
9 changes: 9 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.glitchdotcom.json
.node-gyp
node_modules
.data
.DS_Store
.env
.firebase
test.*.log
tap.info
18 changes: 18 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
root: true

rules:
eqeqeq: [error, allow-null]
no-unused-vars: [error, { vars: all, args: none, ignoreRestSiblings: true }]

parserOptions:
ecmaVersion: 'latest'
sourceType: 'module'

env:
node: true
es6: true
browser: true

extends:
- eslint:recommended
- prettier
32 changes: 16 additions & 16 deletions .github/workflows/gitleaks.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
name: gitleaks
on:
pull_request:
push:
workflow_dispatch:
schedule:
- cron: "0 4 * * *" # run once a day at 4 AM
pull_request:
push:
workflow_dispatch:
schedule:
- cron: '0 4 * * *' # run once a day at 4 AM
jobs:
scan:
name: gitleaks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITLEAKS_NOTIFY_USER_LIST: "@sandergi, @clr-li"
scan:
name: gitleaks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITLEAKS_NOTIFY_USER_LIST: '@sandergi, @clr-li'
51 changes: 25 additions & 26 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,29 @@ name: Automated Tests
on: [push, pull_request]

jobs:
build:
build:
runs-on: ubuntu-latest

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '18.17'
- name: Setup Selenium Server
run: docker pull selenium/standalone-chrome:latest
- name: Start Selenium Server with access to host's localhost
run: docker run -d -p 4444:4444 --network="host" --shm-size=2g selenium/standalone-chrome:latest
- name: Install dependencies
run: npm ci
- name: Create Service Account key for Firebase
run: echo '${{ secrets.FIREBASE_SERVICE_ACCOUNT }}' > gcloud.json
- name: Run tests with chrome
run: |
SELENIUM_REMOTE_URL="http://localhost:4444/wd/hub" SELENIUM_BROWSER=chrome npm test
env:
TOKEN: ${{ secrets.TOKEN }}
GOOGLE_APPLICATION_CREDENTIALS: "gcloud.json"
MERCHANTID: ${{ secrets.MERCHANTID }}
MERCHANTPUBLIC: ${{ secrets.MERCHANTPUBLIC }}
MERCHANTPRIVATE: ${{ secrets.MERCHANTPRIVATE }}
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '18.17'
- name: Setup Selenium Server
run: docker pull selenium/standalone-chrome:latest
- name: Start Selenium Server with access to host's localhost
run: docker run -d -p 4444:4444 --network="host" --shm-size=2g selenium/standalone-chrome:latest
- name: Install dependencies
run: npm ci
- name: Create Service Account key for Firebase
run: echo '${{ secrets.FIREBASE_SERVICE_ACCOUNT }}' > gcloud.json
- name: Run tests with chrome
run: |
SELENIUM_REMOTE_URL="http://localhost:4444/wd/hub" SELENIUM_BROWSER=chrome npm test
env:
TOKEN: ${{ secrets.TOKEN }}
GOOGLE_APPLICATION_CREDENTIALS: 'gcloud.json'
MERCHANTID: ${{ secrets.MERCHANTID }}
MERCHANTPUBLIC: ${{ secrets.MERCHANTPUBLIC }}
MERCHANTPRIVATE: ${{ secrets.MERCHANTPRIVATE }}
10 changes: 10 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.glitchdotcom.json
.node-gyp
node_modules
.data
.DS_Store
.env
.firebase
test.*.log
tap.info
**/*.min.js
12 changes: 12 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"printWidth": 100,
"tabWidth": 4,
"useTabs": false,
"semi": true,
"singleQuote": true,
"quoteProps": "as-needed",
"trailingComma": "all",
"bracketSpacing": true,
"arrowParens": "avoid",
"endOfLine": "auto"
}
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
},
}
5 changes: 2 additions & 3 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
The MIT License (MIT) with the Commons Clause (CC)
=====================
# The MIT License (MIT) with the Commons Clause (CC)

Copyright © `2023` `Alexander Metzger and Claire Li`

Expand Down Expand Up @@ -44,4 +43,4 @@ this Commons Clause License Condition notice.

Software: All Attendance Scanner associated files.
License: MIT
Licensor: Alexander Metzger and Claire Li
Licensor: Alexander Metzger and Claire Li
44 changes: 33 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
# Attendance Scanner
# Attendance Scanner

<!-- [![LineCount](https://tokei.ekzhang.com/b1/github/clr-li/AttendanceScanner)](https://github.com/clr-li/AttendanceScanner)
[![FileCount](https://tokei.ekzhang.com/b1/github/clr-li/AttendanceScanner?category=files)](https://github.com/clr-li/AttendanceScanner) -->

[![LOC](./.badges/lines-of-code.svg)](https://github.com/clr-li/AttendanceScanner)
[![FileCount](./.badges/file-count.svg)](https://github.com/clr-li/AttendanceScanner)
[![WebsiteStatus](https://img.shields.io/website?url=https%3A%2F%2Fattendancescannerqr.web.app%2F
)](https://github.com/clr-li/AttendanceScanner)
[![WebsiteStatus](https://img.shields.io/website?url=https%3A%2F%2Fattendancescannerqr.web.app%2F)](https://github.com/clr-li/AttendanceScanner)
![Tests](https://github.com/clr-li/AttendanceScanner/actions/workflows/tests.yml/badge.svg)
[![Coverage](./.badges/coverage.svg)](https://raw.githubusercontent.com/clr-li/AttendanceScanner/main/public/assets/coverage.svg)

This project (in progress) uses QR codes to take attendance and a SQLite database to store data of businesses, attendees, and events. It uses oauth2 through Firebase Auth to authenticate users using Google as the identity provider and has custom authorization logic. Braintree is used as the payment gateway for the electronic payment/subscription system. Automated tests are written using Node Test Runner and Selenium and CI/CD run through Github Actions.
URL: https://attendancescannerqr.web.app

# Development

## Recommended VS Code plugins
- [es6-string-html](https://marketplace.visualstudio.com/items?itemName=Tobermory.es6-string-html) - syntax highlighting for template literals, useful for HTML, CSS, SQL, and more!

- [es6-string-html](https://marketplace.visualstudio.com/items?itemName=Tobermory.es6-string-html) - syntax highlighting for template literals, useful for HTML, CSS, SQL, and more!
- [Esbenp Prettier](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) - automatically format code on save and via VS Code commands!

## Branches
- `master` - production branch - clone of Glitch branch (Glitch is currently used for hosting the server)
- `main` - main development branch - latest stable version of the code, hosted on Github

- `master` - production branch - clone of Glitch branch (Glitch is currently used for hosting the server)
- `main` - main development branch - latest stable version of the code, hosted on Github

## Local Development

### Setup

1. `git clone https://github.com/clr-li/AttendanceScanner.git`
2. `git remote add glitch [INSERT GLITCH API URL HERE AND REMOVE THESE BRACKETS]`
3. Add the `.data` directory and `.env` file (can be found on Glitch)
Expand All @@ -30,14 +37,17 @@ URL: https://attendancescannerqr.web.app
- After running `npm run dev`, use a browser to go to the localhost port printed (this should automatically open on most systems)

### Workflow

0. Start with `git pull`, and make sure you are on the right branch, e.g. `git checkout main`

&nbsp;&nbsp;For small changes:

1. Make changes to the local `main` branch
2. `git add` and `git commit` any changes locally
3. `git push origin` to push to the Github `main` branch

&nbsp;&nbsp;For larger changes:

1. `git checkout -b [NAME OF NEW DEVELOPMENT BRANCH]` to create a separate branch
2. Make changes and `git add` and `git commit` locally
3. `git push origin` and create a pull request for others to review and merge into `main` after review
Expand All @@ -48,40 +58,52 @@ URL: https://attendancescannerqr.web.app
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- Or to only deploy static files to Firebase: `npm run fire`

### Update database
- To reset the database and its schema, change the `databaseSchema.sql` file accordingly, `npm run deploy` changes like normal, then delete the `.data/ATT.db` file on Glitch and restart the server. The database will automatically get reinitialized.
- To make updates while keeping the existing data, add an update script to the `migrations` folder with the version number and date in its name. Then run it on Glitch.
- To purge the Braintree payment vault test data, login to the Braintree sandbox, click the gear icon and select "Purge Test Data"

- To reset the database and its schema, change the `databaseSchema.sql` file accordingly, `npm run deploy` changes like normal, then delete the `.data/ATT.db` file on Glitch and restart the server. The database will automatically get reinitialized.
- To make updates while keeping the existing data, add an update script to the `migrations` folder with the version number and date in its name. Then run it on Glitch.
- To purge the Braintree payment vault test data, login to the Braintree sandbox, click the gear icon and select "Purge Test Data"

## Automated Testing

1. Before running tests, run `npm install` (freshly installs dependencies from package.json) or `npm ci` (install specific dependency versions from package-lock) to make sure dependencies are installed.

2. Then run `npm test` and check the output in the console for the status of the tests. Console logs during test execution will pipe to `test.log` instead of standard out so you wont see logs in the terminal.

3. Tests live in the `/test` directory and use the builtin [Node Test Runner](https://nodejs.org/docs/latest-v18.x/api/test.html) framework. New tests are always welcome!
3. Linting and automatic formatting can be run with `npm run lint` and `npm run format`.

4. Tests live in the `/test` directory and use the builtin [Node Test Runner](https://nodejs.org/docs/latest-v18.x/api/test.html) framework. New tests are always welcome!

### Github Actions
The tests will automatically run in an environment closely mirroring the production environment when commits are pushed or branches merged. See `.github/workflows/tests.yml` for details. The status of these tests can be seen in the badge at the top of this readme. The coverage badge shows the percentage of lines, branches, and functions covered by the automated tests and will update everytime tests are run locally.

The tests will automatically run in an environment closely mirroring the production environment when commits are pushed or branches merged. See `.github/workflows/tests.yml` for details. The status of these tests can be seen in the badge at the top of this readme. The coverage badge shows the percentage of lines, branches, and functions covered by the automated tests and will update everytime tests are run locally.

### Server Side Tests

Server-side tests live in `server.test.js` and are unit tests of exported functions and endpoints. The endpoints are tested using [Supertest](https://www.npmjs.com/package/supertest) to spin up temporary instances of the HTTPServer to make fast test requests to. The tests use [in-memory SQLite databases](https://www.sqlite.org/inmemorydb.html) so they can easily be cleared between tests (SQLite automatically clears the previous in-memory database when a new one is instantiated). Firebase token verification is mocked since the full OAuth flow can only meaningfully be tested using a client which falls into the next category of tests.

### Cross Browser Client Side Tests

We use [Selenium](https://www.npmjs.com/package/selenium-webdriver) for cross browser tests of the web interface and client side components. By default, tests are run with `chrome` but running tests via `SELENIUM_BROWSER=[insert browser name] npm test` where `[insert browser name]` is replaced with `safari`, `edge`, `firefox`, `opera`, or `ie` (Internet Explorer requires Windows) will test with those respective browsers (make sure to have the browser installed and on path before running tests). The github action tests have been configured to run with `chrome`.

#### Setup Safari Tests

0. Use a mac (with Safari on it) and doublecheck `npm ci` has been run
1. Run `sudo safaridriver --enable` in your terminal and enter your computer password as prompted
2. Enable the 'Allow Remote Automation' option in Safari's Develop menu

#### Setup Tests of the OAuth Flow

By default tests mock the Firebase Authentication layer (to run faster and not require storing Google account credentials). To test with a real Google account, run tests with an account email (`[email protected]`) and password (`TEST_PASSWORD=xxxx`) in the `.env` file. The tests will attempt to automatically login for these test, but they may still require manual input during the login phase if your account has MFA enabled or other security settings that interfere. Currently only supported for Google Chrome.

## Glitch Development

Preferably don't edit directly on Glitch except to change the production `.data` or `.env`. If necessary,

1. Make changes on Glitch
2. Locally `git checkout master` and `git pull glitch` to obtain changes locally
3. `git push origin` changes to the Github `master` branch
4. On Github, create a pull request and merge changes with the Github `main`

### To change the production (Glitch server) `.data` or `.env`

If the changes only apply to Glitch and not local development, just change directly. Otherwise, make sure leave a note somewhere lol
52 changes: 0 additions & 52 deletions badges.js

This file was deleted.

12 changes: 4 additions & 8 deletions firebase.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
{
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
"hosting": {
"public": "public",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"]
}
}
Loading

0 comments on commit 23d3f9c

Please sign in to comment.