From 85f54da883378961d34479da3f9a41d14eb8847b Mon Sep 17 00:00:00 2001 From: Kevin Mas Ruiz Date: Mon, 27 Nov 2023 17:32:55 +0100 Subject: [PATCH] chore: reuse interface for tests --- packages/logging/src/analytics-helpers.spec.ts | 16 ++++++++++------ packages/logging/src/analytics-helpers.ts | 14 -------------- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/packages/logging/src/analytics-helpers.spec.ts b/packages/logging/src/analytics-helpers.spec.ts index e83c20c24..9efda4e1e 100644 --- a/packages/logging/src/analytics-helpers.spec.ts +++ b/packages/logging/src/analytics-helpers.spec.ts @@ -260,9 +260,11 @@ describe('analytics helpers', function () { }; it('should send the event forward when sampled', function () { - const analytics = SampledAnalytics.enabledForAll( - target - ) as SampledAnalytics; + const analytics = new SampledAnalytics({ + target, + sampling: () => true, + }); + expect(analytics.enabled).to.be.true; analytics.identify(iEvt); @@ -272,9 +274,11 @@ describe('analytics helpers', function () { }); it('should not send the event forward when not sampled', function () { - const analytics = SampledAnalytics.disabledForAll( - target - ) as SampledAnalytics; + const analytics = new SampledAnalytics({ + target, + sampling: () => false, + }); + expect(analytics.enabled).to.be.false; analytics.identify(iEvt); diff --git a/packages/logging/src/analytics-helpers.ts b/packages/logging/src/analytics-helpers.ts index b5f8b7f73..390287146 100644 --- a/packages/logging/src/analytics-helpers.ts +++ b/packages/logging/src/analytics-helpers.ts @@ -393,20 +393,6 @@ export class SampledAnalytics implements MongoshAnalytics { this.target = configuration.target || new NoopAnalytics(); } - static enabledForAll(target?: MongoshAnalytics): MongoshAnalytics { - return new SampledAnalytics({ - target, - sampling: () => true, - }); - } - - static disabledForAll(target?: MongoshAnalytics): MongoshAnalytics { - return new SampledAnalytics({ - target, - sampling: () => false, - }); - } - get enabled(): boolean { return this.isEnabled; }