Giter VIP home page Giter VIP logo

js_snippets's Introduction

const axios = require('axios'); const chai = require('chai'); const expect = chai.expect; const fs = require('fs'); const FormData = require('form-data'); const { exec } = require('child_process');

const API_URL = 'https://qsctoreporting.uk.hsbc:7000/DMD/table?responseDataFormat=keyValue'; const GET_API_URL = 'https://qsctoreporting.uk.hsbc:7000/DMD/table'; // Assuming a GET endpoint exists const requestBody = { "dimensionList": [ "Pod ID", "Month Year", "Incident Number SN" ], "measureList": [ "API - Incidents" ], "selections": [ { "FieldName": "Year", "Values": [2024], "fieldType": "N" }, { "FieldName": "Month", "Values": [3], "fieldType": "N" } ] };

const NEXUS_URL = 'http://your-nexus-repo-url/repository/your-repo'; const NEXUS_USERNAME = 'your-username'; const NEXUS_PASSWORD = 'your-password'; const TEST_RESULTS_FILE = './test-results.xml'; const UPLOAD_FLAG = process.argv.includes('--upload');

describe('DMD API Regression Tests', function() { this.timeout(5000); // Increase timeout for API response

it('should return status 200 for POST', async function() {
    const response = await axios.post(API_URL, requestBody);
    expect(response.status).to.equal(200);
});

it('should return status 200 for GET', async function() {
    const response = await axios.get(GET_API_URL);
    expect(response.status).to.equal(200);
});

it('should return data with expected structure', async function() {
    const response = await axios.post(API_URL, requestBody);
    expect(response.data).to.be.an('array');
    response.data.forEach(item => {
        expect(item).to.have.keys(['Pod ID', 'Month Year', 'Incident Number SN', 'API - Incidents']);
    });
});

it('should return correct data for given selections', async function() {
    const response = await axios.post(API_URL, requestBody);
    expect(response.data).to.deep.include({
        "Pod ID": "somePodID",
        "Month Year": "2024-03",
        "Incident Number SN": "someIncidentNumber",
        "API - Incidents": someValue
    });
});

it('should respond within acceptable time limit', async function() {
    const startTime = Date.now();
    const response = await axios.post(API_URL, requestBody);
    const endTime = Date.now();
    expect(endTime - startTime).to.be.below(2000); // 2 seconds
});

});

// Run tests and generate results exec('npx mocha testDmdApi.js --reporter mocha-junit-reporter --reporter-options mochaFile=' + TEST_RESULTS_FILE, (error, stdout, stderr) => { if (error) { console.error(Error running tests: ${error.message}); return; } if (stderr) { console.error(Test stderr: ${stderr}); return; } console.log(Test stdout: ${stdout});

if (UPLOAD_FLAG) {
    // Upload test results
    const form = new FormData();
    form.append('file', fs.createReadStream(TEST_RESULTS_FILE));

    axios.post(NEXUS_URL, form, {
        auth: {
            username: NEXUS_USERNAME,
            password: NEXUS_PASSWORD
        },
        headers: form.getHeaders()
    })
    .then(response => {
        console.log('Upload successful:', response.status);
        console.log('Uploaded results URL:', `${NEXUS_URL}/repository/your-repo/${TEST_RESULTS_FILE}`);
    })
    .catch(error => {
        console.error('Upload failed:', error);
    });
}

});

node testDmdApi.js --upload

js_snippets's People

Contributors

jstreats avatar mananshah9 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.