diff --git a/src/main/webapp/app/service/firebase/firebase-gene-review-service.spec.ts b/src/main/webapp/app/service/firebase/firebase-gene-review-service.spec.ts index 4239f1b8b..0992bbba3 100644 --- a/src/main/webapp/app/service/firebase/firebase-gene-review-service.spec.ts +++ b/src/main/webapp/app/service/firebase/firebase-gene-review-service.spec.ts @@ -7,7 +7,7 @@ import { FirebaseVusService } from './firebase-vus-service'; import { Gene, HistoryOperationType, Mutation, Review, Tumor } from 'app/shared/model/firebase/firebase.model'; import { mock, mockReset } from 'jest-mock-extended'; import { SentryError } from 'app/config/sentry-error'; -import { ReviewLevel } from 'app/shared/util/firebase/firebase-review-utils'; +import { getTumorNameUuid, ReviewLevel, TumorReviewLevel } from 'app/shared/util/firebase/firebase-review-utils'; import { ReviewAction } from 'app/config/constants/firebase'; import _ from 'lodash'; import { ActionType } from 'app/pages/curation/collapsible/ReviewCollapsible'; @@ -395,6 +395,65 @@ describe('Firebase Gene Review Service', () => { }); }); + it('should reject initial excluded cancer type', async () => { + const mutation = new Mutation('V600E'); + const tumor = new Tumor(); + tumor.cancerTypes = [{ code: '', subtype: '', mainType: 'Melanoma' }]; + tumor.cancerTypes_review = new Review('User'); + tumor.excludedCancerTypes = [{ code: 'OCM', subtype: 'Ocular Melanoma', mainType: 'Melanoma' }]; + tumor.excludedCancerTypes_review = new Review('User', undefined, false, false, true); + tumor.excludedCancerTypes_uuid = generateUuid(); + mutation.tumors.push(tumor); + + const reviewLevel = new TumorReviewLevel({ + titleParts: ['Oncogenic Mutations', 'Breast Cancer {excluding Metaplastic Breast Cancer}', 'Name'], + valuePath: 'mutations/0/tumors/0/cancerTypes', + historyLocation: 'Oncogenic Mutations, Breast Cancer {excluding Metaplastic Breast Cancer}', + children: [], + historyInfo: {}, + currentVal: 'Breast Cancer {excluding Metaplastic Breast Cancer}', + reviewInfo: { + reviewPath: 'mutations/0/tumors/0/cancerTypes_review', + review: tumor.cancerTypes_review, + lastReviewedString: 'Breast Cancer', + uuid: getTumorNameUuid(tumor.cancerTypes_uuid, tumor.excludedCancerTypes_uuid), + reviewAction: 3, + }, + historyData: { + oldState: 'Breast Cancer', + newState: 'Breast Cancer {excluding Metaplastic Breast Cancer}', + }, + excludedCancerTypesReviewInfo: { + reviewPath: 'mutations/0/tumors/0/excludedCancerTypes_review', + review: tumor.excludedCancerTypes_review, + lastReviewedString: undefined, + uuid: tumor.excludedCancerTypes_uuid, + }, + currentExcludedCancerTypes: [ + { + code: 'MBC', + mainType: 'Breast Cancer', + subtype: 'Metaplastic Breast Cancer', + }, + ], + }); + + await firebaseGeneReviewService.rejectChanges('BRAF', [reviewLevel], false); + expect(mockFirebaseRepository.update.mock.calls[0][0]).toEqual('/'); + expect(mockFirebaseRepository.update.mock.calls[0][1]).toMatchObject({ + 'Genes/BRAF/mutations/0/tumors/0/cancerTypes_review': { + updateTime: DEFAULT_DATE.getTime(), + updatedBy: mockAuthStore.fullName, + }, + 'Genes/BRAF/mutations/0/tumors/0/excludedCancerTypes': null, + 'Meta/BRAF/lastModifiedAt': DEFAULT_DATETIME_STRING, + 'Meta/BRAF/lastModifiedBy': mockAuthStore.fullName, + [`Meta/BRAF/review/${getTumorNameUuid(tumor.cancerTypes_uuid, tumor.excludedCancerTypes_uuid)}`]: null, + [`Meta/BRAF/review/${tumor.cancerTypes_uuid}`]: null, + [`Meta/BRAF/review/${tumor.excludedCancerTypes_uuid}`]: null, + }); + }); + it('should reject initial excluded RCT', async () => { const mutation = new Mutation('V600E'); const tumor = new Tumor(); diff --git a/src/main/webapp/app/service/firebase/firebase-gene-review-service.ts b/src/main/webapp/app/service/firebase/firebase-gene-review-service.ts index 2877a5853..198ebd9e7 100644 --- a/src/main/webapp/app/service/firebase/firebase-gene-review-service.ts +++ b/src/main/webapp/app/service/firebase/firebase-gene-review-service.ts @@ -157,7 +157,7 @@ export class FirebaseGeneReviewService { const reviewLevelUpdateObject = { [`${firebaseGenePath}/${reviewPath}`]: resetReview, // When user rejects the initial excludedRCTs, then excludedRCTs field should be cleared. - [`${firebaseGenePath}/${fieldPath}`]: review.initialUpdate ? null : review.lastReviewed, + [`${firebaseGenePath}/${fieldPath}`]: review.initialUpdate || review.lastReviewed === undefined ? null : review.lastReviewed, }; updateObject = { ...updateObject, ...reviewLevelUpdateObject }; if ('excludedCancerTypesReviewInfo' in reviewLevel && 'currentExcludedCancerTypes' in reviewLevel) { @@ -165,7 +165,9 @@ export class FirebaseGeneReviewService { const excludedCtReviewPath = tumorReviewLevel.excludedCancerTypesReviewInfo?.reviewPath; const excludedCtPath = excludedCtReviewPath?.replace('_review', ''); updateObject[`${firebaseGenePath}/${excludedCtReviewPath}`] = resetReview; - updateObject[`${firebaseGenePath}/${excludedCtPath}`] = tumorReviewLevel.excludedCancerTypesReviewInfo?.review.lastReviewed; + updateObject[`${firebaseGenePath}/${excludedCtPath}`] = tumorReviewLevel.excludedCancerTypesReviewInfo?.review.initialUpdate + ? null + : tumorReviewLevel.excludedCancerTypesReviewInfo?.review.lastReviewed; } } else if (isDeleteReview(reviewLevel)) { updateObject[`${firebaseGenePath}/${reviewPath}`] = resetReview;