-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1512 from betagouv/feat/update_dataset
Feat/update dataset
- Loading branch information
Showing
16 changed files
with
1,290 additions
and
1,261 deletions.
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
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
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
97 changes: 97 additions & 0 deletions
97
api/services/trip/src/actions/opendata/AppendMarkdownDescription.spec.ts
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,97 @@ | ||
import { OpenDataContextMetadata } from './AppendMarkdownDescription'; | ||
/* eslint-disable max-len */ | ||
import anyTest, { TestInterface } from 'ava'; | ||
import { TripRepositoryProvider } from '../../providers/TripRepositoryProvider'; | ||
import { OpenDataTripSearchInterface } from '../../shared/trip/common/interfaces/TripSearchInterface'; | ||
import { AppendMarkdownDescription } from './AppendMarkdownDescription'; | ||
import sinon, { SinonStub } from 'sinon'; | ||
|
||
interface Context { | ||
// Injected tokens | ||
tripRepositoryProvider: TripRepositoryProvider; | ||
// Injected tokens method's stubs | ||
tripRepositoryProviderStub: SinonStub; | ||
// Tested token | ||
happenMarkdownDescription: AppendMarkdownDescription; | ||
// Constants | ||
} | ||
|
||
const test = anyTest as TestInterface<Partial<Context>>; | ||
|
||
test.beforeEach((t) => { | ||
t.context.tripRepositoryProvider = new TripRepositoryProvider(null); | ||
t.context.happenMarkdownDescription = new AppendMarkdownDescription(t.context.tripRepositoryProvider); | ||
t.context.tripRepositoryProviderStub = sinon.stub(t.context.tripRepositoryProvider, 'searchCount'); | ||
}); | ||
|
||
test.afterEach((t) => {}); | ||
|
||
test('AppendMarkdownDescription: should happen description to existing one', async (t) => { | ||
// Arrange | ||
const existingDescription = | ||
"# Spécificités jeu de données janvier 2021\nLes données concernent également les trajets dont le point de départ OU d'arrivée est situé en dehors du territoire français.\n\n* Nombre trajets collectés et validés par le registre de preuve de covoiturage **96 012**\n* Nombre de trajets exposés dans le jeu de données : **90 443**\n* Nombre de trajets supprimés du jeu de données : **5 569 = 3 103 + 2 998 - 532**\n * Nombre d’occurrences du code INSEE de départ est < 6 : **3 103**\n * Nombre d’occurrences du code INSEE d'arrivée est < 6 : **2 998**\n * Nombre d’occurrences du code INSEE de départ ET d'arrivée est < 6 : **532**"; | ||
t.context.tripRepositoryProviderStub.onCall(0).resolves({ count: '21' }); | ||
t.context.tripRepositoryProviderStub.onCall(1).resolves({ count: '30' }); | ||
|
||
const openDataQueryParam: OpenDataTripSearchInterface = { | ||
date: { | ||
start: new Date('2021-09-01'), | ||
end: new Date('2021-09-30'), | ||
}, | ||
excluded_start_territory_id: [589, 785, 5, 8], | ||
excluded_end_territory_id: [8888, 77, 5, 8], | ||
}; | ||
|
||
const openDataContext: OpenDataContextMetadata = { | ||
queryParam: openDataQueryParam, | ||
excludedTerritories: [ | ||
{ | ||
end_territory_id: 589, | ||
aggregated_trips_journeys: ['trip1', 'trip2'], | ||
}, | ||
{ | ||
end_territory_id: 785, | ||
aggregated_trips_journeys: ['trip3', 'trip4'], | ||
}, | ||
{ | ||
end_territory_id: 5, | ||
aggregated_trips_journeys: ['trip5'], | ||
}, | ||
{ | ||
end_territory_id: 8, | ||
aggregated_trips_journeys: ['trip6'], | ||
}, | ||
{ | ||
start_territory_id: 8888, | ||
aggregated_trips_journeys: ['trip6'], | ||
}, | ||
{ | ||
start_territory_id: 77, | ||
aggregated_trips_journeys: ['trip5'], | ||
}, | ||
{ | ||
start_territory_id: 5, | ||
aggregated_trips_journeys: ['trip7'], | ||
}, | ||
{ | ||
start_territory_id: 8, | ||
aggregated_trips_journeys: ['trip8', 'trip9'], | ||
}, | ||
], | ||
}; | ||
|
||
// Act | ||
const description: string = await t.context.happenMarkdownDescription.call(openDataContext, existingDescription); | ||
|
||
// Assert | ||
const expected_happened_description = | ||
"\n\n# Spécificités jeu de données septembre 2021\nLes données concernent également les trajets dont le point de départ OU d'arrivée est situé en dehors du territoire français.\n\n* Nombre trajets collectés et validés par le registre de preuve de covoiturage **30**\n* Nombre de trajets exposés dans le jeu de données : **21**\n* Nombre de trajets supprimés du jeu de données : **9 = 5 + 6 - 2**\n * Nombre de trajets dont l’occurrence du code INSEE de départ est < 6 : **5**\n * Nombre de trajets dont l’occurrence du code INSEE d'arrivée est < 6 : **6**\n * Nombre de trajets dont l’occurrence du code INSEE de départ ET d'arrivée est < 6 : **2**"; | ||
t.deepEqual(description, `${existingDescription}${expected_happened_description}`); | ||
sinon.assert.calledWithMatch(t.context.tripRepositoryProviderStub.firstCall, openDataQueryParam); | ||
const openDataQueryParamCopy: OpenDataTripSearchInterface = { | ||
...openDataQueryParam, | ||
}; | ||
delete openDataQueryParamCopy.excluded_end_territory_id; | ||
delete openDataQueryParamCopy.excluded_start_territory_id; | ||
sinon.assert.calledWithMatch(t.context.tripRepositoryProviderStub.secondCall, openDataQueryParamCopy); | ||
}); |
Oops, something went wrong.