Skip to content

Commit

Permalink
chore: update component test and generate reports (#2989)
Browse files Browse the repository at this point in the history
  • Loading branch information
utsabc authored Jan 19, 2024
1 parent 34bf49d commit 95f87e9
Show file tree
Hide file tree
Showing 17 changed files with 2,138 additions and 2,578 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/component-test-report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Component Test Reporter

on:
pull_request:
types:
- opened
- reopened
- synchronize

permissions:
id-token: write # allows the JWT to be requested from GitHub's OIDC provider
contents: read # This is required for actions/checkout

jobs:
test_and_upload:
runs-on: ubuntu-latest

steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ secrets.AWS_DEV_ACCOUNT_ID }}:role/${{ secrets.AWS_DEV_S3_SYNC_ROLE }}
aws-region: us-east-1

- name: Checkout
uses: actions/[email protected]
with:
fetch-depth: 1

- name: Setup Node
uses: actions/[email protected]
with:
node-version-file: '.nvmrc'
cache: 'npm'

- name: Install Dependencies
run: npm ci

- name: Run Tests and Generate Report
run: |
npm run test:ts -- component
- name: Uplaod Report to S3
run: |
aws s3 cp ./test_reports/ s3://test-integrations-dev/integrations-test-reports/rudder-transformer/${{ github.event.number }}/ --recursive
- name: Comment on PR with S3 Object URL
uses: actions/github-script@v7
with:
github-token: ${{ secrets.PAT }}
script: |
const { owner, repo } = context.repo;
// Get the pull request number
const prNumber = context.payload.pull_request.number;
const commentBody = `Test report for this run is available at: https://test-integrations-dev.s3.amazonaws.com/integrations-test-reports/rudder-transformer/${prNumber}/test-report.html`;
// Comment on the pull request
github.rest.issues.createComment({
owner,
repo,
issue_number: prNumber,
body: commentBody
});
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,7 @@ dist
**/.DS_Store


.idea
.idea

# component test report
test_reports/
2 changes: 1 addition & 1 deletion src/v0/destinations/tiktok_ads/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe('hashUserField utility test', () => {
const hashedUser = hashUserField(user);

expect(hashedUser).toEqual({
external_id: "a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3",
external_id: 'a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3',
email: '973dfe463ec85785f5f95af5ba3906eedb2d931c24e69824a89ea65dba4e813b',
phone: '422ce82c6fc1724ac878042f7d055653ab5e983d186e616826a72d4384b68af8',
});
Expand Down
24 changes: 24 additions & 0 deletions test/integrations/component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import tags from '../../src/v0/util/tags';
import { Server } from 'http';
import { appendFileSync } from 'fs';
import { responses } from '../testHelper';
import { generateTestReport, initaliseReport } from '../test_reporter/reporter';
import _ from 'lodash';

// To run single destination test cases
// npm run test:ts -- component --destination=adobe_analytics
Expand All @@ -37,6 +39,7 @@ command
.option('-f, --feature <string>', 'Enter Feature Name(processor, router)')
.option('-i, --index <number>', 'Enter Test index')
.option('-g, --generate <string>', 'Enter "true" If you want to generate network file')
.option('-id, --id <string>', 'Enter unique "Id" of the test case you want to run')
.parse();

const opts = command.opts();
Expand All @@ -50,7 +53,10 @@ if (opts.generate === 'true') {

let server: Server;

const REPORT_COMPATIBLE_INTEGRATION = ['klaviyo'];

beforeAll(async () => {
initaliseReport();
const app = new Koa();
app.use(
bodyParser({
Expand Down Expand Up @@ -124,6 +130,16 @@ const testRoute = async (route, tcData: TestCaseData) => {
const outputResp = tcData.output.response || ({} as any);
expect(response.status).toEqual(outputResp.status);

if (REPORT_COMPATIBLE_INTEGRATION.includes(tcData.name?.toLocaleLowerCase())) {
const bodyMatched = _.isEqual(response.body, outputResp.body);
const statusMatched = response.status === outputResp.status;
if (bodyMatched && statusMatched) {
generateTestReport(tcData, response.body, 'passed');
} else {
generateTestReport(tcData, response.body, 'failed');
}
}

if (outputResp?.body) {
expect(response.body).toEqual(outputResp.body);
}
Expand Down Expand Up @@ -181,6 +197,14 @@ describe.each(allTestDataFilePaths)('%s Tests', (testDataPath) => {
if (opts.index !== undefined) {
testData = [testData[parseInt(opts.index)]];
}
if (opts.id) {
testData = testData.filter((data) => {
if (data['id'] === opts.id) {
return true;
}
return false;
});
}
describe(`${testData[0].name} ${testData[0].module}`, () => {
test.each(testData)('$feature -> $description', async (tcData) => {
tcData?.mockFns?.(mockAdapter);
Expand Down
Loading

0 comments on commit 95f87e9

Please sign in to comment.