Skip to content

Commit

Permalink
Stabilize e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
myieye committed Apr 29, 2024
1 parent 248a5ff commit 9ff712c
Show file tree
Hide file tree
Showing 10 changed files with 442 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ backend/Testing/SyncReverseProxy/TestData.cs
.task
deployment/local-dev/collector-config.yaml
local.env
.env.local
cookies.txt
dump.sql
test-results/
22 changes: 16 additions & 6 deletions backend/Testing/Fixtures/IntegrationFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
using System.Runtime.CompilerServices;
using LexCore.Utils;
using Shouldly;
using Squidex.Assets;
using Testing.ApiTests;
using Testing.Services;
using TusDotNetClient;
using static Testing.Services.Constants;

namespace Testing.Fixtures;
Expand Down Expand Up @@ -72,10 +72,20 @@ public async Task FinishLexboxProjectResetWithTemplateRepo(string projectCode)

public async Task FinishLexboxProjectResetWithRepo(string projectCode, FileInfo repo)
{
var client = new TusClient();
client.AdditionalHeaders.Add("Cookie", $".LexBoxAuth={AdminJwt}");
var fileUrl = await client.CreateAsync($"{AdminApiTester.BaseUrl}/api/project/upload-zip/{projectCode}", repo.Length, [("filetype", "application/zip")]);
var responses = await client.UploadAsync(fileUrl, repo, chunkSize: 20);
responses.ShouldAllBe(r => r.StatusCode.ToString() == nameof(HttpStatusCode.NoContent));
Exception? failureException = null;
await AdminApiTester.HttpClient.UploadWithProgressAsync(new Uri($"{AdminApiTester.BaseUrl}/api/project/upload-zip/{projectCode}"),
UploadFile.FromFile(repo, "application/zip"), new UploadOptions
{
Metadata = new Dictionary<string, string> { ["filetype"] = "application/zip" },
ProgressHandler = new DelegatingProgressHandler
{
OnFailedAsync = (e, ct) =>
{
failureException = e.Exception;
return Task.CompletedTask;
}
},
});
if (failureException is not null) throw failureException;
}
}
6 changes: 5 additions & 1 deletion backend/Testing/SyncReverseProxy/SendReceiveServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public async Task SendReceiveAfterProjectReset(HgProtocol protocol)
var projectConfig = _srFixture.InitLocalFlexProjectWithRepo(protocol, "SR_AfterReset");
await using var project = await RegisterProjectInLexBox(projectConfig, _adminApiTester);

await WaitForHgRefreshIntervalAsync();
await WaitForHgRefreshIntervalAsync(); // TODO 765: Remove this

var sendReceiveParams = new SendReceiveParams(protocol, projectConfig);
var srResult = _sendReceiveService.SendReceiveProject(sendReceiveParams, AdminAuth);
Expand All @@ -144,6 +144,8 @@ public async Task SendReceiveAfterProjectReset(HgProtocol protocol)
await _adminApiTester.HttpClient.PostAsync($"{_adminApiTester.BaseUrl}/api/project/resetProject/{projectConfig.Code}", null);
await _adminApiTester.HttpClient.PostAsync($"{_adminApiTester.BaseUrl}/api/project/finishResetProject/{projectConfig.Code}", null);

await WaitForHgRefreshIntervalAsync(); // TODO 765: Remove this

// Step 2: verify project is now empty, i.e. tip is "0000000..."
response = await _adminApiTester.HttpClient.GetAsync(tipUri.Uri);
jsonResult = await response.Content.ReadFromJsonAsync<JsonObject>();
Expand All @@ -167,6 +169,8 @@ public async Task SendReceiveAfterProjectReset(HgProtocol protocol)
var srResultStep3 = _sendReceiveService.SendReceiveProject(sendReceiveParams, AdminAuth);
_output.WriteLine(srResultStep3);

await WaitForHgRefreshIntervalAsync();

// Step 4: verify project tip is same hash as original project tip
response = await _adminApiTester.HttpClient.GetAsync(tipUri.Uri);
jsonResult = await response.Content.ReadFromJsonAsync<JsonObject>();
Expand Down
2 changes: 1 addition & 1 deletion backend/Testing/Testing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</Otherwise>
</Choose>
<ItemGroup>
<PackageReference Include="TusDotNetClient" Version="1.2.0" />
<PackageReference Include="Squidex.Assets.TusClient" Version="6.6.4" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
Expand Down
3 changes: 3 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"test-flaky": "playwright test --retries=3 -j 30%",
"test-hard": "playwright test --repeat-each=3 -j 30%",
"test-report": "playwright show-report test-results/_html-report",
"_env-comment": "Run any command with .env.local loaded: (e.g. `pnpm run env test-flaky`)",
"env": "dotenvx run --env-file=.env.local -- pnpm",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"test:unit": "vitest",
Expand All @@ -25,6 +27,7 @@
"clean": "rimraf node_modules .svelte-kit"
},
"devDependencies": {
"@dotenvx/dotenvx": "^0.37.0",
"@egoist/tailwindcss-icons": "^1.7.4",
"@eslint/js": "^8.56.0",
"@graphql-codegen/cli": "^5.0.0",
Expand Down
Loading

0 comments on commit 9ff712c

Please sign in to comment.