Skip to content

Commit

Permalink
Revert prettier changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vladucu committed Aug 4, 2020
1 parent 2fddc8d commit f2426ea
Showing 1 changed file with 52 additions and 101 deletions.
153 changes: 52 additions & 101 deletions tests/unit/metrics-adapters/mixpanel-test.js
Original file line number Diff line number Diff line change
@@ -1,163 +1,114 @@
import { module, test } from "qunit";
import { setupTest } from "ember-qunit";
import sinon from "sinon";
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import sinon from 'sinon';

let sandbox, config;

module("mixpanel adapter", function (hooks) {
module('mixpanel adapter', function(hooks) {
setupTest(hooks);

hooks.beforeEach(function () {
hooks.beforeEach(function() {
sandbox = sinon.createSandbox();
config = {
token: "meowmeows",
token: 'meowmeows'
};
});

hooks.afterEach(function () {
hooks.afterEach(function() {
sandbox.restore();
});

test("#identify calls `mixpanel.identify` and `mixpanel.people.set` with the right arguments", function (assert) {
const adapter = this.owner
.factoryFor("ember-metrics@metrics-adapter:mixpanel")
.create({ config });
const identify_stub = sandbox
.stub(window.mixpanel, "identify")
.callsFake(() => {
return true;
});
const people_set_stub = sandbox
.stub(window.mixpanel.people, "set")
.callsFake(() => {
return true;
});
test('#identify calls `mixpanel.identify` and `mixpanel.people.set` with the right arguments', function(assert) {
const adapter = this.owner.factoryFor('ember-metrics@metrics-adapter:mixpanel').create({ config });
const identify_stub = sandbox.stub(window.mixpanel, 'identify').callsFake(() => {
return true;
});
const people_set_stub = sandbox.stub(window.mixpanel.people, 'set').callsFake(() => {
return true;
});
adapter.identify({
distinctId: 123,
foo: "bar",
cookie: "chocolate chip",
foo: 'bar',
cookie: 'chocolate chip'
});
adapter.identify({
distinctId: 123,
distinctId: 123
});
assert.ok(
identify_stub.firstCall.calledWith(123),
"it sends the correct arguments and options"
);
assert.ok(
identify_stub.secondCall.calledWith(123),
"it sends the correct arguments"
);
assert.ok(
people_set_stub.firstCall.calledWith({
cookie: "chocolate chip",
foo: "bar",
}),
"it sends the correct arguments and options"
);
assert.equal(
people_set_stub.secondCall,
null,
"people.set does not fire if there are no additional options"
);
assert.ok(identify_stub.firstCall.calledWith(123), 'it sends the correct arguments and options');
assert.ok(identify_stub.secondCall.calledWith(123), 'it sends the correct arguments');
assert.ok(people_set_stub.firstCall.calledWith({ cookie: 'chocolate chip', foo: 'bar' }), 'it sends the correct arguments and options');
assert.equal(people_set_stub.secondCall, null, 'people.set does not fire if there are no additional options');
});

test("#trackEvent calls `mixpanel.track` with the right arguments", function (assert) {
const adapter = this.owner
.factoryFor("ember-metrics@metrics-adapter:mixpanel")
.create({ config });
const stub = sandbox.stub(window.mixpanel, "track").callsFake(() => {
test('#trackEvent calls `mixpanel.track` with the right arguments', function(assert) {
const adapter = this.owner.factoryFor('ember-metrics@metrics-adapter:mixpanel').create({ config });
const stub = sandbox.stub(window.mixpanel, 'track').callsFake(() => {
return true;
});
adapter.trackEvent({
event: "Video played",
event: 'Video played',
videoLength: 213,
id: "hY7gQr0",
id: 'hY7gQr0'
});
adapter.trackEvent({
event: "Ate a cookie",
event: 'Ate a cookie'
});
assert.ok(
stub.firstCall.calledWith("Video played", {
videoLength: 213,
id: "hY7gQr0",
}),
"it sends the correct arguments and options"
);
assert.ok(
stub.secondCall.calledWith("Ate a cookie"),
"it sends the correct arguments"
);
assert.ok(stub.firstCall.calledWith('Video played', { videoLength: 213, id: 'hY7gQr0' }), 'it sends the correct arguments and options');
assert.ok(stub.secondCall.calledWith('Ate a cookie'), 'it sends the correct arguments');
});

test("#trackPage calls `mixpanel.track` with the right arguments", function (assert) {
const adapter = this.owner
.factoryFor("ember-metrics@metrics-adapter:mixpanel")
.create({ config });
const stub = sandbox.stub(window.mixpanel, "track").callsFake(() => {
test('#trackPage calls `mixpanel.track` with the right arguments', function(assert) {
const adapter = this.owner.factoryFor('ember-metrics@metrics-adapter:mixpanel').create({ config });
const stub = sandbox.stub(window.mixpanel, 'track').callsFake(() => {
return true;
});
adapter.trackPage({
page: "/products/1",
page: '/products/1'
});
adapter.trackPage({
event: "Page View",
page: "/products/1",
event: 'Page View',
page: '/products/1'
});
assert.ok(
stub.firstCall.calledWith("page viewed", { page: "/products/1" }),
"it sends the correct arguments and options"
);
assert.ok(
stub.secondCall.calledWith("Page View", { page: "/products/1" }),
"it sends the correct arguments and options"
);
assert.ok(stub.firstCall.calledWith('page viewed', { page: '/products/1' }), 'it sends the correct arguments and options');
assert.ok(stub.secondCall.calledWith('Page View', { page: '/products/1' }), 'it sends the correct arguments and options');
});

test("#alias calls `mixpanel.alias` with the right arguments", function (assert) {
const adapter = this.owner
.factoryFor("ember-metrics@metrics-adapter:mixpanel")
.create({ config });
const stub = sandbox.stub(window.mixpanel, "alias").callsFake(() => {
test('#alias calls `mixpanel.alias` with the right arguments', function(assert) {
const adapter = this.owner.factoryFor('ember-metrics@metrics-adapter:mixpanel').create({ config });
const stub = sandbox.stub(window.mixpanel, 'alias').callsFake(() => {
return true;
});
adapter.alias({
alias: "[email protected]",
original: 123,
alias: '[email protected]',
original: 123
});
adapter.alias({
alias: "[email protected]",
alias: '[email protected]'
});
assert.ok(
stub.firstCall.calledWith("[email protected]", 123),
"it sends the correct arguments and options"
);
assert.ok(
stub.secondCall.calledWith("[email protected]"),
"it sends the correct arguments"
);
assert.ok(stub.firstCall.calledWith('[email protected]', 123), 'it sends the correct arguments and options');
assert.ok(stub.secondCall.calledWith('[email protected]'), 'it sends the correct arguments');
});

test("#init supports extra configs", function (assert) {
test('#init supports extra configs', function (assert) {
const config = {
token: "meowmeows",
token: 'meowmeows',
batch_requests: true,
};
const adapter = this.owner
.factoryFor("ember-metrics@metrics-adapter:mixpanel")
.factoryFor('ember-metrics@metrics-adapter:mixpanel')
.create({ config });
const init_stub = sandbox.stub(window.mixpanel, "init").callsFake(() => {
const init_stub = sandbox.stub(window.mixpanel, 'init').callsFake(() => {
return true;
});
adapter.init();

assert.ok(
init_stub.firstCall.calledWith(config.token, {
api_host: "https://api.mixpanel.com",
api_host: 'https://api.mixpanel.com',
secure_cookie: true,
batch_requests: true,
}),
"it sends the correct config options"
'it sends the correct config options'
);
});
});

0 comments on commit f2426ea

Please sign in to comment.