@adaas/a-concept 0.2.5 → 0.2.7

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.
@@ -591,22 +591,21 @@ describe('A-Feature tests', () => {
591
591
  ]
592
592
  });
593
593
 
594
- feature.process();
595
-
596
- await new Promise<void>(async (resolve) => {
597
- setTimeout(() => {
598
- feature.interrupt();
599
- }, 1000);
600
-
601
-
602
- setTimeout(() => {
603
- expect(feature.state).toBe(A_TYPES__FeatureState.INTERRUPTED);
604
- expect(executionOrder).toEqual(['feature1', 'feature2']);
605
-
606
- resolve();
607
-
608
- }, 3000);
609
- });
594
+ await Promise.all([
595
+ feature.process(),
596
+ new Promise<void>(async (resolve) => {
597
+ setTimeout(() => {
598
+ feature.interrupt();
599
+ resolve();
600
+ }, 800);
601
+ }),
602
+ new Promise<void>(async (resolve) => {
603
+ setTimeout(() => {
604
+ expect(feature.state).toBe(A_TYPES__FeatureState.INTERRUPTED);
605
+ resolve();
606
+ }, 1000);
607
+ })
608
+ ]);
610
609
 
611
610
  }, 5000);
612
611
  it('Should allow to use extension if only parent class provided', async () => {
@@ -644,7 +643,7 @@ describe('A-Feature tests', () => {
644
643
  await baseEntity.test();
645
644
 
646
645
  expect(executionResults).toEqual(['testMethod']);
647
-
646
+
648
647
  await myEntity.test();
649
648
 
650
649
  expect(executionResults).toEqual(['testMethod', 'testMethod']);
@@ -783,4 +782,256 @@ describe('A-Feature tests', () => {
783
782
  ]);
784
783
 
785
784
  })
785
+ it('Should execute Sync operations properly', async () => {
786
+
787
+ const resultChain: string[] = [];
788
+
789
+
790
+ class ChildComponent_A extends A_Component {
791
+ @A_Feature.Extend({
792
+ name: 'testFeature',
793
+ })
794
+ test1() {
795
+ resultChain.push('ChildComponent_A.test');
796
+ }
797
+ }
798
+
799
+ class ChildComponent_B extends A_Component {
800
+ @A_Feature.Extend({
801
+ name: 'testFeature',
802
+ })
803
+ test2() {
804
+ resultChain.push('ChildComponent_B.test');
805
+ }
806
+ }
807
+
808
+
809
+ const testScope = new A_Scope({ name: 'TestScope', components: [ChildComponent_A, ChildComponent_B] });
810
+
811
+ testScope.resolve(ChildComponent_A)!.call('testFeature');
812
+
813
+
814
+ expect(resultChain).toEqual([
815
+ 'ChildComponent_A.test',
816
+ 'ChildComponent_B.test'
817
+ ]);
818
+
819
+ })
820
+
821
+ it('Should execute Async operations properly', async () => {
822
+
823
+ const resultChain: string[] = [];
824
+
825
+
826
+ class ChildComponent_A extends A_Component {
827
+ @A_Feature.Extend({
828
+ name: 'testFeature',
829
+ })
830
+ async test1() {
831
+ resultChain.push('ChildComponent_A.test');
832
+
833
+ await new Promise<void>(async (resolve) => {
834
+ setTimeout(() => {
835
+ resolve();
836
+ }, 3000);
837
+ });
838
+ }
839
+ }
840
+
841
+ class ChildComponent_B extends A_Component {
842
+ @A_Feature.Extend({
843
+ name: 'testFeature',
844
+ })
845
+ async test2() {
846
+ resultChain.push('ChildComponent_B.test');
847
+ }
848
+ }
849
+
850
+ const testScope = new A_Scope({ name: 'TestScope', components: [ChildComponent_A, ChildComponent_B] });
851
+
852
+ await Promise.all([
853
+ new Promise<void>(async (resolve) => {
854
+ setTimeout(() => {
855
+ resultChain.push('feature3');
856
+
857
+ resolve();
858
+ }, 2000);
859
+ }),
860
+ testScope.resolve(ChildComponent_A)!.call('testFeature')
861
+ ]);
862
+
863
+ expect(resultChain).toEqual([
864
+ 'ChildComponent_A.test',
865
+ 'feature3',
866
+ 'ChildComponent_B.test'
867
+ ]);
868
+
869
+ })
870
+ it('Should throw a Sync error when executed sync', async () => {
871
+
872
+ const resultChain: string[] = [];
873
+
874
+
875
+ class ChildComponent_A extends A_Component {
876
+ @A_Feature.Extend({
877
+ name: 'testFeature',
878
+ })
879
+ test1() {
880
+ resultChain.push('ChildComponent_A.test');
881
+ throw new A_Error('Deliberate Sync Error in test1');
882
+ }
883
+ }
884
+
885
+ class ChildComponent_B extends A_Component {
886
+ @A_Feature.Extend({
887
+ name: 'testFeature',
888
+ })
889
+ test2() {
890
+ resultChain.push('ChildComponent_B.test');
891
+ }
892
+ }
893
+
894
+
895
+ const testScope = new A_Scope({ name: 'TestScope', components: [ChildComponent_A, ChildComponent_B] });
896
+
897
+ try {
898
+ testScope.resolve(ChildComponent_A)!.call('testFeature');
899
+ } catch (error) {
900
+ expect(error).toBeInstanceOf(A_Error);
901
+ expect((error as A_Error).originalError).toBeInstanceOf(A_Error)
902
+ expect((error as A_Error).originalError.message).toBe('Deliberate Sync Error in test1');
903
+ }
904
+
905
+ expect(resultChain).toEqual([
906
+ 'ChildComponent_A.test'
907
+ ]);
908
+ const feature = new A_Feature({
909
+ name: 'testFeature',
910
+ component: testScope.resolve(ChildComponent_A)!,
911
+ })
912
+
913
+ try {
914
+ feature.process();
915
+ } catch (error) {
916
+ expect(error).toBeInstanceOf(A_Error);
917
+ expect((error as A_Error).originalError).toBeInstanceOf(A_Error)
918
+ expect((error as A_Error).originalError.message).toBe('Deliberate Sync Error in test1');
919
+ }
920
+
921
+ expect(feature.state).toBe(A_TYPES__FeatureState.FAILED);
922
+
923
+ expect(resultChain).toEqual([
924
+ 'ChildComponent_A.test',
925
+ 'ChildComponent_A.test'
926
+ ]);
927
+ })
928
+ it('Should throw an Async error when executed async', async () => {
929
+
930
+ const resultChain: string[] = [];
931
+
932
+ class ChildComponent_A extends A_Component {
933
+ @A_Feature.Extend({
934
+ name: 'testFeature',
935
+ })
936
+ async test1() {
937
+ resultChain.push('ChildComponent_A.test');
938
+
939
+ await new Promise<void>(async (resolve, reject) => {
940
+ setTimeout(() => {
941
+ reject(new A_Error('Deliberate Async Error in test1'));
942
+ }, 2000);
943
+ });
944
+ }
945
+ }
946
+
947
+ class ChildComponent_B extends A_Component {
948
+ @A_Feature.Extend({
949
+ name: 'testFeature',
950
+ })
951
+ async test2() {
952
+ resultChain.push('ChildComponent_B.test');
953
+ }
954
+ }
955
+
956
+ const testScope = new A_Scope({ name: 'TestScope', components: [ChildComponent_A, ChildComponent_B] });
957
+ try {
958
+ await Promise.all([
959
+ new Promise<void>(async (resolve) => {
960
+ setTimeout(() => {
961
+ resultChain.push('feature3');
962
+
963
+ resolve();
964
+ }, 1000);
965
+ }),
966
+ testScope.resolve(ChildComponent_A)!.call('testFeature')
967
+ ]);
968
+
969
+ } catch (error) {
970
+ expect(error).toBeInstanceOf(A_Error);
971
+ expect((error as A_Error).originalError).toBeInstanceOf(A_Error)
972
+ expect((error as A_Error).originalError.message).toBe('Deliberate Async Error in test1');
973
+ }
974
+ expect(resultChain).toEqual([
975
+ 'ChildComponent_A.test',
976
+ 'feature3'
977
+ ]);
978
+
979
+ const feature = new A_Feature({
980
+ name: 'testFeature',
981
+ component: testScope.resolve(ChildComponent_A)!,
982
+ })
983
+
984
+ try {
985
+ await feature.process();
986
+ } catch (error) {
987
+ expect(error).toBeInstanceOf(A_Error);
988
+ expect((error as A_Error).originalError).toBeInstanceOf(A_Error)
989
+ expect((error as A_Error).originalError.message).toBe('Deliberate Async Error in test1');
990
+ }
991
+
992
+ expect(feature.state).toBe(A_TYPES__FeatureState.FAILED);
993
+
994
+ expect(resultChain).toEqual([
995
+ 'ChildComponent_A.test',
996
+ 'feature3',
997
+ 'ChildComponent_A.test'
998
+ ]);
999
+ })
1000
+
1001
+ it('Should throw an Async error when executed async and error in method', async () => {
1002
+
1003
+ const resultChain: string[] = [];
1004
+
1005
+ class ChildComponent_A extends A_Component {
1006
+ @A_Feature.Extend({
1007
+ name: 'testFeature',
1008
+ })
1009
+ async test1() {
1010
+ resultChain.push('ChildComponent_A.test');
1011
+
1012
+ throw new A_Error('Deliberate Async Error in test1');
1013
+ }
1014
+ }
1015
+
1016
+ const testScope = new A_Scope({ name: 'TestScope', components: [ChildComponent_A] });
1017
+
1018
+ const feature = new A_Feature({
1019
+ name: 'testFeature',
1020
+ component: testScope.resolve(ChildComponent_A)!,
1021
+ })
1022
+
1023
+ try {
1024
+ await feature.process();
1025
+ } catch (error) {
1026
+ expect(error).toBeInstanceOf(A_Error);
1027
+ expect((error as A_Error).originalError).toBeInstanceOf(A_Error)
1028
+ expect((error as A_Error).originalError.message).toBe('Deliberate Async Error in test1');
1029
+ }
1030
+
1031
+ expect(feature.state).toBe(A_TYPES__FeatureState.FAILED);
1032
+
1033
+ expect(resultChain).toEqual([
1034
+ 'ChildComponent_A.test'
1035
+ ]);
1036
+ })
786
1037
  });