public async Task Get_NoPersistedStateRendersExpectedOutput()
        {
            // Arrange
            var provider = await TestData.CreateProvider(apprenticeshipQAStatus : ApprenticeshipQAStatus.NotStarted);

            await User.AsProviderUser(provider.ProviderId, ProviderType.Apprenticeships);

            var flowModel = new FlowModel();

            flowModel.SetApprenticeshipLocationType(ApprenticeshipLocationType.EmployerBased);
            flowModel.SetApprenticeshipIsNational(false);
            var mptxInstance = CreateMptxInstance(flowModel);

            // Act
            var response = await HttpClient.GetAsync(
                $"new-apprenticeship-provider/apprenticeship-employer-locations-regions?providerId={provider.ProviderId}&ffiid={mptxInstance.InstanceId}");

            // Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            var doc = await response.GetDocument();

            var checkboxes = doc.GetElementsByClassName("govuk-checkboxes__input");

            Assert.All(checkboxes, cb => Assert.Null(cb.GetAttribute("checked")));
        }
        public async Task Post_QAStatusNotValidReturnsBadRequest(ApprenticeshipQAStatus qaStatus)
        {
            // Arrange
            var providerId = await TestData.CreateProvider(apprenticeshipQAStatus : qaStatus);

            await User.AsProviderUser(providerId, ProviderType.Apprenticeships);

            var flowModel = new FlowModel();

            flowModel.SetApprenticeshipLocationType(ApprenticeshipLocationType.EmployerBased);
            flowModel.SetApprenticeshipIsNational(false);
            var mptxInstance = CreateMptxInstance(flowModel);

            var subRegion1Id = Region.All.First().SubRegions.First().Id;
            var subRegion2Id = Region.All.Skip(1).First().SubRegions.First().Id;

            var requestContent = new FormUrlEncodedContentBuilder()
                                 .Add("RegionIds", subRegion1Id)
                                 .Add("RegionIds", subRegion2Id)
                                 .ToContent();

            // Act
            var response = await HttpClient.PostAsync(
                $"new-apprenticeship-provider/apprenticeship-employer-locations-regions?providerId={providerId}&ffiid={mptxInstance.InstanceId}",
                requestContent);

            // Assert
            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
        }
        public async Task Get_PersistedStateRendersExpectedOutput()
        {
            // Arrange
            var provider = await TestData.CreateProvider(apprenticeshipQAStatus : ApprenticeshipQAStatus.NotStarted);

            await User.AsProviderUser(provider.ProviderId, ProviderType.Apprenticeships);

            var flowModel = new FlowModel();

            flowModel.SetApprenticeshipLocationType(ApprenticeshipLocationType.EmployerBased);
            flowModel.SetApprenticeshipIsNational(false);
            flowModel.SetApprenticeshipLocationRegionIds(new[] { "E06000001" });  // County Durham
            var mptxInstance = CreateMptxInstance(flowModel);

            // Act
            var response = await HttpClient.GetAsync(
                $"new-apprenticeship-provider/apprenticeship-employer-locations-regions?providerId={provider.ProviderId}&ffiid={mptxInstance.InstanceId}");

            // Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            var doc = await response.GetDocument();

            // SubRegion in state should be selected
            Assert.Equal("checked", doc.GetElementById("RegionIds-E06000001").GetAttribute("checked"));

            // Parent Region should be expanded
            Assert.Contains(
                "govuk-accordion__section--expanded",
                doc.GetElementById("Region-E12000001").ClassList);
        }
        public async Task Post_NoOptionSelectedRendersValidationError()
        {
            // Arrange
            var providerId = await TestData.CreateProvider(apprenticeshipQAStatus : ApprenticeshipQAStatus.NotStarted);

            await User.AsProviderUser(providerId, ProviderType.Apprenticeships);

            var flowModel = new FlowModel();

            flowModel.SetApprenticeshipLocationType(ApprenticeshipLocationType.EmployerBased);
            var mptxInstance = CreateMptxInstance(flowModel);

            var requestContent = new FormUrlEncodedContentBuilder()
                                 .ToContent();

            // Act
            var response = await HttpClient.PostAsync(
                $"new-apprenticeship-provider/apprenticeship-employer-locations?providerId={providerId}&ffiid={mptxInstance.InstanceId}",
                requestContent);

            // Assert
            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);

            var doc = await response.GetDocument();

            doc.AssertHasError("National", "Enter whether you can deliver this training at employers’ locations anywhere in England");
        }
