Skip to content
Open
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
58 changes: 13 additions & 45 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ on:
- "**"
# Remove the line above to run when pushing to master
pull_request:
branches: [ main, dev ]
branches: [ dev ]
repository_dispatch:
types: [ run_api_tests ]
schedule:
- cron: "0 0 * * 0" # Runs every day at midnight (UTC)

jobs:
UnitTest:
Expand All @@ -30,62 +28,32 @@ jobs:
- name: Determine output folder
id: set_output_folder
run: |
# For pull_request events, use the base branch; otherwise use the current branch reference
if [[ $GITHUB_EVENT_NAME == "pull_request" ]]; then
branch_name=$GITHUB_BASE_REF
else
branch_name=$GITHUB_REF_NAME
fi

if [[ $branch_name == "main" ]]; then
echo "output_folder=stage" >> $GITHUB_ENV
elif [[ $branch_name == "dev" ]]; then
echo "output_folder=dev" >> $GITHUB_ENV
else
echo "Unknown branch: $branch_name"
exit 1
fi
echo "output_folder=dev" >> $GITHUB_ENV

- name: Create env file
env:
ENV_CONTENT: ${{ secrets.ENV_FILE }}
run: |
# For pull requests, choose the env file based on the base branch
if [ "${{ github.event_name }}" = "pull_request" ]; then
if [ "${{ github.event.pull_request.base.ref }}" = "main" ]; then
echo "${{ secrets.STAGE_ENV_FILE }}" > .env
else
echo "${{ secrets.ENV_FILE }}" > .env
fi
else
# For non-PR events (push, schedule, repository_dispatch), use the stage env file
echo "${{ secrets.STAGE_ENV_FILE }}" > .env
fi
set +H
tmp_env_file=".env"
printf '%s' "$ENV_CONTENT" > "$tmp_env_file"

- name: Set TIMESTAMP
run: |
# Save the timestamp as an environment variable for reuse in subsequent steps.
echo "TIMESTAMP=$(date '+%d.%m.%Y_%H.%M.%S')" >> $GITHUB_ENV

- name: Run tests with coverage
run: |
# Use the TIMESTAMP variable from the environment.
timestamp=$(date '+%Y-%m-%d_%H-%M-%S')
mkdir -p test_results
log_file="test_results/${TIMESTAMP}_report.log"
echo -e "\nTest Cases Report\n" >> "$log_file"
# Run the tests and append output to the log file
npm run test >> "$log_file" 2>&1
log_file="test_results/${timestamp}_report.log"
echo -e "\nTest Cases Report Report\n" >> $log_file
npm run test >> $log_file 2>&1
# Copy and rename the generated test report with the timestamp
cp test-report.html test_results/test-report_${TIMESTAMP}.html

- name: Set Date Folder
run: |
DATE_FOLDER=$(date '+%d.%m.%Y')
echo "date_folder=${DATE_FOLDER}" >> $GITHUB_ENV
cp test-report.html test_results/test-report_${timestamp}.html

- name: Upload report to Azure
uses: LanceMcCarthy/Action-AzureBlobUpload@v2
with:
source_folder: 'test_results'
destination_folder: '${{ env.date_folder }}'
destination_folder: '${{ env.output_folder }}'
connection_string: ${{ secrets.AZURE_STORAGE_CONNECTION_STRING }}
container_name: 'api-tester'
clean_destination_folder: false
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ build
.tern-port
.DS_Store
src/test-harness.json
test-report.html
test-report*
wallaby.js

jest-html-reporters-attach
seed.data.json
seed.data*
.idea/
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Application configuration is read from .env file. Below are the list of environe
|SEED_ADMIN_PASSWORD |admin password|
|SYSTEM_BASE_URL | TDEI API url|
|ENVIRONMENT | Environement to run api tester dev, stage, prod|
|DEFAULT_PASSWORD | Default password for the users created |
|DEFAULT_USERNAME | TDEI username which has default group permission only|


## API Tester Environment Data
Expand Down
77 changes: 0 additions & 77 deletions api.input.json

This file was deleted.

17 changes: 17 additions & 0 deletions jest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@ expect.extend({
},
});

expect.extend({
toBeAbsentOrNullOrObject(received) {
const pass = received === undefined || received === null || typeof received === 'object';
if (pass) {
return {
message: () => `expected ${received} not to be absent, null, or an object`,
pass: true,
};
} else {
return {
message: () => `expected ${received} to be absent, null, or an object`,
pass: false,
};
}
},
});

process.on('unhandledRejection', (reason, promise) => {
console.error('Unhandled Rejection at:', promise, 'reason:', reason);
// Optionally, you can fail the test if there's an unhandled rejection
Expand Down
Loading
Loading