Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] formater les date dans les export de résultats en utilisant le fuseau Europe/Paris (PIX-15742) #10835

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import dayjs from 'dayjs';
import timezone from 'dayjs/plugin/timezone.js';
import utc from 'dayjs/plugin/utc.js';

dayjs.extend(utc);
dayjs.extend(timezone);

import * as csvSerializer from '../../../../../shared/infrastructure/serializers/csv/csv-serializer.js';

const EMPTY_ARRAY = [];
Expand Down Expand Up @@ -92,7 +96,7 @@ class CampaignProfilesCollectionResultLine {

_getSharedAtColumn() {
return this.campaignParticipationResult.isShared
? dayjs.utc(this.campaignParticipationResult.sharedAt).format()
? dayjs.utc(this.campaignParticipationResult.sharedAt).tz('Europe/Paris').format('DD/MM/YYYY HH:mm')
: this.notShared;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import dayjs from 'dayjs';
import timezone from 'dayjs/plugin/timezone.js';
import utc from 'dayjs/plugin/utc.js';

dayjs.extend(utc);
dayjs.extend(timezone);

import _ from 'lodash';

const STATS_COLUMNS_COUNT = 3;
Expand Down Expand Up @@ -111,10 +115,10 @@ class CampaignAssessmentCsvLine {
this.targetedKnowledgeElementsCount,
this.learningContent.skills.length,
),
dayjs.utc(this.campaignParticipationInfo.createdAt).format(),
dayjs.utc(this.campaignParticipationInfo.createdAt).tz('Europe/Paris').format('DD/MM/YYYY HH:mm'),
this._makeYesNoColumns(this.campaignParticipationInfo.isShared),
this.campaignParticipationInfo.isShared
? dayjs.utc(this.campaignParticipationInfo.sharedAt).format()
? dayjs.utc(this.campaignParticipationInfo.sharedAt).tz('Europe/Paris').format('DD/MM/YYYY HH:mm')
: this.emptyContent,
...(this.stageCollection.hasStage ? [this._getReachedStage()] : []),
...(this.campaignParticipationInfo.isShared
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
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 @@ -11,7 +9,6 @@ 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 All @@ -24,7 +21,7 @@ describe('Integration | Domain | Use Cases | start-writing-campaign-assessment-r
let writableStream;
let csvPromise;
let i18n;
let createdAt, sharedAt;
let createdAt, sharedAt, createdAtFormated, sharedAtFormated;

beforeEach(async function () {
i18n = getI18n();
Expand All @@ -47,9 +44,12 @@ describe('Integration | Domain | Use Cases | start-writing-campaign-assessment-r
});

// participation
createdAt = new Date('2019-02-25');
sharedAt = new Date('2019-03-01');

// heure d'hiver UTC+1
createdAt = new Date('2019-02-25T10:20:00Z');
createdAtFormated = '25/02/2019 11:20';
// heure d'été UTC+2
sharedAt = new Date('2019-06-01T09:05:00Z');
sharedAtFormated = '01/06/2019 11:05';
const learningContent = {
frameworks: [{ id: 'frameworkId', name: 'frameworkName' }],
areas: [{ id: 'recArea1', frameworkId: 'frameworkId', competenceIds: ['recCompetence1'] }],
Expand Down Expand Up @@ -158,9 +158,9 @@ describe('Integration | Domain | Use Cases | start-writing-campaign-assessment-r
`"'${organizationLearner.firstName}";` +
`"${campaignParticipation.participantExternalId}";` +
'1;' +
`"${dayjs.utc(createdAt).format()}";` +
`"${createdAtFormated}";` +
'"Oui";' +
`"${dayjs.utc(sharedAt).format()}";` +
`"${sharedAtFormated}";` +
'1;' +
'"Non";' +
'0,67;' +
Expand Down Expand Up @@ -298,9 +298,9 @@ describe('Integration | Domain | Use Cases | start-writing-campaign-assessment-r
`"'${organizationLearner.firstName}";` +
`"${organizationLearner.attributes.hobby}";` +
'1;' +
`"${dayjs.utc(createdAt).format()}";` +
`"${createdAtFormated}";` +
'"Oui";' +
`"${dayjs.utc(sharedAt).format()}";` +
`"${sharedAtFormated}";` +
'1;' +
'"Non";' +
'0,67;' +
Expand Down Expand Up @@ -407,9 +407,9 @@ describe('Integration | Domain | Use Cases | start-writing-campaign-assessment-r
`"'${organizationLearner.lastName}";` +
`"'${organizationLearner.firstName}";` +
'1;' +
`"${dayjs.utc(createdAt).format()}";` +
`"${createdAtFormated}";` +
'"Oui";' +
`"${dayjs.utc(sharedAt).format()}";` +
`"${sharedAtFormated}";` +
'1;' +
'"Non";' +
'0,67;' +
Expand Down Expand Up @@ -495,7 +495,7 @@ describe('Integration | Domain | Use Cases | start-writing-campaign-assessment-r
`"'${organizationLearner.lastName}";` +
`"'${organizationLearner.firstName}";` +
'0,333;' +
`"${dayjs.utc(createdAt).format()}";` +
`"${createdAtFormated}";` +
'"Non";' +
`"NA";` +
'"NA";' +
Expand Down Expand Up @@ -529,9 +529,10 @@ describe('Integration | Domain | Use Cases | start-writing-campaign-assessment-r
});

context('multiple participations', function () {
let secondParticipationDateCreatedAt;
let secondParticipationDateCreatedAt, secondParticipationCreatedFormated;
beforeEach(async function () {
secondParticipationDateCreatedAt = new Date('2019-03-05');
secondParticipationDateCreatedAt = new Date('2019-03-05T11:23:00Z');
secondParticipationCreatedFormated = '05/03/2019 12:23';
// on utilise un nouveau learner
participant = databaseBuilder.factory.buildUser();

Expand Down Expand Up @@ -633,7 +634,7 @@ describe('Integration | Domain | Use Cases | start-writing-campaign-assessment-r
`"'${organizationLearner.lastName}";` +
`"'${organizationLearner.firstName}";` +
'0,667;' +
`"${dayjs.utc(secondParticipationDateCreatedAt).format()}";` +
`"${secondParticipationCreatedFormated}";` +
'"Non";' +
`"NA";` +
'"NA";' +
Expand All @@ -658,9 +659,9 @@ describe('Integration | Domain | Use Cases | start-writing-campaign-assessment-r
`"'${organizationLearner.lastName}";` +
`"'${organizationLearner.firstName}";` +
'1;' +
`"${dayjs.utc(createdAt).format()}";` +
`"${createdAtFormated}";` +
'"Oui";' +
`"${dayjs.utc(sharedAt).format()}";` +
`"${sharedAtFormated}";` +
'1;' +
'"Non";' +
'0,67;' +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
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 @@ -25,7 +22,6 @@ 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 All @@ -39,6 +35,7 @@ describe('Integration | Domain | Use Cases | start-writing-profiles-collection-c

const createdAt = new Date('2019-02-25T10:00:00Z');
const sharedAt = new Date('2019-03-01T23:04:05Z');
const sharedAtFormated = '02/03/2019 00:04';

beforeEach(async function () {
i18n = getI18n();
Expand Down Expand Up @@ -200,10 +197,10 @@ describe('Integration | Domain | Use Cases | start-writing-profiles-collection-c
const cells = csv.split('\n');

expect(cells[0]).to.be.equals(
'\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"',
'\uFEFF"Nom de l\'organisation";"ID Campagne";"Code";"Nom de la campagne";"Nom du Participant";"Prénom du Participant";"Envoi (O/N)";"Date et heure de l\'envoi (Europe/Paris)";"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";"${dayjs.utc(sharedAt).format()}";52;"Non";2;1;12;5;40`,
`"Observatoire de Pix";${campaign.id};"QWERTY456";"'@Campagne de Test N°2";"'=Bono";"'@Jean";"Oui";"${sharedAtFormated}";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,10 +260,10 @@ describe('Integration | Domain | Use Cases | start-writing-profiles-collection-c
const cells = csv.split('\n');

expect(cells[0]).to.be.equals(
'\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"',
'\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 et heure de l\'envoi (Europe/Paris)";"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";"${dayjs.utc(sharedAt).format()}";52;"Non";2;1;12;5;40`,
`"Observatoire de Pix";${campaign.id};"QWERTY456";"'@Campagne de Test N°2";"'=Bono";"'@Jean";"'+Mon mail pro";"Oui";"${sharedAtFormated}";52;"Non";2;1;12;5;40`,
);
});
});
Expand Down Expand Up @@ -396,7 +393,7 @@ describe('Integration | Domain | Use Cases | start-writing-profiles-collection-c
`"'${organizationLearner.lastName}";` +
`"'${organizationLearner.firstName}";` +
'"Oui";' +
`"${dayjs.utc(sharedAt).format()}";` +
`"${sharedAtFormated}";` +
'52;' +
'"Non";' +
'2;' +
Expand Down Expand Up @@ -474,7 +471,7 @@ describe('Integration | Domain | Use Cases | start-writing-profiles-collection-c
`"'${organizationLearner.firstName}";` +
`"${organizationLearner.division}";` +
'"Oui";' +
`"${dayjs.utc(sharedAt).format()}";` +
`"${sharedAtFormated}";` +
'52;' +
'"Non";' +
'2;' +
Expand Down Expand Up @@ -554,7 +551,7 @@ describe('Integration | Domain | Use Cases | start-writing-profiles-collection-c
`"'${organizationLearner.group}";` +
`"${organizationLearner.studentNumber}";` +
'"Oui";' +
`"${dayjs.utc(sharedAt).format()}";` +
`"${sharedAtFormated}";` +
'52;' +
'"Non";' +
'2;' +
Expand Down
Loading
Loading