Example #1
0
        public void CompareController_AddEmployerJS_Success_RedirectToReturnUrl()
        {
            // Arrange
            Config.SetAppSetting("SearchService:CacheResults", "true");

            var    controller     = UiTestHelper.GetController <CompareController>();
            string returnUrl      = @"\viewing\search-results";
            var    organisationId = 123;
            var    expectedObfuscatedOrganisationId = ViewingControllerTests.ConfigureObfuscator(organisationId);

            var employer = new Core.Models.EmployerSearchModel()
            {
                OrganisationIdEncrypted = expectedObfuscatedOrganisationId,
                OrganisationId          = "123",
                Name = "Org123"
            };

            var model = new AddRemoveButtonViewModel()
            {
                OrganisationIdEncrypted = employer.OrganisationIdEncrypted,
                OrganisationName        = employer.Name
            };

            controller.SearchViewService.LastSearchResults = new SearchViewModel()
            {
                Employers = new PagedResult <Core.Models.EmployerSearchModel>()
                {
                    Results = new List <Core.Models.EmployerSearchModel>()
                    {
                        employer
                    }
                }
            };

            // Act
            var result = controller.AddEmployerJs(employer.OrganisationIdEncrypted, returnUrl) as PartialViewResult;

            // Assert
            Assert.NotNull(result);
            Assert.AreEqual(returnUrl, controller.ViewBag.ReturnUrl);
            Assert.AreEqual("Basket_Button", result.ViewName);
            CompareHelpers.Compare(model, result.Model);
            Assert.AreEqual(controller.CompareViewService.BasketItemCount, 1);
            Assert.IsTrue(controller.CompareViewService.ComparedEmployers.Value.Contains(model.OrganisationIdEncrypted));
            controller.AssertCookieAdded(CookieNames.LastCompareQuery, expectedObfuscatedOrganisationId);
        }
        public IActionResult AddEmployerJs(string employerIdentifier, string returnUrl)
        {
            //Check the parameters are populated
            if (string.IsNullOrWhiteSpace(employerIdentifier))
            {
                return(new HttpBadRequestResult($"Missing {nameof(employerIdentifier)}"));
            }

            if (string.IsNullOrWhiteSpace(returnUrl))
            {
                return(new HttpBadRequestResult($"Missing {nameof(returnUrl)}"));
            }

            //Get the employer from the encrypted identifier
            EmployerSearchModel employer = GetEmployer(employerIdentifier);

            //Add the employer to the compare list
            CompareViewService.AddToBasket(employer.OrganisationIdEncrypted);

            //Save the compared employers to the cookie
            CompareViewService.SaveComparedEmployersToCookie(Request);

            //Setup compare basket
            bool fromSearchResults = returnUrl.Contains("/search-results");
            bool fromEmployer      = returnUrl.StartsWithI("/employer");

            ViewBag.BasketViewModel = new CompareBasketViewModel {
                CanAddEmployers = false,
                CanClearCompare = true,
                CanViewCompare  = fromSearchResults && CompareViewService.BasketItemCount > 1 ||
                                  fromEmployer && CompareViewService.BasketItemCount > 0,
                IsSearchPage   = fromSearchResults,
                IsEmployerPage = fromEmployer
            };

            ViewBag.ReturnUrl = returnUrl;

            var model = new AddRemoveButtonViewModel {
                OrganisationIdEncrypted = employer.OrganisationIdEncrypted, OrganisationName = employer.Name
            };

            return(PartialView("Basket_Button", model));
        }
Example #3
0
        public void CompareController_RemoveEmployerJS_Success_ReturnAddButtons()
        {
            // Arrange
            var    controller         = UiTestHelper.GetController <CompareController>();
            long   organisationId     = 123;
            string employerIdentifier = "abc123";
            string returnUrl          = @"\viewing\search-results";
            var    employer           = new Core.Models.EmployerSearchModel()
            {
                OrganisationIdEncrypted = employerIdentifier,
                OrganisationId          = organisationId.ToString()
            };

            controller.SearchViewService.LastSearchResults = new SearchViewModel()
            {
                Employers = new PagedResult <Core.Models.EmployerSearchModel>()
                {
                    Results = new List <Core.Models.EmployerSearchModel>()
                    {
                        employer
                    }
                }
            };
            controller.CompareViewService.AddToBasket(employer.OrganisationIdEncrypted);
            var model = new AddRemoveButtonViewModel()
            {
                OrganisationIdEncrypted = employer.OrganisationIdEncrypted, OrganisationName = employer.Name
            };

            // Act
            var result = controller.RemoveEmployerJs(employerIdentifier, returnUrl) as PartialViewResult;

            // Assert
            Assert.NotNull(result);
            Assert.AreEqual(returnUrl, controller.ViewBag.ReturnUrl);
            Assert.AreEqual("Basket_Button", result.ViewName);
            CompareHelpers.Compare(model, result.Model);
            Assert.AreEqual(controller.CompareViewService.BasketItemCount, 0);
            Assert.IsFalse(controller.CompareViewService.ComparedEmployers.Value.Contains(employer.OrganisationIdEncrypted));
            controller.AssertCookieDeleted(CookieNames.LastCompareQuery);
        }