-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TECH] Permettre de supprimer une liste de learners de l'orga (PIX-15244
) #10521
- Loading branch information
Showing
13 changed files
with
207 additions
and
9 deletions.
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
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
22 changes: 22 additions & 0 deletions
22
api/src/prescription/learner-management/domain/models/OrganizationLearnerList.js
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,22 @@ | ||
import { logger } from '../../../../shared/infrastructure/utils/logger.js'; | ||
import { CouldNotDeleteLearnersError } from '../errors.js'; | ||
|
||
class OrganizationLearnerList { | ||
constructor({ organizationId, organizationLearnerIds } = {}) { | ||
this.organizationId = organizationId; | ||
this.organizationLearnerIds = organizationLearnerIds; | ||
} | ||
canDeleteOrganizationLearners(organizationLearnerIdsToValidate, userId) { | ||
const result = organizationLearnerIdsToValidate.filter((organizationLearnerId) => { | ||
return !this.organizationLearnerIds.includes(organizationLearnerId); | ||
}); | ||
if (result.length !== 0) { | ||
logger.error( | ||
`User id ${userId} could not delete organization learners because learner id ${result.join(',')} don't belong to organization id ${this.organizationId} "`, | ||
); | ||
throw new CouldNotDeleteLearnersError(); | ||
} | ||
} | ||
} | ||
|
||
export { OrganizationLearnerList }; |
14 changes: 14 additions & 0 deletions
14
api/src/prescription/learner-management/domain/usecases/delete-organization-learners.js
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
58 changes: 58 additions & 0 deletions
58
api/tests/prescription/learner-management/unit/domain/models/OrganizationLearnerList_test.js
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,58 @@ | ||
import { CouldNotDeleteLearnersError } from '../../../../../../src/prescription/learner-management/domain/errors.js'; | ||
import { OrganizationLearnerList } from '../../../../../../src/prescription/learner-management/domain/models/OrganizationLearnerList.js'; | ||
import { logger } from '../../../../../../src/shared/infrastructure/utils/logger.js'; | ||
import { catchErrSync, expect, sinon } from '../../../../../test-helper.js'; | ||
|
||
describe('Unit | Models | OrganizationLearnerListFormat', function () { | ||
describe('#constructor', function () { | ||
it('should initialize valid object', function () { | ||
//when | ||
const payload = { | ||
organizationId: Symbol('organizationId'), | ||
organizationLearnerIds: Symbol('organizationLearnerList'), | ||
}; | ||
const organizationLearnerList = new OrganizationLearnerList(payload); | ||
// then | ||
expect(organizationLearnerList).to.deep.equal(payload); | ||
}); | ||
}); | ||
|
||
describe('#can delete organization learners ', function () { | ||
it('should throw when lists are different', function () { | ||
sinon.stub(logger, 'error'); | ||
//when | ||
const payload = { | ||
organizationId: 777, | ||
organizationLearnerIds: [123, 345], | ||
}; | ||
|
||
const organizationLearnerList = new OrganizationLearnerList(payload); | ||
|
||
const result = catchErrSync(organizationLearnerList.canDeleteOrganizationLearners, organizationLearnerList)( | ||
[456, 123], | ||
'userIdSample', | ||
); | ||
|
||
expect(result).to.be.instanceof(CouldNotDeleteLearnersError); | ||
expect( | ||
logger.error.calledWithExactly( | ||
`User id userIdSample could not delete organization learners because learner id 345 don't belong to organization id 777`, | ||
), | ||
); | ||
}); | ||
|
||
it('should not throw when lists are identical', function () { | ||
const userId = Symbol('123'); | ||
|
||
const payload = { | ||
organizationId: Symbol('organizationId'), | ||
organizationLearnerIds: [123, 345], | ||
}; | ||
|
||
expect(() => { | ||
const organizationLearnerList = new OrganizationLearnerList(payload); | ||
organizationLearnerList.canDeleteOrganizationLearners([123, 345], userId); | ||
}).to.not.throw(); | ||
}); | ||
}); | ||
}); |
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