-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Ajout d'une route pour récupérer les infos de début de parc…
- Loading branch information
Showing
10 changed files
with
522 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
35 changes: 35 additions & 0 deletions
35
api/src/prescription/campaign/domain/usecases/get-presentation-steps.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,35 @@ | ||
import { CampaignCodeError, UserNotAuthorizedToAccessEntityError } from '../../../../shared/domain/errors.js'; | ||
import { ArchivedCampaignError, DeletedCampaignError } from '../errors.js'; | ||
|
||
const getPresentationSteps = async function ({ | ||
userId, | ||
campaignCode, | ||
locale, | ||
badgeRepository, | ||
campaignRepository, | ||
learningContentRepository, | ||
}) { | ||
const campaign = await campaignRepository.getByCode(campaignCode); | ||
|
||
if (!campaign) throw new CampaignCodeError(); | ||
if (campaign.archivedAt) throw new ArchivedCampaignError(); | ||
if (campaign.deletedAt) throw new DeletedCampaignError(); | ||
|
||
const hasUserAccessToResult = await campaignRepository.checkIfUserOrganizationHasAccessToCampaign( | ||
campaign.id, | ||
userId, | ||
); | ||
if (!hasUserAccessToResult) | ||
throw new UserNotAuthorizedToAccessEntityError('User does not have access to this campaign'); | ||
|
||
const campaignBadges = await badgeRepository.findByCampaignId(campaign.id); | ||
const learningContent = await learningContentRepository.findByCampaignId(campaign.id, locale); | ||
|
||
return { | ||
customLandingPageText: campaign.customLandingPageText, | ||
badges: campaignBadges, | ||
competences: learningContent?.competences, | ||
}; | ||
}; | ||
|
||
export { getPresentationSteps }; |
19 changes: 19 additions & 0 deletions
19
...prescription/campaign/infrastructure/serializers/jsonapi/presentation-steps-serializer.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,19 @@ | ||
import jsonapiSerializer from 'jsonapi-serializer'; | ||
|
||
const { Serializer } = jsonapiSerializer; | ||
|
||
const serialize = function (presentationSteps) { | ||
return new Serializer('campaign-presentation-step', { | ||
attributes: ['customLandingPageText', 'badges', 'competences'], | ||
badges: { | ||
ref: 'id', | ||
attributes: ['altMessage', 'imageUrl', 'isAlwaysVisible', 'isCertifiable', 'key', 'message', 'title'], | ||
}, | ||
competences: { | ||
ref: 'id', | ||
attributes: ['index', 'name'], | ||
}, | ||
}).serialize(presentationSteps); | ||
}; | ||
|
||
export { serialize }; |
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/campaign/integration/domain/usecases/get-presentation-steps_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 { usecases } from '../../../../../../src/prescription/campaign/domain/usecases/index.js'; | ||
import { LOCALE } from '../../../../../../src/shared/domain/constants.js'; | ||
import { | ||
databaseBuilder, | ||
domainBuilder, | ||
expect, | ||
learningContentBuilder, | ||
mockLearningContent, | ||
} from '../../../../../test-helper.js'; | ||
|
||
const { FRENCH_SPOKEN } = LOCALE; | ||
|
||
describe('Integration | Campaign | UseCase | get-presentation-steps', function () { | ||
let user, campaign, badges, competences; | ||
|
||
beforeEach(async function () { | ||
const learningContent = domainBuilder.buildLearningContent.withSimpleContent(); | ||
const learningContentObjects = learningContentBuilder.fromAreas(learningContent.frameworks[0].areas); | ||
mockLearningContent(learningContentObjects); | ||
|
||
const targetProfileId = databaseBuilder.factory.buildTargetProfile().id; | ||
|
||
campaign = databaseBuilder.factory.buildCampaign({ targetProfileId }); | ||
|
||
user = databaseBuilder.factory.buildUser.withMembership({ organizationId: campaign.organizationId }); | ||
|
||
badges = [ | ||
databaseBuilder.factory.buildBadge({ targetProfileId }), | ||
databaseBuilder.factory.buildBadge({ targetProfileId }), | ||
]; | ||
|
||
competences = learningContentObjects.competences; | ||
|
||
databaseBuilder.factory.buildCampaignSkill({ | ||
campaignId: campaign.id, | ||
skillId: competences[0].skillIds[0], | ||
}); | ||
|
||
await databaseBuilder.commit(); | ||
}); | ||
|
||
it('should get campaign presentation steps content', async function () { | ||
// when | ||
const result = await usecases.getPresentationSteps({ | ||
userId: user.id, | ||
campaignCode: campaign.code, | ||
locale: FRENCH_SPOKEN, | ||
}); | ||
|
||
// then | ||
expect(result.customLandingPageText).to.equal(campaign.customLandingPageText); | ||
expect(result.badges).to.deep.equal(badges); | ||
expect(result.competences).to.have.lengthOf(competences.length); | ||
expect(result.competences[0].id).to.equal(competences[0].id); | ||
expect(result.competences[0].index).to.equal(competences[0].index); | ||
expect(result.competences[0].name).to.equal(competences[0].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
Oops, something went wrong.