diff --git a/src/models/account.model.ts b/src/models/account.model.ts index e6f87335cd458822a6aac2606f2797b2cfc3240c..0e6ede6d7865eb4c45c99eca0d0e4dd1a64966bf 100644 --- a/src/models/account.model.ts +++ b/src/models/account.model.ts @@ -3,6 +3,7 @@ export interface Account extends AccountAttributes { id?: string _rev?: string _type?: string + // eslint-disable-next-line @typescript-eslint/no-explicit-any cozyMetadata?: Record<string, any> } @@ -12,6 +13,9 @@ export interface AccountAttributes { oauth?: AccountOAuthData identifier?: string state?: string | null + name?: string + // eslint-disable-next-line @typescript-eslint/no-explicit-any + oauth_callback_results?: Record<string, any> } export interface AccountAuthData { @@ -23,4 +27,6 @@ export interface AccountAuthData { export interface AccountOAuthData { access_token: string refresh_token: string + expires_at?: string + token_type?: string } diff --git a/src/models/trigger.model.ts b/src/models/trigger.model.ts index 75dbf3c9a92f5916aeed2b2a4e7b050db198f6d9..a8066eb4d9b971cb526c72eca3fa75b4a6beb064 100644 --- a/src/models/trigger.model.ts +++ b/src/models/trigger.model.ts @@ -1,5 +1,11 @@ export interface Trigger extends TriggerAttributes { _id: string + domain?: string + prefix?: string + debounce?: string + options?: string | null + // eslint-disable-next-line @typescript-eslint/no-explicit-any + cozyMetadata?: Record<string, any> } export interface TriggerAttributes { diff --git a/src/services/__mocks__/accountsData.json b/src/services/__mocks__/accountsData.json deleted file mode 100644 index 30bc62929829c2e728719778f867c6b11965dc40..0000000000000000000000000000000000000000 --- a/src/services/__mocks__/accountsData.json +++ /dev/null @@ -1,67 +0,0 @@ -[ - { - "_id": "88e68b8450cee09fe2f077610901094d", - "_rev": "1-88e68b8450cee09fe2f077610901094d", - "account_type": "enedisgrandlyon", - "name": "", - "oauth": { - "access_token": "MY_ACCESS_TOCKEN", - "expires_at": "2020-10-09T08:00:00.285910671+02:00", - "refresh_token": "", - "token_type": "Bearer" - }, - "oauth_callback_results": { - "issued_at": "1592232569642", - "refresh_token_issued_at": "1592232569642", - "scope": "/my_eneids_scope", - "usage_points_id": "" - }, - "cozyMetadata": { - "createdAt": "2020-11-10T16:42:11.132Z", - "metadataVersion": 1, - "updatedAt": "2020-11-10T16:42:11.132Z" - } - }, - { - "_id": "90e68b8450cee09fe2f077610901094d", - "id": "90e68b8450cee09fe2f077610901094d", - "account_type": "eglgrandlyon", - "auth": { - "credentials_encrypted": "bmFjbHI5OoL+VNCT6JDFYea1dNiBGGNJM1zY0M4uWcjhALJcQT9uk9p9WPD7+1OryCAoYf9eaSE=", - "login": "test" - }, - "identifier": "login", - "state": null, - "_rev": "1-90e68b8450cee09fe2f077610901094d", - "_type": "io.cozy.accounts", - "cozyMetadata": { - "createdAt": "2020-11-10T16:42:11.132Z", - "createdByApp": "ecolyo", - "createdByAppVersion": "0.2.1", - "metadataVersion": 1, - "updatedAt": "2020-11-10T16:42:11.132Z" - } - }, - { - "_id": "89e68b8450cee09fe2f077610901094d", - "_rev": "1-89e68b8450cee09fe2f077610901094d", - "account_type": "grdfgrandlyon", - "name": "", - "oauth": { - "access_token": "MY_ACCESS_TOCKEN", - "expires_at": "2020-10-09T08:00:00.285910671+02:00", - "refresh_token": "", - "token_type": "Bearer" - }, - "oauth_callback_results": { - "id_token": "MY_ID_TOCKEN", - "pce": "12345678987654", - "scope": "/my_grdf_scope" - }, - "cozyMetadata": { - "createdAt": "2020-11-10T16:42:11.132Z", - "metadataVersion": 1, - "updatedAt": "2020-11-10T16:42:11.132Z" - } - } -] diff --git a/src/services/__mocks__/challengesTypeData.json b/src/services/__mocks__/challengesTypeData.json deleted file mode 100644 index fa09ecdb08cdad58ebf186c52d096d9a0efd2ef0..0000000000000000000000000000000000000000 --- a/src/services/__mocks__/challengesTypeData.json +++ /dev/null @@ -1,314 +0,0 @@ -[ - { - "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/src/services/__mocks__/ecogesturesData.json b/src/services/__mocks__/ecogesturesData.json deleted file mode 100644 index 7cd185f6b2466cc98f8b1d50d2a3fd435af0dff1..0000000000000000000000000000000000000000 --- a/src/services/__mocks__/ecogesturesData.json +++ /dev/null @@ -1,44 +0,0 @@ -[ - { - "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" - }, - { - "fluidTypes": [1], - "id": "0034", - "longDescription": "Si on n'a pas transpiré la journée et qu'on ne sent pas mauvais, aucune obligation de se laver tous les jours. Il est même conseillé pour la flore de l'épiderme (la fameuse barrière contre certains pathogènes) de ne pas se laver tous les jours. Vous économiserez ainsi une quantité d'eau non négligeable.", - "longName": "Je décide de supprimer une douche par semaine.", - "nwh": 5, - "pack": 6, - "shortDescription": "", - "shortName": "Vague de sécheresse", - "usage": "Eau chaude sanitaire", - "_id": "0034", - "_rev": "1-ef7ddd778254e3b7d331a88fd17f606d", - "_type": "com.grandlyon.ecolyo.ecogesture" - }, - { - "fluidTypes": [1], - "id": "0037", - "longDescription": "Le terme 'mousseur' désigne la pièce qui est située au bout de votre robinet qui permet de canaliser le jet d’eau. La plupart des robinets sont équipés de mousseurs, mais ceux-ci ne réduisent pas le débit. Il existe différents types 'd’éco-mousseurs' qui limitent le débit à des niveaux variables. Choisissez votre matériel en fonction des besoins à chaque robinet : 5 L/min sera adapté pour un robinet servant uniquement à se laver les mains mais sera assez pénible si vous devez remplir un seau !", - "longName": "J'équipe mes robinets d’éco-mousseurs.", - "nwh": 4, - "pack": 0, - "shortDescription": "", - "shortName": "Super plombier", - "usage": "Eau chaude sanitaire", - "_id": "0037", - "_rev": "1-0b2761dd4aef79556c7aef144060fde6", - "_type": "com.grandlyon.ecolyo.ecogesture" - } -] diff --git a/src/services/__mocks__/fluidStatusData.json b/src/services/__mocks__/fluidStatusData.json deleted file mode 100644 index 3ebade9fd7c44b74db2c03b6682b28f830164e52..0000000000000000000000000000000000000000 --- a/src/services/__mocks__/fluidStatusData.json +++ /dev/null @@ -1,17 +0,0 @@ -[ - { - "fluidType": 0, - "status": "errored", - "lastDataDate": "2020-09-01T00:00:00.000" - }, - { - "fluidType": 1, - "status": "errored", - "lastDataDate": "2020-11-01T00:00:00.000" - }, - { - "fluidType": 2, - "status": "errored", - "lastDataDate": "2020-09-01T00:00:00.000" - } -] diff --git a/src/services/__mocks__/graphData.json b/src/services/__mocks__/graphData.json deleted file mode 100644 index 07923d9ae3a448525f7d961c0359daa28ecedb5d..0000000000000000000000000000000000000000 --- a/src/services/__mocks__/graphData.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "actualData": [ - { - "date": "2020-10-01T00:00:00.000+02:00", - "value": 69.18029999999999, - "valueDetail": [ - 45.127739999999996, - 0.9048899999999999, - 23.147669999999998 - ] - }, - { - "date": "2020-10-02T00:00:00.000+02:00", - "value": 61.65554999999999, - "valueDetail": [40.21918999999999, 0.8064649999999999, 20.629894999999998] - }, - { - "date": "2020-10-03T00:00:00.000+02:00", - "value": -1, - "valueDetail": null - } - ], - "comparisonData": [ - { - "date": "2020-09-01T00:00:00.000+02:00", - "value": 54.090509999999995, - "valueDetail": [35.284358, 0.707513, 18.098639] - }, - { - "date": "2020-09-02T00:00:00.000+02:00", - "value": 56.57427, - "valueDetail": [36.904565999999996, 0.740001, 18.929703] - }, - { - "date": "2020-09-03T00:00:00.000+02:00", - "value": -1, - "valueDetail": null - } - ] -} diff --git a/src/services/__mocks__/konnectorsData.json b/src/services/__mocks__/konnectorsData.json deleted file mode 100644 index 5aed97e6047b6a4ed98630238a27b1483a2e224b..0000000000000000000000000000000000000000 --- a/src/services/__mocks__/konnectorsData.json +++ /dev/null @@ -1,20 +0,0 @@ -[ - { - "_id": "io.cozy.konnectors/enedisgrandlyon", - "name": "Enedis", - "slug": "enedisgrandlyon", - "state": "ready" - }, - { - "_id": "io.cozy.konnectors/eglgrandlyon", - "name": "EGL", - "slug": "eglgrandlyon", - "state": "ready" - }, - { - "_id": "io.cozy.konnectors/grdfgrandlyon", - "name": "GRDF", - "slug": "grdfgrandlyon", - "state": "ready" - } -] \ No newline at end of file diff --git a/src/services/__mocks__/loadDayData.json b/src/services/__mocks__/loadDayData.json deleted file mode 100644 index fa0395bbc5433916ec65659446174f0e2baa5888..0000000000000000000000000000000000000000 --- a/src/services/__mocks__/loadDayData.json +++ /dev/null @@ -1,50 +0,0 @@ -[ - { - "id": "bf1ce3a5774e140056714c4c200c093e", - "_id": "bf1ce3a5774e140056714c4c200c093e", - "_type": "com.grandlyon.enedis.day", - "_rev": "1-4fe971dff073a3c3c6cc12a0246e642e", - "day": 1, - "hour": 0, - "load": 25.25, - "minute": 0, - "month": 11, - "year": 2020 - }, - { - "id": "cf7dc6f44a19b354f99b01ba1a0b4840", - "_id": "cf7dc6f44a19b354f99b01ba1a0b4840", - "_type": "com.grandlyon.enedis.day", - "_rev": "1-4fe971dff073a3c3c6cc12a0246e642e", - "day": 2, - "hour": 0, - "load": 20.5, - "minute": 0, - "month": 11, - "year": 2020 - }, - { - "id": "cf7dc6f44a19b354f99b01ba1a0b4840", - "_id": "cf7dc6f44a19b354f99b01ba1a0b4840", - "_type": "com.grandlyon.enedis.day", - "_rev": "1-4fe971dff073a3c3c6cc12a0246e642e", - "day": 3, - "hour": 0, - "load": 30.33, - "minute": 0, - "month": 11, - "year": 2020 - }, - { - "id": "cf7dc6f44a19b354f99b01ba1a0b4840", - "_id": "cf7dc6f44a19b354f99b01ba1a0b4840", - "_type": "com.grandlyon.enedis.day", - "_rev": "1-4fe971dff073a3c3c6cc12a0246e642e", - "day": 4, - "hour": 0, - "load": 1.22, - "minute": 0, - "month": 11, - "year": 2020 - } -] diff --git a/src/services/__mocks__/loadHourData.json b/src/services/__mocks__/loadHourData.json deleted file mode 100644 index 2804f3618144f80ebb4f8b59341e52394de75b44..0000000000000000000000000000000000000000 --- a/src/services/__mocks__/loadHourData.json +++ /dev/null @@ -1,62 +0,0 @@ -[ - { - "id": "cf7dc6f44a19b354f99b01ba1a0b4840", - "_id": "cf7dc6f44a19b354f99b01ba1a0b4840", - "_type": "com.grandlyon.enedis.hour", - "_rev": "1-4fe971dff073a3c3c6cc12a0246e642e", - "day": 2, - "hour": 0, - "load": 4.5, - "minute": 0, - "month": 11, - "year": 2020 - }, - { - "id": "cf7dc6f44a19b354f99b01ba1a0b4840", - "_id": "cf7dc6f44a19b354f99b01ba1a0b4840", - "_type": "com.grandlyon.enedis.hour", - "_rev": "1-4fe971dff073a3c3c6cc12a0246e642e", - "day": 2, - "hour": 1, - "load": 1.33, - "minute": 0, - "month": 11, - "year": 2020 - }, - { - "id": "cf7dc6f44a19b354f99b01ba1a0b4840", - "_id": "cf7dc6f44a19b354f99b01ba1a0b4840", - "_type": "com.grandlyon.enedis.hour", - "_rev": "1-4fe971dff073a3c3c6cc12a0246e642e", - "day": 2, - "hour": 2, - "load": 3.22, - "minute": 0, - "month": 11, - "year": 2020 - }, - { - "id": "cf7dc6f44a19b354f99b01ba1a0b4840", - "_id": "cf7dc6f44a19b354f99b01ba1a0b4840", - "_type": "com.grandlyon.enedis.hour", - "_rev": "1-4fe971dff073a3c3c6cc12a0246e642e", - "day": 2, - "hour": 3, - "load": 7.82, - "minute": 0, - "month": 11, - "year": 2020 - }, - { - "id": "cf7dc6f44a19b354f99b01ba1a0b4840", - "_id": "cf7dc6f44a19b354f99b01ba1a0b4840", - "_type": "com.grandlyon.enedis.hour", - "_rev": "1-4fe971dff073a3c3c6cc12a0246e642e", - "day": 2, - "hour": 4, - "load": 1.23, - "minute": 0, - "month": 11, - "year": 2020 - } -] diff --git a/src/services/__mocks__/loadMinuteData.json b/src/services/__mocks__/loadMinuteData.json deleted file mode 100644 index 65e093d9c7dd3905f72e49b35298e00e439a88db..0000000000000000000000000000000000000000 --- a/src/services/__mocks__/loadMinuteData.json +++ /dev/null @@ -1,74 +0,0 @@ -[ - { - "id": "bf1ce3a5774e140056714c4c200c093e", - "_id": "bf1ce3a5774e140056714c4c200c093e", - "_type": "com.grandlyon.enedis.minute", - "_rev": "1-4fe971dff073a3c3c6cc12a0246e642e", - "day": 1, - "hour": 23, - "load": 2.25, - "minute": 30, - "month": 11, - "year": 2020 - }, - { - "id": "cf7dc6f44a19b354f99b01ba1a0b4840", - "_id": "cf7dc6f44a19b354f99b01ba1a0b4840", - "_type": "com.grandlyon.enedis.minute", - "_rev": "1-4fe971dff073a3c3c6cc12a0246e642e", - "day": 2, - "hour": 0, - "load": 4.5, - "minute": 0, - "month": 11, - "year": 2020 - }, - { - "id": "cf7dc6f44a19b354f99b01ba1a0b4840", - "_id": "cf7dc6f44a19b354f99b01ba1a0b4840", - "_type": "com.grandlyon.enedis.minute", - "_rev": "1-4fe971dff073a3c3c6cc12a0246e642e", - "day": 2, - "hour": 0, - "load": 1.33, - "minute": 30, - "month": 11, - "year": 2020 - }, - { - "id": "cf7dc6f44a19b354f99b01ba1a0b4840", - "_id": "cf7dc6f44a19b354f99b01ba1a0b4840", - "_type": "com.grandlyon.enedis.minute", - "_rev": "1-4fe971dff073a3c3c6cc12a0246e642e", - "day": 2, - "hour": 1, - "load": 3.22, - "minute": 0, - "month": 11, - "year": 2020 - }, - { - "id": "cf7dc6f44a19b354f99b01ba1a0b4840", - "_id": "cf7dc6f44a19b354f99b01ba1a0b4840", - "_type": "com.grandlyon.enedis.minute", - "_rev": "1-4fe971dff073a3c3c6cc12a0246e642e", - "day": 2, - "hour": 1, - "load": 7.82, - "minute": 30, - "month": 11, - "year": 2020 - }, - { - "id": "cf7dc6f44a19b354f99b01ba1a0b4840", - "_id": "cf7dc6f44a19b354f99b01ba1a0b4840", - "_type": "com.grandlyon.enedis.minute", - "_rev": "1-4fe971dff073a3c3c6cc12a0246e642e", - "day": 2, - "hour": 2, - "load": 1.23, - "minute": 0, - "month": 11, - "year": 2020 - } -] diff --git a/src/services/__mocks__/loadMonthData.json b/src/services/__mocks__/loadMonthData.json deleted file mode 100644 index fd9d2458d76eeee6d3cceeb2d7bb03e8f47975cc..0000000000000000000000000000000000000000 --- a/src/services/__mocks__/loadMonthData.json +++ /dev/null @@ -1,38 +0,0 @@ -[ - { - "id": "bf1ce3a5774e140056714c4c200c093e", - "_id": "bf1ce3a5774e140056714c4c200c093e", - "_type": "com.grandlyon.enedis.month", - "_rev": "1-4fe971dff073a3c3c6cc12a0246e642e", - "day": 1, - "hour": 0, - "load": 125.25, - "minute": 0, - "month": 9, - "year": 2020 - }, - { - "id": "cf7dc6f44a19b354f99b01ba1a0b4840", - "_id": "cf7dc6f44a19b354f99b01ba1a0b4840", - "_type": "com.grandlyon.enedis.month", - "_rev": "1-4fe971dff073a3c3c6cc12a0246e642e", - "day": 1, - "hour": 0, - "load": 220.5, - "minute": 0, - "month": 10, - "year": 2020 - }, - { - "id": "cf7dc6f44a19b354f99b01ba1a0b4840", - "_id": "cf7dc6f44a19b354f99b01ba1a0b4840", - "_type": "com.grandlyon.enedis.month", - "_rev": "1-4fe971dff073a3c3c6cc12a0246e642e", - "day": 1, - "hour": 0, - "load": 130.33, - "minute": 0, - "month": 11, - "year": 2020 - } -] diff --git a/src/services/__mocks__/loadYearData.json b/src/services/__mocks__/loadYearData.json deleted file mode 100644 index 86180661bc2f561cecf5616b144d7b1caf7826b3..0000000000000000000000000000000000000000 --- a/src/services/__mocks__/loadYearData.json +++ /dev/null @@ -1,38 +0,0 @@ -[ - { - "id": "bf1ce3a5774e140056714c4c200c093e", - "_id": "bf1ce3a5774e140056714c4c200c093e", - "_type": "com.grandlyon.enedis.year", - "_rev": "1-4fe971dff073a3c3c6cc12a0246e642e", - "day": 1, - "hour": 0, - "load": 125.25, - "minute": 0, - "month": 1, - "year": 2018 - }, - { - "id": "cf7dc6f44a19b354f99b01ba1a0b4840", - "_id": "cf7dc6f44a19b354f99b01ba1a0b4840", - "_type": "com.grandlyon.enedis.year", - "_rev": "1-4fe971dff073a3c3c6cc12a0246e642e", - "day": 0, - "hour": 0, - "load": 220.5, - "minute": 0, - "month": 0, - "year": 2019 - }, - { - "id": "cf7dc6f44a19b354f99b01ba1a0b4840", - "_id": "cf7dc6f44a19b354f99b01ba1a0b4840", - "_type": "com.grandlyon.enedis.year", - "_rev": "1-4fe971dff073a3c3c6cc12a0246e642e", - "day": 1, - "hour": 0, - "load": 130.33, - "minute": 0, - "month": 1, - "year": 2020 - } -] diff --git a/src/services/__mocks__/triggerStateData.json b/src/services/__mocks__/triggerStateData.json deleted file mode 100644 index c0d19f45d3a1a6edaa92a3b4cbb0d85333e61c07..0000000000000000000000000000000000000000 --- a/src/services/__mocks__/triggerStateData.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "trigger_id": "238ba37b8bc8130bd323edb5c1005c8f", - "status": "errored", - "last_execution": "2020-11-13T10:03:16.4121536Z", - "last_executed_job_id": "238ba37b8bc8130bd323edb5c1006b56", - "last_failure": "2020-11-13T10:03:16.4121536Z", - "last_failed_job_id": "238ba37b8bc8130bd323edb5c1006b56", - "last_error": "fork/exec : no such file or directory", - "last_manual_execution": "2020-11-13T10:03:16.4121536Z", - "last_manual_job_id": "238ba37b8bc8130bd323edb5c1006b56" -} diff --git a/src/services/__mocks__/triggersData.json b/src/services/__mocks__/triggersData.json deleted file mode 100644 index 18a2b6f6d81fe1935fe1952a7b435138d0bced0e..0000000000000000000000000000000000000000 --- a/src/services/__mocks__/triggersData.json +++ /dev/null @@ -1,65 +0,0 @@ -[ - { - "_id": "3ed832cec67e6e0b2c6382edd30df11c", - "domain": "cozy.tools:8080", - "prefix": "cozy35ba44d2d1749e6f21646edce51e7190", - "type": "@cron", - "worker": "konnector", - "arguments": "0 47 8 * * *", - "debounce": "", - "options": null, - "message": { - "account": "88e68b8450cee09fe2f077610901094d", - "konnector": "enedisgrandlyon" - }, - "cozyMetadata": { - "doctypeVersion": "1", - "metadataVersion": 1, - "createdAt": "2020-10-09T08:00:00.6092798Z", - "createdByApp": "ecolyo", - "updatedAt": "2020-10-09T08:00:00.6092798Z" - } - }, - { - "_id": "5ed832cec67e6e0b2c6382edd30df11c", - "domain": "cozy.tools:8080", - "prefix": "cozy35ba44d2d1749e6f21646edce51e7190", - "type": "@cron", - "worker": "konnector", - "arguments": "0 47 8 * * *", - "debounce": "", - "options": null, - "message": { - "account": "90e68b8450cee09fe2f077610901094d", - "konnector": "eglgrandlyon" - }, - "cozyMetadata": { - "doctypeVersion": "1", - "metadataVersion": 1, - "createdAt": "2020-10-09T08:00:00.6092798Z", - "createdByApp": "ecolyo", - "updatedAt": "2020-10-09T08:00:00.6092798Z" - } - }, - { - "_id": "4ed832cec67e6e0b2c6382edd30df11c", - "domain": "cozy.tools:8080", - "prefix": "cozy35ba44d2d1749e6f21646edce51e7190", - "type": "@cron", - "worker": "konnector", - "arguments": "0 47 8 * * *", - "debounce": "", - "options": null, - "message": { - "account": "89e68b8450cee09fe2f077610901094d", - "konnector": "grdfgrandlyon" - }, - "cozyMetadata": { - "doctypeVersion": "1", - "metadataVersion": 1, - "createdAt": "2020-10-09T08:00:00.6092798Z", - "createdByApp": "ecolyo", - "updatedAt": "2020-10-09T08:00:00.6092798Z" - } - } -] \ No newline at end of file diff --git a/src/services/__mocks__/userChallengeData.json b/src/services/__mocks__/userChallengeData.json deleted file mode 100644 index 4ec0e4072ea9c0514845f2c9c6d2c75c14ebb55b..0000000000000000000000000000000000000000 --- a/src/services/__mocks__/userChallengeData.json +++ /dev/null @@ -1,53 +0,0 @@ -{ - "id": "4d9403218ef13e65b2e3a8ad1700c9f0", - "startingDate": "0001-01-01T00:00:00.000Z", - "endingDate": "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/src/services/account.service.spec.ts b/src/services/account.service.spec.ts index e1430004c45d4e668d3d9d62809c3ffe475cd07b..80030f0dc8fb802bba78b08d8cb78bb95d64a292 100644 --- a/src/services/account.service.spec.ts +++ b/src/services/account.service.spec.ts @@ -1,9 +1,9 @@ import { QueryResult } from 'cozy-client' import { AccountAuthData, Account } from 'models' -import mockClient from './__mocks__/client' +import mockClient from '../../test/__mocks__/client' import AccountService from './account.service' -import accountData from './__mocks__/accountsData.json' -import konnectorData from './__mocks__/konnectorsData.json' +import { accountsData } from '../../test/__mocks__/accountsData.mock' +import { konnectorsData } from '../../test/__mocks__/konnectorsData.mock' jest.mock('cozy-harvest-lib/dist/connections/accounts') import * as harvestLibAccounts from 'cozy-harvest-lib/dist/connections/accounts' @@ -11,32 +11,30 @@ const mockHavestLibAccounts = harvestLibAccounts as jest.Mocked< typeof harvestLibAccounts > -const mockAccounts: Account[] = JSON.parse(JSON.stringify(accountData)) - describe('Account service', () => { const accountService = new AccountService(mockClient) describe('createAccount method', () => { it('should return created account for login type', async () => { - mockHavestLibAccounts.createAccount.mockResolvedValueOnce(mockAccounts[2]) + mockHavestLibAccounts.createAccount.mockResolvedValueOnce(accountsData[2]) const mockAuthData: AccountAuthData = { login: 'login', password: 'password', } const result = await accountService.createAccount( - konnectorData[2], + konnectorsData[2], mockAuthData ) - expect(result).toEqual(mockAccounts[2]) + expect(result).toEqual(accountsData[2]) }) }) describe('getAccount method', () => { it('should return account', async () => { - mockHavestLibAccounts.fetchAccount.mockResolvedValueOnce(mockAccounts[2]) + mockHavestLibAccounts.fetchAccount.mockResolvedValueOnce(accountsData[2]) const mockId = 'io.cozy.konnectors/eglgrandlyon' const result = await accountService.getAccount(mockId) - expect(result).toBe(mockAccounts[2]) + expect(result).toBe(accountsData[2]) }) it('should throw error when fetchAccount unsuccessfully', async () => { @@ -53,7 +51,7 @@ describe('Account service', () => { describe('getAccountByType method', () => { it('should return account with account_type equals to eglgrandlyon', async () => { const mockQueryResult: QueryResult<Account[]> = { - data: [mockAccounts[2]], + data: [accountsData[2]], bookmark: '', next: false, skip: 0, @@ -61,7 +59,7 @@ describe('Account service', () => { mockClient.query.mockResolvedValueOnce(mockQueryResult) const mockType = 'eglgrandlyon' const result = await accountService.getAccountByType(mockType) - expect(result).toEqual(mockAccounts[2]) + expect(result).toEqual(accountsData[2]) }) it('should return null when no account find', async () => { @@ -80,15 +78,15 @@ describe('Account service', () => { describe('updateAccount method', () => { it('should return updated account when updateAccount successfully', async () => { - mockHavestLibAccounts.updateAccount.mockResolvedValueOnce(mockAccounts[2]) - const result = await accountService.updateAccount(mockAccounts[2]) - expect(result).toEqual(mockAccounts[2]) + mockHavestLibAccounts.updateAccount.mockResolvedValueOnce(accountsData[2]) + const result = await accountService.updateAccount(accountsData[2]) + expect(result).toEqual(accountsData[2]) }) it('should throw error when updateAccount unsuccessfully', async () => { mockHavestLibAccounts.updateAccount.mockRejectedValueOnce(new Error()) try { - await accountService.updateAccount(mockAccounts[2]) + await accountService.updateAccount(accountsData[2]) } catch (error) { expect(error).toEqual(new Error('Update account failed')) } @@ -97,15 +95,15 @@ describe('Account service', () => { describe('deleteAccount method', () => { it('should return true when destroy successfully', async () => { - mockHavestLibAccounts.deleteAccount.mockResolvedValueOnce(mockAccounts[2]) - const result = await accountService.deleteAccount(mockAccounts[2]) + mockHavestLibAccounts.deleteAccount.mockResolvedValueOnce(accountsData[2]) + const result = await accountService.deleteAccount(accountsData[2]) expect(result).toBe(true) }) it('should throw error when destroy unsuccessfully', async () => { mockHavestLibAccounts.deleteAccount.mockRejectedValueOnce(new Error()) try { - await accountService.deleteAccount(mockAccounts[2]) + await accountService.deleteAccount(accountsData[2]) } catch (error) { expect(error).toEqual(new Error('Delete account failed')) } diff --git a/src/services/connection.service.spec.ts b/src/services/connection.service.spec.ts index 80abf8afd491c8e3e4330f528bc9e66957e617cd..657c4d15fa1a97563b6d84826735b1660490e424 100644 --- a/src/services/connection.service.spec.ts +++ b/src/services/connection.service.spec.ts @@ -1,8 +1,8 @@ import ConnectionService from './connection.service' -import mockClient from './__mocks__/client' -import konnectorsData from './__mocks__/konnectorsData.json' -import accountsData from './__mocks__/accountsData.json' -import triggerData from './__mocks__/triggersData.json' +import mockClient from '../../test/__mocks__/client' +import { konnectorsData } from '../../test/__mocks__/konnectorsData.mock' +import { accountsData } from '../../test/__mocks__/accountsData.mock' +import { triggersData } from '../../test/__mocks__/triggersData.mock' const mockGetKonnector = jest.fn() jest.mock('./konnector.service', () => { @@ -38,8 +38,8 @@ describe('Connection service', () => { it('shoud return created Trigger', async () => { mockGetKonnector.mockResolvedValueOnce(konnectorsData[0]) mockCreateAccount.mockResolvedValueOnce(accountsData[0]) - mockCreateTrigger.mockResolvedValueOnce(triggerData[0]) - const mockResult = { account: accountsData[0], trigger: triggerData[0] } + mockCreateTrigger.mockResolvedValueOnce(triggersData[0]) + const mockResult = { account: accountsData[0], trigger: triggersData[0] } const result = await connectionService.connectNewUser( konnectorsData[0]._id, 'login', diff --git a/src/services/consumption.service.spec.ts b/src/services/consumption.service.spec.ts index 271e2f4d04fcbfee7d8119b2f93012d83448714e..f1f36e4c07fe4ef609613331bc8b60a4c17ced68 100644 --- a/src/services/consumption.service.spec.ts +++ b/src/services/consumption.service.spec.ts @@ -1,5 +1,5 @@ import ConsumptionDataManager from './consumption.service' -import mockClient from './__mocks__/client' +import mockClient from '../../test/__mocks__/client' import { TimeStep } from 'enum/timeStep.enum' import { DateTime } from 'luxon' import { FluidType } from 'enum/fluid.enum' @@ -63,7 +63,6 @@ describe('Consuption service', () => { expect(result).toBeNull() }) it('shoud return a mapped data for one fluid', async () => { - console.log(fluidTypes) mockFetchFluidData.mockResolvedValueOnce(mockFetchDataActual) mockFetchFluidData.mockResolvedValueOnce(mockFetchDataComparison) const mockResult = { diff --git a/src/services/consumptionValidator.service.spec.ts b/src/services/consumptionValidator.service.spec.ts index 40b8216a1215d6298f73491c99c8af616a1fa836..063229635c80fd8adfb5b4dc5d299eb2db497aae 100644 --- a/src/services/consumptionValidator.service.spec.ts +++ b/src/services/consumptionValidator.service.spec.ts @@ -1,9 +1,8 @@ import ConsumptionValidatorService from './consumptionValidator.service' -import mockClient from './__mocks__/client' import { TimeStep } from 'enum/timeStep.enum' import { DateTime } from 'luxon' import { FluidType } from 'enum/fluid.enum' -import { Dataload, TimePeriod } from 'models' +import { TimePeriod } from 'models' const mockTimePeriod: TimePeriod = { startDate: DateTime.fromISO('2020-10-01T00:00:00.000'), diff --git a/src/services/ecogesture.service.spec.ts b/src/services/ecogesture.service.spec.ts index c50a2aafae5da1be11570f2af8a912aa9db5b15d..606feb388d0402d14083c292644e327a3938fa8d 100644 --- a/src/services/ecogesture.service.spec.ts +++ b/src/services/ecogesture.service.spec.ts @@ -1,8 +1,8 @@ import { QueryResult } from 'cozy-client' import { Ecogesture } from 'models' import EcogestureService from './ecogesture.service' -import mockClient from './__mocks__/client' -import ecogesturesData from './__mocks__/ecogesturesData.json' +import mockClient from '../../test/__mocks__/client' +import { ecogesturesData } from '../../test/__mocks__/ecogesturesData.mock' describe('Ecogesture service', () => { const ecogestureService = new EcogestureService(mockClient) diff --git a/src/services/fluid.service.spec.ts b/src/services/fluid.service.spec.ts index 1b856e7b956b684d57f9738d127975d432088afa..4f6e0423f60fb34d41385853e4fc368cd447fff7 100644 --- a/src/services/fluid.service.spec.ts +++ b/src/services/fluid.service.spec.ts @@ -1,9 +1,9 @@ import FluidService from './fluid.service' -import mockClient from './__mocks__/client' -import accountsData from './__mocks__/accountsData.json' -import konnectorsData from './__mocks__/konnectorsData.json' -import triggersData from './__mocks__/triggersData.json' -import triggerStateData from './__mocks__/triggerStateData.json' +import mockClient from '../../test/__mocks__/client' +import { accountsData } from '../../test/__mocks__/accountsData.mock' +import { konnectorsData } from '../../test/__mocks__/konnectorsData.mock' +import { triggersData } from '../../test/__mocks__/triggersData.mock' +import { triggerStateData } from '../../test/__mocks__/triggerStateData.mock' import { DateTime } from 'luxon' import { FluidType } from 'enum/fluid.enum' import { FluidStatus } from 'models' diff --git a/src/services/initialization.service.spec.ts b/src/services/initialization.service.spec.ts index 4dc7a5f94781113d04ad133c7e3ee3aca4f178ed..128632363310530d24e7bc9044bc4e9d2d36e674 100644 --- a/src/services/initialization.service.spec.ts +++ b/src/services/initialization.service.spec.ts @@ -1,12 +1,13 @@ import { QueryResult } from 'cozy-client' -import { DateTime, Duration } from 'luxon' +import { DateTime } from 'luxon' import { FluidStatus, UserChallenge, UserProfile } from 'models' import InitializationService from './initialization.service' -import mockClient from './__mocks__/client' -import mockEcogesturesEntityData from './__mocks__/ecogesturesData.json' -import mockChallengesTypeEntityData from './__mocks__/challengesTypeData.json' -import mockUserChallengeEntityData from './__mocks__/userChallengeData.json' -import { userProfileEntityData } from './__mocks__/userProfile.mock' +import mockClient from '../../test/__mocks__/client' +import { ecogesturesData } from '../../test/__mocks__/ecogesturesData.mock' +import { challengesTypeData } from '../../test/__mocks__/challengesTypeData.mock' +import { userChallengeData } from '../../test/__mocks__/userChallengeData.mock' +import { userProfileEntityData } from '../../test/__mocks__/userProfile.mock' +import { fluidStatusData } from '../../test/__mocks__/fluidStatusData.mock' import challengeTypeData from 'db/challengeTypeData.json' import ecogestureData from 'db/ecogestureData.json' @@ -93,18 +94,6 @@ jest.mock('./fluid.service', () => { }) }) -const mockUserChallengeData: UserChallenge = { - ...mockUserChallengeEntityData, - startingDate: DateTime.fromISO(mockUserChallengeEntityData.startingDate), - endingDate: DateTime.fromISO(mockUserChallengeEntityData.endingDate), - challengeType: { - ...mockUserChallengeEntityData.challengeType, - duration: Duration.fromObject( - mockUserChallengeEntityData.challengeType.duration - ), - }, -} - describe('Initialization service', () => { const initializationService = new InitializationService(mockClient) @@ -250,7 +239,7 @@ describe('Initialization service', () => { it('shoud throw an error when challengeType should be created and created challenge number does not match', async () => { mockGetAllChallengeTypeEntities .mockResolvedValueOnce(null) - .mockResolvedValueOnce(mockChallengesTypeEntityData) + .mockResolvedValueOnce(challengesTypeData) const mockQueryResult: QueryResult<boolean> = { data: true, bookmark: '', @@ -334,7 +323,7 @@ describe('Initialization service', () => { it('shoud throw an error when challengeType should be updated and created challenge number does not match', async () => { mockGetAllChallengeTypeEntities .mockResolvedValueOnce(challengeTypeData) - .mockResolvedValueOnce(mockChallengesTypeEntityData) + .mockResolvedValueOnce(challengesTypeData) mockDeleteChallengeTypeEntities.mockResolvedValue(true) const mockQueryResult: QueryResult<boolean> = { data: true, @@ -425,7 +414,7 @@ describe('Initialization service', () => { it('shoud throw an error when ecogestures should be created and created ecogestures number does not match', async () => { mockGetAllEcogestures .mockResolvedValueOnce(null) - .mockResolvedValueOnce(mockEcogesturesEntityData) + .mockResolvedValueOnce(ecogesturesData) const mockQueryResult: QueryResult<boolean> = { data: true, bookmark: '', @@ -503,7 +492,7 @@ describe('Initialization service', () => { it('shoud throw an error when ecogestures should be updated and created ecogestures number does not match', async () => { mockGetAllEcogestures .mockResolvedValueOnce(ecogestureData) - .mockResolvedValueOnce(mockEcogesturesEntityData) + .mockResolvedValueOnce(ecogesturesData) mockDeleteAllEcogestures.mockResolvedValue(true) const mockQueryResult: QueryResult<boolean> = { data: true, @@ -636,15 +625,15 @@ describe('Initialization service', () => { describe('initUserChallenge method', () => { it('shoud return userchallenges when userchallenges already existing', async () => { - mockGetAllUserChallenges.mockResolvedValueOnce(mockUserChallengeData) + mockGetAllUserChallenges.mockResolvedValueOnce(userChallengeData) const result: UserChallenge[] = await initializationService.initUserChallenge() - expect(result).toEqual(mockUserChallengeData) + expect(result).toEqual(userChallengeData) }) it('shoud return userchallenges when userchallenge should be created', async () => { mockGetAllUserChallenges .mockResolvedValueOnce([]) - .mockResolvedValueOnce(mockUserChallengeData) + .mockResolvedValueOnce(userChallengeData) const mockQueryResult: QueryResult<boolean> = { data: true, bookmark: '', @@ -653,7 +642,7 @@ describe('Initialization service', () => { } mockClient.create.mockResolvedValue(mockQueryResult) const result: UserChallenge[] = await initializationService.initUserChallenge() - expect(result).toEqual(mockUserChallengeData) + expect(result).toEqual(userChallengeData) }) it('shoud throw error when userchallenge should be created and userchallenge is not updated', async () => { @@ -731,26 +720,9 @@ describe('Initialization service', () => { describe('initFluidStatus method', () => { it('shoud return all fluids type', async () => { - const mockFluidStatusData: FluidStatus[] = [ - { - fluidType: 0, - status: 'errored', - lastDataDate: DateTime.fromISO('2020-09-01T00:00:00.000'), - }, - { - fluidType: 1, - status: 'errored', - lastDataDate: DateTime.fromISO('2020-09-01T00:00:00.000'), - }, - { - fluidType: 2, - status: 'errored', - lastDataDate: DateTime.fromISO('2020-09-01T00:00:00.000'), - }, - ] - mockGetFluidStatus.mockResolvedValueOnce(mockFluidStatusData) + mockGetFluidStatus.mockResolvedValueOnce(fluidStatusData) const result: FluidStatus[] = await initializationService.initFluidStatus() - expect(result).toEqual(mockFluidStatusData) + expect(result).toEqual(fluidStatusData) }) it('shoud throw an error when null is retrieved as status', async () => { @@ -778,9 +750,9 @@ describe('Initialization service', () => { describe('initCurrentChallenge method', () => { it('should return updated current Challenge', async () => { - mockGetCurrentChallenge.mockResolvedValueOnce(mockUserChallengeData) + mockGetCurrentChallenge.mockResolvedValueOnce(userChallengeData) const mockUpdatedUserChallenge = { - ...mockUserChallengeData, + ...userChallengeData, maxmaxEnergy: 100, } mockUpdateCurrentChallengeProgress.mockResolvedValueOnce( @@ -808,7 +780,7 @@ describe('Initialization service', () => { }) it('should throw error if current challenge failed to be updated', async () => { - mockGetCurrentChallenge.mockResolvedValueOnce(mockUserChallengeData) + mockGetCurrentChallenge.mockResolvedValueOnce(userChallengeData) mockUpdateCurrentChallengeProgress.mockRejectedValueOnce(new Error()) let error try { @@ -824,7 +796,7 @@ describe('Initialization service', () => { it('should return true if isCurrentChallengeOver return true', async () => { mockIsCurrentChallengeOver.mockResolvedValueOnce(true) const result: boolean = await initializationService.isCurrentChallengeOver( - mockUserChallengeData + userChallengeData ) expect(result).toBe(true) }) @@ -832,7 +804,7 @@ describe('Initialization service', () => { it('should return false if isCurrentChallengeOver return false', async () => { mockIsCurrentChallengeOver.mockResolvedValueOnce(false) const result: boolean = await initializationService.isCurrentChallengeOver( - mockUserChallengeData + userChallengeData ) expect(result).toBe(false) }) @@ -840,11 +812,11 @@ describe('Initialization service', () => { describe('checkAchievement method', () => { it('should return UserChallenge from the id', async () => { - mockCheckAchievement.mockResolvedValueOnce(mockUserChallengeData) + mockCheckAchievement.mockResolvedValueOnce(userChallengeData) const result: UserChallenge | null = await initializationService.checkAchievement( '4d9403218ef13e65b2e3a8ad1700c9f0' ) - expect(result).toEqual(mockUserChallengeData) + expect(result).toEqual(userChallengeData) }) }) }) diff --git a/src/services/konnector.service.spec.ts b/src/services/konnector.service.spec.ts index 9ef12d71d9aeb094da54439a5e583dc8f3e805df..4cead0793814810c2361092ec11349887b6cba67 100644 --- a/src/services/konnector.service.spec.ts +++ b/src/services/konnector.service.spec.ts @@ -1,10 +1,10 @@ import KonnectorService from './konnector.service' import { Konnector } from 'models' -import mockClient from './__mocks__/client' -import accountsData from './__mocks__/accountsData.json' -import konnectorsData from './__mocks__/konnectorsData.json' -import triggersData from './__mocks__/triggersData.json' -import triggerStateData from './__mocks__/triggerStateData.json' +import mockClient from '../../test/__mocks__/client' +import { accountsData } from '../../test/__mocks__/accountsData.mock' +import { konnectorsData } from '../../test/__mocks__/konnectorsData.mock' +import { triggersData } from '../../test/__mocks__/triggersData.mock' +import { triggerStateData } from '../../test/__mocks__/triggerStateData.mock' import { QueryResult } from 'cozy-client' const mockGetTrigger = jest.fn() diff --git a/src/services/konnectorStatus.service.spec.ts b/src/services/konnectorStatus.service.spec.ts index 212c173c9253669667a03b46bdffdc9e39b4a5cc..62b694902837c7429b879529c54628e068df658b 100644 --- a/src/services/konnectorStatus.service.spec.ts +++ b/src/services/konnectorStatus.service.spec.ts @@ -1,6 +1,6 @@ import KonnectorStatusService from './konnectorStatus.service' -import mockClient from './__mocks__/client' -import accountsData from './__mocks__/accountsData.json' +import mockClient from '../../test/__mocks__/client' +import { accountsData } from '../../test/__mocks__/accountsData.mock' const mockGetAccountByType = jest.fn() jest.mock('./account.service', () => { diff --git a/src/services/mail.service.spec.ts b/src/services/mail.service.spec.ts index 58532aa2cd1afaf09f5ba7cef5caf4d0bf592c2c..34150672274a13a74bb505ea3d2f4ead1652b79f 100644 --- a/src/services/mail.service.spec.ts +++ b/src/services/mail.service.spec.ts @@ -1,5 +1,5 @@ import MailService from './mail.service' -import mockClient from './__mocks__/client' +import mockClient from '../../test/__mocks__/client' describe('Mail service', () => { const mailService = new MailService() diff --git a/src/services/queryRunner.service.spec.ts b/src/services/queryRunner.service.spec.ts index 6228f83f6a950f40e5b6e34e556747ee5ad0e86f..cb1c2d72a513387fcdf07ad1e5452a1769316fe1 100644 --- a/src/services/queryRunner.service.spec.ts +++ b/src/services/queryRunner.service.spec.ts @@ -4,12 +4,12 @@ import { TimeStep } from 'enum/timeStep.enum' import { DateTime } from 'luxon' import { Dataload, DataloadEntity } from 'models' import QueryRunner from './queryRunner.service' -import mockClient from './__mocks__/client' -import loadYearData from './__mocks__/loadYearData.json' -import loadMonthData from './__mocks__/loadMonthData.json' -import loadDayData from './__mocks__/loadDayData.json' -import loadHourData from './__mocks__/loadHourData.json' -import loadMinuteData from './__mocks__/loadMinuteData.json' +import mockClient from '../../test/__mocks__/client' +import { loadYearData } from '../../test/__mocks__/loadYearData.mock' +import { loadMonthData } from '../../test/__mocks__/loadMonthData.mock' +import { loadDayData } from '../../test/__mocks__/loadDayData.mock' +import { loadHourData } from '../../test/__mocks__/loadHourData.mock' +import { loadMinuteData } from '../../test/__mocks__/loadMinuteData.mock' describe('queryRunner service', () => { const queryRunner = new QueryRunner(mockClient) diff --git a/src/services/triggers.service.spec.ts b/src/services/triggers.service.spec.ts index 3ebc651476acf0cbf82ae8379720ce7effe4f785..43ae414b73e9f47234ac81d8d23149fd7d6d058f 100644 --- a/src/services/triggers.service.spec.ts +++ b/src/services/triggers.service.spec.ts @@ -1,11 +1,11 @@ import { QueryResult } from 'cozy-client' import { Trigger, TriggerState } from 'models' -import mockClient from './__mocks__/client' +import mockClient from '../../test/__mocks__/client' import TriggerService from './triggers.service' -import accountsData from './__mocks__/accountsData.json' -import konnectorsData from './__mocks__/konnectorsData.json' -import triggersData from './__mocks__/triggersData.json' -import triggerStateData from './__mocks__/triggerStateData.json' +import { accountsData } from '../../test/__mocks__/accountsData.mock' +import { konnectorsData } from '../../test/__mocks__/konnectorsData.mock' +import { triggersData } from '../../test/__mocks__/triggersData.mock' +import { triggerStateData } from '../../test/__mocks__/triggerStateData.mock' const mockCreateTrigger = jest.fn() jest.mock('cozy-harvest-lib/dist/connections/triggers', () => { diff --git a/src/services/userProfile.service.spec.ts b/src/services/userProfile.service.spec.ts index 161e457b298f132c13e3eecdafe873a84d8591d2..9bbd772fb7e734f28f26c1db39a912aadd04dd72 100644 --- a/src/services/userProfile.service.spec.ts +++ b/src/services/userProfile.service.spec.ts @@ -1,7 +1,7 @@ import UserProfileService from './userProfile.service' import { Client, QueryResult } from 'cozy-client' import { UserProfile } from 'models' -import { userProfileEntityData } from './__mocks__/userProfile.mock' +import { userProfileEntityData } from '../../test/__mocks__/userProfile.mock' import { DateTime } from 'luxon' const mockClient = ({ diff --git a/test/__mocks__/accountsData.mock.ts b/test/__mocks__/accountsData.mock.ts new file mode 100644 index 0000000000000000000000000000000000000000..a4f24d97273ad4d134736aecdb14aa8b7f8ac637 --- /dev/null +++ b/test/__mocks__/accountsData.mock.ts @@ -0,0 +1,71 @@ +/* eslint-disable @typescript-eslint/camelcase */ +import { Account } from 'models' + +export const accountsData: Account[] = [ + { + _id: '88e68b8450cee09fe2f077610901094d', + _rev: '1-88e68b8450cee09fe2f077610901094d', + account_type: 'enedisgrandlyon', + name: '', + oauth: { + access_token: 'MY_ACCESS_TOCKEN', + expires_at: '2020-10-09T08:00:00.285910671+02:00', + refresh_token: '', + token_type: 'Bearer', + }, + oauth_callback_results: { + issued_at: '1592232569642', + refresh_token_issued_at: '1592232569642', + scope: '/my_eneids_scope', + usage_points_id: '', + }, + cozyMetadata: { + createdAt: '2020-11-10T16:42:11.132Z', + metadataVersion: 1, + updatedAt: '2020-11-10T16:42:11.132Z', + }, + }, + { + _id: '90e68b8450cee09fe2f077610901094d', + id: '90e68b8450cee09fe2f077610901094d', + account_type: 'eglgrandlyon', + auth: { + credentials_encrypted: + 'bmFjbHI5OoL+VNCT6JDFYea1dNiBGGNJM1zY0M4uWcjhALJcQT9uk9p9WPD7+1OryCAoYf9eaSE=', + login: 'test', + }, + identifier: 'login', + state: null, + _rev: '1-90e68b8450cee09fe2f077610901094d', + _type: 'io.cozy.accounts', + cozyMetadata: { + createdAt: '2020-11-10T16:42:11.132Z', + createdByApp: 'ecolyo', + createdByAppVersion: '0.2.1', + metadataVersion: 1, + updatedAt: '2020-11-10T16:42:11.132Z', + }, + }, + { + _id: '89e68b8450cee09fe2f077610901094d', + _rev: '1-89e68b8450cee09fe2f077610901094d', + account_type: 'grdfgrandlyon', + name: '', + oauth: { + access_token: 'MY_ACCESS_TOCKEN', + expires_at: '2020-10-09T08:00:00.285910671+02:00', + refresh_token: '', + token_type: 'Bearer', + }, + oauth_callback_results: { + id_token: 'MY_ID_TOCKEN', + pce: '12345678987654', + scope: '/my_grdf_scope', + }, + cozyMetadata: { + createdAt: '2020-11-10T16:42:11.132Z', + metadataVersion: 1, + updatedAt: '2020-11-10T16:42:11.132Z', + }, + }, +] diff --git a/test/__mocks__/challengesTypeData.mock.ts b/test/__mocks__/challengesTypeData.mock.ts new file mode 100644 index 0000000000000000000000000000000000000000..b66d7217b14d635aa7e9daa451c2038a780f76fb --- /dev/null +++ b/test/__mocks__/challengesTypeData.mock.ts @@ -0,0 +1,319 @@ +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/src/services/__mocks__/client.ts b/test/__mocks__/client.ts similarity index 100% rename from src/services/__mocks__/client.ts rename to test/__mocks__/client.ts diff --git a/test/__mocks__/datachartData.mock.ts b/test/__mocks__/datachartData.mock.ts new file mode 100644 index 0000000000000000000000000000000000000000..52491972d93c34793f18f65117b463166e9c42d0 --- /dev/null +++ b/test/__mocks__/datachartData.mock.ts @@ -0,0 +1,39 @@ +import { Datachart } from 'models' +import { DateTime } from 'luxon' + +export const graphData: Datachart = { + actualData: [ + { + date: DateTime.fromISO('2020-10-01T00:00:00.000'), + value: 69.18029999999999, + valueDetail: [45.127739999999996, 0.9048899999999999, 23.147669999999998], + }, + { + date: DateTime.fromISO('2020-10-02T00:00:00.000'), + value: 61.65554999999999, + valueDetail: [40.21918999999999, 0.8064649999999999, 20.629894999999998], + }, + { + date: DateTime.fromISO('2020-10-03T00:00:00.000'), + value: -1, + valueDetail: null, + }, + ], + comparisonData: [ + { + date: DateTime.fromISO('2020-09-01T00:00:00.000'), + value: 54.090509999999995, + valueDetail: [35.284358, 0.707513, 18.098639], + }, + { + date: DateTime.fromISO('2020-09-02T00:00:00.000'), + value: 56.57427, + valueDetail: [36.904565999999996, 0.740001, 18.929703], + }, + { + date: DateTime.fromISO('2020-09-03T00:00:00.000'), + value: -1, + valueDetail: null, + }, + ], +} diff --git a/test/__mocks__/ecogesturesData.mock.ts b/test/__mocks__/ecogesturesData.mock.ts new file mode 100644 index 0000000000000000000000000000000000000000..422803d782862d5f5ee9de9c4b2147c25fdd2d49 --- /dev/null +++ b/test/__mocks__/ecogesturesData.mock.ts @@ -0,0 +1,49 @@ +import { Ecogesture } from 'models' + +export const ecogesturesData: Ecogesture[] = [ + { + 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', + }, + { + fluidTypes: [1], + id: '0034', + longDescription: + "Si on n'a pas transpiré la journée et qu'on ne sent pas mauvais, aucune obligation de se laver tous les jours. Il est même conseillé pour la flore de l'épiderme (la fameuse barrière contre certains pathogènes) de ne pas se laver tous les jours. Vous économiserez ainsi une quantité d'eau non négligeable.", + longName: 'Je décide de supprimer une douche par semaine.', + nwh: 5, + pack: 6, + shortDescription: '', + shortName: 'Vague de sécheresse', + usage: 'Eau chaude sanitaire', + _id: '0034', + _rev: '1-ef7ddd778254e3b7d331a88fd17f606d', + _type: 'com.grandlyon.ecolyo.ecogesture', + }, + { + fluidTypes: [1], + id: '0037', + longDescription: + "Le terme 'mousseur' désigne la pièce qui est située au bout de votre robinet qui permet de canaliser le jet d’eau. La plupart des robinets sont équipés de mousseurs, mais ceux-ci ne réduisent pas le débit. Il existe différents types 'd’éco-mousseurs' qui limitent le débit à des niveaux variables. Choisissez votre matériel en fonction des besoins à chaque robinet : 5 L/min sera adapté pour un robinet servant uniquement à se laver les mains mais sera assez pénible si vous devez remplir un seau !", + longName: "J'équipe mes robinets d’éco-mousseurs.", + nwh: 4, + pack: 0, + shortDescription: '', + shortName: 'Super plombier', + usage: 'Eau chaude sanitaire', + _id: '0037', + _rev: '1-0b2761dd4aef79556c7aef144060fde6', + _type: 'com.grandlyon.ecolyo.ecogesture', + }, +] diff --git a/test/__mocks__/fluidStatusData.mock.ts b/test/__mocks__/fluidStatusData.mock.ts new file mode 100644 index 0000000000000000000000000000000000000000..69c78d2d1812b5c1e50b048df1827a86174e203b --- /dev/null +++ b/test/__mocks__/fluidStatusData.mock.ts @@ -0,0 +1,20 @@ +import { DateTime } from 'luxon' +import { FluidStatus } from 'models' + +export const fluidStatusData: FluidStatus[] = [ + { + fluidType: 0, + status: 'errored', + lastDataDate: DateTime.fromISO('2020-09-01T00:00:00.000'), + }, + { + fluidType: 1, + status: 'errored', + lastDataDate: DateTime.fromISO('2020-09-01T00:00:00.000'), + }, + { + fluidType: 2, + status: 'errored', + lastDataDate: DateTime.fromISO('2020-09-01T00:00:00.000'), + }, +] diff --git a/test/__mocks__/konnectorsData.mock.ts b/test/__mocks__/konnectorsData.mock.ts new file mode 100644 index 0000000000000000000000000000000000000000..d9e70b5cb87c0e0c870df11ec771db034fd187a7 --- /dev/null +++ b/test/__mocks__/konnectorsData.mock.ts @@ -0,0 +1,22 @@ +import { Konnector } from 'models' + +export const konnectorsData: Konnector[] = [ + { + _id: 'io.cozy.konnectors/enedisgrandlyon', + name: 'Enedis', + slug: 'enedisgrandlyon', + state: 'ready', + }, + { + _id: 'io.cozy.konnectors/eglgrandlyon', + name: 'EGL', + slug: 'eglgrandlyon', + state: 'ready', + }, + { + _id: 'io.cozy.konnectors/grdfgrandlyon', + name: 'GRDF', + slug: 'grdfgrandlyon', + state: 'ready', + }, +] diff --git a/test/__mocks__/loadDayData.mock.ts b/test/__mocks__/loadDayData.mock.ts new file mode 100644 index 0000000000000000000000000000000000000000..3d669c28c38268500254e6b5cfc69bf590940da7 --- /dev/null +++ b/test/__mocks__/loadDayData.mock.ts @@ -0,0 +1,52 @@ +import { DataloadEntity } from 'models' + +export const loadDayData: DataloadEntity[] = [ + { + id: 'bf1ce3a5774e140056714c4c200c093e', + _id: 'bf1ce3a5774e140056714c4c200c093e', + _type: 'com.grandlyon.enedis.day', + _rev: '1-4fe971dff073a3c3c6cc12a0246e642e', + day: 1, + hour: 0, + load: 25.25, + minute: 0, + month: 11, + year: 2020, + }, + { + id: 'cf7dc6f44a19b354f99b01ba1a0b4840', + _id: 'cf7dc6f44a19b354f99b01ba1a0b4840', + _type: 'com.grandlyon.enedis.day', + _rev: '1-4fe971dff073a3c3c6cc12a0246e642e', + day: 2, + hour: 0, + load: 20.5, + minute: 0, + month: 11, + year: 2020, + }, + { + id: 'cf7dc6f44a19b354f99b01ba1a0b4840', + _id: 'cf7dc6f44a19b354f99b01ba1a0b4840', + _type: 'com.grandlyon.enedis.day', + _rev: '1-4fe971dff073a3c3c6cc12a0246e642e', + day: 3, + hour: 0, + load: 30.33, + minute: 0, + month: 11, + year: 2020, + }, + { + id: 'cf7dc6f44a19b354f99b01ba1a0b4840', + _id: 'cf7dc6f44a19b354f99b01ba1a0b4840', + _type: 'com.grandlyon.enedis.day', + _rev: '1-4fe971dff073a3c3c6cc12a0246e642e', + day: 4, + hour: 0, + load: 1.22, + minute: 0, + month: 11, + year: 2020, + }, +] diff --git a/test/__mocks__/loadHourData.mock.ts b/test/__mocks__/loadHourData.mock.ts new file mode 100644 index 0000000000000000000000000000000000000000..68f43c0a199da2ad9998a0a19bb26152b729d146 --- /dev/null +++ b/test/__mocks__/loadHourData.mock.ts @@ -0,0 +1,64 @@ +import { DataloadEntity } from 'models' + +export const loadHourData: DataloadEntity[] = [ + { + id: 'cf7dc6f44a19b354f99b01ba1a0b4840', + _id: 'cf7dc6f44a19b354f99b01ba1a0b4840', + _type: 'com.grandlyon.enedis.hour', + _rev: '1-4fe971dff073a3c3c6cc12a0246e642e', + day: 2, + hour: 0, + load: 4.5, + minute: 0, + month: 11, + year: 2020, + }, + { + id: 'cf7dc6f44a19b354f99b01ba1a0b4840', + _id: 'cf7dc6f44a19b354f99b01ba1a0b4840', + _type: 'com.grandlyon.enedis.hour', + _rev: '1-4fe971dff073a3c3c6cc12a0246e642e', + day: 2, + hour: 1, + load: 1.33, + minute: 0, + month: 11, + year: 2020, + }, + { + id: 'cf7dc6f44a19b354f99b01ba1a0b4840', + _id: 'cf7dc6f44a19b354f99b01ba1a0b4840', + _type: 'com.grandlyon.enedis.hour', + _rev: '1-4fe971dff073a3c3c6cc12a0246e642e', + day: 2, + hour: 2, + load: 3.22, + minute: 0, + month: 11, + year: 2020, + }, + { + id: 'cf7dc6f44a19b354f99b01ba1a0b4840', + _id: 'cf7dc6f44a19b354f99b01ba1a0b4840', + _type: 'com.grandlyon.enedis.hour', + _rev: '1-4fe971dff073a3c3c6cc12a0246e642e', + day: 2, + hour: 3, + load: 7.82, + minute: 0, + month: 11, + year: 2020, + }, + { + id: 'cf7dc6f44a19b354f99b01ba1a0b4840', + _id: 'cf7dc6f44a19b354f99b01ba1a0b4840', + _type: 'com.grandlyon.enedis.hour', + _rev: '1-4fe971dff073a3c3c6cc12a0246e642e', + day: 2, + hour: 4, + load: 1.23, + minute: 0, + month: 11, + year: 2020, + }, +] diff --git a/test/__mocks__/loadMinuteData.mock.ts b/test/__mocks__/loadMinuteData.mock.ts new file mode 100644 index 0000000000000000000000000000000000000000..02dc8cdfaa2864e74cf2c8581f260c772682c7e1 --- /dev/null +++ b/test/__mocks__/loadMinuteData.mock.ts @@ -0,0 +1,76 @@ +import { DataloadEntity } from 'models' + +export const loadMinuteData: DataloadEntity[] = [ + { + id: 'bf1ce3a5774e140056714c4c200c093e', + _id: 'bf1ce3a5774e140056714c4c200c093e', + _type: 'com.grandlyon.enedis.minute', + _rev: '1-4fe971dff073a3c3c6cc12a0246e642e', + day: 1, + hour: 23, + load: 2.25, + minute: 30, + month: 11, + year: 2020, + }, + { + id: 'cf7dc6f44a19b354f99b01ba1a0b4840', + _id: 'cf7dc6f44a19b354f99b01ba1a0b4840', + _type: 'com.grandlyon.enedis.minute', + _rev: '1-4fe971dff073a3c3c6cc12a0246e642e', + day: 2, + hour: 0, + load: 4.5, + minute: 0, + month: 11, + year: 2020, + }, + { + id: 'cf7dc6f44a19b354f99b01ba1a0b4840', + _id: 'cf7dc6f44a19b354f99b01ba1a0b4840', + _type: 'com.grandlyon.enedis.minute', + _rev: '1-4fe971dff073a3c3c6cc12a0246e642e', + day: 2, + hour: 0, + load: 1.33, + minute: 30, + month: 11, + year: 2020, + }, + { + id: 'cf7dc6f44a19b354f99b01ba1a0b4840', + _id: 'cf7dc6f44a19b354f99b01ba1a0b4840', + _type: 'com.grandlyon.enedis.minute', + _rev: '1-4fe971dff073a3c3c6cc12a0246e642e', + day: 2, + hour: 1, + load: 3.22, + minute: 0, + month: 11, + year: 2020, + }, + { + id: 'cf7dc6f44a19b354f99b01ba1a0b4840', + _id: 'cf7dc6f44a19b354f99b01ba1a0b4840', + _type: 'com.grandlyon.enedis.minute', + _rev: '1-4fe971dff073a3c3c6cc12a0246e642e', + day: 2, + hour: 1, + load: 7.82, + minute: 30, + month: 11, + year: 2020, + }, + { + id: 'cf7dc6f44a19b354f99b01ba1a0b4840', + _id: 'cf7dc6f44a19b354f99b01ba1a0b4840', + _type: 'com.grandlyon.enedis.minute', + _rev: '1-4fe971dff073a3c3c6cc12a0246e642e', + day: 2, + hour: 2, + load: 1.23, + minute: 0, + month: 11, + year: 2020, + }, +] diff --git a/test/__mocks__/loadMonthData.mock.ts b/test/__mocks__/loadMonthData.mock.ts new file mode 100644 index 0000000000000000000000000000000000000000..fc869cb7eda7d64ecc2b7c75a8b9e7122f8be311 --- /dev/null +++ b/test/__mocks__/loadMonthData.mock.ts @@ -0,0 +1,40 @@ +import { DataloadEntity } from 'models' + +export const loadMonthData: DataloadEntity[] = [ + { + id: 'bf1ce3a5774e140056714c4c200c093e', + _id: 'bf1ce3a5774e140056714c4c200c093e', + _type: 'com.grandlyon.enedis.month', + _rev: '1-4fe971dff073a3c3c6cc12a0246e642e', + day: 1, + hour: 0, + load: 125.25, + minute: 0, + month: 9, + year: 2020, + }, + { + id: 'cf7dc6f44a19b354f99b01ba1a0b4840', + _id: 'cf7dc6f44a19b354f99b01ba1a0b4840', + _type: 'com.grandlyon.enedis.month', + _rev: '1-4fe971dff073a3c3c6cc12a0246e642e', + day: 1, + hour: 0, + load: 220.5, + minute: 0, + month: 10, + year: 2020, + }, + { + id: 'cf7dc6f44a19b354f99b01ba1a0b4840', + _id: 'cf7dc6f44a19b354f99b01ba1a0b4840', + _type: 'com.grandlyon.enedis.month', + _rev: '1-4fe971dff073a3c3c6cc12a0246e642e', + day: 1, + hour: 0, + load: 130.33, + minute: 0, + month: 11, + year: 2020, + }, +] diff --git a/test/__mocks__/loadYearData.mock.ts b/test/__mocks__/loadYearData.mock.ts new file mode 100644 index 0000000000000000000000000000000000000000..467b33c64452ed7bc3f74a4d986d1a94d6afb1a2 --- /dev/null +++ b/test/__mocks__/loadYearData.mock.ts @@ -0,0 +1,40 @@ +import { DataloadEntity } from 'models' + +export const loadYearData: DataloadEntity[] = [ + { + id: 'bf1ce3a5774e140056714c4c200c093e', + _id: 'bf1ce3a5774e140056714c4c200c093e', + _type: 'com.grandlyon.enedis.year', + _rev: '1-4fe971dff073a3c3c6cc12a0246e642e', + day: 1, + hour: 0, + load: 125.25, + minute: 0, + month: 1, + year: 2018, + }, + { + id: 'cf7dc6f44a19b354f99b01ba1a0b4840', + _id: 'cf7dc6f44a19b354f99b01ba1a0b4840', + _type: 'com.grandlyon.enedis.year', + _rev: '1-4fe971dff073a3c3c6cc12a0246e642e', + day: 0, + hour: 0, + load: 220.5, + minute: 0, + month: 0, + year: 2019, + }, + { + id: 'cf7dc6f44a19b354f99b01ba1a0b4840', + _id: 'cf7dc6f44a19b354f99b01ba1a0b4840', + _type: 'com.grandlyon.enedis.year', + _rev: '1-4fe971dff073a3c3c6cc12a0246e642e', + day: 1, + hour: 0, + load: 130.33, + minute: 0, + month: 1, + year: 2020, + }, +] diff --git a/test/__mocks__/triggerStateData.mock.ts b/test/__mocks__/triggerStateData.mock.ts new file mode 100644 index 0000000000000000000000000000000000000000..f921419f45ffe068bc02216f477b242971fe6bcd --- /dev/null +++ b/test/__mocks__/triggerStateData.mock.ts @@ -0,0 +1,14 @@ +/* eslint-disable @typescript-eslint/camelcase */ +import { TriggerState } from 'models' + +export const triggerStateData: TriggerState = { + trigger_id: '238ba37b8bc8130bd323edb5c1005c8f', + status: 'errored', + last_execution: '2020-11-13T10:03:16.4121536Z', + last_executed_job_id: '238ba37b8bc8130bd323edb5c1006b56', + last_failure: '2020-11-13T10:03:16.4121536Z', + last_failed_job_id: '238ba37b8bc8130bd323edb5c1006b56', + last_error: 'fork/exec : no such file or directory', + last_manual_execution: '2020-11-13T10:03:16.4121536Z', + last_manual_job_id: '238ba37b8bc8130bd323edb5c1006b56', +} diff --git a/test/__mocks__/triggersData.mock.ts b/test/__mocks__/triggersData.mock.ts new file mode 100644 index 0000000000000000000000000000000000000000..76dbb299a133d110e7f1eee74a341d79193a2b80 --- /dev/null +++ b/test/__mocks__/triggersData.mock.ts @@ -0,0 +1,67 @@ +import { Trigger } from 'models' + +export const triggersData: Trigger[] = [ + { + _id: '3ed832cec67e6e0b2c6382edd30df11c', + domain: 'cozy.tools:8080', + prefix: 'cozy35ba44d2d1749e6f21646edce51e7190', + type: '@cron', + worker: 'konnector', + arguments: '0 47 8 * * *', + debounce: '', + options: null, + message: { + account: '88e68b8450cee09fe2f077610901094d', + konnector: 'enedisgrandlyon', + }, + cozyMetadata: { + doctypeVersion: '1', + metadataVersion: 1, + createdAt: '2020-10-09T08:00:00.6092798Z', + createdByApp: 'ecolyo', + updatedAt: '2020-10-09T08:00:00.6092798Z', + }, + }, + { + _id: '5ed832cec67e6e0b2c6382edd30df11c', + domain: 'cozy.tools:8080', + prefix: 'cozy35ba44d2d1749e6f21646edce51e7190', + type: '@cron', + worker: 'konnector', + arguments: '0 47 8 * * *', + debounce: '', + options: null, + message: { + account: '90e68b8450cee09fe2f077610901094d', + konnector: 'eglgrandlyon', + }, + cozyMetadata: { + doctypeVersion: '1', + metadataVersion: 1, + createdAt: '2020-10-09T08:00:00.6092798Z', + createdByApp: 'ecolyo', + updatedAt: '2020-10-09T08:00:00.6092798Z', + }, + }, + { + _id: '4ed832cec67e6e0b2c6382edd30df11c', + domain: 'cozy.tools:8080', + prefix: 'cozy35ba44d2d1749e6f21646edce51e7190', + type: '@cron', + worker: 'konnector', + arguments: '0 47 8 * * *', + debounce: '', + options: null, + message: { + account: '89e68b8450cee09fe2f077610901094d', + konnector: 'grdfgrandlyon', + }, + cozyMetadata: { + doctypeVersion: '1', + metadataVersion: 1, + createdAt: '2020-10-09T08:00:00.6092798Z', + createdByApp: 'ecolyo', + updatedAt: '2020-10-09T08:00:00.6092798Z', + }, + }, +] diff --git a/src/services/__mocks__/userProfile.mock.ts b/test/__mocks__/userProfile.mock.ts similarity index 100% rename from src/services/__mocks__/userProfile.mock.ts rename to test/__mocks__/userProfile.mock.ts diff --git a/tsconfig.json b/tsconfig.json index 23eca91b15f1fd1d72067b1b6882fb92af925a47..e35a29797c481d1dcb9c165f4c85d81c4b1bd5f3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -20,6 +20,6 @@ ] }, "include": [ - "src/**/*" + "src/**/*", "test/**/*" ] }