-
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
51 changed files
with
3,946 additions
and
285 deletions.
There are no files selected for viewing
186 changes: 0 additions & 186 deletions
186
...r/apps/pci-kubernetes/src/pages/detail/nodepools/new/__snapshots__/New.page.spec.tsx.snap
This file was deleted.
Oops, something went wrong.
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
47 changes: 47 additions & 0 deletions
47
packages/manager/apps/pci-load-balancer/src/api/data/flavors.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,47 @@ | ||
import { describe, it, expect, vi } from 'vitest'; | ||
import { v6 } from '@ovh-ux/manager-core-api'; | ||
import { TAddon } from '@/pages/create/store'; | ||
import { getFlavor } from './flavors'; | ||
import { TFlavor } from '@/api/data/load-balancer'; | ||
|
||
describe('getFlavor', () => { | ||
const projectId = 'test-project'; | ||
const regionName = 'test-region'; | ||
const addon = ({ | ||
technicalName: 'test-flavor', | ||
invoiceName: 'invoiceName', | ||
} as unknown) as TAddon; | ||
|
||
it('should return the correct flavor', async () => { | ||
const mockFlavors: TFlavor[] = [ | ||
{ name: 'test-flavor', region: 'region1', id: 'id1' }, | ||
{ name: 'another-flavor', region: 'region2', id: 'id2' }, | ||
]; | ||
|
||
vi.mocked(v6.get).mockResolvedValue({ data: mockFlavors }); | ||
|
||
const result = await getFlavor(projectId, regionName, addon); | ||
|
||
expect(result).toEqual(mockFlavors[0]); | ||
}); | ||
|
||
it('should return undefined if the flavor is not found', async () => { | ||
const mockFlavors: TFlavor[] = [ | ||
{ name: 'another-flavor', region: 'value2', id: 'id2' }, | ||
]; | ||
|
||
vi.mocked(v6.get).mockResolvedValue({ data: mockFlavors }); | ||
|
||
const result = await getFlavor(projectId, regionName, addon); | ||
|
||
expect(result).toBeUndefined(); | ||
}); | ||
|
||
it('should handle API errors gracefully', async () => { | ||
vi.mocked(v6.get).mockRejectedValue(new Error('API Error')); | ||
|
||
await expect(getFlavor(projectId, regionName, addon)).rejects.toThrow( | ||
'API Error', | ||
); | ||
}); | ||
}); |
46 changes: 46 additions & 0 deletions
46
packages/manager/apps/pci-load-balancer/src/api/data/floating-ips.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,46 @@ | ||
import { describe, it, expect, vi } from 'vitest'; | ||
import { v6 } from '@ovh-ux/manager-core-api'; | ||
import { getFloatingIps, TFloatingIp } from './floating-ips'; | ||
|
||
describe('getFloatingIps', () => { | ||
const projectId = 'test-project-id'; | ||
const region = 'test-region'; | ||
const mockFloatingIps: TFloatingIp[] = [ | ||
{ | ||
associatedEntity: 'entity1', | ||
id: 'id1', | ||
ip: '192.168.1.1', | ||
networkId: 'network1', | ||
status: 'active', | ||
type: 'public', | ||
}, | ||
{ | ||
associatedEntity: 'entity2', | ||
id: 'id2', | ||
ip: '192.168.1.2', | ||
networkId: 'network2', | ||
status: 'inactive', | ||
type: 'private', | ||
}, | ||
]; | ||
|
||
it('should fetch floating IPs for a given project and region', async () => { | ||
vi.mocked(v6.get).mockResolvedValue({ data: mockFloatingIps }); | ||
|
||
const result = await getFloatingIps(projectId, region); | ||
|
||
expect(v6.get).toHaveBeenCalledWith( | ||
`/cloud/project/${projectId}/region/${region}/floatingip`, | ||
); | ||
expect(result).toEqual(mockFloatingIps); | ||
}); | ||
|
||
it('should handle errors when fetching floating IPs', async () => { | ||
const errorMessage = 'Network Error'; | ||
vi.mocked(v6.get).mockRejectedValue(new Error(errorMessage)); | ||
|
||
await expect(getFloatingIps(projectId, region)).rejects.toThrow( | ||
errorMessage, | ||
); | ||
}); | ||
}); |
62 changes: 62 additions & 0 deletions
62
packages/manager/apps/pci-load-balancer/src/api/data/gateways.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,62 @@ | ||
import { describe, it, expect, vi } from 'vitest'; | ||
import { v6 } from '@ovh-ux/manager-core-api'; | ||
import { getSubnetGateways, TSubnetGateway } from './gateways'; | ||
|
||
describe('getSubnetGateways', () => { | ||
const projectId = 'test-project'; | ||
const regionName = 'test-region'; | ||
const subnetId = 'test-subnet'; | ||
|
||
const mockGateways: TSubnetGateway[] = [ | ||
{ | ||
externalInformation: { | ||
ips: [{ ip: '192.168.1.1', subnetId: 'subnet-1' }], | ||
networkId: 'network-1', | ||
}, | ||
id: 'gateway-1', | ||
interfaces: [ | ||
{ | ||
id: 'interface-1', | ||
ip: '192.168.1.2', | ||
networkId: 'network-1', | ||
subnetId: 'subnet-1', | ||
}, | ||
], | ||
model: 'model-1', | ||
name: 'gateway-name-1', | ||
region: 'region-1', | ||
status: 'ACTIVE', | ||
}, | ||
]; | ||
|
||
it('should fetch subnet gateways and return data', async () => { | ||
vi.mocked(v6.get).mockResolvedValueOnce({ data: mockGateways }); | ||
|
||
const result = await getSubnetGateways(projectId, regionName, subnetId); | ||
|
||
expect(v6.get).toHaveBeenCalledWith( | ||
`/cloud/project/${projectId}/region/${regionName}/gateway?subnetId=${subnetId}`, | ||
); | ||
expect(result).toEqual(mockGateways); | ||
}); | ||
|
||
it('should handle empty response', async () => { | ||
vi.mocked(v6.get).mockResolvedValueOnce({ data: [] }); | ||
|
||
const result = await getSubnetGateways(projectId, regionName, subnetId); | ||
|
||
expect(v6.get).toHaveBeenCalledWith( | ||
`/cloud/project/${projectId}/region/${regionName}/gateway?subnetId=${subnetId}`, | ||
); | ||
expect(result).toEqual([]); | ||
}); | ||
|
||
it('should handle API errors', async () => { | ||
const errorMessage = 'API Error'; | ||
vi.mocked(v6.get).mockRejectedValueOnce(new Error(errorMessage)); | ||
|
||
await expect( | ||
getSubnetGateways(projectId, regionName, subnetId), | ||
).rejects.toThrow(errorMessage); | ||
}); | ||
}); |
Oops, something went wrong.