Ejemplo n.º 5
0
        public async Task Get_NotApprenticeshipProvider_ReturnsBadRequest()
        {
            // Arrange
            var providerId = await TestData.CreateProvider(
                apprenticeshipQAStatus : ApprenticeshipQAStatus.NotStarted,
                providerType : ProviderType.FE);

            var standardCode    = 123;
            var standardVersion = 1;
            var standard        = await TestData.CreateStandard(standardCode, standardVersion, standardName : "My standard");

            await User.AsProviderUser(providerId, ProviderType.FE);

            var flowModel = new FlowModel();

            flowModel.SetProviderDetails("Provider 1 rocks");
            flowModel.SetApprenticeshipStandardOrFramework(standard);
            flowModel.SetApprenticeshipDetails(
                marketingInformation: "My apprenticeship",
                website: "http://provider.com/apprenticeship",
                contactTelephone: "01234 5678902",
                contactEmail: "*****@*****.**",
                contactWebsite: "http://provider.com");
            flowModel.SetApprenticeshipLocationType(ApprenticeshipLocationType.EmployerBased);
            flowModel.SetApprenticeshipIsNational(true);
            var mptxInstance = CreateMptxInstance(flowModel);

            // Act
            var response = await HttpClient.GetAsync(
                $"new-apprenticeship-provider/apprenticeship-confirmation?providerId={providerId}&ffiid={mptxInstance.InstanceId}");

            // Assert
            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
        }
Ejemplo n.º 6
0
        public async Task Post_QAStatusNotValid_ReturnsBadRequest(ApprenticeshipQAStatus qaStatus)
        {
            // Arrange
            var provider = await TestData.CreateProvider(apprenticeshipQAStatus : qaStatus);

            var standardCode    = 123;
            var standardVersion = 1;
            var standard        = await TestData.CreateStandard(standardCode, standardVersion, standardName : "My standard");

            await User.AsProviderUser(provider.ProviderId, ProviderType.Apprenticeships);

            var flowModel = new FlowModel();

            flowModel.SetProviderDetails("Provider 1 rocks");
            flowModel.SetApprenticeshipStandard(standard);
            flowModel.SetApprenticeshipDetails(
                marketingInformation: "My apprenticeship",
                website: "http://provider.com/apprenticeship",
                contactTelephone: "01234 5678902",
                contactEmail: "*****@*****.**",
                contactWebsite: "http://provider.com");
            flowModel.SetApprenticeshipLocationType(ApprenticeshipLocationType.EmployerBased);
            flowModel.SetApprenticeshipIsNational(true);
            var mptxInstance = CreateMptxInstance(flowModel);

            var requestContent = new FormUrlEncodedContentBuilder().ToContent();

            // Act
            var response = await HttpClient.PostAsync(
                $"new-apprenticeship-provider/apprenticeship-confirmation?providerId={provider.ProviderId}&ffiid={mptxInstance.InstanceId}",
                requestContent);

            // Assert
            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
        }
        public async Task Post_InvalidRegionIdRendersError()
        {
            // Arrange
            var provider = await TestData.CreateProvider(apprenticeshipQAStatus : ApprenticeshipQAStatus.NotStarted);

            await User.AsProviderUser(provider.ProviderId, ProviderType.Apprenticeships);

            var flowModel = new FlowModel();

            flowModel.SetApprenticeshipLocationType(ApprenticeshipLocationType.EmployerBased);
            flowModel.SetApprenticeshipIsNational(false);
            var mptxInstance = CreateMptxInstance(flowModel);

            var requestContent = new FormUrlEncodedContentBuilder()
                                 .Add("RegionIds", "bad-region-id")
                                 .ToContent();

            // Act
            var response = await HttpClient.PostAsync(
                $"new-apprenticeship-provider/apprenticeship-employer-locations-regions?providerId={provider.ProviderId}&ffiid={mptxInstance.InstanceId}",
                requestContent);

            // Assert
            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);

            var doc = await response.GetDocument();

            var errorSummary = doc.GetElementsByClassName("govuk-error-summary__list").First();

            Assert.Contains(
                errorSummary.GetElementsByTagName("a"),
                e => e.TextContent.Trim() == "Select at least one sub-region");
        }
        public async Task Post_NotApprenticeshipProviderReturnsForbidden()
        {
            // Arrange
            var provider = await TestData.CreateProvider(
                apprenticeshipQAStatus : ApprenticeshipQAStatus.NotStarted,
                providerType : ProviderType.FE);

            await User.AsProviderUser(provider.ProviderId, ProviderType.FE);

            var flowModel = new FlowModel();

            flowModel.SetApprenticeshipLocationType(ApprenticeshipLocationType.EmployerBased);
            flowModel.SetApprenticeshipIsNational(false);
            var mptxInstance = CreateMptxInstance(flowModel);

            var regions = await RegionCache.GetAllRegions();

            var subRegion1Id = regions.First().SubRegions.First().Id;
            var subRegion2Id = regions.Skip(1).First().SubRegions.First().Id;

            var requestContent = new FormUrlEncodedContentBuilder()
                                 .Add("RegionIds", subRegion1Id)
                                 .Add("RegionIds", subRegion2Id)
                                 .ToContent();

            // Act
            var response = await HttpClient.PostAsync(
                $"new-apprenticeship-provider/apprenticeship-employer-locations-regions?providerId={provider.ProviderId}&ffiid={mptxInstance.InstanceId}",
                requestContent);

            // Assert
            Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
        }
