Skip to content

Commit

Permalink
BDD
Browse files Browse the repository at this point in the history
  • Loading branch information
jacopocarlini committed Jul 4, 2022
1 parent 863d06c commit ce3b878
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ target/**/*
/.idea/
emulatorcert.crt
.env
**/*paDemandPaymentNoticeRequest.xml
**/*paDemandPaymentNoticeRequest.xml
/node_modules/
**/package-lock.json
**/package.json
16 changes: 16 additions & 0 deletions integartion-test/features/organizations.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Feature: All about Organizations

Scenario: An organization creates an enrollment
Given the organization "777777"
When the organization enrolls in the service "service-1"
Then the organization is enrolled in the service

Scenario: An organization tries to create an enrollment, but service not found
Given the organization "777777"
When the organization enrolls in the service "service-not-found"
Then the organization gets the status code 404

Scenario: An organization deletes an enrollment
Given the organization "777777" with the service "service-1"
When the organization deletes the service "service-1"
Then the organization isn't enrolled in the service
17 changes: 17 additions & 0 deletions integartion-test/features/services.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Feature: All about Services

Scenario: success services list
Given some services in the DB
When the client get all services
Then the client receives status code of 200
And the client retrieves the list of services

Scenario: get service with success
Given some services in the DB
When the client get service "d"
Then the client receives status code of 200

Scenario: service not found
Given no services in the DB
When the client get service 1
Then the client receives status code of 404
55 changes: 55 additions & 0 deletions integartion-test/features/support/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const axios = require("axios");
const assert = require("assert");

const gps_host = 'http://localhost:9090';

function get(url) {
return axios.get(gps_host + url)
.then(res => {
return res;
})
.catch(error => {
assert.fail(error);
});
}

function post(url, body) {
return axios.post(gps_host + url, body)
.then(res => {
return res;
})
.catch(error => {
assert.fail(error);
});
}

function put(url, body) {
return axios.put(gps_host + url, body)
.then(res => {
return res;
})
.catch(error => {
assert.fail(error);
});
}


function del(url) {
return axios.delete(gps_host + url)
.then(res => {
return res;
})
.catch(error => {
assert.fail(error);
});
}

function randomIban() {
return "IT" + (Math.round(Math.random() * 89999999) + 10000000);
}

function randomName() {
return "Name_" + Math.floor(Math.random() * 100);
}

module.exports = {get, post, put, del, randomIban, randomName}
49 changes: 49 additions & 0 deletions integartion-test/features/support/organizations_steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const assert = require('assert')
const {Given, When, Then} = require('@cucumber/cucumber')
const {post, get, randomIban, randomName} = require("./common");

let responseToCheck;
let organization;
let enrollments;


// Given

Given('the organization {string}', async function (idOrg) {
responseToCheck = await post(`/organizations/${idOrg}`, {companyName: idOrg});
assert.strictEqual(responseToCheck.status, 201);
organization = responseToCheck.data;
organization.code = idOrg;
});

Given('the organization {string} with the service {string}', async function (idOrg, idService) {
responseToCheck = await post(`/organizations/${idOrg}`, {companyName: idOrg,
enrollments: [{
serviceId: idService,
iban: randomIban(),
officeName: randomName()
}]});
assert.strictEqual(responseToCheck.status, 201);
organization = responseToCheck.data;
organization.code = idOrg;
});


// When
When('the organization enrolls in the service {string}', async function (idService) {
responseToCheck = await post(`/organizations/${organization.code}/services/${idService}`, {
iban: randomIban(),
officeName: randomName()
});
assert.strictEqual(responseToCheck.status, 201);
enrollments = responseToCheck.data;
});


// Then

Then(/^the organization is enrolled in the service$/, async function () {
responseToCheck = await get(`/organizations/${organization.code}`);
assert.strictEqual(responseToCheck.status, 200);
assert.deepStrictEqual(responseToCheck.data.enrollments, enrollments)
});
36 changes: 36 additions & 0 deletions integartion-test/features/support/services_steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const assert = require('assert')
const {Given, When, Then} = require('@cucumber/cucumber')
const {get} = require("./common");

let responseToCheck;
let service;


// Given

Given('some services in the DB', function () {
// TODO
});


// When

When('the client get service {string}', async function (idService) {
service = await get(`/services/${idService}`);
});


When('the client get all services', async function () {
responseToCheck = await get('/services');
});


// Then

Then('the client receives status code of {int}', function (statusCode) {
assert.strictEqual(responseToCheck.status, statusCode);
});

Then(/^the client retrieves the list of services$/, function () {
assert.notStrictEqual(responseToCheck.data.length, 0);
});
30 changes: 30 additions & 0 deletions integartion-test/features/test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Test service
pre-condition: service nel DB
1. get services
2. get service

Test org
pre-condition: service nel DB
1. create org senza enrollments
2. post /org/serv per creare un enrollment
3. update del servizio
4. update del org
5. get org
6. get serv
7. delete servi
8. delete org

Test POST spontaneous payment
pre-condition: org e servizio esistenti ed associati
1. invocare la post


test flusso aggiunta servizio
1. creazione org con 1 enrollment
2. org aggiunge servizio

test flusso cancellazione servizio
1. creazione org con 2 enrollment
2. cancella enrollment

test flusso

0 comments on commit ce3b878

Please sign in to comment.