Exemplo n.º 1
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"));
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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)));
        }
Exemplo n.º 4
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_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"));
        }
Exemplo n.º 6
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"));
        }
Exemplo n.º 7
0
        public async Task Get_StoresPassedStandardInState()
        {
            // Arrange
            var providerId = await TestData.CreateProvider(
                apprenticeshipQAStatus : ApprenticeshipQAStatus.NotStarted);

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

            var flowModel = new FlowModel();

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

            var request = new HttpRequestMessage(
                HttpMethod.Get,
                $"new-apprenticeship-provider/standard-selected?" +
                $"providerId={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={providerId}");

            using (new AssertionScope())
            {
                mptxInstance.State.ApprenticeshipStandardOrFramework.Standard.StandardCode.Should().Be(123);
                mptxInstance.State.ApprenticeshipStandardOrFramework.Standard.Version.Should().Be(1);
            }
        }
Exemplo 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 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")))));
        }
Exemplo n.º 9
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());
        }