From b5b275d4f6f72d3291b1a49038eb6f2d7b9aa535 Mon Sep 17 00:00:00 2001
From: MelvLee <github-action@actions-template-sync.noreply.github.com>
Date: Wed, 21 Aug 2024 00:15:49 +0000
Subject: [PATCH] chore: sync met 'BRP-API/brp-shared-dotnet' repo

Signed-off-by: MelvLee <github-action@actions-template-sync.noreply.github.com>
---
 features/step_definitions/als-stepdefs.js | 23 ++++++++-----------
 features/step_definitions/stepdefs.js     | 28 -----------------------
 features/step_definitions/world.js        | 18 ++++++++++++---
 3 files changed, 25 insertions(+), 44 deletions(-)

diff --git a/features/step_definitions/als-stepdefs.js b/features/step_definitions/als-stepdefs.js
index 72d62e2..a76497b 100644
--- a/features/step_definitions/als-stepdefs.js
+++ b/features/step_definitions/als-stepdefs.js
@@ -4,17 +4,6 @@ const { executeSqlStatements } = require('./postgresqlHelpers');
 const { addDefaultAutorisatieSettings,
         handleRequest } = require('./requestHelpers');
 
-const apiEndpointPrefixMap = new Map([
-    ['bewoningen', 'bewoning'],
-    ['personen', 'brp'],
-    ['reisdocumenten', 'reisdocumenten'],
-    ['verblijfplaatshistorie', 'brphistorie'],
-    // niet bestaande endpoints
-    ['ingezetenen', 'brp'],
-    ['paspoorten', 'reisdocumenten'],
-    ['verblijfhistorie', 'brphistorie']
-]);
-
 When(/^([a-zA-Z-]*) wordt gezocht met de volgende parameters$/, async function (endpoint, dataTable) {
     if(this.context.afnemerID === undefined) {
         this.context.afnemerID = this.context.oAuth.clients[0].afnemerID;
@@ -40,7 +29,11 @@ When(/^([a-zA-Z-]*) wordt gezocht met de volgende parameters$/, async function (
 
     await executeSqlStatements(this.context.sql, this.context.sqlData, global.pool);
 
-    await handleRequest(this.context, `${apiEndpointPrefixMap.get(endpoint)}/${endpoint}`, dataTable);
+    const relativeUrl = this.context.apiEndpointPrefixMap.has(endpoint)
+        ? `${this.context.apiEndpointPrefixMap.get(endpoint)}/${endpoint}`
+        : '';
+
+    await handleRequest(this.context, relativeUrl, dataTable);
 });
 
 When(/^([a-zA-Z-]*) wordt gezocht met een '(\w*)' aanroep$/, async function (endpoint, httpMethod) {
@@ -48,5 +41,9 @@ When(/^([a-zA-Z-]*) wordt gezocht met een '(\w*)' aanroep$/, async function (end
         this.context.afnemerID = this.context.oAuth.clients[0].afnemerID;
     }
 
-    await handleRequest(this.context, `${apiEndpointPrefixMap.get(endpoint)}/${endpoint}`, undefined, httpMethod);
+    const relativeUrl = this.context.apiEndpointPrefixMap.has(endpoint)
+        ? `${this.context.apiEndpointPrefixMap.get(endpoint)}/${endpoint}`
+        : '';
+
+    await handleRequest(this.context, relativeUrl, undefined, httpMethod);
 });
diff --git a/features/step_definitions/stepdefs.js b/features/step_definitions/stepdefs.js
index d005ba2..a7fcd05 100644
--- a/features/step_definitions/stepdefs.js
+++ b/features/step_definitions/stepdefs.js
@@ -48,38 +48,10 @@ Before(function({ pickle }) {
         const array = fs.readFileSync(this.context.logFileToAssert).toString().split("\n");
         this.context.nrOfLogLines = array.length;
     }
-});
 
-Before({tags: '@api'}, function() {
-    global.logger.debug('api scope. set baseUrl to apiUrl');
     this.context.baseUrl = this.context.apiUrl;
 });
 
-Before({tags: '@proxy'}, function() {
-    global.logger.debug('proxy scope. set baseUrl to proxyUrl');
-    this.context.baseUrl = this.context.proxyUrl;
-});
-
-Before({tags: '@mock'}, function() {
-    global.logger.debug('mock scope. set baseUrl to mockUrl');
-    this.context.baseUrl = this.context.mockUrl;
-});
-
-Before({tags: '@input-validatie'}, function() {
-    global.logger.debug('input-validatie scope. set baseUrl to autzUrl');
-    this.context.baseUrl = this.context.autzUrl;
-});
-
-Before({tags: '@autorisatie'}, function() {
-    global.logger.debug('autorisatie scope. set baseUrl to autzUrl');
-    this.context.baseUrl = this.context.autzUrl;
-});
-
-Before({tags: '@protocollering'}, function() {
-    global.logger.debug('protocollering scope. set baseUrl to autzUrl');
-    this.context.baseUrl = this.context.autzUrl;
-});
-
 After(async function({ pickle }) {
     if(pickle.tags.map((t) => t.name).includes('@stap-documentatie')) {
         return;
diff --git a/features/step_definitions/world.js b/features/step_definitions/world.js
index 6480dd1..e7117d4 100644
--- a/features/step_definitions/world.js
+++ b/features/step_definitions/world.js
@@ -78,9 +78,21 @@ class World {
     constructor(parameters) {
         this.context = parameters;
 
-        this.context.autzUrl = 'http://localhost:8080/haalcentraal/api'
-        this.context.apiUrl = 'http://localhost:8000/haalcentraal/api'
-        this.context.proxyUrl = 'http://localhost:5002/haalcentraal/api'
+        this.context.apiUrl = 'http://localhost:8080/haalcentraal/api'
+
+        // wanneer een endpoint prefix mapping voorkomt, wordt bij de constructie van de endpoint url de prefix voor de resource naam gezet
+        // bijv. voor de personen resource wordt de endpoint url <apiUrl>/brp/personen
+        // als er geen endpoint prefix mapping voorkomt, wordt de apiUrl gebruikt als endpoint url
+        this.context.apiEndpointPrefixMap = new Map([
+            ['bewoningen', 'bewoning'],
+            ['personen', 'brp'],
+            ['reisdocumenten', 'reisdocumenten'],
+            ['verblijfplaatshistorie', 'brphistorie'],
+            // niet bestaande endpoints
+            ['ingezetenen', 'brp'],
+            ['paspoorten', 'reisdocumenten'],
+            ['verblijfhistorie', 'brphistorie']
+        ]);
 
         this.context.gezagDataPath = './test-data/GezagMock/test-data.json';
         this.context.logFileToAssert = './test-data/logs/brp-proxy.json';