Skip to content

Commit

Permalink
Merge pull request #33 from hmcts/feature/VIH-4559-get-conferences-fo…
Browse files Browse the repository at this point in the history
…r-admins

expose an endpoint to get all conferences for today
  • Loading branch information
shaed-parkar authored Jun 3, 2019
2 parents 806805c + c2b5101 commit 027da23
Show file tree
Hide file tree
Showing 16 changed files with 329 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public static void ForConference(ConferenceSummaryResponse conference)
conference.ScheduledDuration.Should().BeGreaterThan(0);
conference.ScheduledDateTime.Should().NotBe(DateTime.MinValue);
conference.Id.Should().NotBeEmpty();
conference.PendingTasks.Should().BeGreaterThan(0);
}
}
}
3 changes: 2 additions & 1 deletion VideoAPI/Testing.Common/Helper/ApiUriFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public class ConferenceEndpoints
{
private string ApiRoot => "conferences";
public string BookNewConference => $"{ApiRoot}";
public string GetConferenceDetailsByUsername(string username) => $"{ApiRoot}/?username={username}";
public string GetConferenceDetailsByUsername(string username) => $"{ApiRoot}/?username={username}";
public string GetConferencesToday => $"{ApiRoot}/today";
public string GetConferenceDetailsById(Guid conferenceId) => $"{ApiRoot}/{conferenceId}";
public string GetConferenceByHearingRefId(Guid hearingRefId) => $"{ApiRoot}/hearings/{hearingRefId}";
public string RemoveConference(Guid conferenceId) => $"{ApiRoot}/{conferenceId}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ConferenceBuilder
private readonly Conference _conference;
private readonly BuilderSettings _builderSettings;

public ConferenceBuilder(bool ignoreId = false, Guid? knownHearingRefId = null)
public ConferenceBuilder(bool ignoreId = false, Guid? knownHearingRefId = null, DateTime? scheduledDateTime = null)
{
_builderSettings = new BuilderSettings();
if (ignoreId)
Expand All @@ -25,7 +25,8 @@ public ConferenceBuilder(bool ignoreId = false, Guid? knownHearingRefId = null)
}

var hearingRefId = knownHearingRefId ?? Guid.NewGuid();
var scheduleDateTime = DateTime.Today.AddDays(1).AddHours(10).AddMinutes(30);

var scheduleDateTime = scheduledDateTime ?? DateTime.Today.AddDays(1).AddHours(10).AddMinutes(30);
const string caseType = "Civil Money Claims";
var caseNumber = $"Test{Guid.NewGuid():N}";
const string caseName = "Auto vs Manual";
Expand Down Expand Up @@ -68,29 +69,35 @@ public ConferenceBuilder WithParticipant(UserRole userRole, string caseTypeGroup
return this;
}

public ConferenceBuilder WithJudgeTask(string body, TaskType type)
public ConferenceBuilder WithJudgeTask(string body)
{
var judge = _conference.GetParticipants().First(x => x.UserRole == UserRole.Judge);
judge.Should().NotBeNull("Conference does not have a judge");

_conference.AddTask(judge.Id, type, body);
_conference.AddTask(judge.Id, TaskType.Judge, body);
return this;
}

public ConferenceBuilder WithParticipantTask(string body, TaskType type)
public ConferenceBuilder WithParticipantTask(string body)
{
var individual = _conference.GetParticipants().First(x =>
x.UserRole == UserRole.Individual || x.UserRole == UserRole.Representative);
individual.Should().NotBeNull("Conference does not have an individual");
_conference.AddTask(individual.Id, type, body);
_conference.AddTask(individual.Id, TaskType.Participant, body);
return this;
}



public ConferenceBuilder WithHearingTask(string body, TaskType type)
public ConferenceBuilder WithHearingTask(string body)
{
_conference.AddTask(_conference.Id, TaskType.Hearing, body);
return this;
}

public ConferenceBuilder WithTask(string body, TaskType taskType)
{
_conference.AddTask(_conference.Id, type, body);
_conference.AddTask(_conference.Id, taskType, body);
return this;
}

Expand Down
13 changes: 13 additions & 0 deletions VideoAPI/Video.API/Controllers/ConferenceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,19 @@ public async Task<IActionResult> RemoveConference(Guid conferenceId)
return NoContent();
}

[HttpGet("today")]
[SwaggerOperation(OperationId = "GetConferencesToday")]
[ProducesResponseType(typeof(List<ConferenceSummaryResponse>), (int) HttpStatusCode.OK)]
public async Task<IActionResult> GetConferencesToday()
{
var query = new GetConferencesTodayQuery();
var conferences = await _queryHandler.Handle<GetConferencesTodayQuery, List<Conference>>(query);

var mapper = new ConferenceToSummaryResponseMapper();
var response = conferences.Select(mapper.MapConferenceToSummaryResponse);
return Ok(response);
}

