Ejemplo n.º 1
0
        public async Task Get_NotApprenticeshipProvider_ReturnsForbidden()
        {
            // Arrange
            var provider = 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(provider.ProviderId, ProviderType.FE);

            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);

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

            // Assert
            Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public async Task Get_MissingClassroomLocations_RendersExpectedOutput()
        {
            // 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.ClassroomBased);
            var mptxInstance = CreateMptxInstance(flowModel);

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

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

            var doc = await response.GetDocument();

            Assert.NotNull(doc.GetElementsByClassName("govuk-error-summary"));
        }
Ejemplo n.º 4
0
        public async Task PostConfirmation_ValidRequestWithVenue_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.ClassroomBased);
            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.Single().ApprenticeshipLocationType == ApprenticeshipLocationType.ClassroomBased &&
                                                                    q.ApprenticeshipLocations.Single().DeliveryModes.Single() == ApprenticeshipDeliveryMode.BlockRelease &&
                                                                    q.ApprenticeshipLocations.Single().Radius == 5 &&
                                                                    q.ApprenticeshipLocations.Single().VenueId == venueId);
        }
Ejemplo n.º 5
0
        public async Task PostConfirmation_ValidRequestWithRegions_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.SetApprenticeshipLocationRegionIds(new[]
            {
                "E06000001", // County Durham
                "E10000009"  // Dorset
            });
            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().DeliveryModes.Single() == ApprenticeshipDeliveryMode.EmployerAddress &&
                                                                    q.ApprenticeshipLocations.Single().National == false &&
                                                                    q.ApprenticeshipLocations.Single().VenueId == null &&
                                                                    q.ApprenticeshipLocations.Single().SubRegionIds.Contains("E06000001") &&
                                                                    q.ApprenticeshipLocations.Single().SubRegionIds.Contains("E10000009"));
        }
Ejemplo n.º 6
0
        public async Task Get_ValidRequest_RendersExpectedOutput()
        {
            // 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);

            // Act
            var response = await HttpClient.GetAsync(
                $"new-apprenticeship-provider/apprenticeship-confirmation?providerId={provider.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.º 7
0
        public async Task Get_StoresPassedStandardInState()
        {
            // Arrange
            var provider = await TestData.CreateProvider(
                apprenticeshipQAStatus : ApprenticeshipQAStatus.NotStarted);

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

            var flowModel = new FlowModel();

            flowModel.SetApprenticeshipStandard(standard);
            var mptxInstance = CreateMptxInstance(flowModel);

            var request = new HttpRequestMessage(
                HttpMethod.Get,
                $"new-apprenticeship-provider/standard-selected?" +
                $"providerId={provider.ProviderId}&" +
                $"ffiid={mptxInstance.InstanceId}&" +
                $"standardCode=123&version=1");

            await User.AsHelpdesk();

            // Act
            var response = await HttpClient.SendAsync(request);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.Found);
            response.Headers.Location.OriginalString.Should().Be(
                $"/new-apprenticeship-provider/apprenticeship-details?ffiid={mptxInstance.InstanceId}&providerId={provider.ProviderId}");

            using (new AssertionScope())
            {
                mptxInstance.State.ApprenticeshipStandard.StandardCode.Should().Be(123);
                mptxInstance.State.ApprenticeshipStandard.Version.Should().Be(1);
            }
        }
Ejemplo n.º 8
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 provider        = await TestData.CreateProvider(apprenticeshipQAStatus : ApprenticeshipQAStatus.NotStarted);

            var user = await TestData.CreateUser(providerId : provider.ProviderId);

            var adminUser = await TestData.CreateUser();

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

            var apprenticeshipId = (await TestData.CreateApprenticeship(provider.ProviderId,
                                                                        standard,
                                                                        createdBy: user,
                                                                        contactEmail: adminUser.Email,
                                                                        contactTelephone: contactTelephone,
                                                                        contactWebsite: contactWebsite,
                                                                        marketingInformation: marketingInfo,
                                                                        locations: new[]
            {
                CreateApprenticeshipLocation.CreateRegionalEmployerBased(regions)
            })).ApprenticeshipId;
            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.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={provider.ProviderId}&ffiid={mptxInstance.InstanceId}",
                requestContent);

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

            SqlQuerySpy.VerifyQuery <UpdateApprenticeship, OneOf <NotFound, 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")));
        }
Ejemplo n.º 9
0
        public async Task PostConfirmation_ValidRequestWithNationalLocations_CreatesApprenticeshipQASubmissionUpdatesQAStatusAndReturnsConfirmation()
        {
            // 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.ContactEmail == "*****@*****.**" &&
                                                                    q.ContactTelephone == "01234 5678902" &&
                                                                    q.ContactWebsite == "http://provider.com" &&
                                                                    q.CreatedBy.UserId == User.UserId &&
                                                                    q.CreatedOn == Clock.UtcNow &&
                                                                    q.MarketingInformation == "My apprenticeship" &&
                                                                    q.ProviderId == provider.ProviderId &&
                                                                    q.Standard.StandardCode == standardCode &&
                                                                    q.Standard.Version == standardVersion &&
                                                                    q.ApprenticeshipWebsite == "http://provider.com/apprenticeship");

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

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

            var doc = await response.GetDocument();

            Assert.Equal(
                "Quality assurance submitted",
                doc.GetElementsByClassName("govuk-panel__title").Single().TextContent.Trim());
        }