Ejemplo n.º 9
0
        public async Task Get_MissingClassroomLocations_RendersExpectedOutput()
        {
            // Arrange
            var providerId = await TestData.CreateProvider(apprenticeshipQAStatus : ApprenticeshipQAStatus.NotStarted);

            var standardCode    = 123;
            var standardVersion = 1;
            var standard        = await TestData.CreateStandard(standardCode, standardVersion, standardName : "My standard");

            await User.AsProviderUser(providerId, ProviderType.Apprenticeships);

            var flowModel = new FlowModel();

            flowModel.SetProviderDetails("Provider 1 rocks");
            flowModel.SetApprenticeshipStandardOrFramework(standard);
            flowModel.SetApprenticeshipDetails(
                marketingInformation: "My apprenticeship",
                website: "http://provider.com/apprenticeship",
                contactTelephone: "01234 5678902",
                contactEmail: "*****@*****.**",
                contactWebsite: "http://provider.com");
            flowModel.SetApprenticeshipLocationType(ApprenticeshipLocationType.ClassroomBased);
            var mptxInstance = CreateMptxInstance(flowModel);

            // Act
            var response = await HttpClient.GetAsync(
                $"new-apprenticeship-provider/apprenticeship-confirmation?providerId={providerId}&ffiid={mptxInstance.InstanceId}");

            // Assert
            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);

            var doc = await response.GetDocument();

            Assert.NotNull(doc.GetElementsByClassName("govuk-error-summary"));
        }
        public async Task Post_RegionIdSpecifiedStoresExpandedSubRegionsInState()
        {
            // Arrange
            var provider = await TestData.CreateProvider(apprenticeshipQAStatus : ApprenticeshipQAStatus.NotStarted);

            await User.AsProviderUser(provider.ProviderId, ProviderType.Apprenticeships);

            var flowModel = new FlowModel();

            flowModel.SetApprenticeshipLocationType(ApprenticeshipLocationType.EmployerBased);
            flowModel.SetApprenticeshipIsNational(false);
            var mptxInstance = CreateMptxInstance(flowModel);

            var requestContent = new FormUrlEncodedContentBuilder()
                                 .Add("RegionIds", "E12000001")
                                 .ToContent();

            // Act
            var response = await HttpClient.PostAsync(
                $"new-apprenticeship-provider/apprenticeship-employer-locations-regions?providerId={provider.ProviderId}&ffiid={mptxInstance.InstanceId}",
                requestContent);

            // Assert
            var regions = await RegionCache.GetAllRegions();

            var region = regions.Single(r => r.Id == "E12000001");
            var state  = GetMptxInstance <FlowModel>(mptxInstance.InstanceId).State;

            Assert.All(region.SubRegions, sr => state.ApprenticeshipLocationSubRegionIds.Contains(sr.Id));
        }
        public async Task Post_ValidRequestNotNationalUpdatesFlowStateAndRedirects(
            ApprenticeshipLocationType locationType)
        {
            // Arrange
            var providerId = await TestData.CreateProvider(apprenticeshipQAStatus : ApprenticeshipQAStatus.NotStarted);

            await User.AsProviderUser(providerId, ProviderType.Apprenticeships);

            var flowModel = new FlowModel();

            flowModel.SetApprenticeshipLocationType(locationType);
            var mptxInstance = CreateMptxInstance(flowModel);

            var requestContent = new FormUrlEncodedContentBuilder()
                                 .Add("National", false)
                                 .ToContent();

            // Act
            var response = await HttpClient.PostAsync(
                $"new-apprenticeship-provider/apprenticeship-employer-locations?providerId={providerId}&ffiid={mptxInstance.InstanceId}",
                requestContent);

            // Assert
            var state = GetMptxInstance <FlowModel>(mptxInstance.InstanceId).State;

            Assert.False(state.ApprenticeshipIsNational);

            Assert.Equal(HttpStatusCode.Found, response.StatusCode);
            Assert.Equal(
                "/new-apprenticeship-provider/apprenticeship-employer-locations-regions",
                UrlHelper.StripQueryParams(response.Headers.Location.OriginalString));
        }
        public async Task Post_NotApprenticeshipProviderReturnsBadRequest()
        {
            // Arrange
            var providerId = await TestData.CreateProvider(
                apprenticeshipQAStatus : ApprenticeshipQAStatus.NotStarted,
                providerType : ProviderType.FE);

            await User.AsProviderUser(providerId, ProviderType.FE);

            var flowModel = new FlowModel();

            flowModel.SetApprenticeshipLocationType(ApprenticeshipLocationType.EmployerBased);
            var mptxInstance = CreateMptxInstance(flowModel);

            var requestContent = new FormUrlEncodedContentBuilder()
                                 .Add("National", bool.TrueString)
                                 .ToContent();

            // Act
            var response = await HttpClient.PostAsync(
                $"new-apprenticeship-provider/apprenticeship-employer-locations?providerId={providerId}&ffiid={mptxInstance.InstanceId}",
                requestContent);

            // Assert
            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
        }
