Skip to content

Commit

Permalink
feat(mixpanel): MixpanelPeople returns promises (#681)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ihadeed committed Oct 15, 2016
1 parent bbda6e2 commit b95f88c
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 15 deletions.
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();
});

});

0 comments on commit b95f88c

Please sign in to comment.