Skip to content

Commit

Permalink
Merge pull request #4 from BRP-API/chore/sync-met-source-repo_6ece6bd
Browse files Browse the repository at this point in the history
sync met 'BRP-API/brp-shared-dotnet' repo
  • Loading branch information
MelvLee authored Jun 4, 2024
2 parents 17aa81b + 4e887b2 commit e817bb4
Showing 1 changed file with 78 additions and 62 deletions.
140 changes: 78 additions & 62 deletions features/step_definitions/world.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,79 @@
const { createLogger, format, transports } = require('winston');

function setContextProperties(parameters, context) {
for(const key in parameters) {
if(!parameters.hasOwnProperty(key)) continue;
if(key === "__proto__" || key === "constructor") continue;

if(typeof(parameters[key]) === 'object') {
if(context[key] === undefined) {
context[key] = {};
}
setContextProperties(parameters[key], context[key]);
}
else {
context[key] = parameters[key];
}
}
}

function configureSqlSettings(context) {
context.sql = {
useDb: true,
cleanup: true,
deleteIndividualRecords: true,
poolConfig: {
user: 'root',
host: 'localhost',
database: 'rvig_haalcentraal_testdata',
password: 'root',
port: 5432,
allowExitOnIdle: true
}
};
}

function configureOAuthSettings(context) {
context.oAuth = {
enable: true,
accessTokenUrl: 'http://identityserver:6000/connect/token',
clients:[
{
afnemerID: '000008',
gemeenteCode: '0800',
clientId: 'client met gemeentecode (eigen gemeente)',
clientSecret: 'secret',
scopes: [ '000000099000000080000' ],
resourceServer: 'ResourceServer02'
},
{
afnemerID: '000008',
gemeenteCode: '0599',
clientId: 'client met gemeentecode (ander gemeente)',
clientSecret: 'secret',
scopes: [ '000000099000000080000' ],
resourceServer: 'ResourceServer02'
},
{
afnemerID: '000008',
clientId: 'client zonder gemeentecode',
clientSecret: 'secret',
scopes: [ '000000099000000080000' ],
resourceServer: 'ResourceServer02'
}
]
}
}

function configureLogger(context) {
context.logger = createLogger({
level: 'warn',
transports: [
new transports.Console({ format: format.prettyPrint() })
]
});
}

class World {
constructor(parameters) {
this.context = parameters;
Expand All @@ -12,69 +86,11 @@ class World {
this.context.logFileToAssert = './test-data/logs/brp-proxy.json';
this.context.downstreamApiDataPath = './test-data/DownstreamApi';

this.context.sql = {
useDb: true,
cleanup: true,
deleteIndividualRecords: true,
poolConfig: {
user: 'root',
host: 'localhost',
database: 'rvig_haalcentraal_testdata',
password: 'root',
port: 5432,
allowExitOnIdle: true
}
};
configureSqlSettings(this.context);
configureOAuthSettings(this.context);
configureLogger(this.context);

this.context.oAuth = {
enable: true,
accessTokenUrl: 'http://identityserver:6000/connect/token',
clients:[
{
afnemerID: '000008',
gemeenteCode: '0800',
clientId: 'client met gemeentecode (eigen gemeente)',
clientSecret: 'secret',
scopes: [ '000000099000000080000' ],
resourceServer: 'ResourceServer02'
},
{
afnemerID: '000008',
gemeenteCode: '0599',
clientId: 'client met gemeentecode (ander gemeente)',
clientSecret: 'secret',
scopes: [ '000000099000000080000' ],
resourceServer: 'ResourceServer02'
},
{
afnemerID: '000008',
clientId: 'client zonder gemeentecode',
clientSecret: 'secret',
scopes: [ '000000099000000080000' ],
resourceServer: 'ResourceServer02'
}
]
}

this.context.logger = createLogger({
level: 'warn',
transports: [
new transports.Console({ format: format.prettyPrint() })
]
});

if(this.context.parameters?.poolConfig !== undefined) {
this.context.sql.poolConfig.host = this.context.parameters.poolConfig.host;
this.context.sql.poolConfig.user = this.context.parameters.poolConfig.user;
this.context.sql.poolConfig.password = this.context.parameters.poolConfig.password
}
if(this.context.parameters?.client !== undefined) {
this.context.oAuth.clients[0].clientId = this.context.parameters.client.clientId;
this.context.oAuth.clients[0].clientSecret = this.context.parameters.client.clientSecret;
}
if(this.context.parameters?.enableOAuth !== undefined) {
this.context.oAuth.enable = this.context.parameters.enableOAuth === 'true';
}
setContextProperties(parameters.parameters, this.context);
}
}

Expand Down

0 comments on commit e817bb4

Please sign in to comment.