Skip to content

Commit

Permalink
Merge pull request #140 from IndicoDataSolutions/nate/ar_v3_result
Browse files Browse the repository at this point in the history
add v3 result support
  • Loading branch information
nateshim-indico authored Feb 29, 2024
2 parents a8fbc07 + 15b53cb commit 779f48c
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 8 deletions.
11 changes: 11 additions & 0 deletions IndicoV2.Abstractions/Reviews/IReviewsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,16 @@ public interface IReviewsClient
/// <param name="rejected">If review rejected.</param>
/// <returns>Job's Id</returns>
Task<string> SubmitReviewAsync(int submissionId, JObject changes, bool rejected = false, bool? forceComplete = null, CancellationToken cancellationToken = default);

/// <summary>
/// Submits review for <see cref="ISubmission"/>
/// </summary>
/// <param name="submissionId"><see cref="ISubmission"/>'s Id</param>
/// <param name="changes">Changes</param>
/// <param name="forceComplete">Force complete review.</param>
/// <param name="cancellationToken"><c><see cref="CancellationToken"/></c> for handling cancellation of asynchronous operations.</param>
/// <param name="rejected">If review rejected.</param>
/// <returns>Job's Id</returns>
Task<string> SubmitReviewAsync(int submissionId, JArray changes, bool rejected = false, bool? forceComplete = null, CancellationToken cancellationToken = default);
}
}
41 changes: 39 additions & 2 deletions IndicoV2.IntegrationTests/Reviews/ReviewsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
using IndicoV2.IntegrationTests.Utils.DataHelpers;
using IndicoV2.IntegrationTests.Utils.Configs;
using IndicoV2.Reviews;
using IndicoV2.Submissions.Models;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
using Unity;
using System.Text.Json;
using IndicoV2.Submissions;
using System.Linq;
using System.Collections.Generic;

namespace IndicoV2.IntegrationTests.Reviews
{
Expand Down Expand Up @@ -46,10 +51,10 @@ public async Task SetUp()
}

[Test]
public async Task SubmitReviewAsync_ShouldSucceed()
public async Task SubmitReviewAsyncV1Result_ShouldSucceed()
{
// Arrange
var submission = await _dataHelper.Submissions().GetAnyAsync(_workflowId);
var submission = await _dataHelper.Submissions().Get(_workflowId, resultsFileVersion: SubmissionResultsFileVersion.One);
var result = await _submissionResultAwaiter.WaitReady(submission.Id);
var changes = (JObject)result["results"]["document"]["results"];

Expand All @@ -62,5 +67,37 @@ public async Task SubmitReviewAsync_ShouldSucceed()
jobResult.Value<string>("submission_status").Should().Be("pending_review");
jobResult.Value<bool>("success").Should().Be(true);
}


