From 579589c5ada2d95893f83183133ea2f53c3c36ef Mon Sep 17 00:00:00 2001 From: Nathanael Shim Date: Tue, 12 Mar 2024 09:59:14 -0700 Subject: [PATCH 1/2] update tests --- .../DataSets/DataSetsAwaiterTests.cs | 22 ++++++---- .../GraphQLRequest/GraphQLRequestTests.cs | 14 ++++++- .../Models/ModelClientTests.cs | 7 ++-- .../Reporting/ReportingClientTests.cs | 2 +- .../Submissions/SubmissionClientTests.cs | 41 +++++++++++++++++-- IndicoV2/Jobs/JobsClient.cs | 2 +- 6 files changed, 70 insertions(+), 18 deletions(-) diff --git a/IndicoV2.IntegrationTests/Extensions/DataSets/DataSetsAwaiterTests.cs b/IndicoV2.IntegrationTests/Extensions/DataSets/DataSetsAwaiterTests.cs index 2df34da2..3b9a6367 100644 --- a/IndicoV2.IntegrationTests/Extensions/DataSets/DataSetsAwaiterTests.cs +++ b/IndicoV2.IntegrationTests/Extensions/DataSets/DataSetsAwaiterTests.cs @@ -51,22 +51,28 @@ public async Task WaitAllFilesDownloadedOrFailedAsync_ShouldWaitUntilFilesDownlo public async Task WaitFilesProcessedOrFailedAsync_ShouldWaitUntilAllFilesProcessedOrFailed() { // Arrange - var datasSet = await _dataHelper.DataSets().GetAny(); + var dataSet = await _dataHelper.DataSets().GetAny(); var filePaths = new[] {_dataHelper.Files().GetSampleFilePath()}; - await _dataSetsClient.AddFilesAsync(datasSet.Id, filePaths, default); - await _dataSetAwaiter.WaitFilesDownloadedOrFailedAsync(datasSet.Id, TimeSpan.Zero, default); + await _dataSetsClient.AddFilesAsync(dataSet.Id, filePaths, default); + var container = new IndicoTestContainerBuilder().Build(); + var client = container.Resolve(); + _dataSetAwaiter = client.DataSetAwaiter(); + await _dataSetAwaiter.WaitFilesDownloadedOrFailedAsync(dataSet.Id, TimeSpan.Zero, default); - var dataSetFileStatus = await _dataSetsClient.FileUploadStatusAsync(datasSet.Id, default); + var dataSetFileStatus = await _dataSetsClient.FileUploadStatusAsync(dataSet.Id, default); var downloadedFileIds = dataSetFileStatus.Dataset.Files.Where(f => f.Status == FileStatus.Downloaded).Select(f => f.Id.Value); - await _dataSetsClient.ProcessFileAsync(datasSet.Id, downloadedFileIds, default); + await _dataSetsClient.ProcessFileAsync(dataSet.Id, downloadedFileIds, default); // Act - await _dataSetAwaiter.WaitFilesProcessedOrFailedAsync(datasSet.Id, TimeSpan.Zero, default); + container = new IndicoTestContainerBuilder().Build(); + client = container.Resolve(); + _dataSetAwaiter = client.DataSetAwaiter(); + await _dataSetAwaiter.WaitFilesProcessedOrFailedAsync(dataSet.Id, TimeSpan.Zero, default); // Assert - var dataSetWithStauses = await _dataSetsClient.FileUploadStatusAsync(datasSet.Id, default); - dataSetWithStauses.Dataset.Files + var dataSetWithStatuses = await _dataSetsClient.FileUploadStatusAsync(dataSet.Id, default); + dataSetWithStatuses.Dataset.Files .All(f => f.Status is FileStatus.Processed or FileStatus.Failed) .Should().BeTrue(); } diff --git a/IndicoV2.IntegrationTests/GraphQLRequest/GraphQLRequestTests.cs b/IndicoV2.IntegrationTests/GraphQLRequest/GraphQLRequestTests.cs index db7cf20e..18785b9f 100644 --- a/IndicoV2.IntegrationTests/GraphQLRequest/GraphQLRequestTests.cs +++ b/IndicoV2.IntegrationTests/GraphQLRequest/GraphQLRequestTests.cs @@ -1,6 +1,7 @@ using System; using System.Threading.Tasks; using FluentAssertions; +using IndicoV2.DataSets.Models; using IndicoV2.IntegrationTests.Utils; using NUnit.Framework; using Unity; @@ -35,7 +36,18 @@ query ListDatasets($limit: Int){ dynamic variables = new { limit = 1 }; var request = _indicoClient.GraphQLRequest(); var result = await request.Call(query, operationName, variables); - result.Should().NotBeNull(); + foreach (var datasetJson in result.GetValue("datasetsPage").GetValue("datasets")) + { + var dataset = new DataSetFull() + { + Id = datasetJson.GetValue("id"), + Name = datasetJson.GetValue("name"), + RowCount = datasetJson.GetValue("rowCount") + }; + dataset.Id.Should().BeGreaterOrEqualTo(0); + dataset.Name.Should().NotBeNullOrEmpty(); + dataset.RowCount.Should().BeGreaterThan(0); + } } } } diff --git a/IndicoV2.IntegrationTests/Models/ModelClientTests.cs b/IndicoV2.IntegrationTests/Models/ModelClientTests.cs index 99252331..2798aa36 100644 --- a/IndicoV2.IntegrationTests/Models/ModelClientTests.cs +++ b/IndicoV2.IntegrationTests/Models/ModelClientTests.cs @@ -61,8 +61,8 @@ public async Task GetGroup_ShouldReturnModelGroup() } - [TestCase("Invoice Date: 2012-01-02")] - [TestCase("Invoice Date: 2012-02-03 Invoice Number: 123Test")] + [TestCase("AT&T")] + [TestCase("AT&T Xfinity T-Mobile")] public async Task Predict_ShouldReturnPrediction(params string[] data) { // Arrange @@ -75,12 +75,11 @@ public async Task Predict_ShouldReturnPrediction(params string[] data) // Assert predictionResults.Count.Should().Be(data.Length); - var firstPrediction = predictionResults.First().First(); firstPrediction.Label.Should().NotBeNullOrEmpty(); firstPrediction.Text.Should().NotBeNullOrEmpty(); - firstPrediction.Start.Should().BeGreaterThan(0); + firstPrediction.Start.Should().BeGreaterOrEqualTo(0); firstPrediction.End.Should().BeGreaterThan(0); firstPrediction.Confidence.Should().NotBeEmpty(); diff --git a/IndicoV2.IntegrationTests/Reporting/ReportingClientTests.cs b/IndicoV2.IntegrationTests/Reporting/ReportingClientTests.cs index b66a2aed..b5948957 100644 --- a/IndicoV2.IntegrationTests/Reporting/ReportingClientTests.cs +++ b/IndicoV2.IntegrationTests/Reporting/ReportingClientTests.cs @@ -41,7 +41,7 @@ public async Task SnapReportAsync_ShouldGenerateReport() [Test] public async Task ChangeReportAsync_ShouldGenerateReport() { - var jobId = (await _userReportingClient.CreateChangelogReportAsync(null, null, null, default)) + var jobId = (await _userReportingClient.CreateChangelogReportAsync(DateTime.Now, DateTime.Today, null, default)) .UserChangelogReport.JobId; await AssertJobGeneratesNonEmptyReport(jobId); diff --git a/IndicoV2.IntegrationTests/Submissions/SubmissionClientTests.cs b/IndicoV2.IntegrationTests/Submissions/SubmissionClientTests.cs index b86743f4..9edb84a5 100644 --- a/IndicoV2.IntegrationTests/Submissions/SubmissionClientTests.cs +++ b/IndicoV2.IntegrationTests/Submissions/SubmissionClientTests.cs @@ -219,6 +219,12 @@ public async Task ListSubmissions_SubmissionFilterReviewInProgress_ShouldFetchSu submissions.PageInfo.Should().NotBeNull(); submissions.Data.Should().NotBeNull(); submissions.Data.Should().HaveCount(0); + + foreach (Submission submission in submissions.Data) + { + submission.Id.Should().BeGreaterThan(0); + submission.ReviewInProgress.Should().NotBeTrue(); + } } @@ -242,12 +248,41 @@ public async Task ListSubmissions_SubmissionFilterCreatedAt_ShouldFetchSubmissio submissions.Should().NotBeNull(); submissions.PageInfo.Should().NotBeNull(); submissions.Data.Should().NotBeNull(); - var submission = submissions.Data.First(); // Assert submissions.Data.Should().HaveCountGreaterThan(0); - submission.Id.Should().BeGreaterThan(0); - submission.Status.Should().BeOfType(); + foreach (Submission submission in submissions.Data) + { + submission.Id.Should().BeGreaterThan(0); + submission.CreatedAt.Value.Should().BeLessThan(TimeSpan.FromTicks(DateTime.Now.Ticks)); + } + } + + + [Test] + public async Task ListSubmissions_SubmissionFilterStatus_ShouldFetchSubmissions() + { + // Arrange + var listData = await _dataHelper.Submissions().ListAnyAsync(_workflowId); + var filters = new SubmissionFilter + { + Status = SubmissionStatus.PENDING_AUTO_REVIEW + }; + + // Act + var submissions = await _submissionsClient.ListAsync(null, new List { listData.workflowId }, filters, 0, 10); + + submissions.Should().NotBeNull(); + submissions.PageInfo.Should().NotBeNull(); + submissions.Data.Should().NotBeNull(); + // Assert + submissions.Data.Should().HaveCountGreaterThan(0); + foreach (Submission submission in submissions.Data) + { + submission.Id.Should().BeGreaterThan(0); + submission.Status.Should().BeOfType(); + submission.Status.Should().Be(SubmissionStatus.PENDING_AUTO_REVIEW); + } } diff --git a/IndicoV2/Jobs/JobsClient.cs b/IndicoV2/Jobs/JobsClient.cs index a92171af..444b520b 100644 --- a/IndicoV2/Jobs/JobsClient.cs +++ b/IndicoV2/Jobs/JobsClient.cs @@ -29,7 +29,7 @@ public async Task GetStatusAsync(string jobId, CancellationToken canc public async Task GetResultAsync(string jobId, CancellationToken cancellationToken = default) { var result = await _strawberryShake.Jobs().GetResultAsync(jobId, cancellationToken); - // use json decoder to decode result into whatever tresult would be + // use json decoder to decode result into whatever TResult would be return JsonConvert.DeserializeObject(result.Job.Result); } From 9e98591b38862c286ffd196016b6fd953907676a Mon Sep 17 00:00:00 2001 From: Nathanael Shim Date: Tue, 12 Mar 2024 10:01:04 -0700 Subject: [PATCH 2/2] remove unneeded code --- .../Extensions/DataSets/DataSetsAwaiterTests.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/IndicoV2.IntegrationTests/Extensions/DataSets/DataSetsAwaiterTests.cs b/IndicoV2.IntegrationTests/Extensions/DataSets/DataSetsAwaiterTests.cs index 3b9a6367..4eef4af3 100644 --- a/IndicoV2.IntegrationTests/Extensions/DataSets/DataSetsAwaiterTests.cs +++ b/IndicoV2.IntegrationTests/Extensions/DataSets/DataSetsAwaiterTests.cs @@ -54,9 +54,6 @@ public async Task WaitFilesProcessedOrFailedAsync_ShouldWaitUntilAllFilesProcess var dataSet = await _dataHelper.DataSets().GetAny(); var filePaths = new[] {_dataHelper.Files().GetSampleFilePath()}; await _dataSetsClient.AddFilesAsync(dataSet.Id, filePaths, default); - var container = new IndicoTestContainerBuilder().Build(); - var client = container.Resolve(); - _dataSetAwaiter = client.DataSetAwaiter(); await _dataSetAwaiter.WaitFilesDownloadedOrFailedAsync(dataSet.Id, TimeSpan.Zero, default); var dataSetFileStatus = await _dataSetsClient.FileUploadStatusAsync(dataSet.Id, default); @@ -65,9 +62,6 @@ public async Task WaitFilesProcessedOrFailedAsync_ShouldWaitUntilAllFilesProcess await _dataSetsClient.ProcessFileAsync(dataSet.Id, downloadedFileIds, default); // Act - container = new IndicoTestContainerBuilder().Build(); - client = container.Resolve(); - _dataSetAwaiter = client.DataSetAwaiter(); await _dataSetAwaiter.WaitFilesProcessedOrFailedAsync(dataSet.Id, TimeSpan.Zero, default); // Assert