Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added and improved coverage to tests + fixed vulnerabilities #99

Merged
merged 3 commits into from
Sep 18, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Build Working Version

on: push
on: pull_request

jobs:
build:
Expand Down
10 changes: 5 additions & 5 deletions lib/jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ module.exports = {
coverageThreshold: {
global: {
// global thresholds
branches: 20,
functions: 20,
lines: 20,
statements: 20,
branches: 50,
functions: 50,
lines: 80,
statements: 80,
},
},
collectCoverage: true,
collectCoverageFrom: ["**/src/**/*.{js}", "!**/node_modules/**", "!**/coverage/**", "!**/test/**"],
collectCoverageFrom: ["src/*.js", "src/**/*.js", "!src/main.js", "!**/node_modules/**"],
testURL: "http://localhost",
testEnvironment: "jsdom",
transform: {
Expand Down
71 changes: 24 additions & 47 deletions lib/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"copy": "node ./scripts/build/copy-distribution-files.js",
"start": "rollup -c -w",
"build": "npm run bundle && npm run copy",
"test": "jest --transformIgnorePatterns node_modules/?!axios/",
"test:watch": "npm test -- --watch --coverage",
"test:coverage": "npm test -- --coverage --coverageReporters=cobertura",
"test": "jest --collect-coverage --transformIgnorePatterns node_modules/?!axios/",
"test:watch": "npm test --watch --coverage",
"test:coverage": "npm test --collect-coverage --coverageReporters=cobertura",
"test:coverage-dashboard": "npm test --collect-coverage"
},
"author": "DXC Halstack team",
Expand Down
45 changes: 29 additions & 16 deletions lib/test/hal-api-caller.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
import axios from "axios";
import MockAdapter from "axios-mock-adapter";

// Import the function to be tested
import apicaller from '../src/hal-api-caller';
import response from './mocks/options-response.json';
import apicaller from "../src/hal-api-caller";
import optionsResponse from "./mocks/options-response.json";
import getResponse from "./mocks/get-response.json";

describe('options function', () => {
describe("Apicaller functions test", () => {
let mockAxios;

beforeEach(() => {
Expand All @@ -16,16 +17,11 @@ describe('options function', () => {
mockAxios.restore();
});

it('should make a successful OPTIONS request and return HalResponse', async () => {
const url = 'https://example.com';
const headers = { CustomHeader: 'CustomValue' };
const responseData = response;
const responseHeaders = { 'Content-Type': 'application/json' };
const expectedHalResponse = {
body: { _options: responseData },
headers: responseHeaders,
status: 200,
};
it("should make a successful OPTIONS request and return HalResponse", async () => {
const url = "https://example.com";
const headers = { CustomHeader: "CustomValue" };
const responseData = optionsResponse;
const responseHeaders = { "Content-Type": "application/json" };

// Mocking the Axios request and response
mockAxios.onOptions(url).reply(200, responseData, responseHeaders);
Expand All @@ -34,9 +30,26 @@ describe('options function', () => {
const result = await apicaller.options({ url, headers });

// Assertions
expect(result).toBeDefined();
expect(result.halResource).toBeDefined();
expect(result.halResource.getTitle()).toEqual("Options available on Quote ID");
});

it("should make a successful GET request and return HalResponse", async () => {
const url = "https://example.com";
const headers = { CustomHeader: "CustomValue" };
const responseData = getResponse;
const responseHeaders = { "Content-Type": "application/json" };

// Mocking the Axios request and response
mockAxios.onGet(url).reply(200, responseData, responseHeaders);

// Calling the function
const result = await apicaller.get({ url, headers });

// Assertions
expect(result).toBeDefined();
expect(result.halResource).toBeDefined();
expect(result.halResource.getTitle()).toEqual('Options available on Quote ID');
expect(result.halResource.getItems().length).toBe(10);
});
});
Loading
Loading