Skip to content

Commit

Permalink
make codecov happy
Browse files Browse the repository at this point in the history
  • Loading branch information
lilykuang committed Jun 18, 2022
1 parent 88a6dfa commit d7974f1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,32 +120,33 @@ export default class SupersetClientClass {
}

async postForm(url: string, payload: Record<string, any>, target = '_blank') {
if (!url) return;
await this.ensureAuth();
const hiddenForm = document.createElement('form');
hiddenForm.action = url;
hiddenForm.method = 'POST';
hiddenForm.target = target;
const payloadWithToken: Record<string, any> = {
...payload,
csrf_token: this.csrfToken!,
};
if (url) {
await this.ensureAuth();
const hiddenForm = document.createElement('form');
hiddenForm.action = url;
hiddenForm.method = 'POST';
hiddenForm.target = target;
const payloadWithToken: Record<string, any> = {
...payload,
csrf_token: this.csrfToken!,
};

if (this.guestToken) {
payloadWithToken.guest_token = this.guestToken;
}

if (this.guestToken) {
payloadWithToken.guest_token = this.guestToken;
Object.entries(payloadWithToken).forEach(([key, value]) => {
const data = document.createElement('input');
data.type = 'hidden';
data.name = key;
data.value = value;
hiddenForm.appendChild(data);
});

document.body.appendChild(hiddenForm);
hiddenForm.submit();
document.body.removeChild(hiddenForm);
}

Object.entries(payloadWithToken).forEach(([key, value]) => {
const data = document.createElement('input');
data.type = 'hidden';
data.name = key;
data.value = value;
hiddenForm.appendChild(data);
});

document.body.appendChild(hiddenForm);
hiddenForm.submit();
document.body.removeChild(hiddenForm);
}

async reAuthenticate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ describe('SupersetClientClass', () => {
const guestToken = 'test-guest-token';
const postFormPayload = { number: 123, array: [1, 2, 3] };

let authSpy: jest.SpyInstance;
let client: SupersetClientClass;
let appendChild: any;
let removeChild: any;
Expand All @@ -622,6 +623,7 @@ describe('SupersetClientClass', () => {

beforeEach(async () => {
client = new SupersetClientClass({ protocol, host });
authSpy = jest.spyOn(SupersetClientClass.prototype, 'ensureAuth');
await client.init();
appendChild = jest.fn();
removeChild = jest.fn();
Expand Down Expand Up @@ -658,6 +660,7 @@ describe('SupersetClientClass', () => {

expect(appendChild.mock.calls).toHaveLength(1);
expect(removeChild.mock.calls).toHaveLength(1);
expect(authSpy).toHaveBeenCalledTimes(1);
});

it('makes postForm request with guest token', async () => {
Expand All @@ -676,6 +679,7 @@ describe('SupersetClientClass', () => {

expect(appendChild.mock.calls).toHaveLength(1);
expect(removeChild.mock.calls).toHaveLength(1);
expect(authSpy).toHaveBeenCalledTimes(1);
});

it('makes postForm request with payload', async () => {
Expand All @@ -692,6 +696,7 @@ describe('SupersetClientClass', () => {
expect(appendChild.mock.calls).toHaveLength(1);
expect(removeChild.mock.calls).toHaveLength(1);
expect(submit.mock.calls).toHaveLength(1);
expect(authSpy).toHaveBeenCalledTimes(1);
});

it('should do nothing when url is empty string', async () => {
Expand All @@ -700,6 +705,7 @@ describe('SupersetClientClass', () => {
expect(createElement.mock.calls).toHaveLength(0);
expect(appendChild.mock.calls).toHaveLength(0);
expect(removeChild.mock.calls).toHaveLength(0);
expect(authSpy).toHaveBeenCalledTimes(0);
});
});
});

0 comments on commit d7974f1

Please sign in to comment.