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

Ref/mkt 6907 api method #113

Closed
wants to merge 10 commits into from
Closed
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
7 changes: 6 additions & 1 deletion .github/workflows/jira.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
pull_request:
types: [opened]
jobs:
security:
security-jira:
if: ${{ github.actor == 'dependabot[bot]' || github.actor == 'snyk-bot' || contains(github.event.pull_request.head.ref, 'snyk-fix-') || contains(github.event.pull_request.head.ref, 'snyk-upgrade-')}}
runs-on: ubuntu-latest
steps:
Expand All @@ -26,3 +26,8 @@ jobs:
PR: ${{ github.event.pull_request.html_url }}

fields: "${{ secrets.JIRA_FIELDS }}"
- name: Transition issue
uses: atlassian/gajira-transition@v3
with:
issue: ${{ steps.create.outputs.issue }}
transition: ${{ secrets.JIRA_TRANSITION }}
11 changes: 11 additions & 0 deletions .github/workflows/sast-scan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: SAST Scan
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
security-sast:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Semgrep Scan
run: docker run -v /var/run/docker.sock:/var/run/docker.sock -v "${PWD}:/src" returntocorp/semgrep semgrep scan --config auto
2 changes: 1 addition & 1 deletion .github/workflows/sca-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
security:
security-sca:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
Expand Down
64 changes: 64 additions & 0 deletions __test__/uiLocation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import {
LocationType,
Region,
} from "../src/types";
import { ApiRequestProps } from '../src/types/stack.types';
import { dispatchPostRobotRequest } from '../src/utils/adapter';
import { onData, onError } from '../src/utils/utils';

jest.mock("post-robot");
jest.mock("wolfy87-eventemitter");
Expand Down Expand Up @@ -131,6 +134,67 @@ describe("UI Location", () => {
});
});

describe('dispatchPostRobotRequest', () => {
let mockPostRobot: typeof postRobot;
let opts: ApiRequestProps;
let uiLocationInstance: UiLocation;
let onError: jest.Mock;

beforeEach(() => {
mockPostRobot = postRobot;
opts = { method: 'GET', url: '/test' };
uiLocationInstance = new UiLocation(initData);
onError = jest.fn();
uiLocationInstance.api = jest.fn().mockResolvedValue({
method: 'GET',
url: '/test?limit=10&skip=0',
body: {}
});
});

it('should call sendToParent with the correct arguments and resolve with data', async () => {
const mockData = { success: true };
// Call the method that uses uiLocationInstance.api
const result = await uiLocationInstance.api({
method: 'GET',
url: '/test?limit=10&skip=0',
body: {}
});

// Assertions
expect(uiLocationInstance.api).toHaveBeenCalledWith({
method: 'GET',
url: '/test?limit=10&skip=0',
body: {}
});
expect(result).toEqual({
method: 'GET',
url: '/test?limit=10&skip=0',
body: {}
});

});

it('should call onError if sendToParent rejects', async () => {
const mockError = new Error('Test error');

// Mock the api method to reject with an error
uiLocationInstance.api = jest.fn().mockRejectedValue(mockError);

// Mock the onError implementation
onError.mockImplementation((error) => {
throw error;
});

// Call the method that uses uiLocationInstance.api and expect it to throw an error
await expect(uiLocationInstance.api({
method: 'GET',
url: '/test?limit=10&skip=0',
body: {}
})).rejects.toThrow('Test error');
});
});

describe("getConfig", () => {
it("should return config if no installation uid present", async () => {
const uiLocation = new UiLocation(initDataJsonRte as any);
Expand Down
Loading
Loading