@webex/internal-plugin-metrics 3.8.0-next.14 → 3.8.0-next.16

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.
@@ -1375,7 +1375,14 @@ describe('internal-plugin-metrics', () => {
1375
1375
  const getIdentifiersSpy = sinon.spy(cd, 'getIdentifiers');
1376
1376
  const getSubServiceTypeSpy = sinon.spy(cd, 'getSubServiceType');
1377
1377
  const validatorSpy = sinon.spy(cd, 'validator');
1378
- sinon.stub(window.navigator, 'userAgent').get(() => userAgent);
1378
+
1379
+ Object.defineProperty(global, 'navigator', {
1380
+ value: {
1381
+ userAgent,
1382
+ },
1383
+ configurable: true,
1384
+ });
1385
+
1379
1386
  sinon.stub(bowser, 'getParser').returns(userAgent);
1380
1387
 
1381
1388
  const options = {
@@ -1948,7 +1955,7 @@ describe('internal-plugin-metrics', () => {
1948
1955
  assert.deepEqual(webexLoggerLogCalls[2].args, [
1949
1956
  'call-diagnostic-events -> ',
1950
1957
  'CallDiagnosticMetrics: @prepareClientEvent. Generated errors:',
1951
- `generatedError: {"fatal":true,"shownToUser":false,"name":"other","category":"expected","errorCode":4029,"serviceErrorCode":2409005,"errorDescription":"StartRecordingFailed"}`,
1958
+ `generatedError (cached: false): {"fatal":true,"shownToUser":false,"name":"other","category":"expected","errorCode":4029,"serviceErrorCode":2409005,"errorDescription":"StartRecordingFailed"}`,
1952
1959
  ]);
1953
1960
  });
1954
1961
 
@@ -2028,7 +2035,7 @@ describe('internal-plugin-metrics', () => {
2028
2035
  assert.deepEqual(webexLoggerLogCalls[2].args, [
2029
2036
  'call-diagnostic-events -> ',
2030
2037
  'CallDiagnosticMetrics: @prepareClientEvent. Generated errors:',
2031
- `generatedError: {"fatal":true,"shownToUser":false,"name":"other","category":"other","errorCode":9999,"errorData":{"errorName":"Error"},"serviceErrorCode":9999,"rawErrorMessage":"bad times","errorDescription":"UnknownError"}`,
2038
+ `generatedError (cached: false): {"fatal":true,"shownToUser":false,"name":"other","category":"other","errorCode":9999,"errorData":{"errorName":"Error"},"serviceErrorCode":9999,"rawErrorMessage":"bad times","errorDescription":"UnknownError"}`,
2032
2039
  ]);
2033
2040
  });
2034
2041
 
@@ -2101,7 +2108,7 @@ describe('internal-plugin-metrics', () => {
2101
2108
  assert.deepEqual(webexLoggerLogCalls[2].args, [
2102
2109
  'call-diagnostic-events -> ',
2103
2110
  'CallDiagnosticMetrics: @prepareClientEvent. Generated errors:',
2104
- `generatedError: {"fatal":true,"shownToUser":false,"name":"other","category":"other","errorCode":9999,"errorData":{"errorName":"Error"},"serviceErrorCode":9999,"rawErrorMessage":"bad times","errorDescription":"UnknownError"}`,
2111
+ `generatedError (cached: false): {"fatal":true,"shownToUser":false,"name":"other","category":"other","errorCode":9999,"errorData":{"errorName":"Error"},"serviceErrorCode":9999,"rawErrorMessage":"bad times","errorDescription":"UnknownError"}`,
2105
2112
  ]);
2106
2113
  });
2107
2114
 
@@ -2175,7 +2182,7 @@ describe('internal-plugin-metrics', () => {
2175
2182
  assert.deepEqual(webexLoggerLogCalls[2].args, [
2176
2183
  'call-diagnostic-events -> ',
2177
2184
  'CallDiagnosticMetrics: @prepareClientEvent. Generated errors:',
2178
- `generatedError: {"fatal":true,"shownToUser":false,"name":"other","category":"expected","errorCode":4029,"serviceErrorCode":2409005,"errorDescription":"StartRecordingFailed"}`,
2185
+ `generatedError (cached: false): {"fatal":true,"shownToUser":false,"name":"other","category":"expected","errorCode":4029,"serviceErrorCode":2409005,"errorDescription":"StartRecordingFailed"}`,
2179
2186
  ]);
2180
2187
  });
2181
2188
 
@@ -2555,8 +2562,37 @@ describe('internal-plugin-metrics', () => {
2555
2562
  rawErrorMessage: 'bad times',
2556
2563
  };
2557
2564
 
2565
+ it('should be cached if called twice with the same payload', () => {
2566
+ const error = new Error('bad times');
2567
+ const expectedPayload = {
2568
+ category: 'other',
2569
+ errorCode: 9999,
2570
+ errorData: {errorName: 'Error'},
2571
+ serviceErrorCode: 9999,
2572
+ fatal: true,
2573
+ shownToUser: false,
2574
+ name: 'other',
2575
+ rawErrorMessage: 'bad times',
2576
+ errorDescription: 'UnknownError',
2577
+ }
2578
+
2579
+ const [res, cached] = cd.generateClientEventErrorPayload(error);
2580
+ assert.isFalse(cached);
2581
+ assert.deepEqual(res, expectedPayload);
2582
+
2583
+ const [res2, cached2] = cd.generateClientEventErrorPayload(error);
2584
+ assert.isTrue(cached2);
2585
+ assert.deepEqual(res2, expectedPayload);
2586
+
2587
+ // after clearing the cache, it should be false again
2588
+ cd.clearErrorCache();
2589
+ const [res3, cached3] = cd.generateClientEventErrorPayload(error);
2590
+ assert.isFalse(cached3);
2591
+ assert.deepEqual(res3, expectedPayload);
2592
+ });
2593
+
2558
2594
  const checkNameError = (payload: any, isExpectedToBeCalled: boolean) => {
2559
- const res = cd.generateClientEventErrorPayload(payload);
2595
+ const [res, cached] = cd.generateClientEventErrorPayload(payload);
2560
2596
  const expectedResult = {
2561
2597
  category: 'expected',
2562
2598
  errorDescription: 'CameraPermissionDenied',
@@ -2585,7 +2621,7 @@ describe('internal-plugin-metrics', () => {
2585
2621
  });
2586
2622
 
2587
2623
  const checkCodeError = (payload: any, expetedRes: any) => {
2588
- const res = cd.generateClientEventErrorPayload(payload);
2624
+ const [res, cached] = cd.generateClientEventErrorPayload(payload);
2589
2625
  assert.deepEqual(res, expetedRes);
2590
2626
  };
2591
2627
  it('should generate event error payload correctly', () => {
@@ -2611,7 +2647,7 @@ describe('internal-plugin-metrics', () => {
2611
2647
  });
2612
2648
 
2613
2649
  const checkLocusError = (payload: any, isExpectedToBeCalled: boolean) => {
2614
- const res = cd.generateClientEventErrorPayload(payload);
2650
+ const [res, cached] = cd.generateClientEventErrorPayload(payload);
2615
2651
  const expectedResult = {
2616
2652
  category: 'signaling',
2617
2653
  errorDescription: 'NewLocusError',
@@ -2639,7 +2675,7 @@ describe('internal-plugin-metrics', () => {
2639
2675
  });
2640
2676
 
2641
2677
  const checkMeetingInfoError = (payload: any, isExpectedToBeCalled: boolean) => {
2642
- const res = cd.generateClientEventErrorPayload(payload);
2678
+ const [res, cached] = cd.generateClientEventErrorPayload(payload);
2643
2679
  const expectedResult = {
2644
2680
  category: 'signaling',
2645
2681
  errorDescription: 'MeetingInfoLookupError',
@@ -2680,7 +2716,7 @@ describe('internal-plugin-metrics', () => {
2680
2716
  });
2681
2717
 
2682
2718
  it('should return NetworkError code for a NetworkOrCORSERror', () => {
2683
- const res = cd.generateClientEventErrorPayload(
2719
+ const [res, cached] = cd.generateClientEventErrorPayload(
2684
2720
  new WebexHttpError.NetworkOrCORSError({
2685
2721
  url: 'https://example.com',
2686
2722
  statusCode: 0,
@@ -2724,7 +2760,7 @@ describe('internal-plugin-metrics', () => {
2724
2760
  message: 'No codecs present in m-line with MID 0 after filtering.',
2725
2761
  },
2726
2762
  };
2727
- const res = cd.generateClientEventErrorPayload(error);
2763
+ const [res, cached] = cd.generateClientEventErrorPayload(error);
2728
2764
  assert.deepEqual(res, {
2729
2765
  category: 'expected',
2730
2766
  errorCode: 2051,
@@ -2750,7 +2786,7 @@ describe('internal-plugin-metrics', () => {
2750
2786
  message: 'empty local SDP',
2751
2787
  },
2752
2788
  };
2753
- const res = cd.generateClientEventErrorPayload(error);
2789
+ const [res, cached] = cd.generateClientEventErrorPayload(error);
2754
2790
  assert.deepEqual(res, {
2755
2791
  category: 'media',
2756
2792
  errorCode: 2050,
@@ -2775,7 +2811,7 @@ describe('internal-plugin-metrics', () => {
2775
2811
  category: 'expected',
2776
2812
  };
2777
2813
 
2778
- const res = cd.generateClientEventErrorPayload(error);
2814
+ const [res, cached] = cd.generateClientEventErrorPayload(error);
2779
2815
  assert.deepEqual(res, {
2780
2816
  category: 'expected',
2781
2817
  errorDescription: 'UnknownError',
@@ -2804,7 +2840,7 @@ describe('internal-plugin-metrics', () => {
2804
2840
  category: 'expected',
2805
2841
  };
2806
2842
 
2807
- const res = cd.generateClientEventErrorPayload(error);
2843
+ const [res, cached] = cd.generateClientEventErrorPayload(error);
2808
2844
  assert.deepEqual(res, {
2809
2845
  category: 'expected',
2810
2846
  errorDescription: 'NetworkError',
@@ -2819,7 +2855,7 @@ describe('internal-plugin-metrics', () => {
2819
2855
  });
2820
2856
 
2821
2857
  it('should return AuthenticationFailed code for an Unauthorized error', () => {
2822
- const res = cd.generateClientEventErrorPayload(
2858
+ const [res, cached] = cd.generateClientEventErrorPayload(
2823
2859
  new WebexHttpError.Unauthorized({
2824
2860
  url: 'https://example.com',
2825
2861
  statusCode: 0,
@@ -2852,7 +2888,7 @@ describe('internal-plugin-metrics', () => {
2852
2888
  category: 'expected',
2853
2889
  };
2854
2890
 
2855
- const res = cd.generateClientEventErrorPayload(error);
2891
+ const [res, cached] = cd.generateClientEventErrorPayload(error);
2856
2892
  assert.deepEqual(res, {
2857
2893
  category: 'expected',
2858
2894
  errorDescription: 'AuthenticationFailed',
@@ -2867,7 +2903,7 @@ describe('internal-plugin-metrics', () => {
2867
2903
  });
2868
2904
 
2869
2905
  it('should return unknown error otherwise', () => {
2870
- const res = cd.generateClientEventErrorPayload({something: 'new', message: 'bad times'});
2906
+ const [res, cached] = cd.generateClientEventErrorPayload({something: 'new', message: 'bad times'});
2871
2907
  assert.deepEqual(res, {
2872
2908
  category: 'other',
2873
2909
  errorDescription: 'UnknownError',
@@ -2881,7 +2917,7 @@ describe('internal-plugin-metrics', () => {
2881
2917
  });
2882
2918
 
2883
2919
  it('should generate event error payload correctly for locus error 2423012', () => {
2884
- const res = cd.generateClientEventErrorPayload({
2920
+ const [res, cached] = cd.generateClientEventErrorPayload({
2885
2921
  body: {errorCode: 2423012},
2886
2922
  message: 'bad times',
2887
2923
  });
@@ -2897,7 +2933,7 @@ describe('internal-plugin-metrics', () => {
2897
2933
  });
2898
2934
  });
2899
2935
  it('should generate event error payload correctly for locus error 2409062', () => {
2900
- const res = cd.generateClientEventErrorPayload({
2936
+ const [res, cached] = cd.generateClientEventErrorPayload({
2901
2937
  body: {errorCode: 2409062},
2902
2938
  message: 'bad times',
2903
2939
  });
@@ -2914,7 +2950,7 @@ describe('internal-plugin-metrics', () => {
2914
2950
  });
2915
2951
 
2916
2952
  it('should generate event error payload correctly for locus error 2423021', () => {
2917
- const res = cd.generateClientEventErrorPayload({
2953
+ const [res, cached] = cd.generateClientEventErrorPayload({
2918
2954
  body: {errorCode: 2423021},
2919
2955
  message: 'bad times',
2920
2956
  });
@@ -2931,7 +2967,7 @@ describe('internal-plugin-metrics', () => {
2931
2967
  });
2932
2968
 
2933
2969
  it('should generate event error payload correctly for wdm error 4404002', () => {
2934
- const res = cd.generateClientEventErrorPayload({
2970
+ const [res, cached] = cd.generateClientEventErrorPayload({
2935
2971
  body: {errorCode: 4404002},
2936
2972
  message: 'Operation denied due to region restriction',
2937
2973
  });
@@ -2948,7 +2984,7 @@ describe('internal-plugin-metrics', () => {
2948
2984
  });
2949
2985
 
2950
2986
  it('should generate event error payload correctly for wdm error 4404003', () => {
2951
- const res = cd.generateClientEventErrorPayload({
2987
+ const [res, cached] = cd.generateClientEventErrorPayload({
2952
2988
  body: {errorCode: 4404003},
2953
2989
  message: 'Operation denied due to region restriction',
2954
2990
  });
@@ -2966,7 +3002,7 @@ describe('internal-plugin-metrics', () => {
2966
3002
 
2967
3003
  describe('httpStatusCode', () => {
2968
3004
  it('should include httpStatusCode for browser media errors', () => {
2969
- const res = cd.generateClientEventErrorPayload({
3005
+ const [res, cached] = cd.generateClientEventErrorPayload({
2970
3006
  name: 'PermissionDeniedError',
2971
3007
  message: 'bad times',
2972
3008
  statusCode: 401,
@@ -2988,7 +3024,7 @@ describe('internal-plugin-metrics', () => {
2988
3024
  });
2989
3025
 
2990
3026
  it('should include httpStatusCode for SdpOfferCreationErrors', () => {
2991
- const res = cd.generateClientEventErrorPayload({
3027
+ const [res, cached] = cd.generateClientEventErrorPayload({
2992
3028
  name: 'SdpOfferCreationError',
2993
3029
  message: 'bad times',
2994
3030
  statusCode: 404,
@@ -3010,7 +3046,7 @@ describe('internal-plugin-metrics', () => {
3010
3046
  });
3011
3047
 
3012
3048
  it('should include httpStatusCode for service error codes', () => {
3013
- const res = cd.generateClientEventErrorPayload({
3049
+ const [res, cached] = cd.generateClientEventErrorPayload({
3014
3050
  body: {errorCode: 58400},
3015
3051
  message: 'bad times',
3016
3052
  statusCode: 400,
@@ -3029,7 +3065,7 @@ describe('internal-plugin-metrics', () => {
3029
3065
  });
3030
3066
 
3031
3067
  it('should include httpStatusCode for locus service error codes', () => {
3032
- const res = cd.generateClientEventErrorPayload({
3068
+ const [res, cached] = cd.generateClientEventErrorPayload({
3033
3069
  body: {errorCode: 2403001},
3034
3070
  message: 'bad times',
3035
3071
  statusCode: 400,
@@ -3048,7 +3084,7 @@ describe('internal-plugin-metrics', () => {
3048
3084
  });
3049
3085
 
3050
3086
  it('should include httpStatusCode for meetingInfo service error codes', () => {
3051
- const res = cd.generateClientEventErrorPayload({
3087
+ const [res, cached] = cd.generateClientEventErrorPayload({
3052
3088
  body: {data: {meetingInfo: {}}},
3053
3089
  message: 'bad times',
3054
3090
  statusCode: 400,
@@ -3071,7 +3107,7 @@ describe('internal-plugin-metrics', () => {
3071
3107
  statusCode: 400,
3072
3108
  options: {service: '', headers: {}},
3073
3109
  });
3074
- const res = cd.generateClientEventErrorPayload(error);
3110
+ const [res, cached] = cd.generateClientEventErrorPayload(error);
3075
3111
  assert.deepEqual(res, {
3076
3112
  category: 'network',
3077
3113
  errorCode: 1026,
@@ -3090,7 +3126,7 @@ describe('internal-plugin-metrics', () => {
3090
3126
  statusCode: 401,
3091
3127
  options: {service: '', headers: {}},
3092
3128
  });
3093
- const res = cd.generateClientEventErrorPayload(error);
3129
+ const [res, cached] = cd.generateClientEventErrorPayload(error);
3094
3130
  assert.deepEqual(res, {
3095
3131
  category: 'network',
3096
3132
  errorCode: 1010,
@@ -3105,7 +3141,7 @@ describe('internal-plugin-metrics', () => {
3105
3141
  });
3106
3142
 
3107
3143
  it('should include httpStatusCode for unknown errors', () => {
3108
- const res = cd.generateClientEventErrorPayload({
3144
+ const [res, cached] = cd.generateClientEventErrorPayload({
3109
3145
  message: 'bad times',
3110
3146
  statusCode: 404,
3111
3147
  });