From fdd278ff05e6d1b73f32fa9490f216d309a5500a Mon Sep 17 00:00:00 2001
From: Johanna Szepanski <johanna.szepanski@softhouse.se>
Date: Thu, 27 Jun 2024 15:14:38 +0200
Subject: [PATCH] Fixed test for IOC table and live status, fixed som stories
 not working as expected

---
 .../IOC/IOCLiveStatus/IOCLiveStatus.spec.js   |  12 +-
 src/components/IOC/IOCTable/IOCTable.spec.js  |   3 +-
 src/mocks/fixtures/IOCDescription.json        |   2 +-
 src/mocks/fixtures/IOCDetails.json            | 300 +++++++++++++-----
 src/mocks/fixtures/PagedIOCResponse.json      |  11 +-
 src/mocks/mockAPI.js                          |   8 +-
 .../views/IOC/IocDetailsView.stories.js       |  15 +-
 7 files changed, 257 insertions(+), 94 deletions(-)

diff --git a/src/components/IOC/IOCLiveStatus/IOCLiveStatus.spec.js b/src/components/IOC/IOCLiveStatus/IOCLiveStatus.spec.js
index 7976d310..da0e0b67 100644
--- a/src/components/IOC/IOCLiveStatus/IOCLiveStatus.spec.js
+++ b/src/components/IOC/IOCLiveStatus/IOCLiveStatus.spec.js
@@ -13,7 +13,7 @@ function IOCLiveStatusContainer() {
 
   const params = useMemo(
     () => ({
-      ioc_id: 4
+      ioc_id: 15
     }),
     []
   );
@@ -28,12 +28,12 @@ function IOCLiveStatusContainer() {
 
 function commonTests() {
   // Expect IOC name in badge
-  cy.contains("CCCE:SC-IOC-004");
+  cy.contains("CCCE:MOCK2");
 
   // Expected in Info table:
-  cy.contains("0.0.1"); // git reference
-  cy.contains("This is a test IOC with mock data and errors"); // description
-  cy.contains("ccpu-evrtm.tn.esss.lu.se"); // deployed on
+  cy.contains("correct_ioc"); // git reference
+  cy.contains("Test IOC for CCCE"); // description
+  cy.contains("ccce-test-ioc-01.cslab.esss.lu.se"); // deployed on
 
   // Expect alerts to be displayed
   cy.get("#ioc-alerts")
@@ -62,7 +62,7 @@ describe("IOCLiveStatus", () => {
     it("displays the logged in view", () => {
       commonTests();
       // check for procserv logs
-      cy.wait("@getProcservLogs");
+      cy.wait("@fetchProcServLogLines");
       cy.contains("This is some fake log data");
     });
   });
diff --git a/src/components/IOC/IOCTable/IOCTable.spec.js b/src/components/IOC/IOCTable/IOCTable.spec.js
index 6508c8de..227f7b8c 100644
--- a/src/components/IOC/IOCTable/IOCTable.spec.js
+++ b/src/components/IOC/IOCTable/IOCTable.spec.js
@@ -7,7 +7,7 @@ const textColumns = ["IOC name", "Description", "Host", "Network"];
 const columns = ["Status"].concat(textColumns);
 const firstRowData = [
   "Alert 1 warnings1 errors !",
-  "VacS-RFQ:SC-IOC-130",
+  "CCCE:MOCK1",
   "Some description",
   "vacs-accv-vm-ioc",
   "ChannelAccess-FEB"
@@ -21,7 +21,6 @@ describe("IOCTable", () => {
 
     it("Has the correct columns", () => {
       cy.findAllByRole("columnheader").each(($el, index) => {
-        console.debug(index, columns[index]);
         cy.wrap($el).contains(columns[index], { matchCase: false });
       });
     });
diff --git a/src/mocks/fixtures/IOCDescription.json b/src/mocks/fixtures/IOCDescription.json
index dcdd5377..88bfc4e5 100644
--- a/src/mocks/fixtures/IOCDescription.json
+++ b/src/mocks/fixtures/IOCDescription.json
@@ -1,7 +1,7 @@
 [
   {
     "id": 14,
-    "description": "This is a test IOC for demonstrating the deployment tool"
+    "description": ""
   },
   {
     "id": 15,
diff --git a/src/mocks/fixtures/IOCDetails.json b/src/mocks/fixtures/IOCDetails.json
index 80ca251b..eddd427e 100644
--- a/src/mocks/fixtures/IOCDetails.json
+++ b/src/mocks/fixtures/IOCDetails.json
@@ -1,24 +1,77 @@
 [
   {
-    "id": 1,
-    "description": "This is a test IOC for demonstrating the deployment tool",
-    "createdBy": "johnsparger",
-    "namingName": "CCCE:SC-IOC-001",
-    "namingUuid": "77325d6f-6d85-443f-b448-3d99a941e23e",
-    "gitProjectId": 5215,
-    "sourceUrl": "https://gitlab.esss.lu.se/ccce/dev/iocs/e3-ioc-test_49.git",
-    "sourceVersion": "0.0.1",
-    "sourceVersionShort": "0.0.1",
+    "id": 14,
+    "description": "Some description",
+    "createdBy": "mock user 1",
+    "namingName": "CCCE:MOCK1",
+    "namingUuid": "82a01351-2892-491e-932b-6fe438216cfd",
+    "gitProjectId": 5959,
+    "sourceUrl": "https://gitlab.esss.lu.se/ccce/dev/iocs/instances/e3-ioc-test-01.git",
     "activeDeployment": null,
-    "alerts": [],
+    "deployedWithOldPlaybook": true,
+    "alerts": [
+      {
+        "type": "INFO",
+        "message": "IOC is not deployed",
+        "link": null
+      }
+    ],
     "operationInProgress": false,
     "active": null
   },
   {
-    "id": 2,
-    "description": "Test instance used by the CCCE team, with mock data",
-    "createdBy": "christinajenks",
-    "namingName": "CCCE:SC-IOC-002",
+    "id": 15,
+    "description": "Test IOC for CCCE",
+    "namingName": "CCCE:MOCK2",
+    "createdBy": "mock user 2",
+    "namingUuid": "0a7fdee4-cfa6-447f-ab85-ae9335507fd3",
+    "gitProjectId": 5970,
+    "sourceUrl": "https://gitlab.esss.lu.se/ccce/dev/iocs/instances/e3-ioc-test-02.git",
+    "activeDeployment": {
+      "id": 410,
+      "createdBy": "johannaszepanski",
+      "startDate": "2024-06-05T09:37:56.994+0200",
+      "createdAt": "2024-06-05T09:37:24.577+0200",
+      "undeployment": false,
+      "namingName": "CCCE:SC-IOC-020",
+      "gitProjectId": 5970,
+      "sourceVersion": "correct_ioc",
+      "operationId": 560,
+      "endDate": "2024-06-05T09:39:06.763+0200",
+      "iocName": "CCCE:SC-IOC-020",
+      "host": {
+        "hostId": "MTUxX3RydWU=",
+        "externalIdValid": true,
+        "fqdn": "ccce-test-ioc-01.cslab.esss.lu.se",
+        "hostName": "ccce-test-ioc-01",
+        "network": "CSLab-GeneralLab"
+      },
+      "awxJobId": 6588,
+      "sourceUrl": "https://gitlab.esss.lu.se/ccce/dev/iocs/instances/e3-ioc-test-02.git",
+      "sourceVersionShort": "d4df546c",
+      "operationStatus": "FAILED"
+    },
+    "deployedWithOldPlaybook": false,
+    "alerts": [
+      {
+        "type": "ERROR",
+        "message": "Example alert without link",
+        "link": null
+      },
+      {
+        "type": "ERROR",
+        "message": "Example alert with link",
+        "link": "https://google.com"
+      }
+    ],
+    "operationInProgress": false,
+    "active": null
+  },
+  {
+    "id": 18,
+    "description": "Some description",
+    "namingName": "CCCE:MOCK3",
+    "createdBy": "mock user 3",
     "namingUuid": "7bb52b4b-80d8-4cd9-b09a-88a9d1216df9",
     "gitProjectId": 5971,
     "sourceUrl": "https://gitlab.esss.lu.se/ccce/dev/iocs/instances/e3-ioc-test-03.git",
@@ -35,91 +88,194 @@
     "active": null
   },
   {
-    "id": 3,
-    "description": "This is a test IOC with mock data",
-    "createdBy": "gabrielfedel",
-    "namingName": "CCCE:SC-IOC-003",
-    "namingUuid": "40e4561e-6688-4324-b03a-dc6e4c44b06b",
-    "gitProjectId": 9332,
-    "sourceUrl": "https://gitlab.esss.lu.se/iocs/manual/e3-ioc-rastermagnets-evr-1.git",
+    "id": 39,
+    "description": "",
+    "namingName": "CCCE:MOCK4",
+    "createdBy": "mock user 4",
+    "namingUuid": "b4589713-b42a-4131-a086-4307ca381d81",
+    "gitProjectId": 5972,
+    "sourceUrl": "https://gitlab.esss.lu.se/ccce/dev/iocs/instances/e3-ioc-test-04.git",
     "activeDeployment": {
-      "id": 10440,
-      "createdBy": "gabrielfedel",
-      "startDate": "2024-05-08T09:28:47.068+0200",
-      "createdAt": "2024-05-08T09:28:34.497+0200",
+      "id": 408,
+      "createdBy": "johannaszepanski",
+      "startDate": "2024-06-05T09:25:40.892+0200",
+      "createdAt": "2024-06-05T09:25:08.891+0200",
       "undeployment": false,
-      "namingName": "A2T-010Row:SC-IOC-002",
-      "gitProjectId": 9332,
-      "sourceVersion": "0.0.1",
-      "operationId": 13860,
-      "endDate": "2024-05-08T09:31:31.378+0200",
-      "iocName": "A2T-010Row:SC-IOC-002",
+      "namingName": "CCCE:SC-IOC-040",
+      "gitProjectId": 5972,
+      "sourceVersion": "alias",
+      "operationId": 558,
+      "endDate": "2024-06-05T09:26:59.372+0200",
+      "iocName": "CCCE:SC-IOC-040",
       "host": {
-        "hostId": "NDE5NV90cnVl",
+        "hostId": "MTUyX3RydWU=",
         "externalIdValid": true,
-        "fqdn": "ccpu-evrtm.tn.esss.lu.se",
-        "hostName": "ccpu-evrtm",
-        "network": "Controls-Linac"
+        "fqdn": "ccce-test-ioc-02.cslab.esss.lu.se",
+        "hostName": "ccce-test-ioc-02",
+        "network": "CSLab-GeneralLab"
       },
-      "awxJobId": 495642,
-      "sourceUrl": "https://gitlab.esss.lu.se/iocs/manual/e3-ioc-rastermagnets-evr-1.git",
-      "sourceVersionShort": "fd7e5c70",
-      "operationStatus": "SUCCESSFUL"
+      "awxJobId": 6580,
+      "sourceUrl": "https://gitlab.esss.lu.se/ccce/dev/iocs/instances/e3-ioc-test-04.git",
+      "sourceVersionShort": "8fd94089",
+      "operationStatus": "FAILED"
     },
-    "alerts": [],
     "deployedWithOldPlaybook": false,
+    "alerts": [],
     "operationInProgress": false,
-    "active": true
+    "active": null
   },
   {
-    "id": 4,
-    "description": "This is a test IOC with mock data and errors",
-    "createdBy": "gabrielfedel",
-    "namingName": "CCCE:SC-IOC-004",
-    "namingUuid": "40e4561e-6688-4324-b03a-dc6e4c44b06b",
-    "gitProjectId": 9332,
-    "sourceUrl": "https://gitlab.esss.lu.se/iocs/manual/e3-ioc-rastermagnets-evr-1.git",
+    "id": 21,
+    "namingName": "CCCE:MOCK5",
+    "createdBy": "mock user 5",
+    "namingUuid": "094b4411-447b-43f1-966b-6a37faf46366",
+    "gitProjectId": 8094,
+    "sourceUrl": "https://gitlab.esss.lu.se/ccce/dev/iocs/instances/e3-ioc-test-05.git",
     "activeDeployment": {
-      "id": 10440,
-      "createdBy": "gabrielfedel",
-      "startDate": "2024-05-08T09:28:47.068+0200",
-      "createdAt": "2024-05-08T09:28:34.497+0200",
+      "id": 397,
+      "createdBy": "simonrose",
+      "startDate": "2024-04-11T09:30:18.786+0200",
+      "createdAt": "2024-04-11T09:29:48.620+0200",
       "undeployment": false,
-      "namingName": "A2T-010Row:SC-IOC-002",
-      "gitProjectId": 9332,
-      "sourceVersion": "0.0.1",
-      "operationId": 13860,
-      "endDate": "2024-05-08T09:31:31.378+0200",
-      "iocName": "A2T-010Row:SC-IOC-002",
+      "namingName": "CCCE:SC-IOC-050",
+      "gitProjectId": 8094,
+      "sourceVersion": "1.0.0",
+      "operationId": 546,
+      "endDate": "2024-04-11T09:31:53.395+0200",
+      "iocName": "CCCE:SC-IOC-050",
       "host": {
-        "hostId": "NDE5NV90cnVl",
+        "hostId": "MTUyX3RydWU=",
         "externalIdValid": true,
-        "fqdn": "ccpu-evrtm.tn.esss.lu.se",
-        "hostName": "ccpu-evrtm",
-        "network": "Controls-Linac"
+        "fqdn": "ccce-test-ioc-02.cslab.esss.lu.se",
+        "hostName": "ccce-test-ioc-02",
+        "network": "CSLab-GeneralLab"
       },
-      "awxJobId": 495642,
-      "sourceUrl": "https://gitlab.esss.lu.se/iocs/manual/e3-ioc-rastermagnets-evr-1.git",
-      "sourceVersionShort": "fd7e5c70",
+      "awxJobId": 6479,
+      "sourceUrl": "https://gitlab.esss.lu.se/ccce/dev/iocs/instances/e3-ioc-test-05.git",
+      "sourceVersionShort": "da21c190",
       "operationStatus": "SUCCESSFUL"
     },
+    "deployedWithOldPlaybook": false,
+    "alerts": [],
+    "operationInProgress": false,
+    "active": null
+  },
+  {
+    "id": 49,
+    "description": "some fun description",
+    "namingName": "CCCE:MOCK6",
+    "createdBy": "mock user 6",
+    "namingUuid": "36a9cb87-66dc-4ba6-aff8-290389b083d1",
+    "gitProjectId": 12972,
+    "sourceUrl": "https://gitlab.esss.lu.se/ccce/dev/iocs/instances/e3-ioc-jsztest-3.git",
+    "activeDeployment": null,
+    "deployedWithOldPlaybook": true,
+    "alerts": [
+      {
+        "type": "INFO",
+        "message": "IOC is not deployed",
+        "link": null
+      }
+    ],
+    "operationInProgress": false,
+    "active": null
+  },
+  {
+    "id": 40,
+    "namingName": "CCCE:MOCK-TEST",
+    "createdBy": "mock user",
+    "namingUuid": "0eb277a2-0984-4f94-a8de-9c31f0c4948b",
+    "gitProjectId": null,
+    "sourceUrl": null,
+    "activeDeployment": null,
+    "deployedWithOldPlaybook": true,
     "alerts": [
       {
         "type": "ERROR",
-        "message": "Example alert without link"
+        "message": "Cannot find the repository in Gitlab",
+        "link": null
       },
+      {
+        "type": "INFO",
+        "message": "IOC is not deployed",
+        "link": null
+      }
+    ],
+    "operationInProgress": false,
+    "active": null
+  },
+  {
+    "id": 41,
+    "namingName": "CCCE:MOCK7",
+    "createdBy": "mock user 7",
+    "namingUuid": "aa819884-2422-4227-91fb-60245db3d453",
+    "gitProjectId": null,
+    "sourceUrl": null,
+    "activeDeployment": null,
+    "deployedWithOldPlaybook": true,
+    "alerts": [
       {
         "type": "ERROR",
-        "message": "Example alert with link",
-        "link": "https://google.com"
+        "message": "Cannot find the repository in Gitlab",
+        "link": null
+      },
+      {
+        "type": "INFO",
+        "message": "IOC is not deployed",
+        "link": null
       }
     ],
-    "deployedWithOldPlaybook": false,
     "operationInProgress": false,
-    "active": true
+    "active": null
   },
   {
-    "id": 346,
-    "description": "Some description"
+    "id": 42,
+    "description": "some description",
+    "namingName": "CCCE:MOCK8",
+    "createdBy": "mock user 8",
+    "namingUuid": "9f7f3ca9-f088-4c93-9663-6051dc06df68",
+    "gitProjectId": null,
+    "sourceUrl": null,
+    "activeDeployment": null,
+    "deployedWithOldPlaybook": true,
+    "alerts": [
+      {
+        "type": "ERROR",
+        "message": "Cannot find the repository in Gitlab",
+        "link": null
+      },
+      {
+        "type": "INFO",
+        "message": "IOC is not deployed",
+        "link": null
+      }
+    ],
+    "operationInProgress": false,
+    "active": null
+  },
+  {
+    "id": 43,
+    "description": "some description",
+    "namingName": "CCCE:MOCK9",
+    "createdBy": "mock user 9",
+    "namingUuid": "da6be15b-1366-41be-af74-a8c84175cbc1",
+    "gitProjectId": null,
+    "sourceUrl": null,
+    "activeDeployment": null,
+    "deployedWithOldPlaybook": true,
+    "alerts": [
+      {
+        "type": "ERROR",
+        "message": "Cannot find the repository in Gitlab",
+        "link": null
+      },
+      {
+        "type": "INFO",
+        "message": "IOC is not deployed",
+        "link": null
+      }
+    ],
+    "operationInProgress": false,
+    "active": null
   }
 ]
diff --git a/src/mocks/fixtures/PagedIOCResponse.json b/src/mocks/fixtures/PagedIOCResponse.json
index 7bb659dd..5c4f6d0a 100644
--- a/src/mocks/fixtures/PagedIOCResponse.json
+++ b/src/mocks/fixtures/PagedIOCResponse.json
@@ -10,7 +10,16 @@
       "createdBy": "mock user 1",
       "gitProjectId": 5959,
       "deployedWithOldPlaybook": true,
-      "activeDeployment": null
+      "activeDeployment": {
+        "host": {
+          "hostId": "MTUxX3RydWU=",
+          "hostName": "vacs-accv-vm-ioc",
+          "network": "ChannelAccess-FEB",
+          "netBoxHostFromCache": true
+        },
+        "sourceVersion": "correct_ioc",
+        "sourceVersionShort": null
+      }
     },
     {
       "id": 15,
diff --git a/src/mocks/mockAPI.js b/src/mocks/mockAPI.js
index f6e077ad..b2224285 100644
--- a/src/mocks/mockAPI.js
+++ b/src/mocks/mockAPI.js
@@ -214,7 +214,7 @@ function fetchHostStatus(req) {
   return { body, status };
 }
 
-function getProcservLogs(req) {
+function fetchProcServLogLines(req) {
   const body = require("./fixtures/LokiResponse.json");
   return { body };
 }
@@ -291,7 +291,7 @@ const mockAPI = {
     deleteIOC,
     getIocDescription,
     fetchIocStatus,
-    getProcservLogs
+    fetchProcServLogLines
   },
   deployments: {
     getDeployment,
@@ -379,8 +379,8 @@ export const apiHandlers = [
   ),
   makeHandler(
     "GET",
-    qRegExp(".*/iocs/[A-Za-z0-9+/]+/[A-Za-z0-9+/]+/log"),
-    mockAPI.iocs.getProcservLogs,
+    qRegExp(".*/iocs/.*/.*/log"),
+    mockAPI.iocs.fetchProcServLogLines,
     auth
   ),
 
diff --git a/src/stories/views/IOC/IocDetailsView.stories.js b/src/stories/views/IOC/IocDetailsView.stories.js
index 60f4ac58..de85654b 100644
--- a/src/stories/views/IOC/IocDetailsView.stories.js
+++ b/src/stories/views/IOC/IocDetailsView.stories.js
@@ -16,26 +16,25 @@ const Template = (args) => (
   </AppHarness>
 );
 
-export const Default = (args) => <Template {...args} />;
-Default.args = {
+const config = {
   id: 1,
   ...userImpersonatorArgs
 };
 
 export const NotDeployed = (args) => <Template {...args} />;
 NotDeployed.args = {
-  ...Default.args,
-  id: 2
+  ...config,
+  id: 18
 };
 
 export const Deployed = (args) => <Template {...args} />;
 Deployed.args = {
-  ...Default.args,
-  id: 3
+  ...config,
+  id: 39
 };
 
 export const DeployedErrors = (args) => <Template {...args} />;
 DeployedErrors.args = {
-  ...Default.args,
-  id: 4
+  ...config,
+  id: 15
 };
-- 
GitLab