-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): handle Legal Document errors mapping
- Loading branch information
1 parent
f85245b
commit 5636529
Showing
3 changed files
with
67 additions
and
0 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
16 changes: 16 additions & 0 deletions
16
api/src/legal-documents/application/http-error-mapper-configuration.js
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,16 @@ | ||
import { HttpErrors } from '../../shared/application/http-errors.js'; | ||
import { DomainErrorMappingConfiguration } from '../../shared/application/models/domain-error-mapping-configuration.js'; | ||
import { LegalDocumentInvalidDateError, LegalDocumentVersionNotFoundError } from '../domain/errors.js'; | ||
|
||
const legalDocumentsDomainErrorMappingConfiguration = [ | ||
{ | ||
name: LegalDocumentInvalidDateError.name, | ||
httpErrorFn: (error) => new HttpErrors.UnprocessableEntityError(error.message, error.code, error.meta), | ||
}, | ||
{ | ||
name: LegalDocumentVersionNotFoundError.name, | ||
httpErrorFn: (error) => new HttpErrors.NotFoundError(error.message, error.code, error.meta), | ||
}, | ||
].map((domainErrorMappingConfiguration) => new DomainErrorMappingConfiguration(domainErrorMappingConfiguration)); | ||
|
||
export { legalDocumentsDomainErrorMappingConfiguration }; |
49 changes: 49 additions & 0 deletions
49
api/tests/legal-documents/unit/domain/application/http-error-mapper-configuration_test.js
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,49 @@ | ||
import { legalDocumentsDomainErrorMappingConfiguration } from '../../../../../src/legal-documents/application/http-error-mapper-configuration.js'; | ||
import { | ||
LegalDocumentInvalidDateError, | ||
LegalDocumentVersionNotFoundError, | ||
} from '../../../../../src/legal-documents/domain/errors.js'; | ||
import { HttpErrors } from '../../../../../src/shared/application/http-errors.js'; | ||
import { DomainErrorMappingConfiguration } from '../../../../../src/shared/application/models/domain-error-mapping-configuration.js'; | ||
import { expect } from '../../../../test-helper.js'; | ||
|
||
describe('Unit | Legal Documents | Application | HttpErrorMapperConfiguration', function () { | ||
it('contains a list of HttpErrorMapper instances', function () { | ||
// given | ||
// when | ||
// then | ||
legalDocumentsDomainErrorMappingConfiguration.forEach((domainErrorMappingConfiguration) => | ||
expect(domainErrorMappingConfiguration).to.be.instanceOf(DomainErrorMappingConfiguration), | ||
); | ||
}); | ||
|
||
context('when mapping "LegalDocumentInvalidDateError"', function () { | ||
it('returns an UnprocessableEntity Http Error', function () { | ||
//given | ||
const httpErrorMapper = legalDocumentsDomainErrorMappingConfiguration.find( | ||
(httpErrorMapper) => httpErrorMapper.name === LegalDocumentInvalidDateError.name, | ||
); | ||
|
||
//when | ||
const error = httpErrorMapper.httpErrorFn(new LegalDocumentInvalidDateError()); | ||
|
||
//then | ||
expect(error).to.be.instanceOf(HttpErrors.UnprocessableEntityError); | ||
}); | ||
}); | ||
|
||
context('when mapping "LegalDocumentVersionNotFoundError"', function () { | ||
it('returns an NotFound Http Error', function () { | ||
//given | ||
const httpErrorMapper = legalDocumentsDomainErrorMappingConfiguration.find( | ||
(httpErrorMapper) => httpErrorMapper.name === LegalDocumentVersionNotFoundError.name, | ||
); | ||
|
||
//when | ||
const error = httpErrorMapper.httpErrorFn(new LegalDocumentVersionNotFoundError()); | ||
|
||
//then | ||
expect(error).to.be.instanceOf(HttpErrors.NotFoundError); | ||
}); | ||
}); | ||
}); |