Skip to content

Commit

Permalink
build(dedicated): add jest unit tests config
Browse files Browse the repository at this point in the history
resolves: MANAGER-16790

Signed-off-by: David Arsène <[email protected]>
  • Loading branch information
darsene committed Jan 31, 2025
1 parent 755b1fe commit 269c6ea
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ packages/manager/apps/**/dev.proxy.config.mjs
playwright-helpers/config.ts
test-results
e2e-dist
coverage
3 changes: 3 additions & 0 deletions packages/manager/apps/dedicated/babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["@babel/preset-env"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const mock = jest.fn();
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import { VCD_MIGRATION_STATUS } from '../../app/components/dedicated-cloud/dedicatedCloud.constant';
import '../../app/components/dedicated-cloud/dedicatedCloud.service';

describe('DedicatedCloud service test suites', () => {
beforeEach(() => {
angular.mock.module('ovhManagerPccService');

// mocks for dependencies
angular.mock.module(($provide) => {
$provide.value('iceberg', {});
$provide.value('OvhApiDedicatedCloud', {});
$provide.value('OvhHttp', {});
$provide.value('Poller', {});
$provide.value('Poll', {});
$provide.value('coreConfig', {});
});
});

let DedicatedCloud;
let $httpBackend;

beforeEach(() => {
angular.mock.inject([
'DedicatedCloud',
'$httpBackend',
(_DedicatedCloud_, _$httpBackend_) => {
DedicatedCloud = _DedicatedCloud_;
$httpBackend = _$httpBackend_;
},
]);
});

const serviceName = 'serviceName';
it.each([
{
case: 'Migration not allowed',
toMigrateTags: [],
migrationTags: [],
isDone: false,
isAllowed: false,
isToMigrate: false,
},
{
case: 'Migration allowed and done',
toMigrateTags: ['tag1'],
migrationTags: ['tag2'],
isDone: true,
isAllowed: true,
isToMigrate: false,
},
{
case: 'Migration allowed but not done',
toMigrateTags: ['tag1'],
migrationTags: [],
isDone: false,
isAllowed: true,
isToMigrate: true,
},
])(
'should compute PCC migration state for $case',
({ toMigrateTags, migrationTags, isAllowed, isDone, isToMigrate }) => {
$httpBackend
.expectGET(
'/services?resourceName=serviceName%2Foption%2Ftovcdmigration',
)
.respond(200, toMigrateTags);
$httpBackend
.expectGET(
'/services?resourceName=serviceName%2Foption%2Ftovcdmigration%2Fmigration',
)
.respond(200, migrationTags);

const promise = DedicatedCloud.getPCCMigrationState(serviceName);

promise.then((pccState) => {
expect(pccState.isDone).toBe(isDone);
expect(pccState.isAllowed).toBe(isAllowed);
expect(pccState.isToMigrate).toBe(isToMigrate);
});
$httpBackend.flush();
},
);

it('should compute PCC migration state when an error occurs', () => {
$httpBackend
.expectGET('/services?resourceName=serviceName%2Foption%2Ftovcdmigration')
.respond(404);
$httpBackend
.expectGET(
'/services?resourceName=serviceName%2Foption%2Ftovcdmigration%2Fmigration',
)
.respond([]);

const promise = DedicatedCloud.getPCCMigrationState(serviceName);

promise.then((pccState) => {
expect(pccState.isDone).toBe(false);
expect(pccState.isAllowed).toBe(false);
expect(pccState.isToMigrate).toBe(false);
});
$httpBackend.flush();
});

it.each([
{
state: VCD_MIGRATION_STATUS.UNKNOWN,
value: undefined,
isEnabling: false,
isEnabled: false,
hasMigration: false,
},
{
state: VCD_MIGRATION_STATUS.ENABLING,
value: undefined,
isEnabling: true,
isEnabled: false,
hasMigration: true,
},
{
state: VCD_MIGRATION_STATUS.ENABLED,
value: 'vcd name',
isEnabling: false,
isEnabled: true,
hasMigration: true,
},
])(
'should compute VCD migration state for status $state',
({ value, state, isEnabling, isEnabled, hasMigration }) => {
$httpBackend
.expectGET('/dedicatedCloud/serviceName/tag/vcdMigration')
.respond({ state, value });

const promise = DedicatedCloud.getVCDMigrationState(serviceName);

promise.then((vcdState) => {
expect(vcdState.vcdName).toBe(value);
expect(vcdState.isEnabling).toBe(isEnabling);
expect(vcdState.isEnabled).toBe(isEnabled);
expect(vcdState.hasMigration).toBe(hasMigration);
expect(vcdState.state).toBe(state);
});
$httpBackend.flush();
},
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
process(src) {
return { code: `module.exports = ${JSON.stringify(src)};` };
},
};
21 changes: 21 additions & 0 deletions packages/manager/apps/dedicated/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
globals: { mocha: true },
clearMocks: true,
testEnvironment: 'jsdom',
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
moduleFileExtensions: ['js', 'json', 'html', 'node'],
transformIgnorePatterns: ['node_modules/(?!lodash-es|@ovhcloud|@stencil)'],
testMatch: ['**/__tests__/**/*.spec.js'],
transform: {
'\\.html$': '<rootDir>/client/__tests__/jest-html.loader.js',
'^.+\\.js$': 'babel-jest',
},
moduleNameMapper: {
'\\.(css|scss|png|less)$': 'identity-obj-proxy',
'^@ovh-ux/manager-(.*)$': '<rootDir>/../../modules/$1/src/index.js',
'^@ovh-ux/ng-(.*)$': '<rootDir>/../../../components/ng-$1/src/index.js',
},
collectCoverage: false,
collectCoverageFrom: ['client/app/**/*.js', '!client/__tests__/**/*'],
coverageReporters: ['text-summary'],
};
4 changes: 4 additions & 0 deletions packages/manager/apps/dedicated/jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import 'angular';
import 'angular-mocks/angular-mocks';

global.moment = require('moment/min/moment.min.js');
7 changes: 6 additions & 1 deletion packages/manager/apps/dedicated/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
"dev:watch": "yarn run dev",
"start": "lerna exec --stream --scope='@ovh-ux/manager-dedicated' --include-dependencies -- npm run build --if-present",
"start:dev": "lerna exec --stream --scope='@ovh-ux/manager-dedicated' --include-dependencies -- npm run dev --if-present",
"start:watch": "lerna exec --stream --parallel --scope='@ovh-ux/manager-dedicated' --include-dependencies -- npm run dev:watch --if-present"
"start:watch": "lerna exec --stream --parallel --scope='@ovh-ux/manager-dedicated' --include-dependencies -- npm run dev:watch --if-present",
"test": "jest",
"test:coverage": "jest --coverage",
"test:watch": "jest --watch"
},
"dependencies": {
"@ovh-ux/manager-account-migration": "^1.5.2",
Expand Down Expand Up @@ -153,8 +156,10 @@
},
"devDependencies": {
"@ovh-ux/manager-webpack-config": "^7.0.4",
"angular-mocks": "^1.7.x",
"eslint-plugin-angular": "^4.0.1",
"glob": "^7.1.4",
"jest": "^29.5.12",
"webpack": "^5.76.2",
"webpack-merge": "^5.0.2"
},
Expand Down
42 changes: 12 additions & 30 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6027,6 +6027,13 @@
dependencies:
lodash "^4.17.15"

"@ovh-ux/ovh-at-internet@^0.18.1":
version "0.18.1"
resolved "https://registry.yarnpkg.com/@ovh-ux/ovh-at-internet/-/ovh-at-internet-0.18.1.tgz#a9d0d543a187031f61b699c57aaec0529f68a790"
integrity sha512-i0ZFNGrktTsgTw8G2Fx2pn/xkgmwhyJ7JsCx7+RkzEakcV2E3+u5yTfSNlLVyHTMiqKGyjMz330/dw221qVaDw==
dependencies:
lodash-es "^4.17.15"

"@ovh-ux/rollup-plugin-less-inject@^1.0.5":
version "1.0.6"
resolved "https://registry.yarnpkg.com/@ovh-ux/rollup-plugin-less-inject/-/rollup-plugin-less-inject-1.0.6.tgz#8db90747f02d2bb95e3a5563d1c5a77a25edd0ad"
Expand Down Expand Up @@ -11112,7 +11119,7 @@ angular-messages@^1.6.0, angular-messages@^1.7.5, angular-messages@^1.7.6:
resolved "https://registry.yarnpkg.com/angular-messages/-/angular-messages-1.8.3.tgz#56b26807bc81ea5218fe6337979ccb89f5de6825"
integrity sha512-f/ywtg32lqzX8FnXkBJOyn13lbCbo333/xy/5TTFcsH/gZdXoiuERj+dLTOs8xHCkOeFQhFx0VD0DgtMgSag7A==

angular-mocks@^1.7.5:
angular-mocks@^1.7.5, angular-mocks@^1.7.x:
version "1.8.3"
resolved "https://registry.yarnpkg.com/angular-mocks/-/angular-mocks-1.8.3.tgz#c0dd05e5c3fc014e07af6289b23f0e817d7a4724"
integrity sha512-vqsT6zwu80cZ8RY7qRQBZuy6Fq5X7/N5hkV9LzNT0c8b546rw4ErGK6muW1u2JnDKYa7+jJuaGM702bWir4HGw==
Expand Down Expand Up @@ -19551,7 +19558,7 @@ jest-worker@^29.7.0:
merge-stream "^2.0.0"
supports-color "^8.0.0"

[email protected]:
[email protected], jest@^29.5.12:
version "29.7.0"
resolved "https://registry.yarnpkg.com/jest/-/jest-29.7.0.tgz#994676fc24177f088f1c5e3737f5697204ff2613"
integrity sha512-NIy3oAFp9shda19hy4HK0HRTWKtPJmGdnvywu01nOqNC2vZg+Z+fvJDxpMQA88eb2I9EcafcdjYgsDthnYTvGw==
Expand Down Expand Up @@ -26092,16 +26099,7 @@ string-length@^4.0.1:
char-regex "^1.0.2"
strip-ansi "^6.0.0"

"string-width-cjs@npm:string-width@^4.2.0":
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3:
"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down Expand Up @@ -26215,14 +26213,7 @@ stringify-entities@^3.0.0:
character-entities-legacy "^1.0.0"
xtend "^4.0.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

[email protected], strip-ansi@^6.0.0, strip-ansi@^6.0.1:
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", [email protected], strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand Down Expand Up @@ -28984,7 +28975,7 @@ wordwrap@^1.0.0:
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb"
integrity sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q==

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand All @@ -29002,15 +28993,6 @@ wrap-ansi@^6.0.1, wrap-ansi@^6.2.0:
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^8.0.1, wrap-ansi@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"
Expand Down

0 comments on commit 269c6ea

Please sign in to comment.