Skip to content

Commit

Permalink
Merge pull request #148 from phyloref/correct-empty-specimenwrapper
Browse files Browse the repository at this point in the history
We previously ignored the occurrenceID if it was an empty string, and "constructed" an occurrenceID from the other components. This PR modifies that behavior so that an occurrenceID set to a blank string will be treated as an empty occurrenceID -- only a specimen missing an occurrenceID entirely will have one constructed based on the other components.  It also adds a test for this functionality.

It also replaces one use of `substr()` (now deprecated) with `substring()`, updates the OpenTree version in a test that would otherwise fail, and adds the `@shinnn/eslint-config` package, which is needed now for some reason.

Closes #145.
  • Loading branch information
gaurav authored Dec 23, 2024
2 parents 604db46 + 0e86a9c commit fecca6c
Show file tree
Hide file tree
Showing 4 changed files with 235 additions and 1 deletion.
227 changes: 227 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"yargs": "^15.4.1"
},
"devDependencies": {
"@shinnn/eslint-config": "^7.0.0",
"ajv": "^6.12.2",
"chai": "^4.2.0",
"esdoc": "^1.1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/wrappers/SpecimenWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class SpecimenWrapper {
*/
get occurrenceID() {
// Return the occurrenceID if it exists.
if (has(this.specimen, 'occurrenceID') && this.specimen.occurrenceID.trim() !== '') {
if (has(this.specimen, 'occurrenceID')) {
return this.specimen.occurrenceID.trim();
}

Expand Down
6 changes: 6 additions & 0 deletions test/specimens.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ describe('SpecimenWrapper', function () {
expect(wrapped).to.be.an.instanceOf(phyx.SpecimenWrapper);
expect(wrapped.occurrenceID).to.be.undefined;
});
it('should be able to wrap a specimen with an empty occurenceID', function () {
const wrapped = new phyx.SpecimenWrapper(phyx.SpecimenWrapper.fromOccurrenceID(''));

expect(wrapped).to.be.an.instanceOf(phyx.SpecimenWrapper);
expect(wrapped.occurrenceID).to.equal('');
});
it('should be able to extract an occurenceID and catalogNumber from simple specimen IDs', function () {
const wrapper = new phyx.SpecimenWrapper({
occurrenceID: 'Wall 2527, Fiji (uc)',
Expand Down

0 comments on commit fecca6c

Please sign in to comment.