Sha256: 7a4edb12578d30acc76ff90041874a2e4b2d305c5b0f333a234a863cfdbab197

Contents?: true

Size: 1.61 KB

Versions: 2

Compression:

Stored size: 1.61 KB

Contents

//= require workarea/storefront/spec_helper
/*eslint no-unused-vars: 0 */

var gettingUserData = WORKAREA.currentUser.gettingUserData;

function stubSegmentMethods() {
    // This is an aweful idea, but since WORKAREA.currentUser.gettingUserData
    // is a promise, not a function it can't be stubbed with sinon.
    var userData = {
        "logged_in":true,
        "cart_quantity":0,
        "admin":true,
        "user_id":"59b2f28fc254291234daf27b",
        "checkout_id":"E2E1096C6A",
        "user_name":"Ben Crouse",
        "user_email":"user@workarea.com"
    };

    WORKAREA.currentUser.gettingUserData = $.Deferred().resolve(userData);

    sinon.stub(WORKAREA.segmentAnalytics, 'page', function(payload) {
        window.testData.push({
            eventType: 'page',
            data: payload
        });
    });

    sinon.stub(WORKAREA.segmentAnalytics, 'track', function(eventType, data) {
        window.testData.push({
            eventType: eventType,
            data: data
        });
    });

    sinon.stub(WORKAREA.segmentAnalytics, 'identify', function(userId, data) {
        window.testData.push({
            eventType: 'identify',
            userId: userId,
            data: data
        });
    });

    sinon.stub(WORKAREA.segmentAnalytics, 'reset', function() {
        window.testData.push({
            eventType: 'reset'
        });
    });
}

function resetStubs() {
    WORKAREA.segmentAnalytics.page.reset();
    WORKAREA.segmentAnalytics.track.reset();
    WORKAREA.segmentAnalytics.identify.reset();
    WORKAREA.segmentAnalytics.reset.reset();
    WORKAREA.currentUser.gettingUserData = gettingUserData;
}

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
workarea-segment_analytics-1.0.3 test/javascripts/fixtures/stubs.js
workarea-segment_analytics-1.0.2 test/javascripts/fixtures/stubs.js