-
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.
feat(common-api-module): create a common-api module
ref: MANAGER-15700 Signed-off-by: Nicolas Pierre-charles <[email protected]>
- Loading branch information
Nicolas Pierre-charles
committed
Nov 27, 2024
1 parent
969e267
commit c2e58de
Showing
49 changed files
with
1,858 additions
and
31 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
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
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
Empty file.
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 @@ | ||
export * from './src'; |
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 @@ | ||
{ | ||
"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" | ||
} | ||
} |
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,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
179
packages/manager/core/test-utils/src/auth/applications.mock.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,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; |
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,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, | ||
}, | ||
]; |
13 changes: 13 additions & 0 deletions
13
packages/manager/core/test-utils/src/auth/configurations.mock.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,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, | ||
}); |
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,4 @@ | ||
export * from './applications.mock'; | ||
export * from './auth.handler'; | ||
export * from './configurations.mock'; | ||
export * from './user.mock'; |
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,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; |
Oops, something went wrong.