Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/breeding-insight/model/import/germplasm/ExternalUID.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@
export class ExternalUID {

/**
* Get ExternalUID value from germplasm BrAPI external references array based
* on the seedSource value
* Get ExternalUID value from germplasm BrAPI external references array using
* the canonical External UID reference source.
*
* @param externalReferences
* @param source
*/
public static getExternalUIDFromExternalReferences(externalReferences: Array<any>, source : string) : string | undefined {
if (externalReferences === undefined || source === undefined) {
public static getExternalUIDFromExternalReferences(externalReferences: Array<any>) : string | undefined {
if (externalReferences === undefined) {
return undefined;
}
const externalUID = externalReferences.find( ({ referenceSource }) => referenceSource === source );
const externalUID = externalReferences.find( ({ referenceSource }) => referenceSource === "External UID" );
if (externalUID !== undefined) {
return externalUID.referenceID;
} else
Expand Down
4 changes: 2 additions & 2 deletions src/breeding-insight/utils/GermplasmUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export const MOMENT_DATE_PERSISTED_FORMAT = 'DD/MM/YYYY h:mm:ss';
export class GermplasmUtils {
static getExternalUID(germplasm: Germplasm): string | undefined {
let val;
if (germplasm.externalReferences && germplasm.seedSource) {
val = germplasm.externalReferences!.filter(ref => ref.referenceSource == germplasm.seedSource!)
if (germplasm.externalReferences) {
val = germplasm.externalReferences!.filter(ref => ref.referenceSource == "External UID")
.map(ref => ref.referenceID);
return val ? val[0]: "";
}
Expand Down
2 changes: 1 addition & 1 deletion src/views/import/ImportGermplasm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
{{ props.row.data.brAPIObject.additionalInfo.maleParentEntryNo }}
</b-table-column>
<b-table-column field="externalUID" label="External UID" v-slot="props" :th-attrs="(column) => ({scope:'col'})">
{{ ExternalUID.getExternalUIDFromExternalReferences(props.row.data.brAPIObject.externalReferences, props.row.data.brAPIObject.seedSource) }}
{{ ExternalUID.getExternalUIDFromExternalReferences(props.row.data.brAPIObject.externalReferences) }}
</b-table-column>
<b-table-column field="synonyms" label="Synonyms" v-slot="props" :th-attrs="(column) => ({scope:'col'})">
{{ GermplasmUtils.formatSynonyms(props.row.data.brAPIObject.synonyms) }}
Expand Down
51 changes: 51 additions & 0 deletions tests/unit/models/externalUID.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { ExternalUID } from "@/breeding-insight/model/import/germplasm/ExternalUID";

describe('ExternalUID helper returns the correct values.', () => {

it('Returns External UID when canonical External UID reference exists', () => {
const externalReferences = [
{ referenceSource: "USDA", referenceID: "OLD-123" },
{ referenceSource: "External UID", referenceID: "ABC-123" }
];

expect(ExternalUID.getExternalUIDFromExternalReferences(externalReferences)).toBe("ABC-123");
});

it('Returns External UID when canonical External UID reference exists and source is blank', () => {
const externalReferences = [
{ referenceSource: "External UID", referenceID: "ABC-456" }
];

expect(ExternalUID.getExternalUIDFromExternalReferences(externalReferences)).toBe("ABC-456");
});

it('Returns undefined when canonical External UID reference does not exist', () => {
const externalReferences = [
{ referenceSource: "USDA", referenceID: "OLD-123" }
];

expect(ExternalUID.getExternalUIDFromExternalReferences(externalReferences)).toBeUndefined();
});

it('Returns undefined when external references are undefined', () => {
expect(ExternalUID.getExternalUIDFromExternalReferences(undefined as any)).toBeUndefined();
});

});
61 changes: 61 additions & 0 deletions tests/unit/models/germplasmUtils.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { GermplasmUtils } from "@/breeding-insight/utils/GermplasmUtils";

describe('GermplasmUtils External UID helper returns the correct values.', () => {

it('Returns External UID from canonical External UID reference source', () => {
const germplasm: any = {
seedSource: "USDA",
externalReferences: [
{ referenceSource: "USDA", referenceID: "OLD-123" },
{ referenceSource: "External UID", referenceID: "ABC-123" }
]
};

expect(GermplasmUtils.getExternalUID(germplasm)).toBe("ABC-123");
});

it('Returns External UID when seed source is blank and canonical External UID reference exists', () => {
const germplasm: any = {
externalReferences: [
{ referenceSource: "External UID", referenceID: "ABC-456" }
]
};

expect(GermplasmUtils.getExternalUID(germplasm)).toBe("ABC-456");
});

it('Returns undefined when canonical External UID reference does not exist', () => {
const germplasm: any = {
seedSource: "USDA",
externalReferences: [
{ referenceSource: "USDA", referenceID: "OLD-123" }
]
};

expect(GermplasmUtils.getExternalUID(germplasm)).toBeUndefined();
});

it('Returns empty string when external references are missing', () => {
const germplasm: any = {};

expect(GermplasmUtils.getExternalUID(germplasm)).toBe("");
});

});
Loading