Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(pci-load-balancer): add unit tests #13666

Merged
merged 2 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

5 changes: 4 additions & 1 deletion packages/manager/apps/pci-load-balancer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
"start": "lerna exec --stream --scope='@ovh-ux/manager-pci-load-balancer-app' --include-dependencies -- npm run build --if-present",
"start:dev": "lerna exec --stream --scope='@ovh-ux/manager-pci-load-balancer-app' --include-dependencies -- npm run dev --if-present",
"start:watch": "lerna exec --stream --parallel --scope='@ovh-ux/manager-pci-load-balancer-app' --include-dependencies -- npm run dev:watch --if-present",
"test": "vitest run"
"test": "vitest run",
"test:coverage": "vitest run --coverage",
"test:watch": "vitest",
"test:watch:coverage": "vitest --coverage"
},
"dependencies": {
"@ovh-ux/manager-config": "*",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"octavia_load_balancer_pools_detail_overview_edit_name_title": "Namen ändern",
"octavia_load_balancer_pools_detail_overview_edit_name_label": "Name",
"octavia_load_balancer_pools_detail_overview_edit_name_cancel": "Abbrechen",
"octavia_load_balancer_pools_detail_overview_edit_name_confirm": "Ändern"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"octavia_load_balancer_pools_detail_overview_edit_name_title": "Change the name",
"octavia_load_balancer_pools_detail_overview_edit_name_label": "Name",
"octavia_load_balancer_pools_detail_overview_edit_name_cancel": "Cancel",
"octavia_load_balancer_pools_detail_overview_edit_name_confirm": "Edit"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"octavia_load_balancer_pools_detail_overview_edit_name_title": "Cambiar el nombre",
"octavia_load_balancer_pools_detail_overview_edit_name_label": "Nombre",
"octavia_load_balancer_pools_detail_overview_edit_name_cancel": "Cancelar",
"octavia_load_balancer_pools_detail_overview_edit_name_confirm": "Editar"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"octavia_load_balancer_pools_detail_overview_edit_name_title": "Modifier le nom",
"octavia_load_balancer_pools_detail_overview_edit_name_label": "Nom",
"octavia_load_balancer_pools_detail_overview_edit_name_cancel": "Annuler",
"octavia_load_balancer_pools_detail_overview_edit_name_confirm": "Modifier"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"octavia_load_balancer_pools_detail_overview_edit_name_title": "Modifier le nom",
"octavia_load_balancer_pools_detail_overview_edit_name_label": "Nom",
"octavia_load_balancer_pools_detail_overview_edit_name_cancel": "Annuler",
"octavia_load_balancer_pools_detail_overview_edit_name_confirm": "Modifier"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"octavia_load_balancer_pools_detail_overview_edit_name_title": "Modifica il nome",
"octavia_load_balancer_pools_detail_overview_edit_name_label": "Nome",
"octavia_load_balancer_pools_detail_overview_edit_name_cancel": "Annullare",
"octavia_load_balancer_pools_detail_overview_edit_name_confirm": "Modificare"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"octavia_load_balancer_pools_detail_overview_edit_name_title": "Zmień nazwę",
"octavia_load_balancer_pools_detail_overview_edit_name_label": "Nazwa",
"octavia_load_balancer_pools_detail_overview_edit_name_cancel": "Anuluj",
"octavia_load_balancer_pools_detail_overview_edit_name_confirm": "Zmień"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"octavia_load_balancer_pools_detail_overview_edit_name_title": "Alterar o nome",
"octavia_load_balancer_pools_detail_overview_edit_name_label": "Nome",
"octavia_load_balancer_pools_detail_overview_edit_name_cancel": "Anular",
"octavia_load_balancer_pools_detail_overview_edit_name_confirm": "Alterar"
}
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',
);
});
});
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,
);
});
});
Loading
Loading