From f7c793ed718dd85a25df6c4500b16805721eb791 Mon Sep 17 00:00:00 2001
From: Johanna Szepanski <johanna.szepanski@softhouse.se>
Date: Thu, 27 Jun 2024 14:55:56 +0200
Subject: [PATCH] updated mocked api calls and correspondiong mock data

---
 src/mocks/fixtures/IOCDescription.json   |  31 ++-
 src/mocks/fixtures/IOCStatus.json        | 127 +++++-----
 src/mocks/fixtures/PagedIOCResponse.json | 293 ++++++-----------------
 src/mocks/mockAPI.js                     |  45 ++--
 4 files changed, 178 insertions(+), 318 deletions(-)

diff --git a/src/mocks/fixtures/IOCDescription.json b/src/mocks/fixtures/IOCDescription.json
index 063dd243..dcdd5377 100644
--- a/src/mocks/fixtures/IOCDescription.json
+++ b/src/mocks/fixtures/IOCDescription.json
@@ -1,14 +1,39 @@
 [
   {
-    "id": 1,
+    "id": 14,
     "description": "This is a test IOC for demonstrating the deployment tool"
   },
   {
-    "id": 2,
+    "id": 15,
     "description": "Test IOC for CCCE"
   },
   {
-    "id": 346,
+    "id": 18,
     "description": "Some description"
+  },
+  {
+    "id": 39,
+    "description": ""
+  },
+  {
+    "id": 21
+  },
+  {
+    "id": 49,
+    "description": "some fun description"
+  },
+  {
+    "id": 40
+  },
+  {
+    "id": 41
+  },
+  {
+    "id": 42,
+    "description": "some description"
+  },
+  {
+    "id": 43,
+    "description": "some description"
   }
 ]
diff --git a/src/mocks/fixtures/IOCStatus.json b/src/mocks/fixtures/IOCStatus.json
index 58cc6210..b2fdc506 100644
--- a/src/mocks/fixtures/IOCStatus.json
+++ b/src/mocks/fixtures/IOCStatus.json
@@ -1,122 +1,107 @@
 [
   {
-    "id": 346,
-    "active": true,
+    "iocId": 14,
+    "alertSeverity": "ERROR",
     "alerts": [
       {
-        "type": "WARNING",
-        "message": "A temporary gravity anomaly has been detected in the cafeteria. Please secure your trays and beverages. We suspect a rogue black hole passing by, or maybe someone just dropped a super-dense bagel again. Proceed with caution, and remember, what goes up might not come down for a while. Thank you for floating with us today."
+        "type": "ERROR",
+        "message": "IOC's latest deployment failed, IOC may be in inconsistent state",
+        "link": null
       },
       {
-        "type": "ERROR",
-        "message": "The area is currently experiencing an unexpected entropy reversal. As a precaution, ice cream in the freezer may spontaneously melt, then refreeze. We recommend eating it now, just to be safe. Also, be on the lookout for random acts of orderliness. Your messy desk might just organize itself, but don't get your hopes up."
+        "type": "WARNING",
+        "message": "This is a warning message",
+        "link": null
       }
     ],
-    "alertSeverity": "ERROR"
+    "active": true
   },
   {
-    "id": 345,
+    "iocId": 15,
+    "alertSeverity": "WARNING",
     "alerts": [
       {
         "type": "WARNING",
-        "message": "Example alert without link"
+        "message": "This is warning 1",
+        "link": null
       },
       {
-        "type": "ERROR",
-        "message": "Example alert with link",
-        "link": "https://google.com"
+        "type": "WARNING",
+        "message": "This is warning 2",
+        "link": null
       }
     ],
-    "alertSeverity": "ERROR",
-    "active": true
+    "active": null
   },
   {
-    "id": 344,
+    "iocId": 18,
+    "alertSeverity": "INFO",
     "alerts": [
       {
-        "type": "WARNING",
-        "message": "Example alert warning for VacS-RFQ:SC-IOC-110"
+        "type": "INFO",
+        "message": "IOC is not deployed",
+        "link": null
       }
     ],
-    "alertSeverity": "WARNING",
-    "active": true
-  },
-  {
-    "id": 328
+    "active": null
   },
   {
-    "id": 251
+    "iocId": 39,
+    "alertSeverity": null,
+    "alerts": [],
+    "active": null
   },
   {
-    "id": 249,
-    "active": true
+    "iocId": 21,
+    "alertSeverity": null,
+    "alerts": [],
+    "active": null
   },
   {
-    "id": 166,
+    "iocId": 49,
+    "alertSeverity": "INFO",
     "alerts": [
       {
-        "type": "ERROR",
-        "message": "Example alert error for RFQ-010:SC-IOC-001"
+        "type": "INFO",
+        "message": "IOC is not deployed",
+        "link": null
       }
     ],
-    "alertSeverity": "ERROR"
+    "active": null
   },
   {
-    "id": 148,
-    "alerts": [
-      {
-        "type": "WARNING",
-        "message": "Example alert warning for RFQ-010:SC-IOC-977"
-      }
-    ],
-    "alertSeverity": "WARNING",
+    "iocId": 40,
+    "alertSeverity": null,
+    "alerts": [],
     "active": true
   },
   {
-    "id": 116,
+    "iocId": 41,
+    "alertSeverity": null,
+    "alerts": [],
     "active": true
   },
   {
-    "id": 76,
+    "iocId": 42,
+    "alertSeverity": null,
+    "alerts": [],
     "active": true
   },
   {
-    "id": 13,
+    "iocId": 43,
+    "alertSeverity": "ERROR",
     "alerts": [
       {
-        "type": "WARNING",
-        "message": "Example alert warning for RFQ-010:SC-IOC-056"
-      }
-    ],
-    "alertSeverity": "WARNING",
-    "active": true
-  },
-  {
-    "id": 10
-  },
-  {
-    "id": 9,
-    "active": true
-  },
-  {
-    "id": 8
-  },
-  {
-    "id": 6
-  },
-  {
-    "id": 4,
-    "active": true
-  },
-  {
-    "id": 3,
-    "alerts": [
+        "type": "ERROR",
+        "message": "Cannot find the repository in Gitlab",
+        "link": null
+      },
       {
-        "type": "WARNING",
-        "message": "Example alert warning RFQ-010:SC-IOC-006"
+        "type": "INFO",
+        "message": "IOC is not deployed",
+        "link": null
       }
     ],
-    "alertSeverity": "WARNING",
-    "active": true
+    "active": null
   }
 ]
