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

feat(common-api-module): create a common-api module #14301

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .github/workflows/run-bdd-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
yarn exec turbo -- run build --filter="./packages/manager/core/*" --concurrency=5
yarn exec turbo -- run build --filter="./packages/manager-react-components" --concurrency=5
yarn exec turbo -- run build --filter="./packages/manager/modules/order" --concurrency=5
yarn exec turbo -- run build --filter="./packages/manager/modules/common-api" --concurrency=5
# This task is for running the jest tests outside microApps
- name: Run tests Jest
run: yarn test:jest
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"packages/manager/core/url-builder",
"packages/manager/core/utils",
"packages/manager/core/vite-config",
"packages/manager/core/test-utils",
"packages/manager/modules/*",
"packages/manager/tools/*",
"packages/manager-react-components"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ exports[`PlanStep > should render 1`] = `
class="flex flex-col md:flex-row"
>
<div
class="font-sans font-normal p-0 m-0 w-full md:w-5/6 leading-10 text-[1.25rem] text-[grey]"
class="font-sans font-normal p-0 m-0 w-full md:w-5/6 flex text-[grey]"
>
private_registry_create_choose_plan
<div
class="leading-10 text-[1.25rem]"
>
private_registry_create_choose_plan
</div>
</div>
</div>
</div>
Expand Down
Empty file.
1 change: 1 addition & 0 deletions packages/manager/core/test-utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './src';
47 changes: 47 additions & 0 deletions packages/manager/core/test-utils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "@ovh-ux/manager-core-test-utils",
"version": "0.1.0",
"private": true,
"description": "OVHcloud manager core test utils for vitest and jest",
"repository": {
"type": "git",
"url": "git+https://github.com/ovh/manager.git",
"directory": "packages/manager/core/test-utils"
},
"license": "BSD-3-Clause",
"author": "OVH SAS",
"sideEffects": false,
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./dist/types/index.d.ts",
"files": [
"dist"
],
"scripts": {
"build": "tsc",
"dev": "tsc",
"start:watch": "tsc -w"
},
"dependencies": {
"@ovh-ux/manager-core-api": "^0.9.0",
"@ovh-ux/manager-react-components": "^1.41.1",
"@ovh-ux/manager-react-shell-client": "^0.8.1",
"@ovhcloud/ods-common-core": "^17.2.2",
"@ovhcloud/ods-components": "^17.2.2",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.0.1",
"@testing-library/user-event": "^14.5.2",
"element-internals-polyfill": "^1.3.12",
"i18next": "^23.8.2"
},
"devDependencies": {
"msw": "2.1.7",
"typescript": "^5.1.6",
"vite": "^5.2.13",
"vitest": "^2.1.4"
},
"peerDependencies": {
"@tanstack/react-query": "5.x",
"react": "18.x"
}
}
32 changes: 32 additions & 0 deletions packages/manager/core/test-utils/setup-file-msw-ods17.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { beforeAll, afterAll } from 'vitest';
import { odsSetup } from '@ovhcloud/ods-common-core';
import { setupServer } from 'msw/node';
import { toMswHandlers } from './src/utils';
import { getAuthenticationMocks } from './src/auth';
import 'element-internals-polyfill';

odsSetup();

const server = setupServer(
...toMswHandlers([
...getAuthenticationMocks({ isAuthMocked: true, region: 'EU' }),
]),
);

beforeAll(() => {
server.listen({ onUnhandledRequest: 'warn' });

delete global.server;
global.__VERSION__ = null;
global.server = server;
});

afterAll(() => {
server.close();

delete global.__VERSION__;
});

afterEach(() => {
server.resetHandlers();
});
179 changes: 179 additions & 0 deletions packages/manager/core/test-utils/src/auth/applications.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
export const applications = {
cloud: {
universe: 'server',
url: 'https://www.ovh.com/manager/cloud/repsac/',
container: { isDefault: false },
publicURL: 'https://www.ovh.com/manager/cloud/repsac/',
},
dedicated: {
universe: 'server',
url: 'https://www.ovh.com/manager/dedicated/',
container: { isDefault: false, enabled: true, path: 'dedicated' },
publicURL: 'https://www.ovh.com/manager/#/dedicated',
},
hub: {
universe: 'hub',
url: 'https://www.ovh.com/manager/hub/',
container: { isDefault: true, enabled: true, path: 'hub' },
publicURL: 'https://www.ovh.com/manager/#/hub',
},
'public-cloud': {
universe: 'public-cloud',
url: 'https://www.ovh.com/manager/public-cloud/',
container: {
isDefault: false,
enabled: true,
path: 'public-cloud',
},
publicURL: 'https://www.ovh.com/manager/#/public-cloud',
},
telecom: {
universe: 'telecom',
url: 'https://www.ovhtelecom.fr/manager/telecom/',
container: { isDefault: false, enabled: true, path: 'telecom' },
publicURL: 'https://www.ovhtelecom.fr/manager/#/telecom',
},
web: {
universe: 'web',
url: 'https://www.ovh.com/manager/web/',
container: { isDefault: false, enabled: true, path: 'web' },
publicURL: 'https://www.ovh.com/manager/#/web',
},
sunrise: {
url: 'https://www.ovh.com/manager/sunrise/',
container: { isDefault: false },
publicURL: 'https://www.ovh.com/manager/sunrise/',
},
billing: {
universe: 'server',
url: 'https://www.ovh.com/manager/dedicated/#/billing',
container: { isDefault: false },
publicURL: 'https://www.ovh.com/manager/dedicated/#/billing',
},
user: {
universe: 'server',
url: 'https://www.ovh.com/manager/dedicated/',
container: { isDefault: false },
publicURL: 'https://www.ovh.com/manager/dedicated/',
},
exchange: {
universe: 'web',
url: 'https://www.ovh.com/manager/web/',
container: { isDefault: false },
publicURL: 'https://www.ovh.com/manager/web/',
},
sharepoint: {
universe: 'web',
url: 'https://www.ovh.com/manager/web/',
container: { isDefault: false },
publicURL: 'https://www.ovh.com/manager/web/',
},
office: {
universe: 'web',
url: 'https://www.ovh.com/manager/web/',
container: { isDefault: false },
publicURL: 'https://www.ovh.com/manager/web/',
},
telephony: {
universe: 'telecom',
url: 'https://www.ovhtelecom.fr/manager/telecom/',
container: { isDefault: false },
publicURL: 'https://www.ovhtelecom.fr/manager/telecom/',
},
'pack-xdsl': {
universe: 'telecom',
url: 'https://www.ovhtelecom.fr/manager/telecom/',
container: { isDefault: false },
publicURL: 'https://www.ovhtelecom.fr/manager/telecom/',
},
overthebox: {
universe: 'telecom',
url: 'https://www.ovhtelecom.fr/manager/telecom/',
container: { isDefault: false },
publicURL: 'https://www.ovhtelecom.fr/manager/telecom/',
},
freefax: {
universe: 'telecom',
url: 'https://www.ovhtelecom.fr/manager/telecom/',
container: { isDefault: false },
publicURL: 'https://www.ovhtelecom.fr/manager/telecom/',
},
sms: {
universe: 'telecom',
url: 'https://www.ovhtelecom.fr/manager/telecom/',
container: { isDefault: false },
publicURL: 'https://www.ovhtelecom.fr/manager/telecom/',
},
catalog: {
universe: 'hub',
url: 'https://www.ovh.com/manager/catalog',
container: { isDefault: false, enabled: true, path: 'catalog' },
publicURL: 'https://www.ovh.com/manager/#/catalog',
},
iam: {
universe: 'server',
url: 'https://www.ovh.com/manager/security',
container: { isDefault: false, enabled: true, path: 'iam' },
publicURL: 'https://www.ovh.com/manager/#/iam',
},
'carbon-calculator': {
universe: 'server',
url: 'https://www.ovh.com/manager/carbon-calculator/',
container: {
isDefault: false,
enabled: true,
path: 'carbon-calculator',
},
publicURL: 'https://www.ovh.com/manager/#/carbon-calculator',
},
'octavia-load-balancer': {
universe: 'public-cloud',
url: 'https://www.ovh.com/manager/octavia-load-balancer/',
container: {
isDefault: false,
enabled: true,
path: 'public-cloud',
hash: '/pci/projects/:projectId/octavia-load-balancer',
},
publicURL: 'https://www.ovh.com/manager/#/public-cloud',
},
'pci-vouchers': {
universe: 'public-cloud',
url: 'https://www.ovh.com/manager/pci-vouchers/',
container: {
isDefault: false,
enabled: true,
path: 'public-cloud',
hash: '/pci/projects/:projectId/vouchers',
},
publicURL: 'https://www.ovh.com/manager/#/public-cloud',
},
restricted: {
universe: 'server',
url: 'https://www.ovh.com/manager/restricted/',
container: { isDefault: false, path: 'restricted' },
publicURL: 'https://www.ovh.com/manager/restricted/',
},
'vrack-services': {
universe: 'server',
url: 'ttps://www.ovh.com/manager/vrack-services/',
container: {
isDefault: false,
path: 'dedicated',
hash: '/vrack-services',
},
publicURL: 'ttps://www.ovh.com/manager/vrack-services/',
},
};

export const applicationURLs = Object.entries(applications)
.map(([appName, app]) => ({ appName, url: app.publicURL }))
.reduce(
(result, { appName, url }) => ({
...result,
[appName]: url,
}),
{},
);

export default applications;
30 changes: 30 additions & 0 deletions packages/manager/core/test-utils/src/auth/auth.handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import applicationsResponse from './applications.mock';
import { getConfigurationResponse } from './configurations.mock';
import { Handler } from '../types';

export type GetAuthenticationMocks = {
isAuthMocked?: boolean;
region?: string;
};

export const getAuthenticationMocks = ({
isAuthMocked,
region,
}: GetAuthenticationMocks): Handler[] => [
{
url: '/applications',
response: () => applicationsResponse,
status: 200,
method: 'get',
api: 'aapi',
disabled: !isAuthMocked,
},
{
url: '/configuration',
response: () => getConfigurationResponse({ region }),
status: 200,
method: 'get',
api: 'aapi',
disabled: !isAuthMocked,
},
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import applications, { applicationURLs } from './applications.mock';
import user from './user.mock';

export const defaultRegion = 'EU';

export const getConfigurationResponse = ({ region = defaultRegion }): any => ({
region,
user,
applicationURLs,
universe: '',
message: null,
applications,
});
4 changes: 4 additions & 0 deletions packages/manager/core/test-utils/src/auth/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './applications.mock';
export * from './auth.handler';
export * from './configurations.mock';
export * from './user.mock';
53 changes: 53 additions & 0 deletions packages/manager/core/test-utils/src/auth/user.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
export const user = {
legalform: 'corporation',
italianSDI: '0000000',
currency: { code: 'EUR', symbol: '€' },
companyNationalIdentificationNumber: '00000000000000',
zip: '00000',
phoneCountry: 'FR',
nationalIdentificationNumber: null,
organisation: 'Not OVH',
spareEmail: '[email protected]',
name: 'vitest',
vat: null,
phone: '+33.000000000',
phoneType: 'mobile',
email: '[email protected]',
area: 'IN-WB',
corporationType: 'La communauté',
firstname: 'vitest',
fax: null,
nichandle: 'vitest-ovh',
ovhCompany: 'ovh',
city: 'Somewhere',
customerCode: '0000-0000-00',
language: 'fr_FR',
state: 'complete',
address: '2 Rue de la Comté',
birthCity: '',
sex: 'male',
country: 'Terre du milieu',
ovhSubsidiary: 'FR',
birthDay: '1900-05-01',
kycValidated: true,
complementaryAddress: null,
purposeOfPurchase: null,
supportLevel: { level: 'standard' },
certificates: [],
isTrusted: false,
auth: {
method: 'provider',
user: '[email protected]',
description: 'Gandalf le gris',
roles: ['UNPRIVILEGED'],
allowedRoutes: null,
account: 'lsgandalf-ovh',
identities: [
'urn:v1:eu:identity:user:lsgandalf-ovh/provider/[email protected]',
'urn:v1:eu:identity:group:lsgandalf-ovh/Domain Users',
],
},
enterprise: false,
};

export default user;
Loading
Loading