diff --git a/.gitignore b/.gitignore index 977a6ac..78946b3 100644 --- a/.gitignore +++ b/.gitignore @@ -356,3 +356,4 @@ healthchecksdb *.env /Apps.GoogleSheets/ApplicationConstants.cs +/Tests.GoogleSheets/appsettings.json diff --git a/Apps.GoogleSheets.sln b/Apps.GoogleSheets.sln index d6e2ac6..475e850 100644 --- a/Apps.GoogleSheets.sln +++ b/Apps.GoogleSheets.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 17.5.33424.131 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Apps.GoogleSheets", "Apps.GoogleSheets\Apps.GoogleSheets.csproj", "{275D9CE1-A4E8-41E8-A01B-404B1A2D0AD2}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests.GoogleSheets", "Tests.GoogleSheets\Tests.GoogleSheets.csproj", "{B4C40A72-1266-484B-9B9D-A83E6D005044}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {275D9CE1-A4E8-41E8-A01B-404B1A2D0AD2}.Debug|Any CPU.Build.0 = Debug|Any CPU {275D9CE1-A4E8-41E8-A01B-404B1A2D0AD2}.Release|Any CPU.ActiveCfg = Release|Any CPU {275D9CE1-A4E8-41E8-A01B-404B1A2D0AD2}.Release|Any CPU.Build.0 = Release|Any CPU + {B4C40A72-1266-484B-9B9D-A83E6D005044}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B4C40A72-1266-484B-9B9D-A83E6D005044}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B4C40A72-1266-484B-9B9D-A83E6D005044}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B4C40A72-1266-484B-9B9D-A83E6D005044}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Apps.GoogleSheets/Actions/SpreadsheetActions.cs b/Apps.GoogleSheets/Actions/SpreadsheetActions.cs index d9793ab..0a5de9a 100644 --- a/Apps.GoogleSheets/Actions/SpreadsheetActions.cs +++ b/Apps.GoogleSheets/Actions/SpreadsheetActions.cs @@ -15,6 +15,7 @@ using Blackbird.Applications.Sdk.Glossaries.Utils.Converters; using Blackbird.Applications.Sdk.Glossaries.Utils.Dtos; using Blackbird.Applications.Sdk.Common.Exceptions; +using Blackbird.Applications.Sdk.Common.Authentication; namespace Apps.GoogleSheets.Actions { @@ -60,9 +61,19 @@ public async Task UpdateCell( updateRequest.ValueInputOption = UpdateRequest.ValueInputOptionEnum.USERENTERED; updateRequest.IncludeValuesInResponse = true; var result = await ErrorHandler.ExecuteWithErrorHandlingAsync(async () => await updateRequest.ExecuteAsync()); + if (result?.UpdatedData?.Values == null || result.UpdatedData.Values.Count == 0 || result.UpdatedData.Values[0].Count == 0) + { + throw new PluginApplicationException("No updated data was returned from the API. Please check your input and try again"); + } return new CellDto { Value = result?.UpdatedData.Values[0][0].ToString() }; } + [Action("DEBUG: Get auth data", Description = "Can be used only for debugging purposes.")] + public List GetAuthenticationCredentialsProviders() + { + return InvocationContext.AuthenticationCredentialsProviders.ToList(); + } + [Action("Get sheet row", Description = "Get sheet row by address")] public async Task GetRow( [ActionParameter] SpreadsheetFileRequest spreadsheetFileRequest, diff --git a/Apps.GoogleSheets/Apps.GoogleSheets.csproj b/Apps.GoogleSheets/Apps.GoogleSheets.csproj index f2b8dc4..6483d26 100644 --- a/Apps.GoogleSheets/Apps.GoogleSheets.csproj +++ b/Apps.GoogleSheets/Apps.GoogleSheets.csproj @@ -5,7 +5,7 @@ enable Google Sheets Create and edit online spreadsheets. Get insights together with secure sharing in real-time and from any device - 1.4.4 + 1.4.5 Apps.GoogleSheets diff --git a/Tests.GoogleSheets/Base/FileManager.cs b/Tests.GoogleSheets/Base/FileManager.cs new file mode 100644 index 0000000..b291dda --- /dev/null +++ b/Tests.GoogleSheets/Base/FileManager.cs @@ -0,0 +1,28 @@ +using Blackbird.Applications.Sdk.Common.Files; +using Blackbird.Applications.SDK.Extensions.FileManagement.Interfaces; + +namespace Tests.GoogleSheets.Base; + +public class FileManager(string folderLocation) : IFileManagementClient +{ + public Task DownloadAsync(FileReference reference) + { + var path = Path.Combine(folderLocation, @$"Input\{reference.Name}"); + var bytes = File.ReadAllBytes(path); + + var stream = new MemoryStream(bytes); + return Task.FromResult((Stream)stream); + } + + public Task UploadAsync(Stream stream, string contentType, string fileName) + { + var path = Path.Combine(folderLocation, @$"Output\{fileName}"); + new FileInfo(path).Directory!.Create(); + using (var fileStream = File.Create(path)) + { + stream.CopyTo(fileStream); + } + + return Task.FromResult(new FileReference { Name = fileName }); + } +} \ No newline at end of file diff --git a/Tests.GoogleSheets/Base/TestBase.cs b/Tests.GoogleSheets/Base/TestBase.cs new file mode 100644 index 0000000..ddf46c2 --- /dev/null +++ b/Tests.GoogleSheets/Base/TestBase.cs @@ -0,0 +1,29 @@ +using Blackbird.Applications.Sdk.Common.Authentication; +using Blackbird.Applications.Sdk.Common.Invocation; +using Microsoft.Extensions.Configuration; + +namespace Tests.GoogleSheets.Base; + +public class TestBase +{ + protected TestBase() + { + var config = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build(); + Creds = config.GetSection("ConnectionDefinition").GetChildren() + .Select(x => new AuthenticationCredentialsProvider(x.Key, x.Value!)).ToList(); + var folderLocation = config.GetSection("TestFolder").Value!; + + InvocationContext = new InvocationContext + { + AuthenticationCredentialsProviders = Creds, + }; + + FileManager = new FileManager(folderLocation); + } + + protected IEnumerable Creds { get; set; } + + public InvocationContext InvocationContext { get; set; } + + public FileManager FileManager { get; set; } +} \ No newline at end of file diff --git a/Tests.GoogleSheets/SpreadsheetTests.cs b/Tests.GoogleSheets/SpreadsheetTests.cs new file mode 100644 index 0000000..4c0712a --- /dev/null +++ b/Tests.GoogleSheets/SpreadsheetTests.cs @@ -0,0 +1,15 @@ +using Tests.GoogleSheets.Base; + +namespace Tests.CrowGoogleSheetsdin +{ + [TestClass] + public class SpreadsheetTests : TestBase + { + [TestMethod] + public async Task Getrange_ReturnsSuccess() + { + + } + + } +} diff --git a/Tests.GoogleSheets/Tests.GoogleSheets.csproj b/Tests.GoogleSheets/Tests.GoogleSheets.csproj new file mode 100644 index 0000000..9e26233 --- /dev/null +++ b/Tests.GoogleSheets/Tests.GoogleSheets.csproj @@ -0,0 +1,40 @@ + + + + net8.0 + enable + enable + + false + true + + + + + + + + + + + + + + + + + + + + + + + + + + + Always + + + + diff --git a/Tests.GoogleSheets/ValidatorTests.cs b/Tests.GoogleSheets/ValidatorTests.cs new file mode 100644 index 0000000..3199bae --- /dev/null +++ b/Tests.GoogleSheets/ValidatorTests.cs @@ -0,0 +1,30 @@ +using Apps.GoogleSheets.Connections; +using Blackbird.Applications.Sdk.Common.Authentication; +using FluentAssertions; +using Tests.GoogleSheets.Base; + +namespace Tests.GoogleSheets; + +[TestClass] +public class ValidatorTests : TestBase +{ + [TestMethod] + public async Task ValidateConnection_ValidEnterpriseConnection_ShouldBeSuccessful() + { + var validator = new ConnectionValidator(); + + var result = await validator.ValidateConnection(Creds, CancellationToken.None); + Console.WriteLine(result.Message); + result.IsValid.Should().Be(true); + } + + [TestMethod] + public async Task ValidateConnection_InvalidConnection_ShouldFail() + { + var validator = new ConnectionValidator(); + + var newCredentials = Creds.Select(x => new AuthenticationCredentialsProvider(x.KeyName, x.Value + "_incorrect")); + var result = await validator.ValidateConnection(newCredentials, CancellationToken.None); + result.IsValid.Should().Be(false); + } +} \ No newline at end of file diff --git a/Tests.GoogleSheets/appsettings.json.example b/Tests.GoogleSheets/appsettings.json.example new file mode 100644 index 0000000..4da5c7c --- /dev/null +++ b/Tests.GoogleSheets/appsettings.json.example @@ -0,0 +1,8 @@ +{ + "ConnectionDefinition": { + "access_token": "", + "crowdin_plan": "", + "domain": "" + }, + "TestFolder": "C:\\Users\\..." +} \ No newline at end of file