[Test]
public async Task SubmitReviewAsyncV3Result_ShouldSucceed()
{
// Arrange
var submission = await _dataHelper.Submissions().Get(_workflowId, resultsFileVersion: SubmissionResultsFileVersion.Three);
var result = await _submissionResultAwaiter.WaitReady(submission.Id);
submission = (await _dataHelper.Submissions().ListAsync(submissionIds: new List<int>() { submission.Id })).First();
if (submission.Status.ToString() == "PENDING_AUTO_REVIEW")
{
var changes = result["submission_results"];
foreach (JObject change in changes)
{
change["model_results"] = change["model_results"]["ORIGINAL"];
change["component_results"] = change["component_results"]["ORIGINAL"];
}
// Act
var submitReviewJobId = await _reviewsClient.SubmitReviewAsync(submission.Id, (JArray)changes);
var jobResult = await _jobAwaiter.WaitReadyAsync<JObject>(submitReviewJobId, TimeSpan.FromSeconds(1));

// Assert
jobResult.Should().NotBeNull();
jobResult.Value<string>("submission_status").Should().Be("pending_review");
jobResult.Value<bool>("success").Should().Be(true);
}
else
{
// multi-file submissions are not enabled and submission status should default to complete
submission.Status.ToString().Should().Be("COMPLETE");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -22,11 +23,11 @@ public SubmissionHelper(WorkflowHelper workflowHelper, FileHelper fileHelper, IS
_fileHelper = fileHelper;
_submissions = submissions;
}

public async Task<ISubmission> GetAnyAsync(int workflow_id)
{
await using var fileStream = _fileHelper.GetSampleFileStream();

return await GetAnyAsync(fileStream, workflow_id);
}

Expand All @@ -40,6 +41,14 @@ public async Task<ISubmission> GetAnyAsync(Stream content, int workflow_id)

public async Task<int> Get(IWorkflow workflow, Stream content) => (await _submissions.CreateAsync(workflow.Id, new[] { ("csharp_test_content", content) })).Single();

public async Task<ISubmission> Get(int workflowId, SubmissionResultsFileVersion? resultsFileVersion = null, bool bundle = false)
{
var submissionIds = await _submissions.CreateAsync(workflowId, paths: new[] { _fileHelper.GetSampleFilePath() }, resultsFileVersion: resultsFileVersion, bundle: bundle);
var submission = await _submissions.GetAsync(submissionIds.Single());

return submission;
}

public async Task<(int workflowId, int submissionId)> ListAnyAsync(int workflowId)
{
await using var content = _fileHelper.GetSampleFileStream();
Expand All @@ -52,5 +61,13 @@ public async Task<ISubmission> GetAnyAsync(Stream content, int workflow_id)

return (workflowId, submissionIds.First());
}


public async Task<IEnumerable<ISubmission>> ListAsync(IEnumerable<int> submissionIds, int limit = 1000)
{
var submissions = await _submissions.ListAsync(submissionIds, new List<int>(), null, limit: limit);

return submissions;
}
}
}
6 changes: 3 additions & 3 deletions IndicoV2.StrawberryShake/Reviews/ReviewSsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ public class ReviewSsClient : ErrorHandlingWrapper

public ReviewSsClient(ServiceProvider services) => _services = services;

public async Task<string> SubmitReview(int submissionId, JObject changes, bool rejected, bool? forceComplete, CancellationToken cancellationToken)
public async Task<string> SubmitReview(int submissionId, string changes, bool rejected, bool? forceComplete, CancellationToken cancellationToken)
{
if (forceComplete == null)
{
var response = await _services.GetRequiredService<SubmitReviewMutation>().ExecuteAsync(submissionId, changes.ToString(), rejected, cancellationToken);
var response = await _services.GetRequiredService<SubmitReviewMutation>().ExecuteAsync(submissionId, changes, rejected, cancellationToken);
return response.Data.SubmitAutoReview.JobId;
}
else
{
var response = await _services.GetRequiredService<SubmitReviewForceCompleteMutation>().ExecuteAsync(submissionId, changes.ToString(), rejected, forceComplete, cancellationToken);
var response = await _services.GetRequiredService<SubmitReviewForceCompleteMutation>().ExecuteAsync(submissionId, changes, rejected, forceComplete, cancellationToken);
return response.Data.SubmitAutoReview.JobId;
}
}
Expand Down
4 changes: 3 additions & 1 deletion IndicoV2/Reviews/ReviewsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ public ReviewsClient(IndicoClient indicoClient)
}

public async Task<string> SubmitReviewAsync(int submissionId, JObject changes, bool rejected = false, bool? forceComplete = null, CancellationToken cancellationToken = default) =>
await _strawberryShake.Reviews().SubmitReview(submissionId, changes, rejected, forceComplete, cancellationToken);
await _strawberryShake.Reviews().SubmitReview(submissionId, changes.ToString(), rejected, forceComplete, cancellationToken);

public async Task<string> SubmitReviewAsync(int submissionId, JArray changes, bool rejected = false, bool? forceComplete = null, CancellationToken cancellationToken = default) =>
await _strawberryShake.Reviews().SubmitReview(submissionId, changes.ToString(), rejected, forceComplete, cancellationToken);

}
}

0 comments on commit 779f48c

Please sign in to comment.