Skip to content

Commit

Permalink
chore: reuse interface for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kmruiz committed Nov 27, 2023
1 parent 8b21e62 commit 85f54da
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
16 changes: 10 additions & 6 deletions packages/logging/src/analytics-helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
14 changes: 0 additions & 14 deletions packages/logging/src/analytics-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 85f54da

Please sign in to comment.