diff --git a/src/mocks/fixtures/PagedIOCResponse.json b/src/mocks/fixtures/PagedIOCResponse.json
index 0a419578..7bb659dd 100644
--- a/src/mocks/fixtures/PagedIOCResponse.json
+++ b/src/mocks/fixtures/PagedIOCResponse.json
@@ -1,254 +1,115 @@
 {
-  "totalCount": 17,
-  "listSize": 17,
+  "totalCount": 10,
+  "listSize": 10,
   "pageNumber": 0,
-  "limit": 150,
+  "limit": 20,
   "iocList": [
     {
-      "id": 346,
-      "namingName": "VacS-RFQ:SC-IOC-130",
-      "createdBy": "krisztianloki",
-      "gitProjectId": 5336,
-      "activeDeployment": {
-        "host": {
-          "hostId": 3354,
-          "fqdn": "vacs-accv-vm-ioc.tn.esss.lu.se",
-          "hostName": "vacs-accv-vm-ioc",
-          "network": "ChannelAccess-FEB"
-        },
-        "sourceVersion": "1.0.0",
-        "sourceVersionShort": "1.0.0"
-      }
-    },
-    {
-      "id": 345,
-      "namingName": "VacS-RFQ:SC-IOC-119",
-      "createdBy": "krisztianloki",
-      "gitProjectId": 5335,
-      "activeDeployment": {
-        "host": {
-          "hostId": 3354,
-          "fqdn": "vacs-accv-vm-ioc.tn.esss.lu.se",
-          "hostName": "vacs-accv-vm-ioc",
-          "network": "ChannelAccess-FEB"
-        },
-        "sourceVersion": "cc95ff21a09977fd2396ec1999259ec0a5e63147",
-        "sourceVersionShort": "cc95ff21"
-      }
-    },
-    {
-      "id": 344,
-      "description": "some description",
-      "namingName": "VacS-RFQ:SC-IOC-110",
-      "createdBy": "krisztianloki",
-      "gitProjectId": 5334,
-      "activeDeployment": {
-        "host": {
-          "hostId": 3354,
-          "fqdn": "vacs-accv-vm-ioc.tn.esss.lu.se",
-          "hostName": "vacs-accv-vm-ioc",
-          "network": "ChannelAccess-FEB"
-        },
-        "sourceVersion": "9a3585a5bea4372f7d964b7e18b83aa3b1afc61f",
-        "sourceVersionShort": "9a3585a5"
-      }
+      "id": 14,
+      "namingName": "CCCE:MOCK1",
+      "createdBy": "mock user 1",
+      "gitProjectId": 5959,
+      "deployedWithOldPlaybook": true,
+      "activeDeployment": null
     },
     {
-      "id": 328,
-      "namingName": "RFQ-010:SC-IOC-117",
-      "createdBy": "gabrielfedel",
-      "gitProjectId": 5953,
-      "sourceVersion": null,
-      "activeDeployment": {}
-    },
-    {
-      "id": 251,
-      "description": "some description",
-      "namingName": "RFQ-010:SC-IOC-015",
-      "createdBy": "lucianocarneiro",
-      "gitProjectId": 5952,
-      "sourceVersion": null,
-      "activeDeployment": {}
-    },
-    {
-      "id": 249,
-      "description": "some description",
-      "namingName": "RFQ-010:SC-IOC-016",
-      "createdBy": "gabrielfedel",
-      "gitProjectId": 5954,
+      "id": 15,
+      "namingName": "CCCE:MOCK2",
+      "createdBy": "mock user 2",
+      "gitProjectId": 5970,
+      "deployedWithOldPlaybook": false,
       "activeDeployment": {
         "host": {
-          "hostId": 4205,
-          "fqdn": "rfq-rf-vm-ioc.tn.esss.lu.se",
-          "hostName": "rfq-rf-vm-ioc",
-          "network": "ChannelAccess-ACC"
+          "hostId": "MTUxX3RydWU=",
+          "hostName": "ccce-test-ioc-01",
+          "network": "CSLab-GeneralLab",
+          "netBoxHostFromCache": true
         },
-        "sourceVersion": "1.0.1",
-        "sourceVersionShort": "1.0.1"
+        "sourceVersion": "correct_ioc",
+        "sourceVersionShort": null
       }
     },
     {
-      "id": 166,
-      "namingName": "RFQ-010:SC-IOC-001",
-      "createdBy": "gabrielfedel",
-      "gitProjectId": 4314,
-      "activeDeployment": {
-        "host": {
-          "hostId": 2245,
-          "fqdn": "rfq-llrf1-mtca-ioc.tn.esss.lu.se",
-          "hostName": "rfq-llrf1-mtca-ioc",
-          "network": "ChannelAccess-ACC"
-        },
-        "sourceVersion": "3.0.3",
-        "sourceVersionShort": "3.0.3"
-      }
+      "id": 18,
+      "namingName": "CCCE:MOCK3",
+      "createdBy": "mock user 3",
+      "gitProjectId": 5971,
+      "deployedWithOldPlaybook": false,
+      "activeDeployment": null
     },
     {
-      "id": 148,
-      "description": "some description",
-      "namingName": "RFQ-010:SC-IOC-977",
-      "createdBy": "krisztianloki",
-      "gitProjectId": 5429,
+      "id": 39,
+      "namingName": "CCCE:MOCK4",
+      "createdBy": "mock user 4",
+      "gitProjectId": 5972,
+      "deployedWithOldPlaybook": false,
       "activeDeployment": {
         "host": {
-          "hostId": 4178,
-          "fqdn": "rfq-ipc-01.tn.esss.lu.se",
-          "hostName": "rfq-ipc-01",
-          "network": "ChannelAccess-FEB"
+          "hostId": "MTUyX3RydWU=",
+          "hostName": "ccce-test-ioc-02",
+          "network": "CSLab-GeneralLab",
+          "netBoxHostFromCache": true
         },
-        "sourceVersion": "0.0.2-usb",
-        "sourceVersionShort": "0.0.2-usb"
+        "sourceVersion": "alias",
+        "sourceVersionShort": null
       }
     },
     {
-      "id": 116,
-      "description": "some description",
-      "namingName": "RFQ-010:SC-IOC-005",
-      "createdBy": "joaopaulomartins",
-      "gitProjectId": 1697,
+      "id": 21,
+      "namingName": "CCCE:MOCK5",
+      "createdBy": "mock user 5",
+      "gitProjectId": 8094,
+      "deployedWithOldPlaybook": false,
       "activeDeployment": {
         "host": {
-          "hostId": 4696,
-          "fqdn": "rfq-rflps-vm-ioc01.tn.esss.lu.se",
-          "hostName": "rfq-rflps-vm-ioc01",
-          "network": "ChannelAccess-ACC"
+          "hostId": "MTUyX3RydWU=",
+          "hostName": "ccce-test-ioc-02",
+          "network": "CSLab-GeneralLab",
+          "netBoxHostFromCache": true
         },
         "sourceVersion": "1.0.0",
-        "sourceVersionShort": "1.0.0"
-      }
-    },
-    {
-      "id": 76,
-      "description": "some description",
-      "namingName": "RFQ-010:SC-IOC-004",
-      "createdBy": "joaopaulomartins",
-      "gitProjectId": 5257,
-      "activeDeployment": {
-        "host": {
-          "hostId": 4205,
-          "fqdn": "rfq-rf-vm-ioc.tn.esss.lu.se",
-          "hostName": "rfq-rf-vm-ioc",
-          "network": "ChannelAccess-ACC"
-        },
-        "sourceVersion": "1.1.0",
-        "sourceVersionShort": "1.1.0"
+        "sourceVersionShort": null
       }
     },
     {
-      "id": 13,
-      "description": "some description",
-      "namingName": "RFQ-010:SC-IOC-056",
-      "createdBy": "krisztianloki",
-      "gitProjectId": 5056,
-      "activeDeployment": {
-        "host": {
-          "hostId": 4408,
-          "fqdn": "rfq-lob-vm-ioc.tn.esss.lu.se",
-          "hostName": "rfq-lob-vm-ioc",
-          "network": "ChannelAccess-FEB"
-        },
-        "sourceVersion": "2b8a031d7b698a6944e28408cb17241a7df9ec99",
-        "sourceVersionShort": "2b8a031d"
-      }
-    },
-    {
-      "id": 10,
-      "description": "some description",
-      "namingName": "RFQ-010:SC-IOC-011",
-      "createdBy": "anderslindh",
-      "gitProjectId": 4929,
-      "sourceVersion": "961ebd48020add0282688437ae34dd0974b6fa15",
-      "activeDeployment": {},
-      "sourceVersionShort": "961ebd48"
-    },
-    {
-      "id": 9,
-      "description": "some description",
-      "namingName": "RFQ-010:SC-IOC-010",
-      "createdBy": "anderslindh",
-      "gitProjectId": 4875,
-      "activeDeployment": {
-        "host": {
-          "hostId": 4521,
-          "fqdn": "lab-rf-vm-ioc-02.cslab.esss.lu.se",
-          "hostName": "lab-rf-vm-ioc-02",
-          "network": "CSLab-GeneralLab"
-        },
-        "sourceVersion": "0527d4cfa1c64276634961fefa8f480d00faee26",
-        "sourceVersionShort": "0527d4cf"
-      }
+      "id": 49,
+      "namingName": "CCCE:MOCK6",
+      "createdBy": "mock user 6",
+      "gitProjectId": 12972,
+      "deployedWithOldPlaybook": true,
+      "activeDeployment": null
     },
     {
-      "id": 8,
-      "description": "some description",
-      "namingName": "RFQ-010:SC-IOC-009",
-      "createdBy": "anderslindh",
-      "gitProjectId": 4947,
-      "sourceVersion": null,
-      "activeDeployment": {}
+      "id": 40,
+      "namingName": "CCCE:MOCK-TEST",
+      "createdBy": "mock user",
+      "gitProjectId": 12733,
+      "deployedWithOldPlaybook": true,
+      "activeDeployment": null
     },
     {
-      "id": 6,
-      "description": "some description",
-      "namingName": "RFQ-010:SC-IOC-008",
-      "createdBy": "anderslindh",
-      "gitProjectId": 2582,
-      "sourceVersion": null,
-      "activeDeployment": {}
+      "id": 41,
+      "namingName": "CCCE:MOCK7",
+      "createdBy": "mock user 7",
+      "gitProjectId": 12734,
+      "deployedWithOldPlaybook": true,
+      "activeDeployment": null
     },
     {
-      "id": 4,
-      "description": "some description",
-      "namingName": "RFQ-010:SC-IOC-007",
-      "createdBy": "anderslindh",
-      "gitProjectId": 4877,
-      "activeDeployment": {
-        "host": {
-          "hostId": 4521,
-          "fqdn": "lab-rf-vm-ioc-02.cslab.esss.lu.se",
-          "hostName": "lab-rf-vm-ioc-02",
-          "network": "CSLab-GeneralLab"
-        },
-        "sourceVersion": "cb065da1b6e5dcde6da091a93799ac8488e1e818",
-        "sourceVersionShort": "cb065da1"
-      }
+      "id": 42,
+      "namingName": "CCCE:MOCK8",
+      "createdBy": "mock user 8",
+      "gitProjectId": 12735,
+      "deployedWithOldPlaybook": true,
+      "activeDeployment": null
     },
     {
-      "id": 3,
-      "description": "some description",
-      "namingName": "RFQ-010:SC-IOC-006",
-      "createdBy": "anderslindh",
-      "gitProjectId": 4335,
-      "activeDeployment": {
-        "host": {
-          "hostId": 4205,
-          "fqdn": "rfq-rf-vm-ioc.tn.esss.lu.se",
-          "hostName": "rfq-rf-vm-ioc",
-          "network": "ChannelAccess-ACC"
-        },
-        "sourceVersion": "1.0.0",
-        "sourceVersionShort": "1.0.0"
-      }
+      "id": 43,
+      "namingName": "CCCE:MOCK9",
+      "createdBy": "mock user 9",
+      "gitProjectId": 12736,
+      "deployedWithOldPlaybook": true,
+      "activeDeployment": null
     }
   ]
 }
