Skip to content

Commit

Permalink
GPG-829: Remove all the drafts when the report is submitted
Browse files Browse the repository at this point in the history
  • Loading branch information
malinaslevoaca1 committed Jan 25, 2022
1 parent 266fdaf commit 0396f99
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public async Task SubmitController_CheckData_GET_Success()
"Expected ReturnViewModel or Incorrect viewModel returned");
Assert.That(result.ViewData.ModelState.IsValid, "Model is Invalid");

await testService.DiscardDraftFileAsync(model);
await testService.DiscardDraftFileAsync(model, true);
}

[Test]
Expand Down Expand Up @@ -523,7 +523,7 @@ public async Task SubmitController_CheckData_POST_Success_When_Sector_Is_Public_
Assert.AreEqual("SubmissionComplete", result.ActionName, "Incorrect view returned");

// Clean up
await testService.DiscardDraftFileAsync(model);
await testService.DiscardDraftFileAsync(model, true);
}

[Test]
Expand Down Expand Up @@ -946,7 +946,7 @@ public async Task SubmitController_CheckData_POST_When_The_Return_Already_Exists
Assert.AreEqual("SubmissionComplete", result.ActionName);

// Clean up
await testService.DiscardDraftFileAsync(model);
await testService.DiscardDraftFileAsync(model, true);
}

[Test(Author = "Oscar Lagatta")]
Expand Down Expand Up @@ -1206,7 +1206,7 @@ public async Task SubmitController_CheckData_POST_Success_When_OptedOutOfReporti
Assert.AreEqual("SubmissionComplete", result.ActionName, "Incorrect view returned");

// Clean up
await testService.DiscardDraftFileAsync(model);
await testService.DiscardDraftFileAsync(model, true);
}


Expand Down Expand Up @@ -1272,7 +1272,7 @@ public async Task SubmitController_EmployerWebsite_GET_Success()
Assert.Null(resultModel.CompanyLinkToGPGInfo, "CompanyLinkToGPGInfo:Expected a null or empty field");

// Clean up
await testService.DiscardDraftFileAsync(model);
await testService.DiscardDraftFileAsync(model, true);
}

[Test]
Expand Down Expand Up @@ -1412,7 +1412,7 @@ public async Task SubmitController_EmployerWebsite_GET_When_Sector_Is_Public_The
Assert.AreEqual(result.ViewName, "EmployerWebsite");

// Clean up
await testService.DiscardDraftFileAsync(model);
await testService.DiscardDraftFileAsync(model, true);
}

//I don't think this test is necessary as the above does the same thing this just does the same but in opposite
Expand Down Expand Up @@ -1514,7 +1514,7 @@ public async Task SubmitController_EmployerWebsite_POST_VerifyGPGInfoLink_WhatYo
//TODO not really a valid test as there is no code which changes this - you should maybe just be checking there are no modelstate errors but then its a repeat test of one you did earlier
//TODO also your not checking for the correct redirectresult and the rest of the model the correct model - why just test one field remains unchanged?

await testService.DiscardDraftFileAsync(returnViewModel);
await testService.DiscardDraftFileAsync(returnViewModel, true);
}

[Test(Author = "Oscar Lagatta")]
Expand Down Expand Up @@ -1630,7 +1630,7 @@ public async Task SubmitController_EmployerWebsite_POST_When_ViewModel_Not_Valid
controller.ModelState.Values.Select(e => e.Errors).FirstOrDefault()?[0].ErrorMessage);

// Cleanup
await testService.DiscardDraftFileAsync(returnViewModel);
await testService.DiscardDraftFileAsync(returnViewModel, true);
}

[Test]
Expand Down Expand Up @@ -1725,7 +1725,7 @@ public async Task SubmitController_EmployerWebsite_POST_With_CompanyLinkToGPGInf
Assert.That(resultModel.CompanyLinkToGPGInfo.StartsWith("http://"), "Expected CompanyLinkToGPGInfoLink URL Prefix:'http://' ");

// Cleanup
await testService.DiscardDraftFileAsync(returnViewModel);
await testService.DiscardDraftFileAsync(returnViewModel, true);
}

[Test]
Expand Down Expand Up @@ -1811,7 +1811,7 @@ public async Task SubmitController_EmployerWebsite_POST_Without_CompanyLinkToGPG
//TODO you should be checking modelstate.isvalid and also that all other fields dont fail in modelstate

// Cleanup
await testService.DiscardDraftFileAsync(returnViewModel);
await testService.DiscardDraftFileAsync(returnViewModel, true);
}

[Test]
Expand Down Expand Up @@ -2115,7 +2115,7 @@ public async Task SubmitController_EnterCalculations_GET_Wen_User_Has_No_Return_
expectedReturnViewModel.Compare(actualReturnViewModel, null, null, false, true, -1, false);

// Clean up
await testService.DiscardDraftFileAsync(expectedReturnViewModel);
await testService.DiscardDraftFileAsync(expectedReturnViewModel, true);
}

