diff --git a/test/createConnections.js b/test/createConnections.js new file mode 100644 index 0000000000000000000000000000000000000000..76cef9e13f7ae69c793189217c25a7734290e85e --- /dev/null +++ b/test/createConnections.js @@ -0,0 +1,219 @@ +/* eslint-disable @typescript-eslint/no-var-requires */ +/* eslint-disable @typescript-eslint/camelcase */ +const axios = require('axios') +const headers = { + Accept: 'application/json', + Authorization: + 'Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhcHAiLCJpYXQiOjE2MDIyNTExMTEsImlzcyI6ImNvenkudG9vbHM6ODA4MCIsInN1YiI6ImVjb2x5byIsInNlc3Npb25faWQiOiIzZWQ4MzJjZWM2N2U2ZTBiMmM2MzgyZWRkMzAwYTM0MSJ9.vp7r-LxVrwtvSCxTv5NwGV_AJLozUKqFMhCrG3cLCSnU237dp7pCYOq-CXJRLiG2MvTFztPBEZ2-2Zda_aAT5A', + Cookie: + 'cozysessid=AAAAAF-ALvszZWQ4MzJjZWM2N2U2ZTBiMmM2MzgyZWRkMzAwYTM0MYO4rN61eyNbWbrWXaZShPaUM8YPXSjKPqWA7MV1DQfs', + 'content-type': 'application/json', +} + +const dataEnedisAccount = JSON.stringify({ + account_type: 'enedisgrandlyon', + name: '', + oauth: { + access_token: '', + 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: + '/v4/metering_data/production_load_curve.GET /v3/customers/usage_points/addresses.GET /v4/metering_data/consumption_load_curve.GET /v3/customers/usage_points/contracts.GET /v4/metering_data/daily_production.GET /v4/metering_data/daily_consumption.GET /v4/metering_data/daily_consumption_max_power.GET /v3/customers/identity.GET', + usage_points_id: '', + }, +}) + +const dataGrdfAccount = JSON.stringify({ + account_type: 'grdfgrandlyon', + auth: { + credentials_encrypted: + 'bmFjbMKrNCS+4Liakxdu+xNu9I3sSyvda8iAp0o3U3OAymbIeoLhLtxPdsa+3mu/8yTnDudBcJo=', + login: 'test', + }, + id: '89e68b8450cee09fe2f077610901094d', + identifier: 'login', + state: null, +}) + +const dataEglAccount = JSON.stringify({ + account_type: 'eglgrandlyon', + auth: { + credentials_encrypted: + 'bmFjbHI5OoL+VNCT6JDFYea1dNiBGGNJM1zY0M4uWcjhALJcQT9uk9p9WPD7+1OryCAoYf9eaSE=', + login: 'test', + }, + id: '90e68b8450cee09fe2f077610901094d', + identifier: 'login', + state: null, +}) + +const dataEnedisTrigger = JSON.stringify({ + data: { + attributes: { + _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', + }, + }, + }, +}) + +const dataGrdfTrigger = JSON.stringify({ + data: { + attributes: { + _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', + }, + }, + }, +}) + +const dataEglTrigger = JSON.stringify({ + data: { + attributes: { + _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', + }, + }, + }, +}) + +async function launch() { + // Enedis + await axios({ + method: 'put', + url: + 'http://cozy.tools:8080/data/io.cozy.accounts/88e68b8450cee09fe2f077610901094d', + headers: headers, + data: dataEnedisAccount, + }) + .then(function(response) { + console.log(JSON.stringify(response.data)) + }) + .catch(function(error) { + console.log(error) + }) + + await axios({ + method: 'post', + url: 'http://cozy.tools:8080/jobs/triggers', + headers: headers, + data: dataEnedisTrigger, + }) + .then(function(response) { + console.log(JSON.stringify(response.data)) + }) + .catch(function(error) { + console.log(error) + }) + + // GRDF + await axios({ + method: 'put', + url: + 'http://cozy.tools:8080/data/io.cozy.accounts/89e68b8450cee09fe2f077610901094d', + headers: headers, + data: dataGrdfAccount, + }) + .then(function(response) { + console.log(JSON.stringify(response.data)) + }) + .catch(function(error) { + console.log(error) + }) + + await axios({ + method: 'post', + url: 'http://cozy.tools:8080/jobs/triggers', + headers: headers, + data: dataGrdfTrigger, + }) + .then(function(response) { + console.log(JSON.stringify(response.data)) + }) + .catch(function(error) { + console.log(error) + }) + + // EGL + await axios({ + method: 'put', + url: + 'http://cozy.tools:8080/data/io.cozy.accounts/90e68b8450cee09fe2f077610901094d', + headers: headers, + data: dataEglAccount, + }) + .then(function(response) { + console.log(JSON.stringify(response.data)) + }) + .catch(function(error) { + console.log(error) + }) + + await axios({ + method: 'post', + url: 'http://cozy.tools:8080/jobs/triggers', + headers: headers, + data: dataEglTrigger, + }) + .then(function(response) { + console.log(JSON.stringify(response.data)) + }) + .catch(function(error) { + console.log(error) + }) +} + +launch() diff --git a/test/data/accountData.json b/test/data/accountData.json deleted file mode 100644 index 4c2fd685495933077a20ec5aa595a5a5479fd5c3..0000000000000000000000000000000000000000 --- a/test/data/accountData.json +++ /dev/null @@ -1,41 +0,0 @@ -{"io.cozy.accounts": - [ - { - "_id": "88e68b8450cee09fe2f077610901094d", - "account_type": "enedisgrandlyon", - "name": "", - "oauth": { - "access_token": "", - "expires_at": "2020-06-16T04:17:03.285910671+02:00", - "refresh_token": "", - "token_type": "Bearer" - }, - "oauth_callback_results": { - "issued_at": "1592232569642", - "refresh_token_issued_at": "1592232569642", - "scope": "/v4/metering_data/production_load_curve.GET /v3/customers/usage_points/addresses.GET /v4/metering_data/consumption_load_curve.GET /v3/customers/usage_points/contracts.GET /v4/metering_data/daily_production.GET /v4/metering_data/daily_consumption.GET /v4/metering_data/daily_consumption_max_power.GET /v3/customers/identity.GET", - "usage_points_id": "" - } - }, - { - "_id": "89e68b8450cee09fe2f077610901094d", - "account_type": "grdfgrandlyon", - "auth": { - "credentials_encrypted": "bmFjbI7TqHf7FTj8b6T8JyV7ORUSYjziwua6bnbh0P3CE/3dJ9G0w6GdtmhbuqxAgqiQS/uqrZw=", - "login": "test" - }, - "identifier": "login", - "state": null - }, - { - "_id": "90e68b8450cee09fe2f077610901094d", - "account_type": "eglgrandlyon", - "auth": { - "credentials_encrypted": "bmFjbHI5OoL+VNCT6JDFYea1dNiBGGNJM1zY0M4uWcjhALJcQT9uk9p9WPD7+1OryCAoYf9eaSE=", - "login": "test" - }, - "identifier": "login", - "state": null - } - ] -} \ No newline at end of file diff --git a/test/data/jobsData.json b/test/data/jobsData.json deleted file mode 100644 index 7a05460cec611b4fbdb0bee7224f793d43118d6c..0000000000000000000000000000000000000000 --- a/test/data/jobsData.json +++ /dev/null @@ -1,51 +0,0 @@ -{"io.cozy.jobs": - [ - { - "_id": "0813eafc594ef00e8e6b72167c0067a2", - "domain": "cozy.tools:8080", - "worker": "konnector", - "trigger_id": "0813eafc594ef00e8e6b72167c006480", - "message": { - "account": "88e68b8450cee09fe2f077610901094d", - "konnector": "enedisgrandlyon" - }, - "event": null, - "manual_execution": true, - "state": "done", - "queued_at": "2020-10-09T08:00:00.0000000Z", - "started_at": "2020-10-09T08:00:00.0000000Z", - "finished_at": "2020-10-09T08:00:00.0000000Z" - }, - { - "_id": "0823eafc594ef00e8e6b72167c0067a2", - "domain": "cozy.tools:8080", - "worker": "konnector", - "trigger_id": "0823eafc594ef00e8e6b72167c006480", - "message": { - "account": "89e68b8450cee09fe2f077610901094d", - "konnector": "grdfgrandlyon" - }, - "event": null, - "manual_execution": true, - "state": "done", - "queued_at": "2020-10-09T08:00:00.0000000Z", - "started_at": "2020-10-09T08:00:00.0000000Z", - "finished_at": "2020-10-09T08:00:00.0000000Z" - },{ - "_id": "0833eafc594ef00e8e6b72167c0067a2", - "domain": "cozy.tools:8080", - "worker": "konnector", - "trigger_id": "0833eafc594ef00e8e6b72167c006480", - "message": { - "account": "90e68b8450cee09fe2f077610901094d", - "konnector": "eglgrandlyon" - }, - "event": null, - "manual_execution": true, - "state": "done", - "queued_at": "2020-10-09T08:00:00.0000000Z", - "started_at": "2020-10-09T08:00:00.0000000Z", - "finished_at": "2020-10-09T08:00:00.0000000Z" - }, - ] -} \ No newline at end of file diff --git a/test/data/triggerData.json b/test/data/triggerData.json deleted file mode 100644 index 7a88b1157554cb06f5f66440715c23320d970a1d..0000000000000000000000000000000000000000 --- a/test/data/triggerData.json +++ /dev/null @@ -1,86 +0,0 @@ -{"io.cozy.triggers": - [ - { - "_id": "0813eafc594ef00e8e6b72167c006480", - "_rev": "9-d4d186ce53a9bfcc6ce2a0aced39f591", - "arguments": "0 5 9 * * *", - "debounce": "", - "domain": "cozy.tools:8080", - "prefix": "cozy35ba44d2d1749e6f21646edce51e7190", - "message": { - "account": "88e68b8450cee09fe2f077610901094d", - "konnector": "enedisgrandlyon" - }, - "options": null, - "type": "@cron", - "worker": "konnector", - "cozyMetadata": { - "doctypeVersion": "1", - "metadataVersion": 1, - "createdAt": "2020-10-09T08:00:00.0000000Z", - "createdByApp": "ecolyo", - "updatedAt": "2020-10-09T08:00:00.0000000Z", - "updatedByApps": [ - { - "slug": "ecolyo", - "date": "2020-10-09T08:00:00.0000000Z" - } - ] - } - }, - { - "_id": "0823eafc594ef00e8e6b72167c006480", - "arguments": "0 5 9 * * *", - "debounce": "", - "domain": "cozy.tools:8080", - "prefix": "cozy35ba44d2d1749e6f21646edce51e7190", - "message": { - "account": "89e68b8450cee09fe2f077610901094d", - "konnector": "grdfgrandlyon" - }, - "options": null, - "type": "@cron", - "worker": "konnector", - "cozyMetadata": { - "doctypeVersion": "1", - "metadataVersion": 1, - "createdAt": "2020-10-09T08:00:00.0000000Z", - "createdByApp": "ecolyo", - "updatedAt": "2020-10-09T08:00:00.0000000Z", - "updatedByApps": [ - { - "slug": "ecolyo", - "date": "2020-10-09T08:00:00.0000000Z" - } - ] - } - }, - { - "_id": "0833eafc594ef00e8e6b72167c006480", - "arguments": "0 5 9 * * *", - "debounce": "", - "domain": "cozy.tools:8080", - "prefix": "cozy35ba44d2d1749e6f21646edce51e7190", - "message": { - "account": "90e68b8450cee09fe2f077610901094d", - "konnector": "eglgrandlyon" - }, - "options": null, - "type": "@cron", - "worker": "konnector", - "cozyMetadata": { - "doctypeVersion": "1", - "metadataVersion": 1, - "createdAt": "2020-10-09T08:00:00.0000000Z", - "createdByApp": "ecolyo", - "updatedAt": "2020-10-09T08:00:00.0000000Z", - "updatedByApps": [ - { - "slug": "ecolyo", - "date": "2020-10-09T08:00:00.0000000Z" - } - ] - } - } - ] -} \ No newline at end of file