-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
307da5c
commit 3eb5b73
Showing
17 changed files
with
261 additions
and
77 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
packages/pn-personafisica-login/src/models/PFLoginEventsType.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export enum PFLoginEventsType { | ||
SEND_LOGIN = 'SEND_LOGIN', | ||
SEND_IDP_SELECTED = 'SEND_IDP_SELECTED', | ||
SEND_LOGIN_FAILURE = 'SEND_LOGIN_FAILURE', | ||
SEND_LOGIN_METHOD = 'SEND_LOGIN_METHOD', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
packages/pn-personafisica-login/src/utility/MixpanelUtils/PFLoginEventStrategyFactory.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { EventStrategy, EventStrategyFactory } from '@pagopa-pn/pn-commons'; | ||
|
||
import { PFLoginEventsType } from '../../models/PFLoginEventsType'; | ||
import { SendIDPSelectedStrategy } from './Strategies/SendIDPSelectedStrategy'; | ||
import { SendLoginFailureStrategy } from './Strategies/SendLoginFailureStrategy'; | ||
import { SendLoginMethodStrategy } from './Strategies/SendLoginMethodStrategy'; | ||
import { UXScreenViewStrategy } from './Strategies/UXScreenViewStrategy'; | ||
|
||
class PFLoginEventStrategyFactory extends EventStrategyFactory<PFLoginEventsType> { | ||
getStrategy(eventType: PFLoginEventsType): EventStrategy | null { | ||
switch (eventType) { | ||
case PFLoginEventsType.SEND_LOGIN: | ||
return new UXScreenViewStrategy(); | ||
case PFLoginEventsType.SEND_IDP_SELECTED: | ||
return new SendIDPSelectedStrategy(); | ||
case PFLoginEventsType.SEND_LOGIN_FAILURE: | ||
return new SendLoginFailureStrategy(); | ||
case PFLoginEventsType.SEND_LOGIN_METHOD: | ||
return new SendLoginMethodStrategy(); | ||
default: | ||
return null; | ||
} | ||
} | ||
} | ||
|
||
export default new PFLoginEventStrategyFactory(); |
28 changes: 28 additions & 0 deletions
28
...es/pn-personafisica-login/src/utility/MixpanelUtils/Strategies/SendIDPSelectedStrategy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { | ||
EventAction, | ||
EventCategory, | ||
EventPropertyType, | ||
EventStrategy, | ||
TrackedEvent, | ||
} from '@pagopa-pn/pn-commons'; | ||
|
||
type SendIDPSelected = { | ||
SPID_IDP_NAME: string; | ||
SPID_IDP_ID: string; | ||
}; | ||
|
||
export class SendIDPSelectedStrategy implements EventStrategy { | ||
performComputations({ | ||
SPID_IDP_ID, | ||
SPID_IDP_NAME, | ||
}: SendIDPSelected): TrackedEvent<SendIDPSelected> { | ||
return { | ||
[EventPropertyType.TRACK]: { | ||
event_category: EventCategory.UX, | ||
event_type: EventAction.ACTION, | ||
SPID_IDP_ID, | ||
SPID_IDP_NAME, | ||
}, | ||
}; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...s/pn-personafisica-login/src/utility/MixpanelUtils/Strategies/SendLoginFailureStrategy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { | ||
EventCategory, | ||
EventPropertyType, | ||
EventStrategy, | ||
TrackedEvent, | ||
} from '@pagopa-pn/pn-commons'; | ||
|
||
type SendLoginFailure = { | ||
reason: string; | ||
IDP: string | null; | ||
}; | ||
|
||
export class SendLoginFailureStrategy implements EventStrategy { | ||
performComputations({ reason, IDP }: SendLoginFailure): TrackedEvent<SendLoginFailure> { | ||
return { | ||
[EventPropertyType.TRACK]: { | ||
event_category: EventCategory.TECH, | ||
reason, | ||
IDP, | ||
}, | ||
}; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...es/pn-personafisica-login/src/utility/MixpanelUtils/Strategies/SendLoginMethodStrategy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { EventPropertyType, EventStrategy, TrackedEvent } from '@pagopa-pn/pn-commons'; | ||
|
||
type SendLoginMethod = { | ||
entityID: | ||
| 'cie' | ||
| 'posteid' | ||
| 'timid' | ||
| 'spiditalia' | ||
| 'sielteid' | ||
| 'namirialid' | ||
| 'lepidaid' | ||
| 'instesaid' | ||
| 'infocertid' | ||
| 'arubaid'; | ||
}; | ||
|
||
type SendLoginMethodReturn = { | ||
SEND_LOGIN_METHOD: string; | ||
}; | ||
|
||
export class SendLoginMethodStrategy implements EventStrategy { | ||
performComputations({ entityID }: SendLoginMethod): TrackedEvent<SendLoginMethodReturn> { | ||
return { | ||
[EventPropertyType.PROFILE]: { | ||
SEND_LOGIN_METHOD: entityID, | ||
}, | ||
}; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
packages/pn-personafisica-login/src/utility/MixpanelUtils/Strategies/UXScreenViewStrategy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { | ||
EventAction, | ||
EventCategory, | ||
EventPropertyType, | ||
EventStrategy, | ||
TrackedEvent, | ||
} from '@pagopa-pn/pn-commons'; | ||
|
||
export class UXScreenViewStrategy implements EventStrategy { | ||
performComputations(): TrackedEvent { | ||
return { | ||
[EventPropertyType.TRACK]: { | ||
event_category: EventCategory.UX, | ||
event_type: EventAction.SCREEN_VIEW, | ||
}, | ||
}; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...isica-login/src/utility/MixpanelUtils/Strategies/__test__/SendIDPSelectedStrategy.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { EventAction, EventCategory, EventPropertyType } from '@pagopa-pn/pn-commons'; | ||
|
||
import { SendIDPSelectedStrategy } from '../SendIDPSelectedStrategy'; | ||
|
||
describe('Mixpanel - Send IDP Selected Strategy', () => { | ||
it('should return IDP selected event', () => { | ||
const strategy = new SendIDPSelectedStrategy(); | ||
const event = strategy.performComputations({ | ||
SPID_IDP_ID: 'idp_id', | ||
SPID_IDP_NAME: 'idp_name', | ||
}); | ||
|
||
expect(event).toEqual({ | ||
[EventPropertyType.TRACK]: { | ||
event_category: EventCategory.UX, | ||
event_type: EventAction.ACTION, | ||
SPID_IDP_ID: 'idp_id', | ||
SPID_IDP_NAME: 'idp_name', | ||
}, | ||
}); | ||
}); | ||
}); |
21 changes: 21 additions & 0 deletions
21
...sica-login/src/utility/MixpanelUtils/Strategies/__test__/SendLoginFailureStrategy.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { EventCategory, EventPropertyType } from '@pagopa-pn/pn-commons'; | ||
|
||
import { SendLoginFailureStrategy } from '../SendLoginFailureStrategy'; | ||
|
||
describe('Mixpanel - Send Login Failure Strategy', () => { | ||
it('should return login failure event', () => { | ||
const strategy = new SendLoginFailureStrategy(); | ||
const event = strategy.performComputations({ | ||
reason: 'error', | ||
IDP: 'test', | ||
}); | ||
|
||
expect(event).toEqual({ | ||
[EventPropertyType.TRACK]: { | ||
event_category: EventCategory.TECH, | ||
reason: 'error', | ||
IDP: 'test', | ||
}, | ||
}); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
...isica-login/src/utility/MixpanelUtils/Strategies/__test__/SendLoginMethodStrategy.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { EventPropertyType } from '@pagopa-pn/pn-commons'; | ||
|
||
import { SendLoginMethodStrategy } from '../SendLoginMethodStrategy'; | ||
|
||
describe('Mixpanel - Send Login Method Strategy', () => { | ||
it('should return login method event', () => { | ||
const strategy = new SendLoginMethodStrategy(); | ||
const event = strategy.performComputations({ | ||
entityID: 'cie', | ||
}); | ||
|
||
expect(event).toEqual({ | ||
[EventPropertyType.PROFILE]: { | ||
SEND_LOGIN_METHOD: 'cie', | ||
}, | ||
}); | ||
}); | ||
}); |
17 changes: 17 additions & 0 deletions
17
...nafisica-login/src/utility/MixpanelUtils/Strategies/__test__/UXScreenViewStrategy.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { EventAction, EventCategory, EventPropertyType } from '@pagopa-pn/pn-commons'; | ||
|
||
import { UXScreenViewStrategy } from '../UXScreenViewStrategy'; | ||
|
||
describe('Mixpanel - UX Screen View Strategy', () => { | ||
it('should return UX screen view event', () => { | ||
const strategy = new UXScreenViewStrategy(); | ||
|
||
const uxScreenViewEvent = strategy.performComputations(); | ||
expect(uxScreenViewEvent).toEqual({ | ||
[EventPropertyType.TRACK]: { | ||
event_category: EventCategory.UX, | ||
event_type: EventAction.SCREEN_VIEW, | ||
}, | ||
}); | ||
}); | ||
}); |
36 changes: 36 additions & 0 deletions
36
...ersonafisica-login/src/utility/MixpanelUtils/__test__/PFLoginEventStrategyFactory.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { PFLoginEventsType } from '../../../models/PFLoginEventsType'; | ||
import PFLoginEventStrategyFactory from '../PFLoginEventStrategyFactory'; | ||
import { SendIDPSelectedStrategy } from '../Strategies/SendIDPSelectedStrategy'; | ||
import { SendLoginFailureStrategy } from '../Strategies/SendLoginFailureStrategy'; | ||
import { SendLoginMethodStrategy } from '../Strategies/SendLoginMethodStrategy'; | ||
import { UXScreenViewStrategy } from '../Strategies/UXScreenViewStrategy'; | ||
|
||
describe('Event Strategy Factory', () => { | ||
const factory = PFLoginEventStrategyFactory; | ||
|
||
it('should return UXScreenViewStrategy for SEND_LOGIN event', () => { | ||
expect(factory.getStrategy(PFLoginEventsType.SEND_LOGIN)).toBeInstanceOf(UXScreenViewStrategy); | ||
}); | ||
|
||
it('should return SendIDPSelectedStrategy for SEND_IDP_SELECTED event', () => { | ||
expect(factory.getStrategy(PFLoginEventsType.SEND_IDP_SELECTED)).toBeInstanceOf( | ||
SendIDPSelectedStrategy | ||
); | ||
}); | ||
|
||
it('should return SendLoginFailureStrategy for SEND_LOGIN_FAILURE event', () => { | ||
expect(factory.getStrategy(PFLoginEventsType.SEND_LOGIN_FAILURE)).toBeInstanceOf( | ||
SendLoginFailureStrategy | ||
); | ||
}); | ||
|
||
it('should return SendLoginMethodStrategy for SEND_LOGIN_METHOD event', () => { | ||
expect(factory.getStrategy(PFLoginEventsType.SEND_LOGIN_METHOD)).toBeInstanceOf( | ||
SendLoginMethodStrategy | ||
); | ||
}); | ||
|
||
it('should return null for unknown event type', () => { | ||
expect(factory.getStrategy('UNKNOWN_EVENT' as PFLoginEventsType)).toBeNull(); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.