Example #1
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")));
        }
Example #2
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());
        }