Ejemplo n.º 13
0
        public async Task PostConfirmation_ValidRequestWithVenue_CreatesValidApprenticeship()
        {
            // Arrange
            var providerId = await TestData.CreateProvider(apprenticeshipQAStatus : ApprenticeshipQAStatus.NotStarted);

            var standardCode    = 123;
            var standardVersion = 1;
            var standard        = await TestData.CreateStandard(standardCode, standardVersion, standardName : "My standard");

            var venueId = await TestData.CreateVenue(providerId);

            await User.AsProviderUser(providerId, ProviderType.Apprenticeships);

            var flowModel = new FlowModel();

            flowModel.SetProviderDetails("Provider 1 rocks");
            flowModel.SetApprenticeshipStandardOrFramework(standard);
            flowModel.SetApprenticeshipDetails(
                marketingInformation: "My apprenticeship",
                website: "http://provider.com/apprenticeship",
                contactTelephone: "01234 5678902",
                contactEmail: "*****@*****.**",
                contactWebsite: "http://provider.com");
            flowModel.SetApprenticeshipLocationType(ApprenticeshipLocationType.ClassroomBased);
            flowModel.SetClassroomLocationForVenue(
                venueId,
                originalVenueId: null,
                radius: 5,
                deliveryModes: new[] { ApprenticeshipDeliveryMode.BlockRelease });
            var mptxInstance = CreateMptxInstance(flowModel);

            Guid apprenticeshipId = default;

            CosmosDbQueryDispatcher.Callback <CreateApprenticeship, Success>(q => apprenticeshipId = q.Id);

            var requestContent = new FormUrlEncodedContentBuilder().ToContent();

            // Act
            var response = await HttpClient.PostAsync(
                $"new-apprenticeship-provider/apprenticeship-confirmation?providerId={providerId}&ffiid={mptxInstance.InstanceId}",
                requestContent);

            // Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            CosmosDbQueryDispatcher.Verify(mock => mock.ExecuteQuery(It.Is <CreateApprenticeship>(q =>
                                                                                                  q.ApprenticeshipLocations.Single().ApprenticeshipLocationType == ApprenticeshipLocationType.ClassroomBased &&
                                                                                                  q.ApprenticeshipLocations.Single().DeliveryModes.Single() == ApprenticeshipDeliveryMode.BlockRelease &&
                                                                                                  q.ApprenticeshipLocations.Single().Radius == 5 &&
                                                                                                  q.ApprenticeshipLocations.Single().VenueId == venueId)));
        }
Ejemplo n.º 14
0
        public async Task PostConfirmation_ValidRequestWithRegions_CreatesValidApprenticeship()
        {
            // Arrange
            var providerId = await TestData.CreateProvider(apprenticeshipQAStatus : ApprenticeshipQAStatus.NotStarted);

            var standardCode    = 123;
            var standardVersion = 1;
            var standard        = await TestData.CreateStandard(standardCode, standardVersion, standardName : "My standard");

            await User.AsProviderUser(providerId, ProviderType.Apprenticeships);

            var flowModel = new FlowModel();

            flowModel.SetProviderDetails("Provider 1 rocks");
            flowModel.SetApprenticeshipStandardOrFramework(standard);
            flowModel.SetApprenticeshipDetails(
                marketingInformation: "My apprenticeship",
                website: "http://provider.com/apprenticeship",
                contactTelephone: "01234 5678902",
                contactEmail: "*****@*****.**",
                contactWebsite: "http://provider.com");
            flowModel.SetApprenticeshipLocationType(ApprenticeshipLocationType.EmployerBased);
            flowModel.SetApprenticeshipLocationRegionIds(new[]
            {
                "E06000001", // County Durham
                "E10000009"  // Dorset
            });
            var mptxInstance = CreateMptxInstance(flowModel);

            Guid apprenticeshipId = default;

            CosmosDbQueryDispatcher.Callback <CreateApprenticeship, Success>(q => apprenticeshipId = q.Id);

            var requestContent = new FormUrlEncodedContentBuilder().ToContent();

            // Act
            var response = await HttpClient.PostAsync(
                $"new-apprenticeship-provider/apprenticeship-confirmation?providerId={providerId}&ffiid={mptxInstance.InstanceId}",
                requestContent);

            // Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            CosmosDbQueryDispatcher.Verify(mock => mock.ExecuteQuery(It.Is <CreateApprenticeship>(q =>
                                                                                                  q.ApprenticeshipLocations.Single().ApprenticeshipLocationType == ApprenticeshipLocationType.EmployerBased &&
                                                                                                  q.ApprenticeshipLocations.Single().DeliveryModes.Single() == ApprenticeshipDeliveryMode.EmployerAddress &&
                                                                                                  q.ApprenticeshipLocations.Single().National == false &&
                                                                                                  q.ApprenticeshipLocations.Single().VenueId == null &&
                                                                                                  q.ApprenticeshipLocations.Single().Regions.Contains("E06000001") &&
                                                                                                  q.ApprenticeshipLocations.Single().Regions.Contains("E10000009"))));
        }
        public async Task Post_ValidRequestUpdatesStateAndRedirects(
            ApprenticeshipLocationType locationType,
            bool gotClassroomLocation,
            string expectedRedirectLocation)
        {
            // Arrange
            var provider = await TestData.CreateProvider(apprenticeshipQAStatus : ApprenticeshipQAStatus.NotStarted);

            await User.AsProviderUser(provider.ProviderId, ProviderType.Apprenticeships);

            var flowModel = new FlowModel();

            flowModel.SetApprenticeshipLocationType(locationType);
            flowModel.SetApprenticeshipIsNational(false);
            var mptxInstance = CreateMptxInstance(flowModel);

            if (gotClassroomLocation)
            {
                var venueId = (await TestData.CreateVenue(provider.ProviderId)).Id;

                mptxInstance.Update(s => s.SetClassroomLocationForVenue(
                                        venueId,
                                        originalVenueId: null,
                                        radius: 5,
                                        new[] { ApprenticeshipDeliveryMode.BlockRelease }));
            }

            var subRegion1Id = "E06000001";  // County Durham
            var subRegion2Id = "E06000009";  // Blackpool

            var requestContent = new FormUrlEncodedContentBuilder()
                                 .Add("RegionIds", subRegion1Id)
                                 .Add("RegionIds", subRegion2Id)
                                 .ToContent();

            // Act
            var response = await HttpClient.PostAsync(
                $"new-apprenticeship-provider/apprenticeship-employer-locations-regions?providerId={provider.ProviderId}&ffiid={mptxInstance.InstanceId}",
                requestContent);

            // Assert
            var state = GetMptxInstance <FlowModel>(mptxInstance.InstanceId).State;

            Assert.False(state.ApprenticeshipIsNational);

            Assert.Equal(HttpStatusCode.Found, response.StatusCode);
            Assert.Equal(
                expectedRedirectLocation,
                UrlHelper.StripQueryParams(response.Headers.Location.OriginalString));
        }
