Skip to content

Commit

Permalink
[cascading] from release/11.5 to main (#2649)
Browse files Browse the repository at this point in the history
<!--
{"currentBranch":"release/11.5","targetBranch":"main","bypassReviewers":false,"isConflicting":false}
-->

## Cascading from release/11.5 to main

---

:heavy_exclamation_mark: The pull request is conflicting with the target
branch.
You can fix the issue locally with the following commands:

<details open>
  <summary>Using <b>gh CLI</b></summary>

  ```shell
  gh pr checkout 2649
  git pull --ff origin main
  ```

  and update this Pull Request with

  ```shell
  gh pr push 2649
  ```
</details>

<details>
  <summary>Using <b>git</b> only</summary>

  ```shell
  git fetch origin
  git checkout origin/cascading/11.5.0-main
  git pull --ff origin main
  ```

  and update this Pull Request with

  ```shell
  git push origin HEAD:cascading/11.5.0-main
  ```
</details>

---

<small>This Pull Request has been generated with :heart: by the
[Otter](https://github.com/AmadeusITGroup/otter) cascading tool.</small>
  • Loading branch information
kpanot authored Jan 6, 2025
2 parents 48e6670 + 664173b commit cda4545
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 56 deletions.
14 changes: 14 additions & 0 deletions packages/@o3r/core/src/utils/deep-fill/deep-fill.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ describe('Deep fill function', () => {
expect(deepFill(base, source)).toEqual(base);
});

it('should support "null" value in source', () => {
const base = { selection: { field: 'test-field' }, a: 'string' };
const source = { selection: null } as any;

expect(deepFill(base, source)).toEqual({ selection: null, a: 'string' });
});

it('should support "null" value in base', () => {
const base = { selection: null, a: 'string' } as any;
const source = { selection: { field: 'test-field' } };

expect(deepFill(base, source)).toEqual({ selection: { field: 'test-field' }, a: 'string' });
});

it('should keep properties from base not present in the source', () => {
const base = Object.freeze({ a: 1, b: '2', c: true });
const source = Object.freeze({ c: false, a: 3 });
Expand Down
6 changes: 4 additions & 2 deletions packages/@o3r/core/src/utils/deep-fill/deep-fill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@ export function deepFill<T extends { [x: string]: any }>(base: T, source?: { [x:
}
const newObj = { ...base };
for (const key in base) {
if (key in source && typeof base[key] === typeof source[key]) {
if (source[key] === null) {
newObj[key] = immutablePrimitive(null, additionalMappers);
} else if (key in source && typeof base[key] === typeof source[key]) {
const keyOfSource = source[key];
newObj[key] = typeof keyOfSource === 'undefined' ? immutablePrimitive(base[key], additionalMappers) : deepFill(base[key], source[key], additionalMappers);
newObj[key] = typeof keyOfSource === 'undefined' ? immutablePrimitive(base[key], additionalMappers) : deepFill(base[key], keyOfSource, additionalMappers);
} else {
newObj[key] = immutablePrimitive(base[key], additionalMappers);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/@o3r/design/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
"tslib": "^2.6.2"
},
"peerDependencies": {
"@angular-devkit/architect": "^0.1802.0",
"@angular-devkit/schematics": "^18.2.0",
"@angular-devkit/architect": "~0.1802.0 || >=0.1900.0",
"@angular-devkit/schematics": "^18.2.0 || >=19.0.0",
"@o3r/core": "workspace:^",
"@o3r/schematics": "workspace:^",
"@o3r/styling": "workspace:^",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable id-denylist -- `any` is a conditional keyword enforced by the rule interface */
import {
BehaviorSubject,
firstValueFrom,
of,
} from 'rxjs';
import {
Expand All @@ -13,7 +14,6 @@ import {
RulesetExecutor,
} from '../ruleset-executor';
import {
ActionBlock,
Ruleset,
} from '../structure';
import {
Expand Down Expand Up @@ -154,56 +154,28 @@ describe('Filter rulesets event operator', () => {

const rulesetsMapSubject$ = new BehaviorSubject<Record<string, RulesetExecutor>>(firstValue);

// eslint-disable-next-line jest/no-done-callback -- eventually rewrite the test
test('should consider only first ruleset', (done) => {
rulesetsMapSubject$.pipe(
filterRulesetsEventStream(['ruleset1'])
).subscribe((data) => {
expect(data.length).toBe(2);
done();
});
test('should consider only first ruleset', async () => {
const data = await firstValueFrom(rulesetsMapSubject$.pipe(filterRulesetsEventStream(['ruleset1'])));
expect(data.length).toBe(2);
});

// eslint-disable-next-line jest/no-done-callback -- eventually rewrite the test
test('should consider only second ruleset', (done) => {
rulesetsMapSubject$.pipe(
filterRulesetsEventStream(['ruleset2'])
).subscribe((data) => {
expect(data.length).toBe(1);
done();
});
test('should consider only second ruleset', async () => {
const data = await firstValueFrom(rulesetsMapSubject$.pipe(filterRulesetsEventStream(['ruleset2'])));
expect(data.length).toBe(1);
});

// eslint-disable-next-line jest/no-done-callback -- eventually rewrite the test
test('should consider all rulesets by not passing any filter', (done) => {
rulesetsMapSubject$.pipe(
filterRulesetsEventStream()
).subscribe((data) => {
expect(data.length).toBe(3);
done();
});
test('should consider all rulesets by not passing any filter', async () => {
const data = await firstValueFrom(rulesetsMapSubject$.pipe(filterRulesetsEventStream()));
expect(data.length).toBe(3);
});

// eslint-disable-next-line jest/no-done-callback -- eventually rewrite the test
test('should consider all rulesets ids passed', (done) => {
rulesetsMapSubject$.pipe(
filterRulesetsEventStream(['ruleset1', 'ruleset2'])
).subscribe((data) => {
expect(data.length).toBe(3);
done();
});
test('should consider all rulesets ids passed', async () => {
const data = await firstValueFrom(rulesetsMapSubject$.pipe(filterRulesetsEventStream(['ruleset1', 'ruleset2'])));
expect(data.length).toBe(3);
});

test('should not emit if ruleset id does not match any registered ruleset', async () => {
let emittedActions: ActionBlock[] | undefined;

rulesetsMapSubject$.pipe(
filterRulesetsEventStream(['ruleset3'])
).subscribe((data) => {
emittedActions = data;
});

await jest.advanceTimersByTimeAsync(500);
expect(emittedActions).toBe(undefined);
test('should emit an empty array when no rulesets remain active', async () => {
const data = await firstValueFrom(rulesetsMapSubject$.pipe(filterRulesetsEventStream(['ruleset3'])));
expect(data.length).toBe(0);
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
combineLatest,
Observable,
of,
} from 'rxjs';
import {
map,
Expand All @@ -23,11 +24,13 @@ export function filterRulesetsEventStream(restrictiveRuleSets?: string[]) {
? Object.values(rulesets).filter((ruleSet) => restrictiveRuleSets.includes(ruleSet.id))
: Object.values(rulesets);

return combineLatest(activeRulesets.map((ruleset) => ruleset.rulesResultsSubject$)).pipe(
map((item) => item.reduce((acc, currentValue) => {
acc.push(...currentValue);
return acc;
}, [])));
return activeRulesets?.length > 0
? combineLatest(activeRulesets.map((ruleset) => ruleset.rulesResultsSubject$)).pipe(
map((item) => item.reduce((acc, currentValue) => {
acc.push(...currentValue);
return acc;
}, [])))
: of([]);
}),
shareReplay(1)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ describe('Rules engine service', () => {
next: (value) => nextFn(value)
});
// should output no actions as all rulesets are on demand
expect(nextFn).not.toHaveBeenCalled();
expect(nextFn).toHaveBeenCalledWith([]);
sub.unsubscribe();

// activate ruleset 1 via his own linked component
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8544,8 +8544,8 @@ __metadata:
typescript-eslint: "npm:~8.19.0"
zone.js: "npm:~0.14.2"
peerDependencies:
"@angular-devkit/architect": ^0.1802.0
"@angular-devkit/schematics": ^18.2.0
"@angular-devkit/architect": ~0.1802.0 || >=0.1900.0
"@angular-devkit/schematics": ^18.2.0 || >=19.0.0
"@o3r/core": "workspace:^"
"@o3r/schematics": "workspace:^"
"@o3r/styling": "workspace:^"
Expand Down

0 comments on commit cda4545

Please sign in to comment.