diff --git a/src/plugins/mixpanel.ts b/src/plugins/mixpanel.ts index f57303a8f..6fa0000f3 100644 --- a/src/plugins/mixpanel.ts +++ b/src/plugins/mixpanel.ts @@ -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} + */ + @Cordova() + static identify(distinctId: string): Promise { return; } + + /** + * + * @param peopleProperties {string} + * @return {Promise} + */ + @Cordova() + static increment(peopleProperties: any): Promise { return; } + + /** + * + * @param pushId + * @return {Promise} + */ + @Cordova() + static setPushId(pushId: string): Promise { return; } + + /** + * + * @param peopleProperties + * @return {Promise} + */ + @Cordova() + static set(peopleProperties: any): Promise { return; } + + /** + * + * @param peopleProperties + * @return {Promise} + */ + @Cordova() + static setOnce(peopleProperties: any): Promise { return; } } diff --git a/test/plugin.spec.ts b/test/plugin.spec.ts index 5ecbb477a..8109e5cf2 100644 --- a/test/plugin.spec.ts +++ b/test/plugin.spec.ts @@ -1,4 +1,4 @@ -/// +/// import 'es6-shim'; import {Plugin, Cordova} from './../src/plugins/plugin'; diff --git a/test/plugins/mixpanel.spec.ts b/test/plugins/mixpanel.spec.ts new file mode 100644 index 000000000..7eb43d0b4 --- /dev/null +++ b/test/plugins/mixpanel.spec.ts @@ -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(); + }); + +});