Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mixpanel): make MixpanelPeople return promises #681

Merged
merged 6 commits into from
Oct 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 62 additions & 14 deletions src/plugins/mixpanel.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { Cordova, CordovaProperty, Plugin } from './plugin';
import { Cordova, Plugin } from './plugin';

declare var mixpanel: any;

/**
* @private
*/
export const pluginMeta = {
plugin: 'cordova-plugin-mixpanel',
pluginRef: 'mixpanel',
repo: 'https://github.com/samzilverberg/cordova-mixpanel-plugin'
};

/**
* @name Mixpanel
Expand All @@ -18,11 +26,7 @@ declare var mixpanel: any;
*
* ```
*/
@Plugin({
plugin: 'cordova-plugin-mixpanel',
pluginRef: 'mixpanel',
repo: 'https://github.com/samzilverberg/cordova-mixpanel-plugin'
})
@Plugin(pluginMeta)
export class Mixpanel {
/**
*
Expand Down Expand Up @@ -96,17 +100,61 @@ export class Mixpanel {
*
* @returns {MixpanelPeople}
*/
@CordovaProperty
static get people(): MixpanelPeople { return mixpanel.people; };
static get people(): typeof MixpanelPeople {
return MixpanelPeople;
};

}
/**
* @private
*/
export declare class MixpanelPeople {
static identify(distinctId: string, onSuccess?: Function, onFail?: Function): void;
static increment(peopleProperties: any, onSuccess?: Function, onFail?: Function): void;
static setPushId(pushId: string, onSuccess?: Function, onFail?: Function): void;
static set(peopleProperties: any, onSuccess?: Function, onFail?: Function): void;
static setOnce(peopleProperties: any, onSuccess?: Function, onFail?: Function): void;
export class MixpanelPeople {
/**
* @private
*/
static plugin: string = pluginMeta.plugin;
/**
* @private
*/
static pluginRef: string = pluginMeta.pluginRef + '.people';

/**
*
* @param distinctId {string}
* @return {Promise<any>}
*/
@Cordova()
static identify(distinctId: string): Promise<any> { return; }

/**
*
* @param peopleProperties {string}
* @return {Promise<any>}
*/
@Cordova()
static increment(peopleProperties: any): Promise<any> { return; }

/**
*
* @param pushId
* @return {Promise<any>}
*/
@Cordova()
static setPushId(pushId: string): Promise<any> { return; }

/**
*
* @param peopleProperties
* @return {Promise<any>}
*/
@Cordova()
static set(peopleProperties: any): Promise<any> { return; }

/**
*
* @param peopleProperties
* @return {Promise<any>}
*/
@Cordova()
static setOnce(peopleProperties: any): Promise<any> { return; }
}
2 changes: 1 addition & 1 deletion test/plugin.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference path="./../typings/index.d.ts" />
/// <reference path="../typings/index.d.ts" />

import 'es6-shim';
import {Plugin, Cordova} from './../src/plugins/plugin';
Expand Down
28 changes: 28 additions & 0 deletions test/plugins/mixpanel.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {Mixpanel} from '../../src/plugins/mixpanel';
declare const window: any;

window.mixpanel = {
people: {
identify: (args, success, error) => success('Success')
}
};

describe('Mixpanel', () => {

it('should return MixpanelPeople', () => {
expect(Mixpanel.people).toBeDefined();
expect(Mixpanel.people.identify).toBeDefined();
});

it('should call a method of MixpanelPeople', (done) => {
const spy = spyOn(window.mixpanel.people, 'identify').and.callThrough();
Mixpanel.people.identify('veryDistinctSuchIdVeryWow')
.then(result => {
expect(result).toEqual('Success');
done();
});
expect(spy.calls.mostRecent().args[0]).toEqual('veryDistinctSuchIdVeryWow');
expect(window.mixpanel.people.identify).toHaveBeenCalled();
});

});