From 4dea2bc02e0fa29bb67c8a4e9b08ef551775056c Mon Sep 17 00:00:00 2001 From: devinleighsmith <41091511+devinleighsmith@users.noreply.github.com> Date: Wed, 16 Mar 2022 13:17:26 -0700 Subject: [PATCH] Psp 3042 (#1110) * remove lease notes specific repository behaviour. Changing the response navigations was causing failures in some cases. * test corrections. * increment patch number Co-authored-by: Smith --- backend/api/Pims.Api.csproj | 4 ++-- .../dal/Repositories/Interfaces/ILeaseRepository.cs | 2 +- backend/dal/Repositories/LeaseRepository.cs | 13 +++++-------- backend/dal/Services/SecurityDepositService.cs | 3 ++- .../api/Controllers/Leases/LeaseControllerTest.cs | 4 ++-- .../tests/unit/dal/Services/LeaseTermServiceTest.cs | 10 +++++----- frontend/package.json | 2 +- 7 files changed, 18 insertions(+), 20 deletions(-) diff --git a/backend/api/Pims.Api.csproj b/backend/api/Pims.Api.csproj index b59a1771c4..5c9a7f70e2 100644 --- a/backend/api/Pims.Api.csproj +++ b/backend/api/Pims.Api.csproj @@ -2,8 +2,8 @@ 0ef6255f-9ea0-49ec-8c65-c172304b4926 - 1.1.3-21.45 - 1.1.3.21 + 1.1.4-21.45 + 1.1.4.21 true 16BC0468-78F6-4C91-87DA-7403C919E646 diff --git a/backend/dal/Repositories/Interfaces/ILeaseRepository.cs b/backend/dal/Repositories/Interfaces/ILeaseRepository.cs index e79f171752..3092847047 100644 --- a/backend/dal/Repositories/Interfaces/ILeaseRepository.cs +++ b/backend/dal/Repositories/Interfaces/ILeaseRepository.cs @@ -12,7 +12,7 @@ public interface ILeaseRepository : IRepository int Count(); IEnumerable Get(LeaseFilter filter, bool loadPayments = false); long GetRowVersion(long id); - PimsLease Get(long id, bool skipNavigations = false); + PimsLease Get(long id); Paged GetPage(LeaseFilter filter); PimsLease Add(PimsLease lease, bool userOverride = false); PimsLease Update(PimsLease lease, bool commitTransaction = true); diff --git a/backend/dal/Repositories/LeaseRepository.cs b/backend/dal/Repositories/LeaseRepository.cs index 5df5a6b7fd..e78abf59dc 100644 --- a/backend/dal/Repositories/LeaseRepository.cs +++ b/backend/dal/Repositories/LeaseRepository.cs @@ -64,14 +64,12 @@ public long GetRowVersion(long id) this.User.ThrowIfNotAuthorized(Permissions.LeaseView); return this.Context.PimsLeases.Where(l => l.LeaseId == id)?.Select(l => l.ConcurrencyControlNumber)?.FirstOrDefault() ?? throw new KeyNotFoundException(); } - public PimsLease Get(long id, bool skipNavigations = false) + public PimsLease Get(long id) { this.User.ThrowIfNotAuthorized(Permissions.LeaseView); - IQueryable leaseQuery = this.Context.PimsLeases.Where(l => l.LeaseId == id); - if (!skipNavigations) - { - leaseQuery = leaseQuery.Include(l => l.PimsPropertyLeases) + PimsLease lease = this.Context.PimsLeases + .Include(l => l.PimsPropertyLeases) .ThenInclude(p => p.Property) .ThenInclude(p => p.Address) .ThenInclude(p => p.Country) @@ -151,9 +149,8 @@ public PimsLease Get(long id, bool skipNavigations = false) .ThenInclude(t => t.LeasePaymentMethodTypeCodeNavigation) .Include(t => t.PimsLeaseTerms) .ThenInclude(t => t.PimsLeasePayments) - .ThenInclude(t => t.LeasePaymentStatusTypeCodeNavigation); - } - PimsLease lease = leaseQuery.FirstOrDefault() ?? throw new KeyNotFoundException(); + .ThenInclude(t => t.LeasePaymentStatusTypeCodeNavigation) + .FirstOrDefault(l=>l.LeaseId == id) ?? throw new KeyNotFoundException(); lease.LeasePurposeTypeCodeNavigation = this.Context.PimsLeasePurposeTypes.Single(type => type.LeasePurposeTypeCode == lease.LeasePurposeTypeCode); lease.PimsPropertyImprovements = lease.PimsPropertyImprovements.OrderBy(i => i.PropertyImprovementTypeCode).ToArray(); diff --git a/backend/dal/Services/SecurityDepositService.cs b/backend/dal/Services/SecurityDepositService.cs index e8b9de7181..9b1a0991f0 100644 --- a/backend/dal/Services/SecurityDepositService.cs +++ b/backend/dal/Services/SecurityDepositService.cs @@ -55,10 +55,11 @@ public PimsLease UpdateLeaseDepositNote(long leaseId, long leaseRowVersion, stri { _user.ThrowIfNotAuthorized(Permissions.LeaseEdit); ValidateServiceCall(leaseId, leaseRowVersion); - var lease = _leaseRepository.Get(leaseId, true); + var lease = _leaseRepository.Get(leaseId); lease.ReturnNotes = note; _leaseRepository.Update(lease); _leaseRepository.CommitTransaction(); + return _leaseRepository.Get(leaseId); } diff --git a/backend/tests/unit/api/Controllers/Leases/LeaseControllerTest.cs b/backend/tests/unit/api/Controllers/Leases/LeaseControllerTest.cs index c672f46507..2c9140c9d9 100644 --- a/backend/tests/unit/api/Controllers/Leases/LeaseControllerTest.cs +++ b/backend/tests/unit/api/Controllers/Leases/LeaseControllerTest.cs @@ -36,7 +36,7 @@ public void GetLeases_All_Success() var service = helper.GetService>(); var mapper = helper.GetService(); - service.Setup(m => m.Lease.Get(It.IsAny(), false)).Returns(lease); + service.Setup(m => m.Lease.Get(It.IsAny())).Returns(lease); // Act var result = controller.GetLease(1); @@ -46,7 +46,7 @@ public void GetLeases_All_Success() var actualResult = Assert.IsType(actionResult.Value); var expectedResult = mapper.Map(lease); Assert.Equal(expectedResult, actualResult, new DeepPropertyCompare()); - service.Verify(m => m.Lease.Get(It.IsAny(), false), Times.Once()); + service.Verify(m => m.Lease.Get(It.IsAny()), Times.Once()); } #endregion #region UpdateProperties diff --git a/backend/tests/unit/dal/Services/LeaseTermServiceTest.cs b/backend/tests/unit/dal/Services/LeaseTermServiceTest.cs index 04737892d6..bd4c1b8b81 100644 --- a/backend/tests/unit/dal/Services/LeaseTermServiceTest.cs +++ b/backend/tests/unit/dal/Services/LeaseTermServiceTest.cs @@ -38,7 +38,7 @@ public void AddTerm() var leaseRepository = helper.GetService>(); var leaseTermRepository = helper.GetService>(); leaseService.Setup(x => x.IsRowVersionEqual(It.IsAny(), It.IsAny())).Returns(true); - leaseRepository.Setup(x => x.Get(It.IsAny(), false)).Returns(lease); + leaseRepository.Setup(x => x.Get(It.IsAny())).Returns(lease); // Act var term = new PimsLeaseTerm() { TermStartDate = DateTime.Now, LeaseId = lease.Id, Lease = lease }; @@ -47,7 +47,7 @@ public void AddTerm() // Assert leaseTermRepository.Verify(x => x.Add(term), Times.Once); - leaseRepository.Verify(x => x.Get(lease.Id, false), Times.Once); + leaseRepository.Verify(x => x.Get(lease.Id), Times.Once); } [Fact] @@ -204,7 +204,7 @@ public void UpdateTerm() var leaseService = helper.GetService>(); var leaseRepository = helper.GetService>(); leaseService.Setup(x => x.IsRowVersionEqual(It.IsAny(), It.IsAny())).Returns(true); - leaseRepository.Setup(x => x.Get(It.IsAny(), false)).Returns(lease); + leaseRepository.Setup(x => x.Get(It.IsAny())).Returns(lease); var leaseTermRepository = helper.GetService>(); leaseTermRepository.Setup(x => x.GetById(It.IsAny(), It.IsAny())).Returns(originalTerm); @@ -215,7 +215,7 @@ public void UpdateTerm() // Assert leaseTermRepository.Verify(x => x.Update(term), Times.Once); - leaseRepository.Verify(x => x.Get(lease.Id, false), Times.Once); + leaseRepository.Verify(x => x.Get(lease.Id), Times.Once); } [Fact] @@ -324,7 +324,7 @@ public void DeleteTerm() var leaseService = helper.GetService>(); var leaseRepository = helper.GetService>(); leaseService.Setup(x => x.IsRowVersionEqual(It.IsAny(), It.IsAny())).Returns(true); - leaseRepository.Setup(x => x.Get(It.IsAny(), false)).Returns(lease); + leaseRepository.Setup(x => x.Get(It.IsAny())).Returns(lease); var leaseTermRepository = helper.GetService>(); leaseTermRepository.Setup(x => x.GetById(It.IsAny(), It.IsAny())).Returns(originalTerm); diff --git a/frontend/package.json b/frontend/package.json index d29601bc9e..bff5e2525c 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,6 +1,6 @@ { "name": "frontend", - "version": "1.1.3-21.45", + "version": "1.1.4-21.45", "private": true, "dependencies": { "@bcgov/bc-sans": "1.0.1",