Ejemplo n.º 16
0
        public async Task PostConfirmation_ValidRequestWithNationalLocations_CreatesValidApprenticeship()
        {
            // Arrange
            var provider = await TestData.CreateProvider(apprenticeshipQAStatus : ApprenticeshipQAStatus.NotStarted);

            var standardCode    = 123;
            var standardVersion = 1;
            var standard        = await TestData.CreateStandard(standardCode, standardVersion, standardName : "My standard");

            await User.AsProviderUser(provider.ProviderId, ProviderType.Apprenticeships);

            var flowModel = new FlowModel();

            flowModel.SetProviderDetails("Provider 1 rocks");
            flowModel.SetApprenticeshipStandard(standard);
            flowModel.SetApprenticeshipDetails(
                marketingInformation: "My apprenticeship",
                website: "http://provider.com/apprenticeship",
                contactTelephone: "01234 5678902",
                contactEmail: "*****@*****.**",
                contactWebsite: "http://provider.com");
            flowModel.SetApprenticeshipLocationType(ApprenticeshipLocationType.EmployerBased);
            flowModel.SetApprenticeshipIsNational(true);
            var mptxInstance = CreateMptxInstance(flowModel);

            Guid apprenticeshipId = default;

            SqlQuerySpy.Callback <CreateApprenticeship, Success>(q => apprenticeshipId = q.ApprenticeshipId);

            var requestContent = new FormUrlEncodedContentBuilder().ToContent();

            // Act
            var response = await HttpClient.PostAsync(
                $"new-apprenticeship-provider/apprenticeship-confirmation?providerId={provider.ProviderId}&ffiid={mptxInstance.InstanceId}",
                requestContent);

            // Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            SqlQuerySpy.VerifyQuery <CreateApprenticeship, Success>(q =>
                                                                    q.ApprenticeshipLocations.Single().ApprenticeshipLocationType == ApprenticeshipLocationType.EmployerBased &&
                                                                    q.ApprenticeshipLocations.Single().National == true &&
                                                                    q.ApprenticeshipLocations.Single().VenueId == null);
        }
        public async Task Get_HelpdeskUserCannotAccess()
        {
            // Arrange
            var providerId = await TestData.CreateProvider(apprenticeshipQAStatus : ApprenticeshipQAStatus.NotStarted);

            await User.AsHelpdesk();

            var flowModel = new FlowModel();

            flowModel.SetApprenticeshipLocationType(ApprenticeshipLocationType.EmployerBased);
            var mptxInstance = CreateMptxInstance(flowModel);

            // Act
            var response = await HttpClient.GetAsync(
                $"new-apprenticeship-provider/apprenticeship-employer-locations?providerId={providerId}&ffiid={mptxInstance.InstanceId}");

            // Assert
            Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
        }
        public async Task Get_QAStatusNotValidReturnsBadRequest(ApprenticeshipQAStatus qaStatus)
        {
            // Arrange
            var providerId = await TestData.CreateProvider(apprenticeshipQAStatus : qaStatus);

            await User.AsProviderUser(providerId, ProviderType.Apprenticeships);

            var flowModel = new FlowModel();

            flowModel.SetApprenticeshipLocationType(ApprenticeshipLocationType.EmployerBased);
            var mptxInstance = CreateMptxInstance(flowModel);

            // Act
            var response = await HttpClient.GetAsync(
                $"new-apprenticeship-provider/apprenticeship-employer-locations?providerId={providerId}&ffiid={mptxInstance.InstanceId}");

            // Assert
            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
        }
        public async Task Post_MissingClassroomLocations_RendersErrorMessage()
        {
            // Arrange
            var provider = await TestData.CreateProvider(apprenticeshipQAStatus : ApprenticeshipQAStatus.NotStarted);

            var standardCode    = 123;
            var standardVersion = 1;
            var standard        = await TestData.CreateStandard(standardCode, standardVersion, standardName : "My standard");

            await User.AsProviderUser(provider.ProviderId, ProviderType.Apprenticeships);

            var flowModel = new FlowModel();

            flowModel.SetProviderDetails("Provider 1 rocks");
            flowModel.SetApprenticeshipStandardOrFramework(standard);
            flowModel.SetApprenticeshipDetails(
                marketingInformation: "My apprenticeship",
                website: "http://provider.com/apprenticeship",
                contactTelephone: "01234 5678902",
                contactEmail: "*****@*****.**",
                contactWebsite: "http://provider.com");
            flowModel.SetApprenticeshipLocationType(ApprenticeshipLocationType.ClassroomBased);
            var mptxInstance = CreateMptxInstance(flowModel);

            Guid apprenticeshipId = default;

            CosmosDbQueryDispatcher.Callback <CreateApprenticeship, Success>(q => apprenticeshipId = q.Id);

            var requestContent = new FormUrlEncodedContentBuilder().ToContent();

            // Act
            var response = await HttpClient.PostAsync(
                $"new-apprenticeship-provider/apprenticeship-confirmation?providerId={provider.ProviderId}&ffiid={mptxInstance.InstanceId}",
                requestContent);

            // Assert
            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);

            var doc = await response.GetDocument();

            Assert.NotNull(doc.GetElementsByClassName("govuk-error-summary"));
        }
        public async Task Get_NotApprenticeshipProviderReturnsForbidden()
        {
            // Arrange
            var provider = await TestData.CreateProvider(
                apprenticeshipQAStatus : ApprenticeshipQAStatus.NotStarted,
                providerType : ProviderType.FE);

            await User.AsProviderUser(provider.ProviderId, ProviderType.FE);

            var flowModel = new FlowModel();

            flowModel.SetApprenticeshipLocationType(ApprenticeshipLocationType.EmployerBased);
            flowModel.SetApprenticeshipIsNational(false);
            var mptxInstance = CreateMptxInstance(flowModel);

            // Act
            var response = await HttpClient.GetAsync(
                $"new-apprenticeship-provider/apprenticeship-employer-locations-regions?providerId={provider.ProviderId}&ffiid={mptxInstance.InstanceId}");

            // Assert
            Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
        }
