Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amirbenun committed Oct 10, 2024
1 parent 1a08242 commit f3f0b37
Showing 1 changed file with 78 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,84 @@ describe('Agentless Agent service', () => {
);
});

it('should delete agentless agent for ESS', async () => {
const returnValue = {
id: 'mocked',
};

(axios as jest.MockedFunction<typeof axios>).mockResolvedValueOnce(returnValue);
jest.spyOn(appContextService, 'getConfig').mockReturnValue({
agentless: {
enabled: true,
api: {
url: 'http://api.agentless.com',
tls: {
certificate: '/path/to/cert',
key: '/path/to/key',
ca: '/path/to/ca',
},
},
},
} as any);
jest
.spyOn(appContextService, 'getCloud')
.mockReturnValue({ isCloudEnabled: true } as any);

const deleteAgentlessAgentReturnValue = await agentlessAgentService.deleteAgentlessAgent(
'mocked-agentless-agent-policy-id',
);

expect(axios).toHaveBeenCalledTimes(1);
expect(deleteAgentlessAgentReturnValue).toEqual(returnValue);
expect(axios).toHaveBeenCalledWith(
expect.objectContaining({
headers: expect.anything(),
httpsAgent: expect.anything(),
method: 'DELETE',
url: 'http://api.agentless.com/api/v1/ess/deployments/mocked-agentless-agent-policy-id',
})
);
});

it('should delete agentless agent for serverless', async () => {
const returnValue = {
id: 'mocked',
};

(axios as jest.MockedFunction<typeof axios>).mockResolvedValueOnce(returnValue);
jest.spyOn(appContextService, 'getConfig').mockReturnValue({
agentless: {
enabled: true,
api: {
url: 'http://api.agentless.com',
tls: {
certificate: '/path/to/cert',
key: '/path/to/key',
ca: '/path/to/ca',
},
},
},
} as any);
jest
.spyOn(appContextService, 'getCloud')
.mockReturnValue({ isCloudEnabled: true, isServerlessEnabled: true } as any);

const deleteAgentlessAgentReturnValue = await agentlessAgentService.deleteAgentlessAgent(
'mocked-agentless-agent-policy-id',
);

expect(axios).toHaveBeenCalledTimes(1);
expect(deleteAgentlessAgentReturnValue).toEqual(returnValue);
expect(axios).toHaveBeenCalledWith(
expect.objectContaining({
headers: expect.anything(),
httpsAgent: expect.anything(),
method: 'DELETE',
url: 'http://api.agentless.com/api/v1/serverless/deployments/mocked-agentless-agent-policy-id',
})
);
});

it('should redact sensitive information from debug logs', async () => {
const returnValue = {
id: 'mocked',
Expand Down

0 comments on commit f3f0b37

Please sign in to comment.