diff --git a/src/components/Report/ReportView.tsx b/src/components/Report/ReportView.tsx index d88bea4e0d7784ca9abb68d90da940927882a9e2..bc6a42517d11ee66fddb3eedb988826d05f3da69 100644 --- a/src/components/Report/ReportView.tsx +++ b/src/components/Report/ReportView.tsx @@ -24,7 +24,7 @@ const ReportView: React.FC = () => { useEffect(() => { let subscribed = true - const updateUserProfileReport = async () => { + const updateProfileReport = async () => { if (reportNotification) { const profileService = new ProfileService(client) try { @@ -33,7 +33,7 @@ const ReportView: React.FC = () => { .then(updatedProfile => { if (subscribed && updatedProfile) { dispatch(updateProfile(updatedProfile)) - dispatch(toogleReportNotification(true)) + dispatch(toogleReportNotification(false)) } }) } catch (err) { @@ -41,7 +41,7 @@ const ReportView: React.FC = () => { } } } - updateUserProfileReport() + updateProfileReport() return () => { subscribed = false } diff --git a/src/models/index.ts b/src/models/index.ts index 9260f60bd223e30a149c6a20f1d2907b4285dcff..3cf6149eded356ff9fed9414f1db4797d9aa5543 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -14,4 +14,3 @@ export * from './report.model' export * from './timePeriod.model' export * from './trigger.model' export * from './userInstanceSettings.model' -export * from './userProfile.model' diff --git a/src/store/index.ts b/src/store/index.ts index 1631a46ce0908ae333b3e75ab0a421b2df591c07..cd5bb566ffe0d22a4b502040eee20f3c9171f8fc 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -2,6 +2,13 @@ import { combineReducers } from 'redux' import { globalReducer } from 'store/global/global.reducer' import { profileReducer } from './profile/profile.reducer' import { modalReducer } from 'store/modal/modal.reducer' +import { GlobalState, ModalState, Profile } from 'models' + +export interface EcolyoState { + global: GlobalState + profile: Profile + modal: ModalState +} export const ecolyoReducer = combineReducers({ global: globalReducer, @@ -9,4 +16,4 @@ export const ecolyoReducer = combineReducers({ modal: modalReducer, }) -export type EcolyoState = ReturnType<typeof ecolyoReducer> +// export type EcolyoState = ReturnType<typeof ecolyoReducer> diff --git a/src/targets/services/monthlyReportNotification.ts b/src/targets/services/monthlyReportNotification.ts index fa033821a94d04ac621515915ad2febb71ebcac1..4776e3fb8879f0d30e9b9f358835319bd47afb91 100644 --- a/src/targets/services/monthlyReportNotification.ts +++ b/src/targets/services/monthlyReportNotification.ts @@ -5,7 +5,7 @@ import { DateTime } from 'luxon' import { runService } from './service' import { createEmail } from './createEmail' import { TimePeriod } from 'models' -import UserProfileService from 'services/userProfile.service' +import ProfileService from 'services/profile.service' import ConsumptionService from 'services/consumption.service' import PerformanceIndicatorService from 'services/performanceIndicator.service' import MailService from 'services/mail.service' @@ -20,9 +20,9 @@ const monthlyReportNotification = async ({ client, }: MonthlyReportNotificationProps) => { log('info', 'Fetching user profile...') - const upm = new UserProfileService(client) - const userProfil = await upm.getUserProfile() - if (!userProfil || !userProfil.report.sendReportNotification) { + const upm = new ProfileService(client) + const userProfil = await upm.getProfile() + if (!userProfil || !userProfil.sendReportNotification) { log('info', 'End of process - Report Notification disabled in user profile') return } diff --git a/test/__mocks__/challengesTypeData.mock.ts b/test/__mocks__/challengesTypeData.mock.ts deleted file mode 100644 index b66d7217b14d635aa7e9daa451c2038a780f76fb..0000000000000000000000000000000000000000 --- a/test/__mocks__/challengesTypeData.mock.ts +++ /dev/null @@ -1,319 +0,0 @@ -import { ChallengeType } from 'models' - -export const challengesTypeData: ChallengeType[] = [ - { - id: 'CHA00000001', - _id: 'CHA00000001', - _type: 'com.grandlyon.ecolyo.challengetype', - _rev: '1-ae99679ff8a70a4de91071c9310df415', - cozyMetadata: { - createdAt: '2020-11-03T08:56:10.479Z', - createdByApp: 'ecolyo', - createdByAppVersion: '0.2.1', - metadataVersion: 1, - updatedAt: '2020-11-03T08:56:10.479Z', - updatedByApps: [ - { - date: '2020-11-03T08:56:10.479Z', - slug: 'ecolyo', - version: '0.2.1', - }, - ], - }, - description: "Connecter l'application Ecolyo à un distributeur d'énergie", - duration: { - days: 0, - }, - fluidTypes: [0, 1, 2], - level: 1, - relationships: { - availableEcogestures: { - data: [ - { - _id: '0085', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - { - _id: '0092', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - ], - }, - }, - title: 'Ecolyo Royal', - type: 1, - }, - { - id: 'CHA00000002', - _id: 'CHA00000002', - _type: 'com.grandlyon.ecolyo.challengetype', - _rev: '1-d38ff490140e8b18829d88791d987938', - cozyMetadata: { - createdAt: '2020-11-03T08:56:10.541Z', - createdByApp: 'ecolyo', - createdByAppVersion: '0.2.1', - metadataVersion: 1, - updatedAt: '2020-11-03T08:56:10.541Z', - updatedByApps: [ - { - date: '2020-11-03T08:56:10.541Z', - slug: 'ecolyo', - version: '0.2.1', - }, - ], - }, - description: - 'Et si dans les 7 prochains jours vous réussissiez à consommer moins que dans les 7 derniers ?', - duration: { - days: 7, - }, - fluidTypes: [0, 1, 2], - level: 2, - relationships: { - availableEcogestures: { - data: [ - { - _id: '0032', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - { - _id: '0034', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - { - _id: '0041', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - { - _id: '0042', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - { - _id: '0043', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - { - _id: '0045', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - { - _id: '0050', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - { - _id: '0058', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - { - _id: '0064', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - { - _id: '0066', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - { - _id: '0071', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - { - _id: '0078', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - { - _id: '0082', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - { - _id: '0093', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - ], - }, - }, - title: 'Coques en stock', - type: 0, - }, - { - id: 'CHA00000003', - _id: 'CHA00000003', - _type: 'com.grandlyon.ecolyo.challengetype', - _rev: '1-6cef2075f6e074123c836c69653423d6', - cozyMetadata: { - createdAt: '2020-11-03T08:56:10.571Z', - createdByApp: 'ecolyo', - createdByAppVersion: '0.2.1', - metadataVersion: 1, - updatedAt: '2020-11-03T08:56:10.571Z', - updatedByApps: [ - { - date: '2020-11-03T08:56:10.571Z', - slug: 'ecolyo', - version: '0.2.1', - }, - ], - }, - description: - 'Et si dans les 4 prochaines semaines vous réussissiez à consommer moins que dans les 4 dernières ?', - duration: { - days: 28, - }, - fluidTypes: [0, 1, 2], - level: 3, - relationships: { - availableEcogestures: { - data: [ - { - _id: '0032', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - { - _id: '0034', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - { - _id: '0041', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - { - _id: '0042', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - { - _id: '0043', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - { - _id: '0045', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - { - _id: '0050', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - { - _id: '0058', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - { - _id: '0064', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - { - _id: '0066', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - { - _id: '0071', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - { - _id: '0078', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - { - _id: '0082', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - { - _id: '0093', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - ], - }, - }, - title: 'Méga Coques en stock', - type: 0, - }, - { - id: 'CHA00000004', - _id: 'CHA00000004', - _type: 'com.grandlyon.ecolyo.challengetype', - _rev: '1-cabdfd17ee34fa66628055be718668e5', - cozyMetadata: { - createdAt: '2020-11-03T08:56:10.606Z', - createdByApp: 'ecolyo', - createdByAppVersion: '0.2.1', - metadataVersion: 1, - updatedAt: '2020-11-03T08:56:10.606Z', - updatedByApps: [ - { - date: '2020-11-03T08:56:10.606Z', - slug: 'ecolyo', - version: '0.2.1', - }, - ], - }, - description: - 'Et si dans les 7 prochains jours vous réussissiez à consommer moins que dans les 7 derniers', - duration: { - days: 7, - }, - fluidTypes: [0, 1, 2], - level: 901, - relationships: { - availableEcogestures: { - data: [ - { - _id: '0032', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - { - _id: '0034', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - { - _id: '0041', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - { - _id: '0042', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - { - _id: '0043', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - { - _id: '0045', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - { - _id: '0050', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - { - _id: '0058', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - { - _id: '0064', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - { - _id: '0066', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - { - _id: '0071', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - { - _id: '0078', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - { - _id: '0082', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - { - _id: '0093', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - ], - }, - }, - title: 'Winter is leaving', - type: 0, - }, -] diff --git a/test/__mocks__/userChallengeData.mock.ts b/test/__mocks__/userChallengeData.mock.ts deleted file mode 100644 index 3bf14e8631aa787e7e5f73786e5c7bc757a39c98..0000000000000000000000000000000000000000 --- a/test/__mocks__/userChallengeData.mock.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { DateTime, Duration } from 'luxon' -import { UserChallenge } from 'models' - -export const userChallengeData: UserChallenge = { - id: '4d9403218ef13e65b2e3a8ad1700c9f0', - startingDate: DateTime.fromISO('0001-01-01T00:00:00.000Z'), - endingDate: DateTime.fromISO('2020-11-17T00:00:00.000+01:00'), - state: 0, - selectedEcogestures: [ - { - fluidTypes: [0], - id: '0032', - longDescription: - 'Bien souvent les chauffe-eau sont réglés pour une température de 70 °C dans le ballon, ce qui n’est pas économique et peut même être dangereux ! Au-dessus de 60 °C vous augmentez aussi l’entartrage. L’eau ne doit pas être trop froide non plus pour éviter le risque de prolifération de micro-organismes comme les légionelles. A noter : parfois l’accès au réglage n’est pas directement visible… il faut alors retirer le capot en plastique situé sous le chauffe-eau pour y accéder.', - longName: 'Je règle la température de mon eau chaude entre 55 et 60 °C.', - nwh: 6, - pack: 8, - shortDescription: '', - shortName: 'Contrôle du nuage', - usage: 'Eau chaude sanitaire', - _id: '0032', - _rev: '1-67f1ea36efdd892c96bf64a8943154cd', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - ], - challengeType: { - id: 'CHA00000001', - type: 1, - title: 'Ecolyo Royal', - description: "Connecter l'application Ecolyo à un distributeur d'énergie", - level: 1, - duration: { - days: 0, - }, - fluidTypes: [0, 1, 2], - availableEcogestures: [ - { - fluidTypes: [0], - id: '0032', - longDescription: - 'Bien souvent les chauffe-eau sont réglés pour une température de 70 °C dans le ballon, ce qui n’est pas économique et peut même être dangereux ! Au-dessus de 60 °C vous augmentez aussi l’entartrage. L’eau ne doit pas être trop froide non plus pour éviter le risque de prolifération de micro-organismes comme les légionelles. A noter : parfois l’accès au réglage n’est pas directement visible… il faut alors retirer le capot en plastique situé sous le chauffe-eau pour y accéder.', - longName: - 'Je règle la température de mon eau chaude entre 55 et 60 °C.', - nwh: 6, - pack: 8, - shortDescription: '', - shortName: 'Contrôle du nuage', - usage: 'Eau chaude sanitaire', - _id: '0032', - _rev: '1-67f1ea36efdd892c96bf64a8943154cd', - _type: 'com.grandlyon.ecolyo.ecogesture', - }, - ], - }, - maxEnergy: -1, - currentEnergy: -1, - badge: 1, - fluidTypes: [0, 1, 2], -} diff --git a/test/__mocks__/userProfile.mock.ts b/test/__mocks__/userProfile.mock.ts deleted file mode 100644 index 3ebe2cd2cc8d44325bd935252706a24bfcafa05c..0000000000000000000000000000000000000000 --- a/test/__mocks__/userProfile.mock.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { DateTime } from 'luxon' - -export const userProfileData = { - _id: '4d9403218ef13e65b2e3a8ad1700bc41', - _rev: '16-57473da4fc26315247c217083175dfa0', - challengeTypeHash: '1136feb6185c7643e071d14180c0e95782aa4ba3', - ecogestureHash: '9798a0aaccb47cff906fc4931a2eff5f9371dd8b', - haveSeenFavoriteModal: false, - haveSeenOldFluidModal: false, - id: '4d9403218ef13e65b2e3a8ad1700bc41', - isFirstConnection: true, - level: 1, - notificationEcogesture: ['0085', '0092'], - report: { - haveSeenLastReport: true, - monthlyReportDate: DateTime.fromISO('2020-11-03T00:00:00.000+01:00'), - sendReportNotification: false, - }, -}