Ejemplo n.º 21
0
        public async Task Get_ValidRequest_RendersExpectedOutput()
        {
            // Arrange
            var providerId = await TestData.CreateProvider(apprenticeshipQAStatus : ApprenticeshipQAStatus.NotStarted);

            var standardCode    = 123;
            var standardVersion = 1;
            var standard        = await TestData.CreateStandard(standardCode, standardVersion, standardName : "My standard");

            await User.AsProviderUser(providerId, ProviderType.Apprenticeships);

            var flowModel = new FlowModel();

            flowModel.SetProviderDetails("Provider 1 rocks");
            flowModel.SetApprenticeshipStandardOrFramework(standard);
            flowModel.SetApprenticeshipDetails(
                marketingInformation: "My apprenticeship",
                website: "http://provider.com/apprenticeship",
                contactTelephone: "01234 5678902",
                contactEmail: "*****@*****.**",
                contactWebsite: "http://provider.com");
            flowModel.SetApprenticeshipLocationType(ApprenticeshipLocationType.EmployerBased);
            flowModel.SetApprenticeshipIsNational(true);
            var mptxInstance = CreateMptxInstance(flowModel);

            // Act
            var response = await HttpClient.GetAsync(
                $"new-apprenticeship-provider/apprenticeship-confirmation?providerId={providerId}&ffiid={mptxInstance.InstanceId}");

            // Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            var doc = await response.GetDocument();

            Assert.Equal("http://provider.com/apprenticeship", doc.GetSummaryListValueWithKey("Apprenticeship website"));
            Assert.Equal("*****@*****.**", doc.GetSummaryListValueWithKey("Email"));
            Assert.Equal("01234 5678902", doc.GetSummaryListValueWithKey("Telephone"));
            Assert.Equal("http://provider.com", doc.GetSummaryListValueWithKey("Contact URL"));
        }
