Skip to content

Commit

Permalink
Fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
lucianogorza committed Dec 15, 2023
1 parent 075cc26 commit a112e78
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@ jest.mock('../../../../react-services', () => ({
}),
}));

const mockedResponseClusterStatus = {
data: {
data: {
enabled: 'yes',
running: 'yes',
},
error: 0,
},
};

describe('Register agent service', () => {
beforeEach(() => jest.clearAllMocks());
describe('getRemoteConfiguration', () => {
Expand Down Expand Up @@ -51,14 +41,13 @@ describe('Register agent service', () => {
},
};

WzRequest.apiReq = jest
.fn()
.mockResolvedValueOnce(mockedResponseClusterStatus)
.mockResolvedValueOnce(mockedResponse);
WzRequest.apiReq = jest.fn().mockResolvedValueOnce(mockedResponse);
const nodeName = 'example-node';
const res = await RegisterAgentService.getRemoteConfiguration(
'example-node',
nodeName,
false,
);
console.log(res);
expect(res.name).toBe(nodeName);
expect(res.haveSecureConnection).toBe(true);
});
Expand All @@ -84,13 +73,11 @@ describe('Register agent service', () => {
},
},
};
WzRequest.apiReq = jest
.fn()
.mockResolvedValueOnce(mockedResponseClusterStatus)
.mockResolvedValueOnce(mockedResponse);
WzRequest.apiReq = jest.fn().mockResolvedValueOnce(mockedResponse);
const nodeName = 'example-node';
const res = await RegisterAgentService.getRemoteConfiguration(
'example-node',
nodeName,
false,
);
expect(res.name).toBe(nodeName);
expect(res.haveSecureConnection).toBe(false);
Expand Down Expand Up @@ -124,13 +111,11 @@ describe('Register agent service', () => {
},
},
};
WzRequest.apiReq = jest
.fn()
.mockResolvedValueOnce(mockedResponseClusterStatus)
.mockResolvedValueOnce(mockedResponse);
WzRequest.apiReq = jest.fn().mockResolvedValueOnce(mockedResponse);
const nodeName = 'example-node';
const res = await RegisterAgentService.getRemoteConfiguration(
'example-node',
nodeName,
false,
);
expect(res.name).toBe(nodeName);
expect(res.isUdp).toEqual(true);
Expand Down Expand Up @@ -164,13 +149,11 @@ describe('Register agent service', () => {
},
},
};
WzRequest.apiReq = jest
.fn()
.mockResolvedValueOnce(mockedResponseClusterStatus)
.mockResolvedValueOnce(mockedResponse);
WzRequest.apiReq = jest.fn().mockResolvedValueOnce(mockedResponse);
const nodeName = 'example-node';
const res = await RegisterAgentService.getRemoteConfiguration(
'example-node',
nodeName,
false,
);
expect(res.name).toBe(nodeName);
expect(res.isUdp).toEqual(false);
Expand Down Expand Up @@ -204,13 +187,11 @@ describe('Register agent service', () => {
},
},
};
WzRequest.apiReq = jest
.fn()
.mockResolvedValueOnce(mockedResponseClusterStatus)
.mockResolvedValueOnce(mockedResponse);
WzRequest.apiReq = jest.fn().mockResolvedValueOnce(mockedResponse);
const nodeName = 'example-node';
const res = await RegisterAgentService.getRemoteConfiguration(
'example-node',
nodeName,
false,
);
expect(res.name).toBe(nodeName);
expect(res.isUdp).toEqual(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ async function getRemoteConfiguration(
{},
);
}
const items = ((result.data || {}).data || {}).affected_items || [];
const items = result?.data?.data?.affected_items || [];
const remote = items[0]?.remote;
if (remote) {
const remoteFiltered = remote.filter((item: RemoteItem) => {
Expand Down

0 comments on commit a112e78

Please sign in to comment.