Skip to content

Commit

Permalink
feat(admin): Add a button to send a new certification center invitation
Browse files Browse the repository at this point in the history
  • Loading branch information
theotime2005 committed Jan 27, 2025
1 parent 60ac86b commit fa4d53f
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
10 changes: 10 additions & 0 deletions admin/app/components/certification-centers/invitations.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ export default class CertificationCenterInvitations extends Component {
>
Annuler l’invitation
</PixButton>
<PixButton
@size="small"
@variant="error"
class="certification-center-invitations-actions__button"
aria-label="Renvoyer l’invitation de {{invitation.email}}"
@triggerAction={{fn @onSendNewCertificationCenterInvitation invitation}}
@iconBefore=""
>
Renvoyer l’invitation
</PixButton>
</td>
</tr>
{{/each}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,24 @@ export default class AuthenticatedCertificationCentersGetInvitationsController e
this.isLoading = false;
}

@action
async sendNewCertificationCenterInvitation(certificationCenterInvitation) {
this.isLoading = true;
const { email, language, role } = certificationCenterInvitation;
try {
await this.store.queryRecord('certification-center-invitation', {
email,
language,
role,
certificationCenterId: this.model.certificationCenterId,
});

this.pixToast.sendSuccessNotification({ message: `Un email a bien a été envoyé à l'adresse ${email}.` });
} catch (err) {
this.errorResponseHandler.notify(err, this.CUSTOM_ERROR_MESSAGES);
}
}

_isEmailToInviteValid(email) {
if (!email) {
this.userEmailToInviteError = 'Ce champ est requis.';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@

<CertificationCenters::Invitations
@certificationCenterInvitations={{this.model.certificationCenterInvitations}}
@onSendNewCertificationCenterInvitation={{this.sendNewCertificationCenterInvitation}}
@onCancelCertificationCenterInvitation={{this.cancelCertificationCenterInvitation}}
/>
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,58 @@ module('Unit | Controller | authenticated/certification-centers/get/invitations'
sinon.assert.calledWith(notificationErrorStub, { message: 'Une erreur s’est produite, veuillez réessayer.' });
assert.ok(true);
});

module('#sendNewInvitation', function () {
test('It sends a new invitation', async function (assert) {
// given
const controller = this.owner.lookup('controller:authenticated/certification-centers/get/invitations');

const store = this.owner.lookup('service:store');
const queryRecordStub = sinon.stub();
store.queryRecord = queryRecordStub;
const certificationCenterInvitation = {
email: '[email protected]',
language: 'en',
role: 'member',
certificationCenterId: 1,
};
// when
await controller.sendNewCertificationCenterInvitation(certificationCenterInvitation);

// then
assert.ok(
queryRecordStub.calledWith('certification-center-invitation', {
...certificationCenterInvitation,
}),
);
});

test('When an error occurs, it should send a notification error', async function (assert) {
// given
const controller = this.owner.lookup('controller:authenticated/certification-centers/get/invitations');
const store = this.owner.lookup('service:store');
const anError = Symbol('an error');
store.queryRecord = sinon.stub().rejects(anError);
const notifyStub = sinon.stub();
class ErrorResponseHandler extends Service {
notify = notifyStub;
}
this.owner.register('service:error-response-handler', ErrorResponseHandler);
const customErrors = Symbol('custom errors');
controller.CUSTOM_ERROR_MESSAGES = customErrors;
const certificationCenterInvitation = {
email: '[email protected]',
language: 'en',
role: 'member',
certificationCenterId: 1,
};

// when
await controller.sendNewCertificationCenterInvitation(certificationCenterInvitation);

// then
assert.ok(notifyStub.calledWithExactly(anError, customErrors));
});
});
});
});

0 comments on commit fa4d53f

Please sign in to comment.