Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 140 additions & 0 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
name: run_api_tests

on:
push:
branches-ignore:
- "**"
# Remove the line above to run when pushing to master
pull_request:
branches: [dev]
repository_dispatch:
types: [run_api_tests]
schedule:
- cron: "0 0 * * 0"
workflow_dispatch:

###############
# Set the Job #
###############
jobs:
UnitTest:
name: API Test Cases
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
# Full git history is needed to get a proper
# list of changed files within `super-linter`
fetch-depth: 0

- name: Install npm dependencies
run: npm install

- name: Create env file
run: |
echo "${{ secrets.ENV_FILE }}" > .env

- name: Create Test Log Directory
run: |
echo "Creating test log directory"
TIMESTAMP=$(date +"%Y-%m-%d_%H-%M-%S")
echo "TIMESTAMP=$TIMESTAMP" >> $GITHUB_ENV
LOG_DIR="user-management-api-test-report-${TIMESTAMP}"
mkdir -p "$LOG_DIR"
echo "Test log directory created: $LOG_DIR"
ls -la "$LOG_DIR"

- name: Run api test cases
run: |
echo "Starting test run"
LOG_DIR="user-management-api-test-report-${{ env.TIMESTAMP }}"
LOG_FILE="${LOG_DIR}/test-${{ env.TIMESTAMP }}.log"
echo "Log directory: $LOG_DIR"
echo "Log file: $LOG_FILE"
echo "Running npm test and capturing output..."
npm run test | tee "$LOG_FILE"
TEST_EXIT_CODE=${PIPESTATUS[0]}
echo "Test run complete. Log file created: $LOG_FILE"
cat "$LOG_FILE"
exit $TEST_EXIT_CODE

- name: Install Python and Azure Dependencies
if: always()
run: |
sudo apt-get update
sudo apt-get install python3-pip -y
pip3 install azure-storage-blob

# - name: Upload API Test Report to Azure Blob Storage
# if: always()
# env:
# AZURE_STORAGE_ACCOUNT_NAME: ${{ secrets.AZURE_STORAGE_ACCOUNT_NAME }}
# AZURE_STORAGE_ACCOUNT_KEY: ${{ secrets.AZURE_STORAGE_ACCOUNT_KEY }}
# AZURE_STORAGE_CONTAINER_NAME: ${{ secrets.AZURE_STORAGE_CONTAINER_NAME }}
# run: |
# echo "
# from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient
# import os

# connect_str = os.getenv('AZURE_STORAGE_ACCOUNT_KEY')
# account_name = os.getenv('AZURE_STORAGE_ACCOUNT_NAME')
# blob_service_client = BlobServiceClient(account_url=f'https://{account_name}.blob.core.windows.net', credential=connect_str)
# container_client = blob_service_client.get_container_client(os.getenv('AZURE_STORAGE_CONTAINER_NAME'))

# log_dir = './user-management-api-test-report-' + os.getenv('TIMESTAMP')
# if os.path.exists(log_dir):
# for file_name in os.listdir(log_dir):
# local_file_name = os.path.join(log_dir, file_name)
# blob_client = container_client.get_blob_client(file_name)
# with open(local_file_name, 'rb') as data:
# blob_client.upload_blob(data, overwrite=True)
# file_path = '/home/runner/work/TDEI-management-api-tester/TDEI-management-api-tester/test-report.html'
# timestamp = os.getenv('TIMESTAMP')
# blob_name = f'management-test-report-{timestamp}.html'
# blob_client = container_client.get_blob_client(blob_name)
# with open(file_path, 'rb') as data:
# blob_client.upload_blob(data, overwrite=True)
# " > upload_to_blob.py
# python3 upload_to_blob.py

- name: Upload log to Azure
uses: LanceMcCarthy/Action-AzureBlobUpload@v2
with:
source_folder: "user-management-api-test-report-${{ env.TIMESTAMP }}"
destination_folder: "${{ env.TIMESTAMP }}"
connection_string: ${{ secrets.AZURE_STORAGE_CONNECTION_STRING }}
container_name: "management-api-tester"
clean_destination_folder: false
delete_if_exists: false

- name: Upload report to Azure
uses: LanceMcCarthy/Action-AzureBlobUpload@v2
with:
source_folder: "test-report.html"
destination_folder: "${{ env.TIMESTAMP }}"
connection_string: ${{ secrets.AZURE_STORAGE_CONNECTION_STRING }}
container_name: "management-api-tester"
clean_destination_folder: false
delete_if_exists: false

- name: send email notification
if: always()
uses: dawidd6/action-send-mail@v3
with:
server_address: smtp.gmail.com
server_port: 587
username: ${{ secrets.EMAIL_USER }}
password: ${{ secrets.EMAIL_PASSWORD }}
subject: ${{ job.status }} - User Management API Testing Report | ${{ github.event_name == 'pull_request' && format('{0}-{1}', 'PR', github.event.pull_request.title) || 'Triggered via Schema Changed' }}
to: gs-tdei-coreteam@gaussiansolutions.com
cc: sureshd@gaussiansolutions.com
bcc: rakeshd@gaussiansolutions.com
from: Workflow Notification
attachments: test-report.html
html_body: |
<h2>API Testing Report</h2>
<p>Workflow: <a href="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}">${{ github.workflow }}</a></p>
<p>Repository: <a href="${{ github.server_url }}/${{ github.repository }}">${{ github.repository }}</a></p>
${{ github.event_name == 'pull_request' && format('<p>Pull Request: <a href="{0}">{1}</a></p>', github.event.pull_request.html_url, github.event.pull_request.title) || '<br>' }}
14 changes: 14 additions & 0 deletions api.input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"dev": {
"users": {
"poc": "adella.legros3@gmail.com",
"default_user": "defaultuser@mailinator.com"
}
},
"stage": {
"users": {
"poc": "frederic71@gmail.com",
"default_user": "defaultuser@mailinator.com"
}
}
}
11 changes: 4 additions & 7 deletions global-setup.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import seed from "./src/data.seed";

const setup = async (): Promise<void> => {
// whatever you need to setup globally
console.log("Setup!!");
await seed.generate();
};

export default setup;
module.exports = async function () {
console.log("Seading the information !!");
global.seedData = await seed.generate();
}
10 changes: 10 additions & 0 deletions global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// global.d.ts
declare global {
namespace NodeJS {
interface Global {
seedData: SeedData; // Replace 'any' with the actual type of your seed data
}
}
}

export { };
16 changes: 12 additions & 4 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@ import type { Config } from 'jest';

export default async (): Promise<Config> => {
return {
verbose: true,
verbose: false,
preset: 'ts-jest',
testEnvironment: 'node',
testTimeout: 15000,
globalSetup: "./global-setup.ts",
reporters: [
"default",
["./node_modules/jest-html-reporter", {
"pageTitle": "Test Report",
"includeFailureMsg": true
["jest-html-reporters", {
"filename": "test-report.html",
"urlForTestFiles": "https://github.com/TaskarCenterAtUW/TDEI-management-api-tester/tree/dev",
"enableMergeData": true,
"inlineSource": true,
"pageTitle": `TDEI User Management API Test Report - ${new Date().toLocaleString()}`,
"logoImgPath": "src/tdei_logo.png",
"customInfos": [{
"title": "Project",
"value": "TDEI User Management API Tester"
}]
}]
],
transform: {
Expand Down
Loading