Skip to content

Commit

Permalink
[BUGFIX] Corriger l'inscription en local sur la double mire SCO (PIX-…
Browse files Browse the repository at this point in the history
  • Loading branch information
pix-service-auto-merge authored Nov 15, 2024
2 parents 420bb90 + 374dc88 commit 5068b71
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { randomUUID } from 'node:crypto';

import jsonapiSerializer from 'jsonapi-serializer';

const { Serializer } = jsonapiSerializer;
Expand All @@ -13,6 +11,12 @@ const serializeIdentity = function (scoOrganizationLearner) {
const serializeWithUsernameGeneration = function (scoOrganizationLearner) {
return new Serializer('sco-organization-learner', {
attributes: ['lastName', 'firstName', 'birthdate', 'username'],
transform(scoOrganizationLearner) {
return {
...scoOrganizationLearner,
id: scoOrganizationLearner.username,
};
},
}).serialize(scoOrganizationLearner);
};

Expand All @@ -21,7 +25,7 @@ const serializeExternal = function (scoOrganizationLearner) {
transform(externalUser) {
return {
...externalUser,
id: randomUUID(),
id: externalUser.accessToken,
};
},
attributes: ['accessToken'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe('Acceptance | Controller | sco-organization-learners', function () {
});

describe('PUT /api/sco-organization-learners/possibilities', function () {
it('should return the organizationLearner linked to the user and a 200 status code response', async function () {
it('returns the organizationLearner linked to the user and a 200 status code response', async function () {
//given
const organization = databaseBuilder.factory.buildOrganization({
isManagingStudents: true,
Expand Down Expand Up @@ -150,15 +150,18 @@ describe('Acceptance | Controller | sco-organization-learners', function () {
});

// then
const expectedUsername = 'billy.thekid0508';

expect(response.statusCode).to.equal(200);
expect(response.result).to.deep.equal({
data: {
attributes: {
birthdate: '2005-08-05',
'first-name': 'Billy',
'last-name': 'TheKid',
username: 'billy.thekid0508',
username: expectedUsername,
},
id: expectedUsername,
type: 'sco-organization-learners',
},
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import _ from 'lodash';

import * as serializer from '../../../../../lib/infrastructure/serializers/jsonapi/sco-organization-learner-serializer.js';
import { OrganizationLearner } from '../../../../../src/shared/domain/models/OrganizationLearner.js';
import { OrganizationLearner } from '../../../../../src/shared/domain/models/index.js';
import { expect } from '../../../../test-helper.js';

describe('Unit | Serializer | JSONAPI | sco-organization-learner-serializer', function () {
Expand Down Expand Up @@ -36,7 +34,7 @@ describe('Unit | Serializer | JSONAPI | sco-organization-learner-serializer', fu
});

describe('#serializeWithUsernameGeneration', function () {
it('should convert into JSON API data', function () {
it('converts into JSON API data with id set to a unique value being the username', function () {
// given
const organizationLearner = {
firstName: 'John',
Expand All @@ -47,13 +45,14 @@ describe('Unit | Serializer | JSONAPI | sco-organization-learner-serializer', fu

const expectedSerializedOrganizationLearner = {
data: {
type: 'sco-organization-learners',
attributes: {
'first-name': organizationLearner.firstName,
'last-name': organizationLearner.lastName,
birthdate: organizationLearner.birthdate,
username: organizationLearner.username,
},
id: organizationLearner.username,
type: 'sco-organization-learners',
},
};

Expand All @@ -66,7 +65,7 @@ describe('Unit | Serializer | JSONAPI | sco-organization-learner-serializer', fu
});

describe('#serializeExternal', function () {
it('should convert into JSON API data and generate random id', function () {
it('converts into JSON API data with id set to a unique value being the accessToken', function () {
// given
const organizationLearner = {
accessToken: 'some token',
Expand All @@ -77,6 +76,7 @@ describe('Unit | Serializer | JSONAPI | sco-organization-learner-serializer', fu
attributes: {
'access-token': organizationLearner.accessToken,
},
id: organizationLearner.accessToken,
type: 'external-users',
},
};
Expand All @@ -85,8 +85,7 @@ describe('Unit | Serializer | JSONAPI | sco-organization-learner-serializer', fu
const json = serializer.serializeExternal(organizationLearner);

// then
expect(_.omit(json, 'data.id')).to.deep.equal(expectedSerializedOrganizationLearner);
expect(json.data.id).to.be.a('string');
expect(json).to.deep.equal(expectedSerializedOrganizationLearner);
});
});

Expand Down
2 changes: 1 addition & 1 deletion mon-pix/app/components/routes/register-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export default class RegisterForm extends Component {
(errorResponse) => {
this.scoOrganizationLearner.unloadRecord();
this.isLoading = false;
errorResponse.errors.forEach((error) => {
errorResponse.errors?.forEach((error) => {
if (error.status === '404') {
return (this.errorMessage =
'Vous êtes un élève ? <br> Vérifiez vos informations (prénom, nom et date de naissance) ou contactez un enseignant. <br><br> Vous êtes un enseignant ? <br> L’accès à un parcours n’est pas disponible pour le moment.');
Expand Down

0 comments on commit 5068b71

Please sign in to comment.