From 69384d9727a6b4f07e3c8a7a62c20fd63bc62d78 Mon Sep 17 00:00:00 2001
From: Georgi Michev <georgi.michev@vereign.com>
Date: Fri, 24 Nov 2023 16:39:36 +0200
Subject: [PATCH] Update webhook for policy change

Update the test with more relevant scenarios, which are meant for
demonstration only.

Signed-off-by: Georgi Michev <georgi.michev@vereign.com>
---
 src/main/resources/REST/json/Webhook.json     | 12 ++++++
 .../{version}/notifychange/POST.feature       | 41 ++++++++++++++++++-
 2 files changed, 52 insertions(+), 1 deletion(-)
 create mode 100644 src/main/resources/REST/json/Webhook.json

diff --git a/src/main/resources/REST/json/Webhook.json b/src/main/resources/REST/json/Webhook.json
new file mode 100644
index 00000000..40a3535d
--- /dev/null
+++ b/src/main/resources/REST/json/Webhook.json
@@ -0,0 +1,12 @@
+{
+  "successful_address": {
+    "subscriber": "vereign.test.policy",
+    "webhook_url": "https://webhook.site/4d79f1a0-9608-4d5b-9187-dfe18ae3467b"
+  },
+  "missing_url": {
+    "subscriber": "vereign.rest.policy"
+  },
+  "missing_subscriber": {
+    "webhook_url": "https://webhook.site/4d79f1a0-9608-4d5b-9187-dfe18ae3467b"
+  }
+}
\ No newline at end of file
diff --git a/src/test/resources/features/tsa/policy/policy/{respository}/{group}/{name}/{version}/notifychange/POST.feature b/src/test/resources/features/tsa/policy/policy/{respository}/{group}/{name}/{version}/notifychange/POST.feature
index d34d63ab..0e4afc7e 100644
--- a/src/test/resources/features/tsa/policy/policy/{respository}/{group}/{name}/{version}/notifychange/POST.feature
+++ b/src/test/resources/features/tsa/policy/policy/{respository}/{group}/{name}/{version}/notifychange/POST.feature
@@ -1,6 +1,6 @@
 #Copyright (c) 2023 Vereign AG [https://www.vereign.com]
 
-@rest @all @tsa @policy @phase2 @IDM.TSA.E1.00007 @wip
+@rest @all @tsa @policy @phase2 @IDM.TSA.E1.00007 @IDM.TSA.E1.00008 @wip
 Feature: API - TSA -Policy - :group/:name/:version/notifychange POST
   As user
   I want to be able to subscribe for events for the Policy service
@@ -21,3 +21,42 @@ Feature: API - TSA -Policy - :group/:name/:version/notifychange POST
     And The same message should have field {type} which has value {update_policy}
     And the response is valid according to the {update_policy_message_schema.json} REST schema
     Then I unlock the policy group {example} name {test} version {1.0}
+
+  Scenario: TSA - Get notifications from Webhook for policy change - Positive
+    When I load the REST request {Webhook.json} with profile {successful_address}
+    And I send the request to the notify change
+    Then the status code should be {200}
+    And I lock the Policy group {example} name {test} version {1.0}
+    Then the status code should be {200}
+    Then I should see a message with field {repository} which has value {policies}
+    Then I should see a message with field {name} which has value {locked}
+    Then I should see a message with field {version} which has value {1.0}
+    Then I should see a message with field {group} which has value {example}
+
+  @negative
+  Scenario: TSA - Subscribe for second time to the Webhook for policy change - Negative
+    When I load the REST request {Webhook.json} with profile {successful_address}
+    And I send the request to the notify change with group {example} name {test} version {1.0} via TSA Policy API
+    Then the status code should be {500}
+    Then the field {message} has the value {subscriber already exists}
+
+  @negative
+  Scenario: TSA - Get notifications from Webhook for policy change with missing url - Negative
+    When I load the REST request {Webhook.json} with profile {missing_url}
+    And I send the request to the notify change with group {example} name {test} version {1.0} via TSA Policy API
+    Then the status code should be {400}
+    Then the field {message} has the value {"webhook_url" is missing from body}
+
+  @negative
+  Scenario: TSA - Get notifications from Webhook for policy change with missing subscriber - Negative
+    When I load the REST request {Webhook.json} with profile {missing_subscriber}
+    And I send the request to the notify change with group {example} name {test} version {1.0} via TSA Policy API
+    Then the status code should be {400}
+    Then the field {message} has the value {"subscriber" is missing from body}
+
+  @negative
+  Scenario: TSA - Get notifications from Webhook for non-existing policy - Negative
+    When I load the REST request {Webhook.json} with profile {successful_address}
+    And I send the request to the notify change with group {example} name {non_existing} version {1.0} via TSA Policy API
+    Then the status code should be {500}
+    Then the field {message} has the value {mongo: no documents in result}
-- 
GitLab