diff --git a/src/mocks/mockAPI.js b/src/mocks/mockAPI.js
index a43c3edc..f6e077ad 100644
--- a/src/mocks/mockAPI.js
+++ b/src/mocks/mockAPI.js
@@ -220,18 +220,10 @@ function getProcservLogs(req) {
 }
 
 function fetchIocStatus(req) {
-  const params = getParameters(req, "/monitoring/status/:id");
+  const params = getParameters(req, "/iocs/:ioc_id/status");
   const data = require("./fixtures/IOCStatus.json");
-  const { id, alertSeverity, alerts, active } = data.find(
-    (x) => `${x.id}` === params.id
-  );
+  const body = data.find((x) => `${x.iocId}` === params.ioc_id);
 
-  const body = {
-    iocId: id,
-    alertSeverity,
-    alerts,
-    active
-  };
   console.debug("fetchIocStatus", data, params, body);
   const status = body ? 200 : 404;
 
@@ -297,7 +289,9 @@ const mockAPI = {
     getIOC,
     createIoc,
     deleteIOC,
-    getIocDescription
+    getIocDescription,
+    fetchIocStatus,
+    getProcservLogs
   },
   deployments: {
     getDeployment,
@@ -317,10 +311,6 @@ const mockAPI = {
     listProjects,
     listTagsAndCommitIds
   },
-  monitoring: {
-    getProcservLogs,
-    fetchIocStatus
-  },
   statistics: {
     currentlyActiveIocs,
     activeIocHistory,
@@ -382,6 +372,18 @@ export const apiHandlers = [
     mockAPI.iocs.getIocDescription
   ),
 
+  makeHandler(
+    "GET",
+    qRegExp(".*/iocs/[0-9]+/status"),
+    mockAPI.iocs.fetchIocStatus
+  ),
+  makeHandler(
+    "GET",
+    qRegExp(".*/iocs/[A-Za-z0-9+/]+/[A-Za-z0-9+/]+/log"),
+    mockAPI.iocs.getProcservLogs,
+    auth
+  ),
+
   // records
   makeHandler("GET", qRegExp(".*/records"), mockAPI.records.findAllRecords),
 
@@ -452,19 +454,6 @@ export const apiHandlers = [
     mockAPI.hosts.findHostWithStatusById
   ),
 
-  // monitoring
-  makeHandler(
-    "GET",
-    qRegExp(".*/monitoring/procserv/host/.+"),
-    mockAPI.monitoring.getProcservLogs,
-    auth
-  ),
-  makeHandler(
-    "GET",
-    qRegExp(".*/monitoring/status/.+"),
-    mockAPI.monitoring.fetchIocStatus
-  ),
-
   // statistics
   makeHandler(
     "GET",
-- 
GitLab