mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-02-21 00:23:00 +08:00
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:
parent
bbda6e22a2
commit
b95f88c165
@ -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; }
|
||||
}
|
||||
|
@ -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';
|
||||
|
28
test/plugins/mixpanel.spec.ts
Normal file
28
test/plugins/mixpanel.spec.ts
Normal 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();
|
||||
});
|
||||
|
||||
});
|
Loading…
Reference in New Issue
Block a user