[Test(Author = "Oscar Lagatta")]
Expand Down Expand Up @@ -2173,7 +2173,7 @@ public async Task SubmitController_EnterCalculations_GET_When_User_Has_Return_In
var testDataRepository = UiTestHelper.DIContainer.Resolve<IDataRepository>();
var testDraftFileBL = new DraftFileBusinessLogic(testDataRepository);
var testService = new SubmissionService(testDataRepository, null, testDraftFileBL);
await testService.DiscardDraftFileAsync(actualReturnViewModel);
await testService.DiscardDraftFileAsync(actualReturnViewModel, true);
}

[Test]
Expand Down Expand Up @@ -2417,7 +2417,7 @@ public async Task SubmitController_EnterCalculations_POST_MaxValidValues_NoError
Assert.AreEqual("CheckData", result.ActionName, "Expected a RedirectToRouteResult to CheckData");

// Cleanup
await testService.DiscardDraftFileAsync(returnViewModel);
await testService.DiscardDraftFileAsync(returnViewModel, true);
}

[Test]
Expand Down Expand Up @@ -2500,7 +2500,7 @@ public async Task SubmitController_EnterCalculations_POST_MinValidValues_NoError
Assert.AreEqual("CheckData", result.ActionName, "Expected a RedirectToRouteResult to CheckData");

// Cleanup
await testService.DiscardDraftFileAsync(returnViewModel);
await testService.DiscardDraftFileAsync(returnViewModel, true);
}

[Test]
Expand Down Expand Up @@ -2650,7 +2650,7 @@ public async Task SubmitController_EnterCalculations_POST_Success_PrivateSector(
});

// Cleanup
await testService.DiscardDraftFileAsync(returnViewModel);
await testService.DiscardDraftFileAsync(returnViewModel, true);
}

[Test]
Expand Down Expand Up @@ -2787,7 +2787,7 @@ public async Task SubmitController_EnterCalculations_POST_Success_PublicSector()
});

// Cleanup
await testService.DiscardDraftFileAsync(returnViewModel);
await testService.DiscardDraftFileAsync(returnViewModel, true);
}

[Test]
Expand Down Expand Up @@ -2922,7 +2922,7 @@ public async Task SubmitController_EnterCalculations_POST_ValidValueInFields_NoE
});

// Cleanup
await testService.DiscardDraftFileAsync(returnViewModel);
await testService.DiscardDraftFileAsync(returnViewModel, true);
}

[Test]
Expand Down Expand Up @@ -3049,7 +3049,7 @@ public async Task SubmitController_EnterCalculations_POST_PayQuarters_Not_Requir
});

// Cleanup
await testService.DiscardDraftFileAsync(returnViewModel);
await testService.DiscardDraftFileAsync(returnViewModel, true);
}

[Test]
Expand Down Expand Up @@ -3126,7 +3126,7 @@ public async Task SubmitController_EnterCalculations_POST_PayQuarters_And_OptedO
result.ViewData.ModelState["OptedOutOfReportingPayQuarters"].Errors[0].ErrorMessage);

// Cleanup
await testService.DiscardDraftFileAsync(returnViewModel);
await testService.DiscardDraftFileAsync(returnViewModel, true);
}

[Test(Author = "Oscar Lagatta")]
Expand Down Expand Up @@ -3328,7 +3328,7 @@ public async Task SubmitController_EnterCalculations_POST_ZeroValidValueInFields
});

// Cleanup
await testService.DiscardDraftFileAsync(returnViewModel);
await testService.DiscardDraftFileAsync(returnViewModel, true);
}

[Test]
Expand Down Expand Up @@ -3881,7 +3881,7 @@ public async Task SubmitController_Organisation_Size_POST_Success()
Assert.AreEqual("EmployerWebsite", result.ActionName, "Expected a RedirectToActionResult to EmployerWebsite");

// Cleanup
await testService.DiscardDraftFileAsync(returnViewModel);
await testService.DiscardDraftFileAsync(returnViewModel, true);
}

[Test(Author = "Oscar Lagatta")]
Expand Down Expand Up @@ -3967,7 +3967,7 @@ public async Task SubmitController_OrganisationSize_GET_Success()
Assert.NotNull(result);

// Clean up
await testService.DiscardDraftFileAsync(returnViewModel);
await testService.DiscardDraftFileAsync(returnViewModel, true);
}

[Test(Author = "Oscar Lagatta")]
Expand Down Expand Up @@ -4136,7 +4136,7 @@ public async Task SubmitController_PersonResponsible_GET_Success()
Assert.Null(resultModel.JobTitle, "JobTitle:Expected a null or empty field");

// Clean up
await testService.DiscardDraftFileAsync(returnViewModel);
await testService.DiscardDraftFileAsync(returnViewModel, true);
}

