Skip to content

Commit

Permalink
[FEATURE] Afficher dans les exports les dates aux formats UTC afin de…
Browse files Browse the repository at this point in the history
… faciliter le traitement avec l'heure (PIX-13289)

 #10803
  • Loading branch information
pix-service-auto-merge authored Dec 13, 2024
2 parents 105d747 + 8b13c0b commit 24df91b
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class CampaignProfilesCollectionResultLine {

_getSharedAtColumn() {
return this.campaignParticipationResult.isShared
? dayjs.utc(this.campaignParticipationResult.sharedAt).format('YYYY-MM-DD')
? dayjs.utc(this.campaignParticipationResult.sharedAt).format()
: this.notShared;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ class CampaignAssessmentCsvLine {
this.targetedKnowledgeElementsCount,
this.learningContent.skills.length,
),
dayjs.utc(this.campaignParticipationInfo.createdAt).format('YYYY-MM-DD'),
dayjs.utc(this.campaignParticipationInfo.createdAt).format(),
this._makeYesNoColumns(this.campaignParticipationInfo.isShared),
this.campaignParticipationInfo.isShared
? dayjs.utc(this.campaignParticipationInfo.sharedAt).format('YYYY-MM-DD')
? dayjs.utc(this.campaignParticipationInfo.sharedAt).format()
: this.emptyContent,
...(this.stageCollection.hasStage ? [this._getReachedStage()] : []),
...(this.campaignParticipationInfo.isShared
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import stream from 'node:stream';

import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc.js';
const { PassThrough } = stream;

import { usecases } from '../../../../../../src/prescription/campaign/domain/usecases/index.js';
Expand All @@ -9,6 +11,7 @@ import { Assessment } from '../../../../../../src/shared/domain/models/Assessmen
import { CampaignParticipationStatuses, KnowledgeElement } from '../../../../../../src/shared/domain/models/index.js';
import { getI18n } from '../../../../../../src/shared/infrastructure/i18n/i18n.js';
import { databaseBuilder, expect, mockLearningContent, streamToPromise } from '../../../../../test-helper.js';
dayjs.extend(utc);

describe('Integration | Domain | Use Cases | start-writing-campaign-assessment-results-to-stream', function () {
describe('#startWritingCampaignAssessmentResultsToStream', function () {
Expand Down Expand Up @@ -155,9 +158,9 @@ describe('Integration | Domain | Use Cases | start-writing-campaign-assessment-r
`"'${organizationLearner.firstName}";` +
`"${campaignParticipation.participantExternalId}";` +
'1;' +
'2019-02-25;' +
`"${dayjs.utc(createdAt).format()}";` +
'"Oui";' +
'2019-03-01;' +
`"${dayjs.utc(sharedAt).format()}";` +
'1;' +
'"Non";' +
'0,67;' +
Expand Down Expand Up @@ -295,9 +298,9 @@ describe('Integration | Domain | Use Cases | start-writing-campaign-assessment-r
`"'${organizationLearner.firstName}";` +
`"${organizationLearner.attributes.hobby}";` +
'1;' +
'2019-02-25;' +
`"${dayjs.utc(createdAt).format()}";` +
'"Oui";' +
'2019-03-01;' +
`"${dayjs.utc(sharedAt).format()}";` +
'1;' +
'"Non";' +
'0,67;' +
Expand Down Expand Up @@ -404,9 +407,9 @@ describe('Integration | Domain | Use Cases | start-writing-campaign-assessment-r
`"'${organizationLearner.lastName}";` +
`"'${organizationLearner.firstName}";` +
'1;' +
'2019-02-25;' +
`"${dayjs.utc(createdAt).format()}";` +
'"Oui";' +
'2019-03-01;' +
`"${dayjs.utc(sharedAt).format()}";` +
'1;' +
'"Non";' +
'0,67;' +
Expand Down Expand Up @@ -492,7 +495,7 @@ describe('Integration | Domain | Use Cases | start-writing-campaign-assessment-r
`"'${organizationLearner.lastName}";` +
`"'${organizationLearner.firstName}";` +
'0,333;' +
`2019-02-25;` +
`"${dayjs.utc(createdAt).format()}";` +
'"Non";' +
`"NA";` +
'"NA";' +
Expand Down Expand Up @@ -630,7 +633,7 @@ describe('Integration | Domain | Use Cases | start-writing-campaign-assessment-r
`"'${organizationLearner.lastName}";` +
`"'${organizationLearner.firstName}";` +
'0,667;' +
`2019-03-05;` +
`"${dayjs.utc(secondParticipationDateCreatedAt).format()}";` +
'"Non";' +
`"NA";` +
'"NA";' +
Expand All @@ -655,9 +658,9 @@ describe('Integration | Domain | Use Cases | start-writing-campaign-assessment-r
`"'${organizationLearner.lastName}";` +
`"'${organizationLearner.firstName}";` +
'1;' +
'2019-02-25;' +
`"${dayjs.utc(createdAt).format()}";` +
'"Oui";' +
'2019-03-01;' +
`"${dayjs.utc(sharedAt).format()}";` +
'1;' +
'"Non";' +
'0,67;' +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import stream from 'node:stream';

import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc.js';
const { PassThrough } = stream;

import * as campaignRepository from '../../../../../../lib/infrastructure/repositories/campaign-repository.js';
Expand All @@ -23,6 +25,7 @@ import { getI18n } from '../../../../../../src/shared/infrastructure/i18n/i18n.j
import * as competenceRepository from '../../../../../../src/shared/infrastructure/repositories/competence-repository.js';
import * as organizationRepository from '../../../../../../src/shared/infrastructure/repositories/organization-repository.js';
import { databaseBuilder, expect, streamToPromise } from '../../../../../test-helper.js';
dayjs.extend(utc);

describe('Integration | Domain | Use Cases | start-writing-profiles-collection-campaign-results-to-stream', function () {
describe('#startWritingCampaignProfilesCollectionResultsToStream', function () {
Expand Down Expand Up @@ -200,7 +203,7 @@ describe('Integration | Domain | Use Cases | start-writing-profiles-collection-c
'\uFEFF"Nom de l\'organisation";"ID Campagne";"Code";"Nom de la campagne";"Nom du Participant";"Prénom du Participant";"Envoi (O/N)";"Date de l\'envoi";"Nombre de pix total";"Certifiable (O/N)";"Nombre de compétences certifiables";"Niveau pour la compétence nom en français recCompetence1";"Nombre de pix pour la compétence nom en français recCompetence1";"Niveau pour la compétence nom en français recCompetence2";"Nombre de pix pour la compétence nom en français recCompetence2"',
);
expect(cells[1]).to.be.equals(
`"Observatoire de Pix";${campaign.id};"QWERTY456";"'@Campagne de Test N°2";"'=Bono";"'@Jean";"Oui";2019-03-01;52;"Non";2;1;12;5;40`,
`"Observatoire de Pix";${campaign.id};"QWERTY456";"'@Campagne de Test N°2";"'=Bono";"'@Jean";"Oui";"${dayjs.utc(sharedAt).format()}";52;"Non";2;1;12;5;40`,
);
expect(cells[2]).to.be.equals(
`"Observatoire de Pix";${campaign.id};"QWERTY456";"'@Campagne de Test N°2";"'=Bono";"'@Jean";"Non";"NA";"NA";"NA";"NA";"NA";"NA";"NA";"NA"`,
Expand Down Expand Up @@ -263,7 +266,7 @@ describe('Integration | Domain | Use Cases | start-writing-profiles-collection-c
'\uFEFF"Nom de l\'organisation";"ID Campagne";"Code";"Nom de la campagne";"Nom du Participant";"Prénom du Participant";"Mail Perso";"Envoi (O/N)";"Date de l\'envoi";"Nombre de pix total";"Certifiable (O/N)";"Nombre de compétences certifiables";"Niveau pour la compétence nom en français recCompetence1";"Nombre de pix pour la compétence nom en français recCompetence1";"Niveau pour la compétence nom en français recCompetence2";"Nombre de pix pour la compétence nom en français recCompetence2"',
);
expect(cells[1]).to.be.equals(
`"Observatoire de Pix";${campaign.id};"QWERTY456";"'@Campagne de Test N°2";"'=Bono";"'@Jean";"'+Mon mail pro";"Oui";2019-03-01;52;"Non";2;1;12;5;40`,
`"Observatoire de Pix";${campaign.id};"QWERTY456";"'@Campagne de Test N°2";"'=Bono";"'@Jean";"'+Mon mail pro";"Oui";"${dayjs.utc(sharedAt).format()}";52;"Non";2;1;12;5;40`,
);
});
});
Expand Down Expand Up @@ -393,7 +396,7 @@ describe('Integration | Domain | Use Cases | start-writing-profiles-collection-c
`"'${organizationLearner.lastName}";` +
`"'${organizationLearner.firstName}";` +
'"Oui";' +
'2019-03-01;' +
`"${dayjs.utc(sharedAt).format()}";` +
'52;' +
'"Non";' +
'2;' +
Expand Down Expand Up @@ -471,7 +474,7 @@ describe('Integration | Domain | Use Cases | start-writing-profiles-collection-c
`"'${organizationLearner.firstName}";` +
`"${organizationLearner.division}";` +
'"Oui";' +
'2019-03-01;' +
`"${dayjs.utc(sharedAt).format()}";` +
'52;' +
'"Non";' +
'2;' +
Expand Down Expand Up @@ -551,7 +554,7 @@ describe('Integration | Domain | Use Cases | start-writing-profiles-collection-c
`"'${organizationLearner.group}";` +
`"${organizationLearner.studentNumber}";` +
'"Oui";' +
'2019-03-01;' +
`"${dayjs.utc(sharedAt).format()}";` +
'52;' +
'"Non";' +
'2;' +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ import stream from 'node:stream';

const { PassThrough } = stream;

import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc.js';

import * as campaignCsvExportService from '../../../../../../src/prescription/campaign/domain/services/campaign-csv-export-service.js';
import { startWritingCampaignAssessmentResultsToStream } from '../../../../../../src/prescription/campaign/domain/usecases/start-writing-campaign-assessment-results-to-stream.js';
import { CampaignTypeError } from '../../../../../../src/shared/domain/errors.js';
import { StageCollection } from '../../../../../../src/shared/domain/models/user-campaign-results/StageCollection.js';
import { getI18n } from '../../../../../../src/shared/infrastructure/i18n/i18n.js';
import { catchErr, domainBuilder, expect, sinon, streamToPromise } from '../../../../../test-helper.js';
dayjs.extend(utc);

describe('Unit | Domain | Use Cases | start-writing-campaign-assessment-results-to-stream', function () {
let campaignRepository,
Expand Down Expand Up @@ -543,6 +547,8 @@ describe('Unit | Domain | Use Cases | start-writing-campaign-assessment-results-

it('should process result for each participation and add it to csv', async function () {
// given
const createdAt = new Date('2020-01-01');
const sharedAt = new Date('2020-02-01');
const { user: admin, campaign, organization } = _buildOrganizationAndUserWithMembershipAndCampaign();
const badge = domainBuilder.buildBadge({ title: 'badge sup' });
const targetProfile = domainBuilder.buildTargetProfile({
Expand All @@ -551,8 +557,8 @@ describe('Unit | Domain | Use Cases | start-writing-campaign-assessment-results-
const learningContent = domainBuilder.buildLearningContent.withSimpleContent();
const participantInfo = domainBuilder.buildCampaignParticipationInfo({
campaignParticipationId: 12,
createdAt: new Date('2020-01-01'),
sharedAt: new Date('2020-02-01'),
createdAt,
sharedAt,
});
const knowledgeElement = domainBuilder.buildKnowledgeElement({
status: 'validated',
Expand Down Expand Up @@ -611,9 +617,9 @@ describe('Unit | Domain | Use Cases | start-writing-campaign-assessment-results-
`"${participantInfo.participantLastName}";` +
`"${participantInfo.participantFirstName}";` +
'1;' +
'2020-01-01;' +
`"${dayjs.utc(createdAt).format()}";` +
'"Oui";' +
'2020-02-01;' +
`"${dayjs.utc(sharedAt).format()}";` +
'"Oui";' +
'1;' +
'1;' +
Expand Down
Loading

0 comments on commit 24df91b

Please sign in to comment.