Skip to content

Commit

Permalink
fix: Add test on undefined qualification attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
LucsT committed Feb 12, 2024
1 parent 4b998e0 commit c075416
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions packages/cozy-client/src/models/document/qualification.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,42 @@ import {
import * as qualificationModel from '../../assets/qualifications.json'
import logger from '../../logger'

jest.mock('../../assets/qualifications.json', () => ({
qualifications: [
{
label: 'isp_invoice',
purpose: 'invoice',
sourceCategory: 'telecom',
sourceSubCategory: 'internet',
subjects: ['subscription']
},
{
label: 'national_id_card',
purpose: 'attestation',
sourceCategory: 'gov',
sourceSubCategory: 'civil_registration',
subjects: ['identity']
},
{
label: 'health_invoice',
purpose: 'invoice',
sourceCategory: 'health'
},
{
label: 'other_identity_document',
purpose: 'attestation',
subjects: ['identity']
},
{
label: 'dummy_empty'
}
],
purposeKnownValues: ['attestation', 'invoice'],
sourceCategoryKnownValues: ['telecom', 'health', 'gov'],
sourceSubCategoryKnownValues: ['civil_registration', 'internet'],
subjectsKnownValues: ['identity', 'subscription']
}))

describe('document qualification', () => {
beforeEach(() => {
jest.spyOn(logger, 'warn').mockImplementation(() => jest.fn())
Expand Down Expand Up @@ -133,6 +169,17 @@ describe('qualifications items', () => {
})
})

it('should not have undefined attributes', () => {
const qualification = Qualification.getByLabel('dummy_empty')
expect(Object.hasOwn(qualification, 'purpose')).toBe(false)
expect(Object.hasOwn(qualification, 'sourceCategory')).toBe(false)
expect(Object.hasOwn(qualification, 'sourceSubCategory')).toBe(false)
expect(Object.hasOwn(qualification, 'subjects')).toBe(false)
Object.keys(qualification).forEach(key => {
expect(qualification[key]).toBeDefined()
})
})

it('should define authorized attributes', () => {
qualificationModel.qualifications.forEach(q => {
if (q.purpose) {
Expand Down

0 comments on commit c075416

Please sign in to comment.