[Test(Author = "Oscar Lagatta")]
Expand Down Expand Up @@ -4302,7 +4302,7 @@ public async Task SubmitController_PersonResponsible_POST_Success()
//TODO you should be checking each error message is exact as per config file

// Cleanup
await testService.DiscardDraftFileAsync(returnViewModel);
await testService.DiscardDraftFileAsync(returnViewModel, true);
}

[Test(Author = "Oscar Lagatta")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ public async Task
Assert.AreEqual(testOrganisation.OrganisationId, actualModel.OrganisationId);
Assert.AreEqual(testYear, actualModel.AccountingDate.Year);

testDraftFileFileBusinessLogic.DiscardDraft(actualDraftFile, null);
testDraftFileFileBusinessLogic.DiscardDraft(actualDraftFile, null, true);
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface IDraftFileBusinessLogic
Draft GetExistingOrNew(long organisationId, int snapshotYear, long userIdRequestingAccess);
Draft UpdateAndCommit(ReturnViewModel postedReturnViewModel, Draft draft, long userIdRequestingAccess);
void KeepDraftFileLockedToUser(Draft draftExpectedToBeLocked, long userIdRequestingLock);
void DiscardDraft(Draft draftToDiscard, Return submittedReturn);
void DiscardDraft(Draft draftToDiscard, Return submittedReturn, bool reportSubmitted);

}

Expand Down Expand Up @@ -98,13 +98,13 @@ public void KeepDraftFileLockedToUser(Draft draftExpectedToBeLocked, long userId
SetDraftAccessInformation(userIdRequestingLock, draftExpectedToBeLocked);
}

public void DiscardDraft(Draft draftToDiscard, Return submittedReturn)
public void DiscardDraft(Draft draftToDiscard, Return submittedReturn, bool reportSubmitted)
{
List<DraftReturn> matchingReturns = dataRepository.GetAll<DraftReturn>()
.Where(dr => dr.OrganisationId == draftToDiscard.OrganisationId)
.Where(dr => dr.SnapshotYear == draftToDiscard.SnapshotYear)
.AsEnumerable()
.Where(dr => dr.IsEmpty() || dr.IsSameAsSubmittedReturn(submittedReturn))
.Where(dr => reportSubmitted || dr.IsEmpty() || dr.IsSameAsSubmittedReturn(submittedReturn))
.ToList();

foreach (DraftReturn matchingReturn in matchingReturns)
Expand Down
6 changes: 3 additions & 3 deletions GenderPayGap.WebUI/Classes/Presentation/SubmissionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public interface ISubmissionService

void UpdateAndCommitDraftFile(long userRequestingTheUpdate, ReturnViewModel returnViewModel);
Task KeepDraftFileLockedToUserAsync(ReturnViewModel returnViewModel, long userIdRequestingLock);
Task DiscardDraftFileAsync(ReturnViewModel returnViewModel);
Task DiscardDraftFileAsync(ReturnViewModel returnViewModel, bool reportSubmitted = false);
Task<Draft> GetDraftIfAvailableAsync(long organisationId, int snapshotYear);

#endregion
Expand Down Expand Up @@ -559,10 +559,10 @@ public async Task KeepDraftFileLockedToUserAsync(ReturnViewModel returnViewModel
_draftFileBusinessLogic.KeepDraftFileLockedToUser(returnViewModel.ReportInfo.Draft, userIdRequestingLock);
}

public async Task DiscardDraftFileAsync(ReturnViewModel returnViewModel)
public async Task DiscardDraftFileAsync(ReturnViewModel returnViewModel, bool reportSubmitted)
{
var submittedReturn = this.GetReturnFromDatabase(returnViewModel.OrganisationId, returnViewModel.AccountingDate.Year);
_draftFileBusinessLogic.DiscardDraft(returnViewModel.ReportInfo.Draft, submittedReturn);
_draftFileBusinessLogic.DiscardDraft(returnViewModel.ReportInfo.Draft, submittedReturn, reportSubmitted);
}

#endregion
Expand Down
3 changes: 2 additions & 1 deletion GenderPayGap.WebUI/Controllers/SubmitController.CheckData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ public async Task<IActionResult> CheckData(ReturnViewModel postedReturnViewModel
{
if (databaseReturn.ReturnId != postedReturnViewModel.ReturnId)
{
await submissionService.DiscardDraftFileAsync(postedReturnViewModel, true);
throw new ReportAlreadySubmittedException
{
OrganisationId = postedReturn.Organisation.OrganisationId,
Expand Down Expand Up @@ -267,7 +268,7 @@ public async Task<IActionResult> CheckData(ReturnViewModel postedReturnViewModel
GetSubmittedOrUpdated(postedReturn),
emailSendingService);

await submissionService.DiscardDraftFileAsync(postedReturnViewModel);
await submissionService.DiscardDraftFileAsync(postedReturnViewModel, true);

return RedirectToAction("SubmissionComplete");
}
Expand Down

0 comments on commit 0396f99

Please sign in to comment.