From 7fd5886ee90cb320ad007ad653bf67089228cca6 Mon Sep 17 00:00:00 2001 From: Ibby Date: Tue, 11 Oct 2016 19:46:35 -0400 Subject: [PATCH 1/6] feat(mixpanel): make MixpanelPeople return promises --- src/plugins/mixpanel.ts | 44 +++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/src/plugins/mixpanel.ts b/src/plugins/mixpanel.ts index f57303a8f2..7996bfc374 100644 --- a/src/plugins/mixpanel.ts +++ b/src/plugins/mixpanel.ts @@ -103,10 +103,42 @@ export class Mixpanel { /** * @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 plugin: string = 'cordova-plugin-mixpanel'; + private pluginRef: string = 'mixpanel.people'; + + /** + * + * @param distinctId {string} + * @return {Promise} + */ + static identify(distinctId: string): Promise { return; } + + /** + * + * @param peopleProperties {string} + * @return {Promise} + */ + static increment(peopleProperties: any): Promise { return; } + + /** + * + * @param pushId + * @return {Promise} + */ + static setPushId(pushId: string): Promise { return; } + + /** + * + * @param peopleProperties + * @return {Promise} + */ + static set(peopleProperties: any): Promise { return; } + + /** + * + * @param peopleProperties + * @return {Promise} + */ + static setOnce(peopleProperties: any): Promise { return; } } From eb7f975cbee4d1668c4fd6309db495154c551d7e Mon Sep 17 00:00:00 2001 From: Ibby Date: Tue, 11 Oct 2016 19:48:20 -0400 Subject: [PATCH 2/6] remove decorator from people property --- src/plugins/mixpanel.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/plugins/mixpanel.ts b/src/plugins/mixpanel.ts index 7996bfc374..b080c2d6af 100644 --- a/src/plugins/mixpanel.ts +++ b/src/plugins/mixpanel.ts @@ -96,8 +96,7 @@ export class Mixpanel { * * @returns {MixpanelPeople} */ - @CordovaProperty - static get people(): MixpanelPeople { return mixpanel.people; }; + static people: MixpanelPeople = MixpanelPeople; } /** From 666f65980a8bfb9ada0cb06ff18584053a288b85 Mon Sep 17 00:00:00 2001 From: Ibby Date: Tue, 11 Oct 2016 20:59:22 -0400 Subject: [PATCH 3/6] add cordova decorator' --- src/plugins/mixpanel.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/plugins/mixpanel.ts b/src/plugins/mixpanel.ts index b080c2d6af..9a0969a54b 100644 --- a/src/plugins/mixpanel.ts +++ b/src/plugins/mixpanel.ts @@ -111,6 +111,7 @@ export class MixpanelPeople { * @param distinctId {string} * @return {Promise} */ + @Cordova() static identify(distinctId: string): Promise { return; } /** @@ -118,6 +119,7 @@ export class MixpanelPeople { * @param peopleProperties {string} * @return {Promise} */ + @Cordova() static increment(peopleProperties: any): Promise { return; } /** @@ -125,6 +127,7 @@ export class MixpanelPeople { * @param pushId * @return {Promise} */ + @Cordova() static setPushId(pushId: string): Promise { return; } /** @@ -132,6 +135,7 @@ export class MixpanelPeople { * @param peopleProperties * @return {Promise} */ + @Cordova() static set(peopleProperties: any): Promise { return; } /** @@ -139,5 +143,6 @@ export class MixpanelPeople { * @param peopleProperties * @return {Promise} */ + @Cordova() static setOnce(peopleProperties: any): Promise { return; } } From 5da50173e85e865cd2b447d799af68808a98d074 Mon Sep 17 00:00:00 2001 From: Ibby Date: Fri, 14 Oct 2016 06:01:34 -0400 Subject: [PATCH 4/6] test(mixpanel): add mixpanel tests --- test/plugin.spec.ts | 2 +- test/plugins/mixpanel.spec.ts | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 test/plugins/mixpanel.spec.ts diff --git a/test/plugin.spec.ts b/test/plugin.spec.ts index 5ecbb477a1..8109e5cf25 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 0000000000..efef582ad3 --- /dev/null +++ b/test/plugins/mixpanel.spec.ts @@ -0,0 +1,33 @@ +/// + +import 'es6-shim'; +import {Plugin, Cordova} from '../../src/plugins/plugin'; +import {pluginMeta, MixpanelPeople, Mixpanel} from '../../src/plugins/mixpanel'; +declare const window: any; +declare const mixpanel: 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(); + }); + +}); From 46114af6ae52cecb1ae2f6a1e263f6298ee643d0 Mon Sep 17 00:00:00 2001 From: Ibby Date: Fri, 14 Oct 2016 06:02:44 -0400 Subject: [PATCH 5/6] test(mixpanel): remove unused imports --- test/plugins/mixpanel.spec.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/test/plugins/mixpanel.spec.ts b/test/plugins/mixpanel.spec.ts index efef582ad3..7eb43d0b40 100644 --- a/test/plugins/mixpanel.spec.ts +++ b/test/plugins/mixpanel.spec.ts @@ -1,10 +1,5 @@ -/// - -import 'es6-shim'; -import {Plugin, Cordova} from '../../src/plugins/plugin'; -import {pluginMeta, MixpanelPeople, Mixpanel} from '../../src/plugins/mixpanel'; +import {Mixpanel} from '../../src/plugins/mixpanel'; declare const window: any; -declare const mixpanel: any; window.mixpanel = { people: { From ed3e15439f7529db4dfd8a83b537cd02192947ae Mon Sep 17 00:00:00 2001 From: Ibby Date: Fri, 14 Oct 2016 06:03:13 -0400 Subject: [PATCH 6/6] fix(mixpanel): fix MixpanelPeople class closes #667 --- src/plugins/mixpanel.ts | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/plugins/mixpanel.ts b/src/plugins/mixpanel.ts index 9a0969a54b..6fa0000f35 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,15 +100,23 @@ export class Mixpanel { * * @returns {MixpanelPeople} */ - static people: MixpanelPeople = MixpanelPeople; + static get people(): typeof MixpanelPeople { + return MixpanelPeople; + }; } /** * @private */ export class MixpanelPeople { - private plugin: string = 'cordova-plugin-mixpanel'; - private pluginRef: string = 'mixpanel.people'; + /** + * @private + */ + static plugin: string = pluginMeta.plugin; + /** + * @private + */ + static pluginRef: string = pluginMeta.pluginRef + '.people'; /** *