/// <summary>
/// Get non-closed conferences for a participant by their username
/// </summary>
Expand Down
37 changes: 37 additions & 0 deletions VideoAPI/VideoApi.DAL/Queries/GetConferencesTodayQuery.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using VideoApi.DAL.Queries.Core;
using VideoApi.Domain;

namespace VideoApi.DAL.Queries
{
public class GetConferencesTodayQuery : IQuery
{
}

public class GetConferencesTodayQueryHandler : IQueryHandler<GetConferencesTodayQuery, List<Conference>>
{
private readonly VideoApiDbContext _context;

public GetConferencesTodayQueryHandler(VideoApiDbContext context)
{
_context = context;
}

public async Task<List<Conference>> Handle(GetConferencesTodayQuery query)
{
var today = DateTime.Today;
var tomorrow = DateTime.Today.AddDays(1);
return await _context.Conferences
.Include("Participants.ParticipantStatuses")
.Include("ConferenceStatuses")
.Include("Tasks").AsNoTracking()
.Where(x => x.ScheduledDateTime >= today && x.ScheduledDateTime < tomorrow)
.OrderBy(x => x.ScheduledDateTime)
.ToListAsync();
}
}
}
8 changes: 7 additions & 1 deletion VideoAPI/VideoApi.IntegrationTests/Api/Conferences.feature
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,10 @@ Feature: Conferences
Scenario: Get details for a non-existent conference by hearing ref id
Given I have a get details for a conference request with a nonexistent hearing ref id
When I send the request to the endpoint
Then the response should have the status NotFound and success status False
Then the response should have the status NotFound and success status False
Scenario: Get conferences for today only
Given I have a many conferences
And When I send the request to the endpoint
When I send the request to the endpoint
Then the response should have the status OK and success status True
And the summary of conference details should be retrieved
22 changes: 22 additions & 0 deletions VideoAPI/VideoApi.IntegrationTests/Api/Conferences.feature.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
using System;
using System.Collections.Generic;
using VideoApi.Contract.Responses;
using VideoApi.Domain;

