Commit cdfd5e4d authored by Valentin Le Gauche's avatar Valentin Le Gauche
Browse files

Merge branch...

Merge branch '50-donner-la-possibilite-de-stocker-les-differents-meetingscenario-crees' into 'master'

Resolve "Donner la possibilité de stocker les différents MeetingScenario créés"

Closes #50

See merge request tx-techno-num/impactometre!43
parents 1e784825 c98f3770
'use strict'
const meetingScenarios = require('../../database/meeting/meetingScenarios')
const MeetingScenario = require('../../model/classes/meeting/MeetingScenario')
/**
* Create a scenario corresponding to a meeting and add it to the database.
* @param {String} user - The user who creates the scenario.
* @param {Number} meetingDuration - The scenario duration in minutes.
* @param {Object} payload - A JSON object that contains three arrays that enable to create the three
* category damages (hardware, software, transport) linked to the meeting. The payload is like:
* { [array_of_all_hardware_data], [array_of_all_software_data], [array_of_all_journey data]}.
*/
function create ({ user, meetingDuration, payload }) {
// Create new MeetingScenario
const meetingScenario = new MeetingScenario({ user, meetingDuration, payload })
// Add it to the database
meetingScenarios.set(meetingScenario.id, meetingScenario)
}
/**
* Read a non-writable meeting scenario.
* @param {String} id - The id of the meeting scenario we want to return.
* @returns {MeetingScenario} The meeting scenario we want to return.
*/
function read (id) {
const meetingScenario = meetingScenarios.get(id)
if (meetingScenario !== undefined) {
return meetingScenario
} else {
throw new Error('Required MeetingScenario not available in database.')
}
}
/**
* Update a meeting scenario.
* @param {String} id - The id of the meeting scenario we want to update.
* @param {Object} payload - A JSON object that contains all necessary data to update a meeting scenario.
*/
function update (id, payload) {
throw new Error('Not implemented yet')
}
/**
* Delete a meeting scenario from the database.
* @param {String} id - The id of the meeting scenario we want to delete.
* @returns {Boolean} True if deletion succeeds, false if not.
*/
function remove (id) {
return meetingScenarios.delete(id)
}
exports.create = create
exports.read = read
exports.update = update
exports.remove = remove
......@@ -4,7 +4,7 @@ const {
hardwareLifetime,
hardwareOperatingTimePerDay,
meetingComponents
} = require('../../../constants/meeting')
} = require('../../constants/meeting')
const hardware = {
/**
......
'use strict'
/**
* The hashmap that contains all the meeting scenarios created.
* They are indexed by their id.
*/
const meetingScenarios = new Map()
module.exports = meetingScenarios
......@@ -2,7 +2,7 @@
const {
meetingComponents
} = require('../../../constants/meeting')
} = require('../../constants/meeting')
const software = {
RENAVISIO: {
......
......@@ -2,7 +2,7 @@
const {
transportationMeanSubCategories
} = require('../../../constants/meeting')
} = require('../../constants/meeting')
const transportationMean = {
PLANE_INTERCONTINENTAL_ONE_PERSON_KM: {
......
......@@ -9,7 +9,7 @@ const {
bounds
} = require('../../../constants/meeting')
const hardwareDatabase = require('../../database/meeting/hardware')
const hardwareDatabase = require('../../../database/meeting/hardware')
const Damage = require('../shared/Damage')
const Component = require('../shared/Component')
......
......@@ -10,8 +10,8 @@ const {
minuteToSeconds,
bounds
} = require('../../../constants/meeting')
const networkDatabase = require('../../database/meeting/network')
const softwareDatabase = require('../../database/meeting/software')
const networkDatabase = require('../../../database/meeting/network')
const softwareDatabase = require('../../../database/meeting/software')
/**
* Software class.
......
'use strict'
const transportationMeanDatabase = require('../../database/meeting/transportationMean')
const transportationMeanDatabase = require('../../../database/meeting/transportationMean')
/**
* TransportationMan class.
......
'use strict'
const uniqid = require('uniqid')
/**
* Abstract class Scenario.
*/
......@@ -10,9 +12,12 @@ class Scenario {
*/
constructor (user) {
if (new.target === Scenario) throw TypeError('Cannot create instance of Scenario because abstract class')
this._id = uniqid()
this._user = user
}
// Getters
/**
* Getter of the user who creates the scenario.
*/
......@@ -20,12 +25,23 @@ class Scenario {
return this._user
}
/**
* Getter of the scenario id.
*/
get id () {
return this._id
}
// Setters
/**
* Setter of the user who creates the scenario.
*/
set user (user) {
this._user = user
}
// Other methods
}
module.exports = Scenario
'use strict'
const assert = require('assert')
const { create, read, remove } = require('../../../controllers/meeting/meetingScenario')
const { meetingCategoryDamage } = require('../../../constants/meeting')
const hardwareDatabase = require('../../../database/meeting/hardware')
const transportDatabase = require('../../../database/meeting/transportationMean')
const softwareDatabase = require('../../../database/meeting/software')
const meetingScenarios = require('../../../database/meeting/meetingScenarios')
describe('meetingScenario controller', () => {
// The user who creates the meeting
const user = 'vlegauch'
// The meeting duration in minutes
const meetingDuration = 120
// The JSON object that enables to creates components linked to the meeting
const payload = {
[meetingCategoryDamage.HARDWARE]: [
{ name: hardwareDatabase.DESKTOP.name },
{ name: hardwareDatabase.DESKTOP.name },
{ name: hardwareDatabase.DESKTOP.name },
{ name: hardwareDatabase.LAPTOP.name },
{ name: hardwareDatabase.LOGITECH_KIT.name },
{ name: hardwareDatabase.TV.name },
{ name: hardwareDatabase.TV.name },
{ name: hardwareDatabase.METAL_STRUCTURE.name }
],
[meetingCategoryDamage.SOFTWARE]: [{ name: softwareDatabase.SKYPE.name }],
[meetingCategoryDamage.JOURNEY]: [
{
passenger: 'Passenger 1',
mean: transportDatabase.CAR_ELECTRIC_ONE_KM.name,
distance: 120,
numberOfPeople: 4
},
{
passenger: 'Passenger 1',
mean: transportDatabase.BUS_LARGE_DISTANCE_ONE_PERSON_KM.name,
distance: 40,
numberOfPeople: 1
},
{
passenger: 'Passenger 2',
mean: transportDatabase.CAR_ELECTRIC_ONE_KM.name,
distance: 120,
numberOfPeople: 4
},
{
passenger: 'Passenger 2',
mean: transportDatabase.TRAIN_REGIONAL_ONE_PERSON_KM.name,
distance: 300,
numberOfPeople: 1
},
{
passenger: 'Passenger 2',
mean: transportDatabase.BIKE_ONE_PERSON_ONE_KM.name,
distance: 10,
numberOfPeople: 1
}
]
}
create({ user, meetingDuration, payload })
describe('#create()', () => {
// Create the meeting scenario
it('shoud create a meeting scenario and add it the database', () => {
assert.deepStrictEqual(
meetingScenarios.size,
1
)
})
})
describe('#read()', () => {
it('should read a meetingScenario thanks to its id', () => {
meetingScenarios.forEach(element => {
const id = element.id
assert.deepStrictEqual(
read(id),
meetingScenarios.get(id)
)
})
})
})
describe('#remove()', () => {
it('should remove a meetingScenario thanks to its id', () => {
meetingScenarios.forEach(element => {
const id = element.id
remove(id)
assert.deepStrictEqual(
meetingScenarios.get(id),
undefined
)
})
})
})
})
......@@ -9,9 +9,9 @@ const {
meetingCategoryDamage,
bounds
} = require('../../../../constants/meeting')
const transportDatabase = require('../../../../model/database/meeting/transportationMean')
const softwareDatabase = require('../../../../model/database/meeting/software')
const hardwareDatabase = require('../../../../model/database/meeting/hardware')
const transportDatabase = require('../../../../database/meeting/transportationMean')
const softwareDatabase = require('../../../../database/meeting/software')
const hardwareDatabase = require('../../../../database/meeting/hardware')
describe('CategoryDamage class', () => {
describe('#computeDamage()', () => {
......
'use strict'
const chai = require('chai')
const hardwareDatabase = require('../../../../model/database/meeting/hardware')
const hardwareDatabase = require('../../../../database/meeting/hardware')
const Hardware = require('../../../../model/classes/meeting/Hardware')
const Damage = require('../../../../model/classes/shared/Damage')
const {
......
'use strict'
const assert = require('assert')
const transportDatabase = require('../../../../model/database/meeting/transportationMean')
const transportDatabase = require('../../../../database/meeting/transportationMean')
const TransportationMean = require('../../../../model/classes/meeting/TransportationMean')
const Journey = require('../../../../model/classes/meeting/Journey')
const Damage = require('../../../../model/classes/shared/Damage')
......
......@@ -3,9 +3,9 @@
const assert = require('assert')
const CategoryDamage = require('../../../../model/classes/meeting/CategoryDamage')
const MeetingDamage = require('../../../../model/classes/meeting/MeetingDamage')
const transportDatabase = require('../../../../model/database/meeting/transportationMean')
const hardwareDatabase = require('../../../../model/database/meeting/hardware')
const softwareDatabase = require('../../../../model/database/meeting/software')
const transportDatabase = require('../../../../database/meeting/transportationMean')
const hardwareDatabase = require('../../../../database/meeting/hardware')
const softwareDatabase = require('../../../../database/meeting/software')
const {
meetingCategoryDamage,
bounds
......
......@@ -3,9 +3,9 @@
const assert = require('assert')
const MeetingScenario = require('../../../../model/classes/meeting/MeetingScenario')
const MeetingDamage = require('../../../../model/classes/meeting/MeetingDamage')
const hardwareDatabase = require('../../../../model/database/meeting/hardware')
const transportDatabase = require('../../../../model/database/meeting/transportationMean')
const softwareDatabase = require('../../../../model/database/meeting/software')
const hardwareDatabase = require('../../../../database/meeting/hardware')
const transportDatabase = require('../../../../database/meeting/transportationMean')
const softwareDatabase = require('../../../../database/meeting/software')
const {
meetingCategoryDamage,
bounds
......
......@@ -2,10 +2,10 @@
const assert = require('assert')
const constants = require('../../../../constants/meeting')
const softwareDatabase = require('../../../../model/database/meeting/software')
const softwareDatabase = require('../../../../database/meeting/software')
const Software = require('../../../../model/classes/meeting/Software')
const Damage = require('../../../../model/classes/shared/Damage')
const networkDatabase = require('../../../../model/database/meeting/network')
const networkDatabase = require('../../../../database/meeting/network')
describe('Software class', () => {
describe('#getInboundBandwith()', () => {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment