Skip to content

Commit 742f398

Browse files
authored
Migration tests (#51)
* Migration tests * Whoops * maybe python was a bad idea * Aha! * Syntax highlighting failed me * Unfuck DB * oh shit i forgot these * ah fuck im too tired for this * mhm logging * Page tests * forgot password * uhhh yeah * shit i forgot to actually run the tests * AHHHH * im gonna go crazy * NOW? PLEASE? * i just want this to work man * i will throw myself off a bridge * i mean it * oh my fucking god all this time it couldn't find the project to run i want to kms * MAYBE?????????????? * why did I design it this way what * OK I FEEL IT * ok last one im going to sleep now * this time fr fr * Testing how an error looks * errr * Finalize testing * Fix warning?
1 parent d2bd94f commit 742f398

16 files changed

+2579
-13
lines changed

.github/workflows/build_and_test.yml

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,34 @@ on:
66
jobs:
77
build:
88
runs-on: ubuntu-latest
9-
9+
1010
env:
1111
Solution_Name: ReplayBrowser.sln
12-
12+
13+
services:
14+
postgres:
15+
image: postgres:latest
16+
env:
17+
POSTGRES_USER: postgres
18+
POSTGRES_PASSWORD: postgres
19+
POSTGRES_DB: ReplayBrowser
20+
ports:
21+
- 5432:5432
22+
options: >-
23+
--health-cmd pg_isready
24+
--health-interval 10s
25+
--health-timeout 5s
26+
--health-retries 5
27+
1328
steps:
29+
# SETUP
30+
1431
- name: Checkout
1532
uses: actions/checkout@v3
1633

34+
- name: Seed database
35+
run: PGPASSWORD='postgres' psql -h localhost -U postgres -d ReplayBrowser -f ./Tools/replaybrowser_ci_seed.sql
36+
1737
- name: Install .NET Core
1838
uses: actions/setup-dotnet@v3
1939
with:
@@ -22,8 +42,38 @@ jobs:
2242
- name: Verify .NET Core version
2343
run: dotnet --version
2444

45+
- name: Install dotnet-ef
46+
run: dotnet tool install --global dotnet-ef
47+
48+
- name: Verify dotnet-ef version
49+
run: dotnet ef --version
50+
51+
- name: Setup Python
52+
uses: actions/setup-python@v4
53+
with:
54+
python-version: '3.x'
55+
56+
- name: Install python dependencies
57+
run: |
58+
python -m pip install --upgrade pip
59+
pip install pyppeteer
60+
2561
- name: Restore NuGet Packages
2662
run: dotnet restore ./ReplayBrowser/ReplayBrowser.csproj
2763

64+
- name: Write appsettings.Secret.json file # This file is used to store the connection string for the database
65+
run: echo "{\"ConnectionStrings\":{\"DefaultConnection\":\"Host=localhost;Port=5432;Database=ReplayBrowser;Username=postgres;Password=postgres\"}}" > ./ReplayBrowser/appsettings.Secret.json
66+
67+
# BUILD AND TEST
68+
2869
- name: Build Solution
29-
run: dotnet build ./ReplayBrowser/ReplayBrowser.csproj
70+
run: dotnet build ./ReplayBrowser/ReplayBrowser.csproj --no-restore --configuration Testing
71+
72+
- name: Check pending migrations
73+
run: python ./Tools/check_model_pending_changes.py # Exits with 1 if there are pending migrations
74+
75+
- name: Run Migrations
76+
run: dotnet ef database update --project ./ReplayBrowser/ReplayBrowser.csproj --no-build --verbose
77+
78+
- name: Run Tests
79+
run: python ./Tools/test_pages_for_errors.py

ReplayBrowser.sln

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ Global
66
GlobalSection(SolutionConfigurationPlatforms) = preSolution
77
Debug|Any CPU = Debug|Any CPU
88
Release|Any CPU = Release|Any CPU
9+
Testing|Any CPU = Testing|Any CPU
910
EndGlobalSection
1011
GlobalSection(ProjectConfigurationPlatforms) = postSolution
1112
{C1E45DF7-3B40-4B1C-9966-35D4C666A735}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1213
{C1E45DF7-3B40-4B1C-9966-35D4C666A735}.Debug|Any CPU.Build.0 = Debug|Any CPU
14+
{C1E45DF7-3B40-4B1C-9966-35D4C666A735}.Testing|Any CPU.ActiveCfg = Testing|Any CPU
15+
{C1E45DF7-3B40-4B1C-9966-35D4C666A735}.Testing|Any CPU.Build.0 = Testing|Any CPU
1316
{C1E45DF7-3B40-4B1C-9966-35D4C666A735}.Release|Any CPU.ActiveCfg = Release|Any CPU
1417
{C1E45DF7-3B40-4B1C-9966-35D4C666A735}.Release|Any CPU.Build.0 = Release|Any CPU
1518
EndGlobalSection

ReplayBrowser/Controllers/ReplayController.cs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using ReplayBrowser.Data.Models;
77
using ReplayBrowser.Helpers;
88
using ReplayBrowser.Services;
9+
using ReplayBrowser.Services.ReplayParser;
910

1011
namespace ReplayBrowser.Controllers;
1112

@@ -17,12 +18,14 @@ public class ReplayController : Controller
1718
private readonly ReplayDbContext _dbContext;
1819
private readonly AccountService _accountService;
1920
private readonly ReplayHelper _replayHelper;
21+
private readonly ReplayParserService _replayParserService;
2022

21-
public ReplayController(ReplayDbContext dbContext, AccountService accountService, ReplayHelper replayHelper)
23+
public ReplayController(ReplayDbContext dbContext, AccountService accountService, ReplayHelper replayHelper, ReplayParserService replayParserService)
2224
{
2325
_dbContext = dbContext;
2426
_accountService = accountService;
2527
_replayHelper = replayHelper;
28+
_replayParserService = replayParserService;
2629
}
2730

2831
[HttpGet("{replayId}")]
@@ -39,6 +42,42 @@ public async Task<IActionResult> GetReplay(int replayId)
3942
return Ok(replay);
4043
}
4144

45+
/// <summary>
46+
/// Tells the server to parse a replay based on a provided url.
47+
/// </summary>
48+
/// <returns></returns>
49+
[HttpPost("replay/parse")]
50+
public async Task<IActionResult> ParseReplay(
51+
[FromQuery] string url
52+
)
53+
{
54+
if (User.Identity is null || !User.Identity.IsAuthenticated)
55+
{
56+
return Unauthorized();
57+
}
58+
59+
var guidRequestor = AccountHelper.GetAccountGuid(User);
60+
61+
var requestor = await _dbContext.Accounts
62+
.Include(a => a.Settings)
63+
.Include(a => a.History)
64+
.FirstOrDefaultAsync(a => a.Guid == guidRequestor);
65+
66+
if (requestor == null)
67+
{
68+
return NotFound("Account is null. This should not happen.");
69+
}
70+
71+
if (!requestor.IsAdmin)
72+
return Unauthorized("You are not an admin.");
73+
74+
ReplayParserService.Queue.Add(url);
75+
if (_replayParserService.RequestQueueConsumption())
76+
return Ok();
77+
78+
return BadRequest("The replay parser is currently busy.");
79+
}
80+
4281
/// <summary>
4382
/// Deletes all stored profiles for a server group.
4483
/// </summary>

0 commit comments

Comments
 (0)