github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/ui/src/redux/customAnalytics/customAnalyticsSagas.spec.ts (about)

     1  // Copyright 2020 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  import { expectSaga } from "redux-saga-test-plan";
    12  import sinon from "sinon";
    13  import Analytics from "analytics-node";
    14  
    15  import { signUpEmailSubscription } from "./customAnalyticsSagas";
    16  import {
    17    signUpForEmailSubscription,
    18  } from "./customAnanlyticsActions";
    19  
    20  const sandbox = sinon.createSandbox();
    21  
    22  describe("customAnalyticsSagas", () => {
    23    describe("signUpEmailSubscription generator", () => {
    24      afterEach(() => {
    25        sandbox.reset();
    26      });
    27  
    28      it("calls analytics#identify with user email in args ", () => {
    29        const analyticsIdentifyFn = sandbox.stub(Analytics.prototype, "identify");
    30        const clusterId = "cluster-1";
    31        const email = "foo@bar.com";
    32        const action = signUpForEmailSubscription(clusterId, email);
    33  
    34        return expectSaga(signUpEmailSubscription, action)
    35          .dispatch(action)
    36          .run()
    37          .then(() => {
    38            const expectedAnalyticsMessage = {
    39              userId: clusterId,
    40              traits: {
    41                email,
    42              },
    43            };
    44            analyticsIdentifyFn.calledOnceWith(expectedAnalyticsMessage);
    45          });
    46      });
    47    });
    48  });