@adaas/a-utils 0.1.24 → 0.1.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adaas/a-utils",
3
- "version": "0.1.24",
3
+ "version": "0.1.25",
4
4
  "description": "A-Utils is a set of utilities that are used across the ADAAS ecosystem. This package is designed to be a collection of utilities that are used across the ADAAS ecosystem.",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./dist/index.cjs",
@@ -80,7 +80,7 @@
80
80
  "build": "tsup --config tsup.config.ts"
81
81
  },
82
82
  "dependencies": {
83
- "@adaas/a-concept": "^0.1.46"
83
+ "@adaas/a-concept": "^0.1.47"
84
84
  },
85
85
  "devDependencies": {
86
86
  "@types/chai": "^4.3.14",
@@ -612,6 +612,71 @@ describe('A-Command tests', () => {
612
612
  expect([A_Command_Status.COMPLETED, A_Command_Status.FAILED])
613
613
  .toContain(command.status);
614
614
  });
615
+
616
+ it('Should stop command execution in case of error', async () => {
617
+
618
+ class FailingProcessor extends A_Component {
619
+
620
+ @A_Feature.Extend({
621
+ name: A_CommandFeatures.onExecute
622
+ })
623
+ async step1(
624
+ @A_Inject(A_Caller) command: ErrorTestCommand
625
+ ) {
626
+ await new Promise(resolve => setTimeout(resolve, 500));
627
+
628
+ testExecutionLog.push('Step 1 executed');
629
+ }
630
+
631
+ @A_Feature.Extend({
632
+ name: A_CommandFeatures.onExecute
633
+ })
634
+ async step2(
635
+ @A_Inject(A_Caller) command: ErrorTestCommand
636
+ ) {
637
+ await new Promise(resolve => setTimeout(resolve, 500));
638
+ testExecutionLog.push('Step 2 executed');
639
+ throw new Error('Simulated error in step 2');
640
+ }
641
+
642
+ @A_Feature.Extend({
643
+ name: A_CommandFeatures.onExecute
644
+ })
645
+ async step3(
646
+ @A_Inject(A_Caller) command: ErrorTestCommand
647
+ ) {
648
+ testExecutionLog.push('Step 3 executed');
649
+ }
650
+ }
651
+
652
+ const container = new A_Container({
653
+ name: 'Error Stop Test Container',
654
+ components: [
655
+ FailingProcessor,
656
+ A_StateMachine
657
+ ],
658
+ entities: [ErrorTestCommand]
659
+ });
660
+
661
+ const concept = new A_Concept({
662
+ containers: [container]
663
+ });
664
+
665
+ await concept.load();
666
+
667
+ const command = new ErrorTestCommand({ shouldFail: true });
668
+ container.scope.register(command);
669
+
670
+ await command.execute();
671
+
672
+ expect(command.status).toBe(A_Command_Status.FAILED);
673
+ expect(command.error).toBeDefined();
674
+ expect(command.isProcessed).toBe(true);
675
+ expect(testExecutionLog).toEqual([
676
+ 'Step 1 executed',
677
+ 'Step 2 executed'
678
+ ]); // Step 3 should not be executed
679
+ });
615
680
  });
616
681
 
617
682
  // =============================================================================