Skip to content

Commit

Permalink
Migration tests (#51)
Browse files Browse the repository at this point in the history
* 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?
  • Loading branch information
Simyon264 authored Aug 26, 2024
1 parent d2bd94f commit 742f398
Show file tree
Hide file tree
Showing 16 changed files with 2,579 additions and 13 deletions.
56 changes: 53 additions & 3 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,34 @@ on:
jobs:
build:
runs-on: ubuntu-latest

env:
Solution_Name: ReplayBrowser.sln


services:
postgres:
image: postgres:latest
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: ReplayBrowser
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
# SETUP

- name: Checkout
uses: actions/checkout@v3

- name: Seed database
run: PGPASSWORD='postgres' psql -h localhost -U postgres -d ReplayBrowser -f ./Tools/replaybrowser_ci_seed.sql

- name: Install .NET Core
uses: actions/setup-dotnet@v3
with:
Expand All @@ -22,8 +42,38 @@ jobs:
- name: Verify .NET Core version
run: dotnet --version

- name: Install dotnet-ef
run: dotnet tool install --global dotnet-ef

- name: Verify dotnet-ef version
run: dotnet ef --version

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Install python dependencies
run: |
python -m pip install --upgrade pip
pip install pyppeteer
- name: Restore NuGet Packages
run: dotnet restore ./ReplayBrowser/ReplayBrowser.csproj

- name: Write appsettings.Secret.json file # This file is used to store the connection string for the database
run: echo "{\"ConnectionStrings\":{\"DefaultConnection\":\"Host=localhost;Port=5432;Database=ReplayBrowser;Username=postgres;Password=postgres\"}}" > ./ReplayBrowser/appsettings.Secret.json

# BUILD AND TEST

- name: Build Solution
run: dotnet build ./ReplayBrowser/ReplayBrowser.csproj
run: dotnet build ./ReplayBrowser/ReplayBrowser.csproj --no-restore --configuration Testing

- name: Check pending migrations
run: python ./Tools/check_model_pending_changes.py # Exits with 1 if there are pending migrations

- name: Run Migrations
run: dotnet ef database update --project ./ReplayBrowser/ReplayBrowser.csproj --no-build --verbose

- name: Run Tests
run: python ./Tools/test_pages_for_errors.py
3 changes: 3 additions & 0 deletions ReplayBrowser.sln
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
Testing|Any CPU = Testing|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C1E45DF7-3B40-4B1C-9966-35D4C666A735}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C1E45DF7-3B40-4B1C-9966-35D4C666A735}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C1E45DF7-3B40-4B1C-9966-35D4C666A735}.Testing|Any CPU.ActiveCfg = Testing|Any CPU
{C1E45DF7-3B40-4B1C-9966-35D4C666A735}.Testing|Any CPU.Build.0 = Testing|Any CPU
{C1E45DF7-3B40-4B1C-9966-35D4C666A735}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C1E45DF7-3B40-4B1C-9966-35D4C666A735}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
Expand Down
41 changes: 40 additions & 1 deletion ReplayBrowser/Controllers/ReplayController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using ReplayBrowser.Data.Models;
using ReplayBrowser.Helpers;
using ReplayBrowser.Services;
using ReplayBrowser.Services.ReplayParser;

namespace ReplayBrowser.Controllers;

Expand All @@ -17,12 +18,14 @@ public class ReplayController : Controller
private readonly ReplayDbContext _dbContext;
private readonly AccountService _accountService;
private readonly ReplayHelper _replayHelper;
private readonly ReplayParserService _replayParserService;

public ReplayController(ReplayDbContext dbContext, AccountService accountService, ReplayHelper replayHelper)
public ReplayController(ReplayDbContext dbContext, AccountService accountService, ReplayHelper replayHelper, ReplayParserService replayParserService)
{
_dbContext = dbContext;
_accountService = accountService;
_replayHelper = replayHelper;
_replayParserService = replayParserService;
}

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

/// <summary>
/// Tells the server to parse a replay based on a provided url.
/// </summary>
/// <returns></returns>
[HttpPost("replay/parse")]
public async Task<IActionResult> ParseReplay(
[FromQuery] string url
)
{
if (User.Identity is null || !User.Identity.IsAuthenticated)
{
return Unauthorized();
}

var guidRequestor = AccountHelper.GetAccountGuid(User);

var requestor = await _dbContext.Accounts
.Include(a => a.Settings)
.Include(a => a.History)
.FirstOrDefaultAsync(a => a.Guid == guidRequestor);

if (requestor == null)
{
return NotFound("Account is null. This should not happen.");
}

if (!requestor.IsAdmin)
return Unauthorized("You are not an admin.");

ReplayParserService.Queue.Add(url);
if (_replayParserService.RequestQueueConsumption())
return Ok();

return BadRequest("The replay parser is currently busy.");
}

/// <summary>
/// Deletes all stored profiles for a server group.
/// </summary>
Expand Down
Loading

0 comments on commit 742f398

Please sign in to comment.