Skip to content

Commit

Permalink
Merge pull request #63 from yeha98555/fix/checkingToken-test-error
Browse files Browse the repository at this point in the history
fix: Update checkingToken to handle env variable loading issue in Jest
  • Loading branch information
yeha98555 committed Jun 13, 2023
2 parents 86f57c8 + 023fc3f commit f3362a3
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 39 deletions.
25 changes: 25 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
NODE_ENV=development

PORT=3000

MONGODB_USER=user
MONGODB_PASSWORD=password
MONGODB_DATABASE=test
MONGODB_CONNECT_STRING=mongodb+srv://<user>:<password>@xxxxxxxxxxx/<database>?retryWrites=true&w=majority
MONGODB_ENDPOINT=xxxxxxxxxxxxxxxx.docdb.amazonaws.com

JWT_SECRET=secret
LOG_FILE_DIR=logs

# NewebPay
NEWEBPAY_VERSION=1.5
NEWEBPAY_MERCHANT_ID=MSxxxxxxx
NEWEBPAY_HASH_KEY=key
NEWEBPAY_HASH_IV=iv
NEWEBPAY_NOTIFY_URL=https://ticket-haven-dev.onrender.com/orders/payment_notify
NEWEBPAY_RETURN_URL=http://ticket-haven-dev.onrender.com/orders/payment_return
PAYMENT_RETURN_URL=http://ticket-haven-platform.vercel.app/payment-completed

# ticket checkin code
TICKET_CHECKING_KEY=secret
TICKET_CHECKING_IV=secret
106 changes: 72 additions & 34 deletions .github/workflows/aws.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,78 @@ on:
- main

jobs:
deploy:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3

- name: Use Node.js
uses: actions/setup-node@v3

- name: Install Dependencies
run: yarn install

- name: Copy .env.example to .env
run: cp .env.test .env

- name: Run tests
run: yarn test

- name: Rollback
if: ${{ failure() && github.event_name == 'push' }}
run: |
git checkout ${{ github.sha }}^1
git push --force
# Post a comment on the pull request
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
-d '{"body": "The CI job has failed. The last commit has been rolled back."}' \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/issues/${{ github.event.pull_request.number }}/comments"
deploy:
needs: test
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3

- name: Use Node.js
uses: actions/setup-node@v3

- name: Install Dependencies
run: yarn install

- name: Run tests
run: yarn test

- name: Build
if: ${{ success() && github.event_name == 'push' }}
run: yarn build

- name: Create deployment package
if: ${{ success() && github.event_name == 'push' }}
run: zip -r deploy.zip . -x ".git/*" -x ".github/*" -x ".vscode/*" -x ".hursky/*" -x "mock/*" -x "__test__/*"

- name: Deploy to AWS
if: ${{ success() && github.event_name == 'push' }}
uses: einaregilsson/beanstalk-deploy@v21
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
application_name: ${{ secrets.AWS_APP_NAME }}
environment_name: ${{ secrets.AWS_APP_ENV_NAME }}
existing_bucket_name: ${{ secrets.AWS_BUCKET_NAME }}
version_label: ${{ github.run_id }}
region: ${{ secrets.AWS_REGION }}
deployment_package: deploy.zip
use_existing_version_if_available: true
- name: Checkout Repo
uses: actions/checkout@v3

- name: Use Node.js
uses: actions/setup-node@v3

- name: Install Dependencies
run: yarn install

- name: Build
run: yarn build

- name: Create deployment package
run: zip -r deploy.zip . -x ".git/*" -x ".github/*" -x ".vscode/*" -x ".hursky/*" -x "mock/*" -x "__test__/*"

- name: Deploy to AWS
uses: einaregilsson/beanstalk-deploy@v21
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
application_name: ${{ secrets.AWS_APP_NAME }}
environment_name: ${{ secrets.AWS_APP_ENV_NAME }}
existing_bucket_name: ${{ secrets.AWS_BUCKET_NAME }}
version_label: ${{ github.run_id }}
region: ${{ secrets.AWS_REGION }}
deployment_package: deploy.zip
use_existing_version_if_available: true

- name: Rollback
if: ${{ failure() && github.event_name == 'push' }}
run: |
git checkout ${{ github.sha }}^1
git push --force
# Post a comment on the pull request
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
-d '{"body": "The CI job has failed. The last commit has been rolled back."}' \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/issues/${{ github.event.pull_request.number }}/comments"
38 changes: 34 additions & 4 deletions .github/workflows/render.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- develop

jobs:
build-and-deploy:
test:
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -22,15 +22,45 @@ jobs:
- name: Install Dependencies
run: yarn install

- name: Copy .env.example to .env
run: cp .env.test .env

- name: Run tests
run: yarn test

- name: Rollback
if: ${{ failure() && github.event_name == 'push' }}
run: |
git checkout ${{ github.sha }}^1
git push --force
# Post a comment on the pull request
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
-d '{"body": "The CI job has failed. The last commit has been rolled back."}' \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/issues/${{ github.event.pull_request.number }}/comments"
deploy:
needs: test
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
steps:
- name: Checkout Repo
uses: actions/checkout@v3

- name: Use Node.js
uses: actions/setup-node@v3

- name: Install Dependencies
run: yarn install

- name: Build
if: ${{ success() && github.event_name == 'push' }}
run: yarn build

- name: Deploy to Render
if: ${{ success() && github.event_name == 'push' }}
uses: johnbeynon/render-deploy-action@v0.0.8
with:
service-id: ${{ secrets.SERVICE_ID_DEVELOP }} # Can be found as part of the Deploy Hook
Expand All @@ -39,7 +69,7 @@ jobs:
- name: Rollback
if: ${{ failure() && github.event_name == 'push' }}
run: |
git reset HEAD~
git checkout ${{ github.sha }}^1
git push --force
# Post a comment on the pull request
Expand Down
7 changes: 6 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
/**
* @type {import('ts-jest').JestConfigWithTsJest}
*/
const { pathsToModuleNameMapper } = require('ts-jest');
const { compilerOptions } = require('./tsconfig');

require('dotenv').config();

module.exports = {
setupFiles: ['dotenv/config'],
coverageDirectory: 'coverage',
preset: 'ts-jest',
testEnvironment: 'node',
Expand Down

0 comments on commit f3362a3

Please sign in to comment.