namespace VideoApi.IntegrationTests.Contexts
{
public class ConferenceTestContext
{
public ConferenceTestContext()
{
SeededConferences = new List<Guid>();
}

public ConferenceDetailsResponse ConferenceDetails { get; set; }
public Conference SeededConference { get; set; }
public List<Guid> SeededConferences { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public async Task should_update_status_to_done(TaskType taskType)
const string updatedBy = "[email protected]";
var conferenceWithAlert = new ConferenceBuilder(true)
.WithParticipant(UserRole.Individual, "Claimant")
.WithParticipantTask(body, taskType)
.WithTask(body, taskType)
.Build();
var seededConference = await TestDataManager.SeedConference(conferenceWithAlert);
_newConferenceId = seededConference.Id;
Expand Down Expand Up @@ -75,7 +75,7 @@ public async Task should_throw_task_not_found_exception()
const string updatedBy = "[email protected]";
var conferenceWithAlert = new ConferenceBuilder(true)
.WithParticipant(UserRole.Individual, "Claimant")
.WithParticipantTask(body, TaskType.Participant)
.WithParticipantTask(body)
.Build();
var seededConference = await TestDataManager.SeedConference(conferenceWithAlert);
_newConferenceId = seededConference.Id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public async Task should_get_conference_for_username()
.WithParticipant(UserRole.Representative, "Defendant", username)
.WithParticipant(UserRole.Judge, null)
.WithConferenceStatus(ConferenceState.InSession)
.WithHearingTask("Test Task", TaskType.Hearing)
.WithHearingTask("Test Task")
.Build();
_newConferenceId2 = conference2.Id;

Expand All @@ -65,22 +65,22 @@ public async Task should_get_conference_for_username()
.WithParticipant(UserRole.Representative, "Defendant", username)
.WithParticipant(UserRole.Judge, null)
.WithConferenceStatus(ConferenceState.Suspended)
.WithJudgeTask("Test Task", TaskType.Judge)
.WithJudgeTask("Test Task")
.Build();
_newConferenceId4 = conference4.Id;

var conference5 = new ConferenceBuilder(true)
.WithParticipant(UserRole.Representative, "Defendant")
.WithParticipant(UserRole.Judge, null)
.WithConferenceStatus(ConferenceState.Suspended)
.WithParticipantTask("Test Task", TaskType.Participant)
.WithParticipantTask("Test Task")
.Build();
_newConferenceId5 = conference5.Id;

var conference6 = new ConferenceBuilder(true)
.WithParticipant(UserRole.Representative, "Defendant")
.WithParticipant(UserRole.Judge, null)
.WithParticipantTask("Test Task", TaskType.Participant)
.WithParticipantTask("Test Task")
.Build();
_newConferenceId6 = conference6.Id;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FluentAssertions;
using NUnit.Framework;
using Testing.Common.Helper.Builders.Domain;
using VideoApi.DAL;
using VideoApi.DAL.Queries;
using VideoApi.Domain;
using VideoApi.Domain.Enums;
using Task = System.Threading.Tasks.Task;

namespace VideoApi.IntegrationTests.Database.Queries
{
public class GetConferencesTodayQueryTests : DatabaseTestsBase
{
private GetConferencesTodayQueryHandler _handler;
private Guid _newConferenceId1;
private Guid _newConferenceId2;
private Guid _newConferenceId3;
private Guid _newConferenceId4;
private Guid _newConferenceId5;
private Guid _newConferenceId6;

[SetUp]
public void Setup()
{
var context = new VideoApiDbContext(VideoBookingsDbContextOptions);
_handler = new GetConferencesTodayQueryHandler(context);
_newConferenceId1 = Guid.Empty;
_newConferenceId2 = Guid.Empty;
_newConferenceId3 = Guid.Empty;
_newConferenceId4 = Guid.Empty;
_newConferenceId5 = Guid.Empty;
_newConferenceId6 = Guid.Empty;
}

[TearDown]
public async Task TearDown()
{
TestContext.WriteLine("Cleaning conferences for GetConferencesTodayQueryHandler");
await TestDataManager.RemoveConference(_newConferenceId1);
await TestDataManager.RemoveConference(_newConferenceId2);
await TestDataManager.RemoveConference(_newConferenceId3);
await TestDataManager.RemoveConference(_newConferenceId4);
await TestDataManager.RemoveConference(_newConferenceId5);
await TestDataManager.RemoveConference(_newConferenceId6);
}

[Test]
public async Task should_get_conference_today()
{
var today = DateTime.Today.AddHours(10);
var tomorrow = DateTime.Today.AddDays(1).AddHours(10);
var yesterday = DateTime.Today.AddDays(1).AddHours(10);
var conference1 = new ConferenceBuilder(true, scheduledDateTime: yesterday)
.WithParticipant(UserRole.Representative, "Defendant")
.WithParticipant(UserRole.Judge, null)
.WithConferenceStatus(ConferenceState.Closed)
.Build();
_newConferenceId1 = conference1.Id;

var conference2 = new ConferenceBuilder(true, scheduledDateTime: today)
.WithParticipant(UserRole.Representative, "Defendant")
.WithParticipant(UserRole.Judge, null)
.WithConferenceStatus(ConferenceState.InSession)
.Build();
_newConferenceId2 = conference2.Id;

var conference3 = new ConferenceBuilder(true, scheduledDateTime: tomorrow)
.WithParticipant(UserRole.Representative, "Defendant")
.WithParticipant(UserRole.Judge, null)
.WithConferenceStatus(ConferenceState.Paused)
.Build();
_newConferenceId3 = conference3.Id;

var conference4 = new ConferenceBuilder(true, scheduledDateTime: yesterday)
.WithParticipant(UserRole.Representative, "Defendant")
.WithParticipant(UserRole.Judge, null)
.WithConferenceStatus(ConferenceState.Suspended)
.Build();
_newConferenceId4 = conference4.Id;

var conference5 = new ConferenceBuilder(true, scheduledDateTime: tomorrow)
.WithParticipant(UserRole.Representative, "Defendant")
.WithParticipant(UserRole.Judge, null)
.WithConferenceStatus(ConferenceState.Suspended)
.Build();
_newConferenceId5 = conference5.Id;

var conference6 = new ConferenceBuilder(true, scheduledDateTime: today)
.WithParticipant(UserRole.Representative, "Defendant")
.WithParticipant(UserRole.Judge, null)
.Build();
_newConferenceId6 = conference6.Id;

await TestDataManager.SeedConference(conference1);
await TestDataManager.SeedConference(conference2);
await TestDataManager.SeedConference(conference3);
await TestDataManager.SeedConference(conference4);
await TestDataManager.SeedConference(conference5);
await TestDataManager.SeedConference(conference6);

var expectedConferences = new List<Conference> {conference2, conference6};
var conferences = await _handler.Handle(new GetConferencesTodayQuery());

conferences.Should().NotBeEmpty();
conferences.Select(x => x.Id).Should().BeEquivalentTo(expectedConferences.Select(x => x.Id));
conferences.Count.Should().Be(expectedConferences.Count);
}
}
}
Loading

0 comments on commit 027da23

Please sign in to comment.