feat(mixpanel): MixpanelPeople returns promises (#681)

* feat(mixpanel): make MixpanelPeople return promises

* remove decorator from people property

* add cordova decorator'

* test(mixpanel): add mixpanel tests

* test(mixpanel): remove unused imports

* fix(mixpanel): fix MixpanelPeople class

closes #667
This commit is contained in:
Ibrahim Hadeed 2016-10-15 07:41:37 -07:00 committed by GitHub
parent bbda6e22a2
commit b95f88c165
3 changed files with 91 additions and 15 deletions

View File

@ -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
@ -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 {
/**
*
@ -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; }
}

View File

@ -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';

View File

@ -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();
});
});