Ejemplo n.º 22
0
        public async Task PostConfirmation_ValidRequestWithNationalLocations_CreatesApprenticeshipQASubmissionUpdatesQAStatusAndReturnsConfirmation()
        {
            // Arrange
            var providerId = await TestData.CreateProvider(apprenticeshipQAStatus : ApprenticeshipQAStatus.NotStarted);

            var standardCode    = 123;
            var standardVersion = 1;
            var standard        = await TestData.CreateStandard(standardCode, standardVersion, standardName : "My standard");

            await User.AsProviderUser(providerId, ProviderType.Apprenticeships);

            var flowModel = new FlowModel();

            flowModel.SetProviderDetails("Provider 1 rocks");
            flowModel.SetApprenticeshipStandardOrFramework(standard);
            flowModel.SetApprenticeshipDetails(
                marketingInformation: "My apprenticeship",
                website: "http://provider.com/apprenticeship",
                contactTelephone: "01234 5678902",
                contactEmail: "*****@*****.**",
                contactWebsite: "http://provider.com");
            flowModel.SetApprenticeshipLocationType(ApprenticeshipLocationType.EmployerBased);
            flowModel.SetApprenticeshipIsNational(true);
            var mptxInstance = CreateMptxInstance(flowModel);

            Guid apprenticeshipId = default;

            CosmosDbQueryDispatcher.Callback <CreateApprenticeship, Success>(q => apprenticeshipId = q.Id);

            var requestContent = new FormUrlEncodedContentBuilder().ToContent();

            // Act
            var response = await HttpClient.PostAsync(
                $"new-apprenticeship-provider/apprenticeship-confirmation?providerId={providerId}&ffiid={mptxInstance.InstanceId}",
                requestContent);

            // Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            CosmosDbQueryDispatcher.Verify(mock => mock.ExecuteQuery(It.Is <CreateApprenticeship>(q =>
                                                                                                  q.ApprenticeshipTitle == "My standard" &&
                                                                                                  q.ApprenticeshipType == ApprenticeshipType.StandardCode &&
                                                                                                  q.ContactEmail == "*****@*****.**" &&
                                                                                                  q.ContactTelephone == "01234 5678902" &&
                                                                                                  q.ContactWebsite == "http://provider.com" &&
                                                                                                  q.CreatedByUser.UserId == User.UserId &&
                                                                                                  q.CreatedDate == Clock.UtcNow &&
                                                                                                  q.MarketingInformation == "My apprenticeship" &&
                                                                                                  q.ProviderId == providerId &&
                                                                                                  q.StandardOrFramework.Standard.StandardCode == standardCode &&
                                                                                                  q.StandardOrFramework.Standard.Version == standardVersion &&
                                                                                                  q.Url == "http://provider.com/apprenticeship" &&
                                                                                                  q.Status == 2)));

            SqlQuerySpy.VerifyQuery <CreateApprenticeshipQASubmission, int>(q =>
                                                                            q.Apprenticeships.Single().ApprenticeshipId == apprenticeshipId &&
                                                                            q.Apprenticeships.Single().ApprenticeshipMarketingInformation == "My apprenticeship" &&
                                                                            q.Apprenticeships.Single().ApprenticeshipTitle == "My standard" &&
                                                                            q.ProviderId == providerId &&
                                                                            q.ProviderMarketingInformation == "Provider 1 rocks" &&
                                                                            q.SubmittedByUserId == User.UserId &&
                                                                            q.SubmittedOn == Clock.UtcNow);

            SqlQuerySpy.VerifyQuery <SetProviderApprenticeshipQAStatus, None>(q =>
                                                                              q.ProviderId == providerId && q.ApprenticeshipQAStatus == ApprenticeshipQAStatus.Submitted);

            var doc = await response.GetDocument();

            Assert.Equal(
                "Quality assurance submitted",
                doc.GetElementsByClassName("govuk-panel__title").Single().TextContent.Trim());
        }
Ejemplo n.º 23
0
        public async Task PostConfirmation_ValidRequestWithExistingApprenticeshipRegionsAndVenue_UpdatesApprenticeship()
        {
            // Arrange
            var ukprn            = 12347;
            var providerUserId   = $"{ukprn}-user";
            var adminUserId      = $"admin-user";
            var contactTelephone = "1111 111 1111";
            var contactWebsite   = "https://somerandomprovider.com";
            var marketingInfo    = "Providing Online training";
            var regions          = new List <string> {
                "123"
            };
            var standardCode    = 123;
            var standardVersion = 1;
            var providerId      = await TestData.CreateProvider(apprenticeshipQAStatus : ApprenticeshipQAStatus.NotStarted);

            var user = await TestData.CreateUser(providerUserId, "*****@*****.**", "Provider 1", "Person", providerId);

            var adminUser = await TestData.CreateUser(adminUserId, "*****@*****.**", "admin", "admin", null);

            var standard = await TestData.CreateStandard(standardCode, standardVersion, standardName : "My standard");

            var apprenticeshipId = await TestData.CreateApprenticeship(providerId,
                                                                       standard,
                                                                       createdBy : user,
                                                                       contactEmail : adminUser.Email,
                                                                       contactTelephone : contactTelephone,
                                                                       contactWebsite : contactWebsite,
                                                                       marketingInformation : marketingInfo,
                                                                       locations : new[]
            {
                CreateApprenticeshipLocation.CreateRegions(regions)
            });

            var venueId = await TestData.CreateVenue(providerId);

            await User.AsProviderUser(providerId, ProviderType.Apprenticeships);

            var flowModel = new FlowModel();

            flowModel.SetProviderDetails("Provider 1 rocks");
            flowModel.SetApprenticeshipStandardOrFramework(standard);
            flowModel.SetApprenticeshipDetails(
                marketingInformation: "My apprenticeship",
                website: "http://provider.com/apprenticeship",
                contactTelephone: "01234 5678902",
                contactEmail: "*****@*****.**",
                contactWebsite: "http://provider.com");
            flowModel.SetApprenticeshipLocationType(ApprenticeshipLocationType.ClassroomBasedAndEmployerBased);
            flowModel.SetApprenticeshipLocationRegionIds(new[]
            {
                "E06000001", // County Durham
                "E10000009"  // Dorset
            });
            flowModel.SetApprenticeshipId(apprenticeshipId);
            flowModel.SetClassroomLocationForVenue(
                venueId,
                originalVenueId: null,
                radius: 5,
                deliveryModes: new[] { ApprenticeshipDeliveryMode.BlockRelease });
            var mptxInstance = CreateMptxInstance(flowModel);

            var requestContent = new FormUrlEncodedContentBuilder().ToContent();

            // Act
            var response = await HttpClient.PostAsync(
                $"new-apprenticeship-provider/apprenticeship-confirmation?providerId={providerId}&ffiid={mptxInstance.InstanceId}",
                requestContent);

            // Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            CosmosDbQueryDispatcher.Verify(mock => mock.ExecuteQuery(It.Is <UpdateApprenticeship>(q =>
                                                                                                  q.ApprenticeshipLocations.Any(l =>
                                                                                                                                l.ApprenticeshipLocationType == ApprenticeshipLocationType.ClassroomBased &&
                                                                                                                                l.DeliveryModes.Single() == ApprenticeshipDeliveryMode.BlockRelease &&
                                                                                                                                l.Radius == 5 &&
                                                                                                                                l.VenueId == venueId) &&
                                                                                                  q.ApprenticeshipLocations.Any(l =>
                                                                                                                                l.ApprenticeshipLocationType == ApprenticeshipLocationType.EmployerBased &&
                                                                                                                                l.DeliveryModes.Single() == ApprenticeshipDeliveryMode.EmployerAddress &&
                                                                                                                                l.National == false &&
                                                                                                                                l.VenueId == null &&
                                                                                                                                l.Regions.Contains("E06000001") &&
                                                                                                                                l.Regions.Contains("E10000009")))));
        }
