Skip to content

Commit

Permalink
fix: Open country selection for FR papers
Browse files Browse the repository at this point in the history
Two documents have a slightly different route between
their FR and foreign versions: the driving license and
the national identity card.

The creation of one of these FR papers does not offer
a country selection step, which poses a problem if you
wish to edit the country after the paper has been created.

The best approach is to load the paperDefinition of
the foreign version to open the country selection step.
  • Loading branch information
Merkur39 committed Oct 22, 2024
1 parent 863d7d4 commit bfb3db3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
7 changes: 2 additions & 5 deletions src/components/ModelSteps/Edit/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import set from 'lodash/set'
import { CONTACTS_DOCTYPE, FILES_DOCTYPE } from 'src/constants'

import { getReferencedBy } from 'cozy-client'
import { isForeignPaper } from 'cozy-client/dist/models/paper'

/**
* Checks if the edition of the metadata of type "Information" is permitted
Expand Down Expand Up @@ -118,10 +117,8 @@ export const updateReferencedContact = async ({
export const getPaperDefinitionByFile = (papersDefinitions, file) => {
return papersDefinitions.find(paper => {
const countryCondition =
Object.keys(file.metadata).includes('country') && paper.country
? isForeignPaper(file)
? paper.country === 'foreign'
: paper.country === 'fr'
file.metadata.country && paper.country
? paper.country === 'foreign'
: true

return paper.label === file.metadata.qualification.label && countryCondition
Expand Down
13 changes: 10 additions & 3 deletions src/components/ModelSteps/Edit/helpers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,8 @@ describe('updateReferencedContact', () => {
})
})

describe('getPaperDefinitionByFile', () => {
// eslint-disable-next-line jest/no-focused-tests
fdescribe('getPaperDefinitionByFile', () => {
describe('paperDefinition has no country defined', () => {
it('should return the paperDefinition "isp_invoice"', () => {
const fakeFile = makeFakeFile({ qualificationLabel: 'isp_invoice' })
Expand Down Expand Up @@ -423,7 +424,10 @@ describe('getPaperDefinitionByFile', () => {
})
const res = getPaperDefinitionByFile(mockPapersDefinitions, fakeFile)

expect(res).toMatchObject({ label: 'driver_license', country: 'fr' })
expect(res).toMatchObject({
label: 'driver_license',
country: 'foreign'
})
})

it('for "fr" country in file', () => {
Expand All @@ -433,7 +437,10 @@ describe('getPaperDefinitionByFile', () => {
})
const res = getPaperDefinitionByFile(mockPapersDefinitions, fakeFile)

expect(res).toMatchObject({ label: 'driver_license', country: 'fr' })
expect(res).toMatchObject({
label: 'driver_license',
country: 'foreign'
})
})
})

Expand Down

0 comments on commit bfb3db3

Please sign in to comment.