From f2b797b1a6d12136e9ec0e74e3bc902204dc8175 Mon Sep 17 00:00:00 2001 From: Manuel Rodriguez Date: Fri, 20 Sep 2024 16:41:24 -0700 Subject: [PATCH 1/2] Added logic for re-enabling a document type --- source/backend/api/Services/DocumentSyncService.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/backend/api/Services/DocumentSyncService.cs b/source/backend/api/Services/DocumentSyncService.cs index be54e48183..7356a1ae12 100644 --- a/source/backend/api/Services/DocumentSyncService.cs +++ b/source/backend/api/Services/DocumentSyncService.cs @@ -162,6 +162,7 @@ public DocumentSyncResponse SyncPimsDocumentTypes(SyncModel model) var matchingDocumentType = pimsDocumentTypes.FirstOrDefault(x => x.DocumentType == documentTypeModel.Name); if (matchingDocumentType == null) { + // New documents var newPimsDocType = new PimsDocumentTyp() { DocumentType = documentTypeModel.Name, @@ -173,16 +174,19 @@ public DocumentSyncResponse SyncPimsDocumentTypes(SyncModel model) } else { + // Existing documents var subtypeCodes = matchingDocumentType.PimsDocumentCategorySubtypes.Select(x => x.DocumentCategoryTypeCode).ToList(); var needsLabelUpdate = matchingDocumentType.DocumentTypeDescription != documentTypeModel.Label; var needsCategoryUpdate = !(subtypeCodes.All(documentTypeModel.Categories.Contains) && subtypeCodes.Count == documentTypeModel.Categories.Count); var needsOrderUpdate = matchingDocumentType.DisplayOrder != documentTypeModel.DisplayOrder; - if (needsLabelUpdate || needsCategoryUpdate || needsOrderUpdate) + var needsToBeEnabled = matchingDocumentType.IsDisabled != true; + if (needsLabelUpdate || needsCategoryUpdate || needsOrderUpdate || needsToBeEnabled) { matchingDocumentType.DocumentTypeDescription = documentTypeModel.Label; matchingDocumentType.PimsDocumentCategorySubtypes = subcategories; matchingDocumentType.DisplayOrder = documentTypeModel.DisplayOrder; + matchingDocumentType.IsDisabled = false; updatedDocumentTypes.Add(documentTypeRepository.Update(matchingDocumentType)); } From 7e667c0607490945d45c4061727395da273d0ef1 Mon Sep 17 00:00:00 2001 From: Manuel Rodriguez Date: Mon, 23 Sep 2024 11:18:24 -0700 Subject: [PATCH 2/2] Updated logic to update if disabled. Updated tests --- .../api/Services/DocumentSyncService.cs | 2 +- .../api/Services/DocumentSyncServiceTest.cs | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/source/backend/api/Services/DocumentSyncService.cs b/source/backend/api/Services/DocumentSyncService.cs index 7356a1ae12..f579463d27 100644 --- a/source/backend/api/Services/DocumentSyncService.cs +++ b/source/backend/api/Services/DocumentSyncService.cs @@ -180,7 +180,7 @@ public DocumentSyncResponse SyncPimsDocumentTypes(SyncModel model) var needsLabelUpdate = matchingDocumentType.DocumentTypeDescription != documentTypeModel.Label; var needsCategoryUpdate = !(subtypeCodes.All(documentTypeModel.Categories.Contains) && subtypeCodes.Count == documentTypeModel.Categories.Count); var needsOrderUpdate = matchingDocumentType.DisplayOrder != documentTypeModel.DisplayOrder; - var needsToBeEnabled = matchingDocumentType.IsDisabled != true; + var needsToBeEnabled = matchingDocumentType.IsDisabled == true; if (needsLabelUpdate || needsCategoryUpdate || needsOrderUpdate || needsToBeEnabled) { matchingDocumentType.DocumentTypeDescription = documentTypeModel.Label; diff --git a/source/backend/tests/unit/api/Services/DocumentSyncServiceTest.cs b/source/backend/tests/unit/api/Services/DocumentSyncServiceTest.cs index 4a0dbee13f..b36460e3ed 100644 --- a/source/backend/tests/unit/api/Services/DocumentSyncServiceTest.cs +++ b/source/backend/tests/unit/api/Services/DocumentSyncServiceTest.cs @@ -546,6 +546,7 @@ public void Update_SyncPimsDocumentTypes_NoLabelChange() DocumentCategoryTypeCode = "TEST_CATEGORY" }, }, + IsDisabled = false, DisplayOrder = 1, }, }); @@ -563,6 +564,42 @@ public void Update_SyncPimsDocumentTypes_NoLabelChange() result.Updated.Should().BeEmpty(); } + [Fact] + public void Update_SyncPimsDocumentTypes_Disabled() + { + // Arrange + var service = this.CreateDocumentySyncServiceWithPermissions(Permissions.DocumentAdmin); + + SyncModel model = this.CreateSyncModel(documentTypeModels: new List() { new Pims.Api.Models.PimsSync.DocumentTypeModel() { Name = "TEST", Label = "test", Categories = new List() { "TEST_CATEGORY" }, DisplayOrder = 1 } }); + + var pimsDocumentRepository = this._helper.GetService>(); + pimsDocumentRepository.Setup(x => x.GetAll()).Returns(new List() { + new PimsDocumentTyp() { + DocumentType = "TEST", + DocumentTypeDescription = "test", + PimsDocumentCategorySubtypes = new List() { + new PimsDocumentCategorySubtype() { + DocumentCategoryTypeCode = "TEST_CATEGORY" + }, + }, + IsDisabled = true, + DisplayOrder = 1, + }, + }); + pimsDocumentRepository.Setup(x => x.Add(It.IsAny())).Returns(new PimsDocumentTyp()); + pimsDocumentRepository.Setup(x => x.Update(It.IsAny())).Returns(new PimsDocumentTyp()); + + // Act + var result = service.SyncPimsDocumentTypes(model); + + // Assert + pimsDocumentRepository.Verify(x => x.Add(It.IsAny()), Times.Never()); + pimsDocumentRepository.Verify(x => x.Update(It.IsAny()), Times.Once()); + result.Added.Should().BeEmpty(); + result.Deleted.Should().BeEmpty(); + result.Updated.Should().HaveCount(1); + } + [Fact] public void Update_SyncPimsDocumentTypes_CategoryChange() {