-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added DELETE /api/subsystems/subsystemId endpoint
- Loading branch information
Showing
9 changed files
with
312 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* @license | ||
* Copyright CERN and copyright holders of ALICE O2. This software is | ||
* distributed under the terms of the GNU General Public License v3 (GPL | ||
* Version 3), copied verbatim in the file "COPYING". | ||
* | ||
* See http://alice-o2.web.cern.ch/license for full licensing information. | ||
* | ||
* In applying this license CERN does not waive the privileges and immunities | ||
* granted to it by virtue of its status as an Intergovernmental Organization | ||
* or submit itself to any jurisdiction. | ||
*/ | ||
|
||
const { | ||
repositories: { | ||
SubsystemRepository, | ||
}, | ||
utilities: { | ||
QueryBuilder, | ||
TransactionHelper, | ||
}, | ||
} = require('../../database'); | ||
|
||
/** | ||
* DeleteSubsystemUseCase | ||
*/ | ||
class DeleteSubsystemUseCase { | ||
/** | ||
* Executes this use case. | ||
* | ||
* @param {Object} dto The GetAllSubsystems DTO which contains all request data. | ||
* @returns {Promise} Promise object represents the result of this use case. | ||
*/ | ||
async execute(dto = {}) { | ||
const queryBuilder = new QueryBuilder(); | ||
const { params } = dto; | ||
const { subsystemId } = params; | ||
|
||
queryBuilder.where('id').is(subsystemId); | ||
|
||
return TransactionHelper.provide(() => SubsystemRepository.removeOne(queryBuilder)); | ||
} | ||
} | ||
|
||
module.exports = DeleteSubsystemUseCase; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* @license | ||
* Copyright CERN and copyright holders of ALICE O2. This software is | ||
* distributed under the terms of the GNU General Public License v3 (GPL | ||
* Version 3), copied verbatim in the file "COPYING". | ||
* | ||
* See http://alice-o2.web.cern.ch/license for full licensing information. | ||
* | ||
* In applying this license CERN does not waive the privileges and immunities | ||
* granted to it by virtue of its status as an Intergovernmental Organization | ||
* or submit itself to any jurisdiction. | ||
*/ | ||
|
||
const { repositories: { SubsystemRepository } } = require('../../../lib/database'); | ||
const { subsystem: { CreateSubsystemUseCase, DeleteSubsystemUseCase } } = require('../../../lib/usecases'); | ||
const { dtos: { CreateSubsystemDto } } = require('../../../lib/domain'); | ||
const chai = require('chai'); | ||
|
||
const { expect } = chai; | ||
|
||
module.exports = () => { | ||
let createdSubsystem; | ||
|
||
beforeEach(async () => { | ||
const createSubsystemDto = await CreateSubsystemDto.validateAsync({ | ||
body: { | ||
name: `SYSTEM#${new Date().getTime()}`, | ||
}, | ||
}); | ||
|
||
createdSubsystem = await new CreateSubsystemUseCase() | ||
.execute(createSubsystemDto); | ||
}); | ||
|
||
it('should remove a subsystem', async () => { | ||
const nSubsystemsBefore = await SubsystemRepository.count(); | ||
|
||
await new DeleteSubsystemUseCase() | ||
.execute({ | ||
params: { | ||
subsystemId: createdSubsystem.id, | ||
}, | ||
}); | ||
|
||
const nSubsystemsAfter = await SubsystemRepository.count(); | ||
expect(nSubsystemsAfter).to.be.lessThan(nSubsystemsBefore); | ||
}); | ||
|
||
it('should return the removed subsystem', async () => { | ||
const nSubsystemsBefore = await SubsystemRepository.count(); | ||
|
||
const result = await new DeleteSubsystemUseCase() | ||
.execute({ | ||
params: { | ||
subsystemId: createdSubsystem.id, | ||
}, | ||
}); | ||
|
||
const nSubsystemsAfter = await SubsystemRepository.count(); | ||
expect(nSubsystemsAfter).to.be.lessThan(nSubsystemsBefore); | ||
|
||
expect(result.id).to.equal(createdSubsystem.id); | ||
expect(result.name).to.equal(createdSubsystem.name); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters