Skip to content
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

Migration tests #51

Merged
merged 29 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading