-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
49 changed files
with
287 additions
and
274 deletions.
There are no files selected for viewing
This file contains 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,18 @@ | ||
name: GitHub Actions Demo | ||
run-name: ${{ github.actor }} is testing out GitHub Actions 🚀 | ||
on: [push] | ||
jobs: | ||
Explore-GitHub-Actions: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." | ||
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" | ||
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." | ||
- name: Check out repository code | ||
uses: actions/checkout@v3 | ||
- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." | ||
- run: echo "🖥️ The workflow is now ready to test your code on the runner." | ||
- name: List files in the repository | ||
run: | | ||
ls ${{ github.workspace }} | ||
- run: echo "🍏 This job's status is ${{ job.status }}." |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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 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,70 @@ | ||
using System.Data.Common; | ||
using growth.Backend.Data; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Mvc.Testing; | ||
using Microsoft.AspNetCore.TestHost; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Npgsql; | ||
using Respawn; | ||
using Testcontainers.PostgreSql; | ||
|
||
namespace Growth.Tests; | ||
|
||
public class GrowthApiFactory : WebApplicationFactory<Program>, IAsyncLifetime | ||
{ | ||
private readonly PostgreSqlContainer _dbContainer = new PostgreSqlBuilder() | ||
.WithImage("postgres:latest") | ||
.WithDatabase("growth_db") | ||
.WithUsername("postgres") | ||
.WithPassword("postgres") | ||
.Build(); | ||
|
||
private DbConnection _dbConnection = default!; | ||
private Respawner _respawner = default!; | ||
|
||
public HttpClient HttpClient { get; private set; } = default!; | ||
|
||
protected void ConfigureWebHost(IWebHostBuilder builder) | ||
{ | ||
builder.ConfigureTestServices(services => | ||
{ | ||
var descriptor = services.SingleOrDefault(s => s.ServiceType == typeof(DbContextOptions<GrowthDbContext>)); | ||
|
||
if (descriptor is not null) | ||
{ | ||
services.Remove(descriptor); | ||
} | ||
|
||
services.AddDbContext<GrowthDbContext>(options => | ||
{ | ||
options.UseNpgsql(_dbContainer.GetConnectionString()); | ||
}); | ||
}); | ||
|
||
} | ||
|
||
public async Task InitializeAsync() | ||
{ | ||
await _dbContainer.StartAsync(); | ||
_dbConnection = new NpgsqlConnection(_dbContainer.GetConnectionString()); | ||
|
||
HttpClient = CreateClient(); | ||
await _dbConnection.OpenAsync(); | ||
_respawner = await Respawner.CreateAsync(_dbConnection, new RespawnerOptions | ||
{ | ||
DbAdapter = DbAdapter.Postgres, | ||
SchemasToInclude = new[] { "public" } | ||
}); | ||
} | ||
|
||
public async Task ResetDatabaseAsync() | ||
{ | ||
await _respawner.ResetAsync(_dbConnection); | ||
} | ||
|
||
public async Task DisposeAsync() | ||
{ | ||
await _dbContainer.StopAsync(); | ||
} | ||
} |
This file contains 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 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 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 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 |
---|---|---|
@@ -1,36 +1,22 @@ | ||
using growth.Backend.Features.Audio; | ||
using growth.Backend.Features.Entry; | ||
using growth.Backend.Features.Entry.Endpoints; | ||
using growth.Backend.Features.Journals.Endpoints; | ||
using growth.Backend.Features.Motivation; | ||
using growth.Backend.Features.Unsplash; | ||
using growth.Backend.Shared; | ||
|
||
namespace growth.Backend.Extensions; | ||
|
||
public static class EndpointExtensions | ||
{ | ||
public static WebApplication MapEndpoints(this WebApplication app) | ||
{ | ||
app.MapGroup("/journal").WithTags("Journal") | ||
.MapGetJournal() | ||
.MapGetJournals() | ||
.MapCreateJournal() | ||
.MapDeleteJournal(); | ||
|
||
app.MapGroup("/entry").WithTags("JournalEntry") | ||
.MapGetJournalEntry() | ||
.MapGetJournalEntries() | ||
.MapCreateJournalEntry() | ||
.MapUpdateJournalEntry() | ||
.MapDeleteJournalEntry(); | ||
var endpoints = typeof(Program).Assembly | ||
.GetTypes() | ||
.Where(t => t.IsAssignableTo(typeof(IEndpoint)) && !t.IsAbstract && !t.IsInterface) | ||
.Select(Activator.CreateInstance) | ||
.Cast<IEndpoint>(); | ||
|
||
app.MapGroup("/audio").MapGetAudioFiles(); | ||
app.MapGroup("/photos").MapGetPhotos().WithTags("Photos"); | ||
app.MapGroup("/quote").MapGetQuote(); | ||
foreach (var endpoint in endpoints) | ||
{ | ||
endpoint.Map(app); | ||
} | ||
|
||
app.MapGroup("/image").WithTags("Image") | ||
.MapGetPhoto() | ||
.MapSelectPhoto(); | ||
return app; | ||
} | ||
} |
This file contains 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,17 @@ | ||
using growth.Backend.Data; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace growth.Backend.Extensions; | ||
|
||
public static class ServiceExtensions | ||
{ | ||
public static void ApplyMigrations(this IApplicationBuilder app) | ||
{ | ||
using var serviceScope = app.ApplicationServices | ||
.GetRequiredService<IServiceScopeFactory>() | ||
.CreateScope(); | ||
|
||
using var context = serviceScope.ServiceProvider.GetService<GrowthDbContext>(); | ||
context?.Database.Migrate(); | ||
} | ||
} |
This file contains 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
Oops, something went wrong.