-
Notifications
You must be signed in to change notification settings - Fork 4
feat!: modernize SDK contract, add CI tests, and improve migration docs #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
da6f96f
feat!: modernize client contract and runtime targets
javorosas 6fe0e1b
test(ci): add regression test project and run it before publish
javorosas a6757fc
docs: prioritize migration guidance and update usage examples
javorosas 32357ae
ci: add PR workflow for build and tests
javorosas fb34b3b
ci: run tests on pull requests and main pushes
javorosas 8e30da7
docs: add CI badge to README
javorosas 6ba9736
ci: install .NET 6 runtime alongside .NET 10 for tests
javorosas 6b6f47f
fix: address Copilot review findings with safe cleanups
javorosas 8ad9890
ci: test SDK against net6.0 and net8.0
javorosas ce6cdcc
test: expand wrapper coverage for routes, errors, cancellation and st…
javorosas 9df0ced
Add organization team management support (#47)
javorosas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| pull_request: | ||
| push: | ||
| branches: | ||
| - main | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup .NET | ||
| uses: actions/setup-dotnet@v4 | ||
| with: | ||
| dotnet-version: "10.0.x" | ||
|
|
||
| - name: Restore dependencies | ||
| run: dotnet restore | ||
|
|
||
| - name: Build | ||
| run: dotnet build facturapi-net.sln --configuration Release --no-restore | ||
|
|
||
| test: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| include: | ||
| - test_framework: net6.0 | ||
| runtime_version: 6.0.x | ||
| - test_framework: net8.0 | ||
| runtime_version: 8.0.x | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup .NET | ||
| uses: actions/setup-dotnet@v4 | ||
| with: | ||
| dotnet-version: | | ||
| 10.0.x | ||
| ${{ matrix.runtime_version }} | ||
|
|
||
| - name: Restore dependencies | ||
| run: dotnet restore | ||
|
|
||
| - name: Build | ||
| run: dotnet build facturapi-net.sln --configuration Release --no-restore | ||
|
|
||
| - name: Test | ||
| run: dotnet test FacturapiTest/FacturapiTest.csproj --framework ${{ matrix.test_framework }} --configuration Release --no-build |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| using Facturapi; | ||
| using Facturapi.Wrappers; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Net; | ||
| using System.Net.Http; | ||
| using System.Text; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Xunit; | ||
|
|
||
| namespace FacturapiTest | ||
| { | ||
| public class ClientCompatibilityTests | ||
| { | ||
| [Fact] | ||
| public void Router_ListCustomers_AllowsNullQueryValues() | ||
| { | ||
| var query = new Dictionary<string, object> | ||
| { | ||
| ["foo"] = null!, | ||
| [""] = "ignored" | ||
| }; | ||
|
|
||
| var url = Router.ListCustomers(query); | ||
|
|
||
| Assert.Equal("customers?foo=", url); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task RetentionCancelAsync_ThrowsFacturapiExceptionWithStatus() | ||
| { | ||
| var handler = new StubHttpMessageHandler((request, cancellationToken) => | ||
| { | ||
| var response = new HttpResponseMessage(HttpStatusCode.BadRequest) | ||
| { | ||
| Content = new StringContent("{\"message\":\"bad retention\",\"status\":400}", Encoding.UTF8, "application/json") | ||
| }; | ||
| return Task.FromResult(response); | ||
| }); | ||
|
|
||
| var httpClient = new HttpClient(handler) | ||
| { | ||
| BaseAddress = new Uri("https://www.facturapi.io/v2/") | ||
| }; | ||
| var wrapper = new RetentionWrapper("test_key", "v2", httpClient); | ||
|
|
||
| var exception = await Assert.ThrowsAsync<FacturapiException>(() => | ||
| wrapper.CancelAsync("ret_123", cancellationToken: CancellationToken.None)); | ||
|
|
||
| Assert.Equal(400, exception.Status); | ||
| Assert.Equal("bad retention", exception.Message); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task InvoiceStampDraftAsync_AndLegacyMethod_BothWork() | ||
| { | ||
| var handler = new StubHttpMessageHandler((request, cancellationToken) => | ||
| { | ||
| var response = new HttpResponseMessage(HttpStatusCode.OK) | ||
| { | ||
| Content = new StringContent("{\"id\":\"inv_123\"}", Encoding.UTF8, "application/json") | ||
| }; | ||
| return Task.FromResult(response); | ||
| }); | ||
|
|
||
| var httpClient = new HttpClient(handler) | ||
| { | ||
| BaseAddress = new Uri("https://www.facturapi.io/v2/") | ||
| }; | ||
| var wrapper = new InvoiceWrapper("test_key", "v2", httpClient); | ||
|
|
||
| var fromAsync = await wrapper.StampDraftAsync("inv_123"); | ||
| #pragma warning disable CS0618 | ||
| var fromLegacy = await wrapper.StampDraft("inv_123"); | ||
| #pragma warning restore CS0618 | ||
|
|
||
| Assert.Equal("inv_123", fromAsync.Id); | ||
| Assert.Equal("inv_123", fromLegacy.Id); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task CreateWithCustomHttpClient_DoesNotDisposeInjectedClient() | ||
| { | ||
| var handler = new StubHttpMessageHandler((request, cancellationToken) => | ||
| { | ||
| var response = new HttpResponseMessage(HttpStatusCode.OK) | ||
| { | ||
| Content = new StringContent("{\"ok\":true}", Encoding.UTF8, "application/json") | ||
| }; | ||
| return Task.FromResult(response); | ||
| }); | ||
|
|
||
| var injectedHttpClient = new HttpClient(handler) | ||
| { | ||
| BaseAddress = new Uri("https://www.facturapi.io/v2/") | ||
| }; | ||
|
|
||
| var client = FacturapiClient.CreateWithCustomHttpClient("test_key", injectedHttpClient, "v2"); | ||
|
|
||
| var healthy = await client.Tool.HealthCheckAsync(); | ||
| Assert.True(healthy); | ||
|
|
||
| client.Dispose(); | ||
|
|
||
| var response = await injectedHttpClient.GetAsync("check"); | ||
| Assert.True(response.IsSuccessStatusCode); | ||
| } | ||
|
|
||
| private sealed class StubHttpMessageHandler : HttpMessageHandler | ||
| { | ||
| private readonly Func<HttpRequestMessage, CancellationToken, Task<HttpResponseMessage>> handler; | ||
|
|
||
| public StubHttpMessageHandler(Func<HttpRequestMessage, CancellationToken, Task<HttpResponseMessage>> handler) | ||
| { | ||
| this.handler = handler; | ||
| } | ||
|
|
||
| protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | ||
| { | ||
| return this.handler(request, cancellationToken); | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFrameworks>net6.0;net8.0</TargetFrameworks> | ||
| <IsPackable>false</IsPackable> | ||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" /> | ||
| <PackageReference Include="xunit" Version="2.6.6" /> | ||
| <PackageReference Include="xunit.runner.visualstudio" Version="2.5.7"> | ||
| <PrivateAssets>all</PrivateAssets> | ||
| <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
| </PackageReference> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\facturapi-net.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.