-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(pci-load-balancer): add unit tests
ref: DTCORE-2770 Signed-off-by: Yoann Fievez <[email protected]>
- Loading branch information
Showing
13 changed files
with
1,161 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
packages/manager/apps/pci-load-balancer/src/api/data/l7Policies.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import { v6 } from '@ovh-ux/manager-core-api'; | ||
import { | ||
getL7Policies, | ||
getPolicy, | ||
deletePolicy, | ||
createPolicy, | ||
updatePolicy, | ||
TL7Policy, | ||
} from './l7Policies'; | ||
import { | ||
LoadBalancerOperatingStatusEnum, | ||
LoadBalancerProvisioningStatusEnum, | ||
} from './load-balancer'; | ||
|
||
describe('l7Policies API', () => { | ||
const projectId = 'test-project'; | ||
const region = 'test-region'; | ||
const listenerId = 'test-listener'; | ||
const policyId = 'test-policy'; | ||
const policy: TL7Policy = { | ||
id: 'test-policy', | ||
name: 'Test Policy', | ||
description: 'Test Description', | ||
operatingStatus: LoadBalancerOperatingStatusEnum.ONLINE, | ||
provisioningStatus: LoadBalancerProvisioningStatusEnum.ACTIVE, | ||
redirectHttpCode: 301, | ||
redirectPoolId: null, | ||
redirectPrefix: null, | ||
redirectUrl: null, | ||
action: 'REDIRECT_TO_URL', | ||
position: 1, | ||
listenerId: 'test-listener', | ||
}; | ||
|
||
it('should fetch L7 policies', async () => { | ||
const mockData = [policy]; | ||
(v6.get as any).mockResolvedValue({ data: mockData }); | ||
|
||
const result = await getL7Policies(projectId, listenerId, region); | ||
expect(result).toEqual(mockData); | ||
expect(v6.get).toHaveBeenCalledWith( | ||
`/cloud/project/${projectId}/region/${region}/loadbalancing/l7Policy?listenerId=${listenerId}`, | ||
); | ||
}); | ||
|
||
it('should fetch a single policy', async () => { | ||
(v6.get as any).mockResolvedValue({ data: policy }); | ||
|
||
const result = await getPolicy(projectId, region, policyId); | ||
expect(result).toEqual(policy); | ||
expect(v6.get).toHaveBeenCalledWith( | ||
`/cloud/project/${projectId}/region/${region}/loadbalancing/l7Policy/${policyId}`, | ||
); | ||
}); | ||
|
||
it('should delete a policy', async () => { | ||
const mockData = { success: true }; | ||
(v6.delete as any).mockResolvedValue({ data: mockData }); | ||
|
||
const result = await deletePolicy(projectId, region, policyId); | ||
expect(result).toEqual(mockData); | ||
expect(v6.delete).toHaveBeenCalledWith( | ||
`/cloud/project/${projectId}/region/${region}/loadbalancing/l7Policy/${policyId}`, | ||
); | ||
}); | ||
|
||
it('should create a policy', async () => { | ||
const mockData = { id: 'new-policy' }; | ||
(v6.post as any).mockResolvedValue({ data: mockData }); | ||
|
||
const result = await createPolicy(projectId, region, listenerId, policy); | ||
expect(result).toEqual(mockData); | ||
expect(v6.post).toHaveBeenCalledWith( | ||
`/cloud/project/${projectId}/region/${region}/loadbalancing/l7Policy`, | ||
{ | ||
listenerId, | ||
...policy, | ||
}, | ||
); | ||
}); | ||
|
||
it('should update a policy', async () => { | ||
const mockData = { success: true }; | ||
(v6.put as any).mockResolvedValue({ data: mockData }); | ||
|
||
const result = await updatePolicy(projectId, region, policy); | ||
expect(result).toEqual(mockData); | ||
expect(v6.put).toHaveBeenCalledWith( | ||
`/cloud/project/${projectId}/region/${region}/loadbalancing/l7Policy/${policy.id}`, | ||
{ | ||
name: policy.name, | ||
position: policy.position, | ||
action: policy.action, | ||
redirectHttpCode: policy.redirectHttpCode, | ||
redirectPoolId: policy.redirectPoolId, | ||
redirectPrefix: policy.redirectPrefix, | ||
redirectUrl: policy.redirectUrl, | ||
}, | ||
); | ||
}); | ||
}); |
95 changes: 95 additions & 0 deletions
95
packages/manager/apps/pci-load-balancer/src/api/data/l7Rules.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import { v6 } from '@ovh-ux/manager-core-api'; | ||
import { | ||
getL7Rules, | ||
deleteL7Rule, | ||
createL7Rule, | ||
updateL7Rule, | ||
getL7Rule, | ||
TL7Rule, | ||
} from './l7Rules'; | ||
import { | ||
LoadBalancerOperatingStatusEnum, | ||
LoadBalancerProvisioningStatusEnum, | ||
} from './load-balancer'; | ||
|
||
describe('L7 Rules API', () => { | ||
const projectId = 'test-project'; | ||
const region = 'test-region'; | ||
const policyId = 'test-policy'; | ||
const ruleId = 'test-rule'; | ||
const rule: TL7Rule = { | ||
id: ruleId, | ||
operatingStatus: LoadBalancerOperatingStatusEnum.ONLINE, | ||
provisioningStatus: LoadBalancerProvisioningStatusEnum.ACTIVE, | ||
key: 'test-key', | ||
value: 'test-value', | ||
invert: false, | ||
ruleType: 'HOST_NAME', | ||
compareType: 'EQUAL_TO', | ||
}; | ||
|
||
it('should get L7 rules', async () => { | ||
const mockData = [rule]; | ||
(v6.get as any).mockResolvedValue({ data: mockData }); | ||
|
||
const result = await getL7Rules(projectId, region, policyId); | ||
expect(result).toEqual(mockData); | ||
expect(v6.get).toHaveBeenCalledWith( | ||
`/cloud/project/${projectId}/region/${region}/loadbalancing/l7Policy/${policyId}/l7Rule`, | ||
); | ||
}); | ||
|
||
it('should delete an L7 rule', async () => { | ||
const mockData = {}; | ||
(v6.delete as any).mockResolvedValue({ data: mockData }); | ||
|
||
const result = await deleteL7Rule(projectId, region, policyId, ruleId); | ||
expect(result).toEqual(mockData); | ||
expect(v6.delete).toHaveBeenCalledWith( | ||
`/cloud/project/${projectId}/region/${region}/loadbalancing/l7Policy/${policyId}/l7Rule/${ruleId}`, | ||
); | ||
}); | ||
|
||
it('should create an L7 rule', async () => { | ||
const mockData = rule; | ||
(v6.post as any).mockResolvedValue({ data: mockData }); | ||
|
||
const result = await createL7Rule(projectId, region, policyId, rule); | ||
expect(result).toEqual(mockData); | ||
expect(v6.post).toHaveBeenCalledWith( | ||
`/cloud/project/${projectId}/region/${region}/loadbalancing/l7Policy/${policyId}/l7Rule`, | ||
rule, | ||
); | ||
}); | ||
|
||
it('should update an L7 rule', async () => { | ||
const updatedRule = { ...rule, value: 'updated-value' }; | ||
const mockData = updatedRule; | ||
(v6.put as any).mockResolvedValue({ data: mockData }); | ||
|
||
const result = await updateL7Rule(projectId, region, policyId, updatedRule); | ||
expect(result).toEqual(mockData); | ||
expect(v6.put).toHaveBeenCalledWith( | ||
`/cloud/project/${projectId}/region/${region}/loadbalancing/l7Policy/${policyId}/l7Rule/${rule.id}`, | ||
{ | ||
ruleType: updatedRule.ruleType, | ||
compareType: updatedRule.compareType, | ||
key: updatedRule.key, | ||
value: updatedRule.value, | ||
invert: updatedRule.invert, | ||
}, | ||
); | ||
}); | ||
|
||
it('should get a specific L7 rule', async () => { | ||
const mockData = rule; | ||
(v6.get as any).mockResolvedValue({ data: mockData }); | ||
|
||
const result = await getL7Rule(projectId, region, policyId, ruleId); | ||
expect(result).toEqual(mockData); | ||
expect(v6.get).toHaveBeenCalledWith( | ||
`/cloud/project/${projectId}/region/${region}/loadbalancing/l7Policy/${policyId}/l7Rule/${ruleId}`, | ||
); | ||
}); | ||
}); |
37 changes: 37 additions & 0 deletions
37
packages/manager/apps/pci-load-balancer/src/api/data/listener.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { describe, it, expect, vi } from 'vitest'; | ||
import { v6 } from '@ovh-ux/manager-core-api'; | ||
import { deleteListener, getListener } from './listener'; | ||
|
||
describe('listener API', () => { | ||
const projectId = 'test-project'; | ||
const region = 'test-region'; | ||
const listenerId = 'test-listener'; | ||
|
||
describe('deleteListener', () => { | ||
it('should delete a listener and return data', async () => { | ||
const mockResponse = { success: true }; | ||
vi.mocked(v6.delete).mockResolvedValueOnce({ data: mockResponse }); | ||
|
||
const result = await deleteListener(projectId, region, listenerId); | ||
|
||
expect(v6.delete).toHaveBeenCalledWith( | ||
`/cloud/project/${projectId}/region/${region}/loadbalancing/listener/${listenerId}`, | ||
); | ||
expect(result).toEqual(mockResponse); | ||
}); | ||
}); | ||
|
||
describe('getListener', () => { | ||
it('should get a listener and return data', async () => { | ||
const mockListener = { id: listenerId, name: 'test-listener' }; | ||
vi.mocked(v6.get).mockResolvedValueOnce({ data: mockListener }); | ||
|
||
const result = await getListener(projectId, region, listenerId); | ||
|
||
expect(v6.get).toHaveBeenCalledWith( | ||
`/cloud/project/${projectId}/region/${region}/loadbalancing/listener/${listenerId}`, | ||
); | ||
expect(result).toEqual(mockListener); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.