Ejemplo n.º 24
0
        public async Task PostConfirmation_ValidRequestWithRegionsAndVenue_CreatesValidApprenticeship()
        {
            // Arrange
            var provider = await TestData.CreateProvider(apprenticeshipQAStatus : ApprenticeshipQAStatus.NotStarted);

            var standardCode    = 123;
            var standardVersion = 1;
            var standard        = await TestData.CreateStandard(standardCode, standardVersion, standardName : "My standard");

            var venueId = (await TestData.CreateVenue(provider.ProviderId, createdBy: User.ToUserInfo())).VenueId;

            await User.AsProviderUser(provider.ProviderId, ProviderType.Apprenticeships);

            var flowModel = new FlowModel();

            flowModel.SetProviderDetails("Provider 1 rocks");
            flowModel.SetApprenticeshipStandard(standard);
            flowModel.SetApprenticeshipDetails(
                marketingInformation: "My apprenticeship",
                website: "http://provider.com/apprenticeship",
                contactTelephone: "01234 5678902",
                contactEmail: "*****@*****.**",
                contactWebsite: "http://provider.com");
            flowModel.SetApprenticeshipLocationType(ApprenticeshipLocationType.ClassroomBasedAndEmployerBased);
            flowModel.SetApprenticeshipLocationRegionIds(new[]
            {
                "E06000001", // County Durham
                "E10000009"  // Dorset
            });
            flowModel.SetClassroomLocationForVenue(
                venueId,
                originalVenueId: null,
                radius: 5,
                deliveryModes: new[] { ApprenticeshipDeliveryMode.BlockRelease });
            var mptxInstance = CreateMptxInstance(flowModel);

            Guid apprenticeshipId = default;

            SqlQuerySpy.Callback <CreateApprenticeship, Success>(q => apprenticeshipId = q.ApprenticeshipId);

            var requestContent = new FormUrlEncodedContentBuilder().ToContent();

            // Act
            var response = await HttpClient.PostAsync(
                $"new-apprenticeship-provider/apprenticeship-confirmation?providerId={provider.ProviderId}&ffiid={mptxInstance.InstanceId}",
                requestContent);

            // Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            SqlQuerySpy.VerifyQuery <CreateApprenticeship, Success>(q =>
                                                                    q.ApprenticeshipLocations.Any(l =>
                                                                                                  l.ApprenticeshipLocationType == ApprenticeshipLocationType.ClassroomBased &&
                                                                                                  l.DeliveryModes.Single() == ApprenticeshipDeliveryMode.BlockRelease &&
                                                                                                  l.Radius == 5 &&
                                                                                                  l.VenueId == venueId) &&
                                                                    q.ApprenticeshipLocations.Any(l =>
                                                                                                  l.ApprenticeshipLocationType == ApprenticeshipLocationType.EmployerBased &&
                                                                                                  l.DeliveryModes.Single() == ApprenticeshipDeliveryMode.EmployerAddress &&
                                                                                                  l.National == false &&
                                                                                                  l.VenueId == null &&
                                                                                                  l.SubRegionIds.Contains("E06000001") &&
                                                                                                  l.SubRegionIds.Contains("E10000009")));
        }