From 15b53cb903700c4364b4d8e6d85ff0d1d7933c1b Mon Sep 17 00:00:00 2001 From: Nathanael Shim Date: Tue, 27 Feb 2024 13:47:27 -0800 Subject: [PATCH] add v3 result support --- .../Reviews/IReviewsClient.cs | 11 +++++ .../Reviews/ReviewsClientTests.cs | 41 ++++++++++++++++++- .../Submissions/SubmissionHelper.cs | 21 +++++++++- .../Reviews/ReviewSsClient.cs | 6 +-- IndicoV2/Reviews/ReviewsClient.cs | 4 +- 5 files changed, 75 insertions(+), 8 deletions(-) diff --git a/IndicoV2.Abstractions/Reviews/IReviewsClient.cs b/IndicoV2.Abstractions/Reviews/IReviewsClient.cs index daa36a30..9c54d8c0 100644 --- a/IndicoV2.Abstractions/Reviews/IReviewsClient.cs +++ b/IndicoV2.Abstractions/Reviews/IReviewsClient.cs @@ -17,5 +17,16 @@ public interface IReviewsClient /// If review rejected. /// Job's Id Task SubmitReviewAsync(int submissionId, JObject changes, bool rejected = false, bool? forceComplete = null, CancellationToken cancellationToken = default); + + /// + /// Submits review for + /// + /// 's Id + /// Changes + /// Force complete review. + /// for handling cancellation of asynchronous operations. + /// If review rejected. + /// Job's Id + Task SubmitReviewAsync(int submissionId, JArray changes, bool rejected = false, bool? forceComplete = null, CancellationToken cancellationToken = default); } } diff --git a/IndicoV2.IntegrationTests/Reviews/ReviewsClientTests.cs b/IndicoV2.IntegrationTests/Reviews/ReviewsClientTests.cs index b3b5b1bd..a78a3cbd 100644 --- a/IndicoV2.IntegrationTests/Reviews/ReviewsClientTests.cs +++ b/IndicoV2.IntegrationTests/Reviews/ReviewsClientTests.cs @@ -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 { @@ -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"]; @@ -62,5 +67,37 @@ public async Task SubmitReviewAsync_ShouldSucceed() jobResult.Value("submission_status").Should().Be("pending_review"); jobResult.Value("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() { 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(submitReviewJobId, TimeSpan.FromSeconds(1)); + + // Assert + jobResult.Should().NotBeNull(); + jobResult.Value("submission_status").Should().Be("pending_review"); + jobResult.Value("success").Should().Be(true); + } + else + { + // multi-file submissions are not enabled and submission status should default to complete + submission.Status.ToString().Should().Be("COMPLETE"); + } + } } } diff --git a/IndicoV2.IntegrationTests/Utils/DataHelpers/Submissions/SubmissionHelper.cs b/IndicoV2.IntegrationTests/Utils/DataHelpers/Submissions/SubmissionHelper.cs index 8c9ef80d..c9ad4067 100644 --- a/IndicoV2.IntegrationTests/Utils/DataHelpers/Submissions/SubmissionHelper.cs +++ b/IndicoV2.IntegrationTests/Utils/DataHelpers/Submissions/SubmissionHelper.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; @@ -22,11 +23,11 @@ public SubmissionHelper(WorkflowHelper workflowHelper, FileHelper fileHelper, IS _fileHelper = fileHelper; _submissions = submissions; } - + public async Task GetAnyAsync(int workflow_id) { await using var fileStream = _fileHelper.GetSampleFileStream(); - + return await GetAnyAsync(fileStream, workflow_id); } @@ -40,6 +41,14 @@ public async Task GetAnyAsync(Stream content, int workflow_id) public async Task Get(IWorkflow workflow, Stream content) => (await _submissions.CreateAsync(workflow.Id, new[] { ("csharp_test_content", content) })).Single(); + public async Task 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(); @@ -52,5 +61,13 @@ public async Task GetAnyAsync(Stream content, int workflow_id) return (workflowId, submissionIds.First()); } + + + public async Task> ListAsync(IEnumerable submissionIds, int limit = 1000) + { + var submissions = await _submissions.ListAsync(submissionIds, new List(), null, limit: limit); + + return submissions; + } } } diff --git a/IndicoV2.StrawberryShake/Reviews/ReviewSsClient.cs b/IndicoV2.StrawberryShake/Reviews/ReviewSsClient.cs index 51605132..d56ec3a3 100644 --- a/IndicoV2.StrawberryShake/Reviews/ReviewSsClient.cs +++ b/IndicoV2.StrawberryShake/Reviews/ReviewSsClient.cs @@ -16,16 +16,16 @@ public class ReviewSsClient : ErrorHandlingWrapper public ReviewSsClient(ServiceProvider services) => _services = services; - public async Task SubmitReview(int submissionId, JObject changes, bool rejected, bool? forceComplete, CancellationToken cancellationToken) + public async Task SubmitReview(int submissionId, string changes, bool rejected, bool? forceComplete, CancellationToken cancellationToken) { if (forceComplete == null) { - var response = await _services.GetRequiredService().ExecuteAsync(submissionId, changes.ToString(), rejected, cancellationToken); + var response = await _services.GetRequiredService().ExecuteAsync(submissionId, changes, rejected, cancellationToken); return response.Data.SubmitAutoReview.JobId; } else { - var response = await _services.GetRequiredService().ExecuteAsync(submissionId, changes.ToString(), rejected, forceComplete, cancellationToken); + var response = await _services.GetRequiredService().ExecuteAsync(submissionId, changes, rejected, forceComplete, cancellationToken); return response.Data.SubmitAutoReview.JobId; } } diff --git a/IndicoV2/Reviews/ReviewsClient.cs b/IndicoV2/Reviews/ReviewsClient.cs index 6134a30b..5dfeb364 100644 --- a/IndicoV2/Reviews/ReviewsClient.cs +++ b/IndicoV2/Reviews/ReviewsClient.cs @@ -19,8 +19,10 @@ public ReviewsClient(IndicoClient indicoClient) } public async Task 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 SubmitReviewAsync(int submissionId, JArray changes, bool rejected = false, bool? forceComplete = null, CancellationToken cancellationToken = default) => + await _strawberryShake.Reviews().SubmitReview(submissionId, changes.ToString(), rejected, forceComplete, cancellationToken); } } \ No newline at end of file