Skip to content

Commit 17a844f

Browse files
committed
Update package.json to modify script paths and adjust TypeScript configuration
1 parent b9e9c2c commit 17a844f

File tree

5 files changed

+433
-4
lines changed

5 files changed

+433
-4
lines changed

package.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
"scripts": {
99
"prebuild": "cpr README.md dist/README.md && cpr LICENSE dist/LICENSE && cpr package.json dist/package.json",
1010
"build": "nest build",
11-
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
11+
"format": "prettier --write \"src/**/*.ts\" \"tests/**/*.ts\"",
1212
"start": "NODE_ENV=production nest start",
1313
"start:dev": "nest start --watch",
1414
"start:debug": "nest start --debug 0.0.0.0 --watch",
1515
"start:prod": "NODE_ENV=production node dist/main",
16-
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\"",
17-
"lint:fix": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
16+
"lint": "eslint \"{src,apps,libs,test,tests}/**/*.ts\"",
17+
"lint:fix": "eslint \"{src,apps,libs,test,tests}/**/*.ts\" --fix",
1818
"test": "jest",
1919
"test:watch": "jest --watch",
2020
"test:cov": "jest --coverage",
@@ -71,7 +71,11 @@
7171
"json",
7272
"ts"
7373
],
74-
"rootDir": "src",
74+
"rootDir": ".",
75+
"moduleNameMapper": {
76+
"^~/(.*)$": "<rootDir>/src/$1",
77+
"^@/(.*)$": "<rootDir>/$1"
78+
},
7579
"testRegex": ".*\\.spec\\.ts$",
7680
"transform": {
7781
"^.+\\.(t|j)s$": "ts-jest"
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { LogLevel } from '@nestjs/common';
2+
import { getLogLevel } from '~/_common/functions/get-log-level';
3+
4+
describe('getLogLevel', () => {
5+
it('par defaut retourne les niveaux de info', () => {
6+
expect(getLogLevel()).toEqual(['error', 'fatal', 'warn', 'log'] as LogLevel[]);
7+
});
8+
9+
it('mappe "error"', () => {
10+
expect(getLogLevel('error')).toEqual(['error', 'fatal'] as LogLevel[]);
11+
});
12+
13+
it('mappe "warn"', () => {
14+
expect(getLogLevel('warn')).toEqual(['error', 'fatal', 'warn'] as LogLevel[]);
15+
});
16+
17+
it('mappe "debug"', () => {
18+
expect(getLogLevel('debug')).toEqual(['error', 'fatal', 'warn', 'log', 'debug'] as LogLevel[]);
19+
});
20+
21+
it('mappe "verbose"', () => {
22+
expect(getLogLevel('verbose')).toEqual(['error', 'fatal', 'warn', 'log', 'debug', 'verbose'] as LogLevel[]);
23+
});
24+
25+
it('unknown => info par defaut', () => {
26+
expect(getLogLevel('unknown')).toEqual(getLogLevel('info'));
27+
});
28+
});
29+
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import { BackendCodesEnumError } from '~/backend-runner/_interfaces/backend-codes.enum';
2+
import { CatchAllExecutor } from '~/backend-runner/_executors/catch-all.executor';
3+
4+
describe('CatchAllExecutor helpers', () => {
5+
const executor = new CatchAllExecutor({} as any);
6+
7+
describe('extractLastJsonImproved', () => {
8+
it('retourne une erreur "No output" si stdout est vide', () => {
9+
const res = (executor as any).extractLastJsonImproved('');
10+
expect(res).toEqual({
11+
status: BackendCodesEnumError.INVALID_JSON_RESPONSE,
12+
message: 'No output',
13+
});
14+
});
15+
16+
it('retourne une erreur "No JSON output" s il n y a aucun JSON valide', () => {
17+
const res = (executor as any).extractLastJsonImproved('hello world');
18+
expect(res).toEqual({
19+
status: BackendCodesEnumError.INVALID_JSON_RESPONSE,
20+
message: 'No JSON output',
21+
});
22+
});
23+
24+
it('retourne le dernier JSON extrait de stdout', () => {
25+
const res = (executor as any).extractLastJsonImproved('prefix {"a":1} middle {"b":2}');
26+
expect(res).toEqual({ b: 2 });
27+
});
28+
29+
it('ignore les accolades dans les strings', () => {
30+
const res = (executor as any).extractLastJsonImproved('{"a":"{not json}", "b":1}');
31+
expect(res).toEqual({ a: '{not json}', b: 1 });
32+
});
33+
});
34+
35+
describe('validationRecursive', () => {
36+
it('produit un mapping des contraintes recursif (en profondeur 1)', () => {
37+
const error = {
38+
property: 'root',
39+
constraints: { isDefined: 'Root required' },
40+
children: [
41+
{
42+
property: 'child',
43+
constraints: { isString: 'Child must be a string' },
44+
children: [],
45+
},
46+
],
47+
} as any;
48+
49+
const validations = (executor as any).validationRecursive(error);
50+
expect(validations).toEqual({
51+
root: 'Root required',
52+
'root.child': 'Child must be a string',
53+
});
54+
});
55+
56+
it('produit un mapping des contraintes recursif (en profondeur 2)', () => {
57+
const error = {
58+
property: 'root',
59+
constraints: { isDefined: 'Root required' },
60+
children: [
61+
{
62+
property: 'child',
63+
constraints: { isString: 'Child must be a string' },
64+
children: [
65+
{
66+
property: 'grand',
67+
constraints: { isNumber: 'Grand must be a number' },
68+
children: [],
69+
},
70+
],
71+
},
72+
],
73+
} as any;
74+
75+
const validations = (executor as any).validationRecursive(error);
76+
expect(validations).toEqual({
77+
root: 'Root required',
78+
'root.child': 'Child must be a string',
79+
'root.child.child': 'Child must be a string',
80+
'root.child.child.grand': 'Grand must be a number',
81+
});
82+
});
83+
});
84+
});
85+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { ValidationError } from 'class-validator';
2+
import { IsActionConstraintValidator } from '~/backend-runner/_validators/is-action-constraint.validator';
3+
import { BackendConfigActionDto } from '~/backend-runner/_dto/backend-config-v1.dto';
4+
import { ActionType } from '~/backend-runner/_enum/action-type.enum';
5+
import { OnErrorType } from '~/backend-runner/_enum/on-error-type.enum';
6+
7+
describe('IsActionConstraintValidator', () => {
8+
const validator = new IsActionConstraintValidator();
9+
10+
it("retourne true pour une structure d'actions valide", async () => {
11+
const dto = new BackendConfigActionDto();
12+
dto.script = 'echo hello';
13+
dto.onError = OnErrorType.STOP;
14+
15+
await expect(
16+
validator.validate({
17+
[ActionType.LIST_BACKENDS]: dto,
18+
} as any),
19+
).resolves.toBe(true);
20+
});
21+
22+
it("retourne false si une cle n'est pas une ActionType valide", async () => {
23+
const dto = new BackendConfigActionDto();
24+
dto.script = 'echo hello';
25+
26+
await expect(
27+
validator.validate({
28+
NOT_A_REAL_ACTION: dto,
29+
} as any),
30+
).resolves.toBe(false);
31+
});
32+
33+
it('rejette si le DTO BackendConfigActionDto est invalide', async () => {
34+
const dto = new BackendConfigActionDto();
35+
// Script invalide => @IsString() + @IsNotEmpty()
36+
dto.script = '';
37+
38+
await expect(
39+
validator.validate({
40+
[ActionType.LIST_BACKENDS]: dto,
41+
} as any),
42+
).rejects.toEqual(expect.any(Array<ValidationError>));
43+
});
44+
});
45+

0 commit comments

Comments
 (0)