Skip to content

Commit 0b73e9f

Browse files
authored
Test/be (#23)
* test: be * test: be * chore: test controller * fix: ci * fix: ci * chore: test booking * fix: fmt * test: be
1 parent 3155e3c commit 0b73e9f

File tree

31 files changed

+697
-96
lines changed

31 files changed

+697
-96
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,7 @@ jobs:
3131
run: dotnet restore src/Evently.Server/Evently.Server.csproj
3232
- name: Build
3333
run: dotnet build --no-restore src/Evently.Server/Evently.Server.csproj
34+
- name: Run .NET Unit Tests
35+
run: dotnet test tests/Evently.Server.Test/Evently.Server.Test.csproj
3436
- name: Test Docker Image
3537
run: docker build --tag=expo-connect/latest --file=src/Evently.Server/Dockerfile .

Evently.slnx

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
<Solution>
2-
<Folder Name="/Solution Items/">
3-
<File Path=".editorconfig" />
4-
<File Path=".gitignore" />
5-
<File Path="Makefile" />
6-
</Folder>
7-
<Folder Name="/src/">
8-
<Project Path="src\evently.client\evently.client.esproj" Type="{54A90642-561A-4BB1-A94E-469ADEE60C69}">
9-
<Configuration Solution="Release|Any CPU" Project="Debug|Any CPU" />
10-
</Project>
11-
<Project Path="src\Evently.Server\Evently.Server.csproj" Type="Classic C#" />
12-
</Folder>
1+
<Solution>
2+
<Folder Name="/Solution Items/">
3+
<File Path=".editorconfig"/>
4+
<File Path=".gitignore"/>
5+
<File Path="Makefile"/>
6+
</Folder>
7+
<Folder Name="/src/">
8+
<Project Path="src\evently.client\evently.client.esproj">
9+
<Configuration Solution="Release|Any CPU" Project="Debug|Any CPU"/>
10+
</Project>
11+
<Project Path="src\Evently.Server\Evently.Server.csproj"/>
12+
</Folder>
13+
<Folder Name="/tests/">
14+
<Project Path="tests\Evently.Server.Test\Evently.Server.Test.csproj" Type="Classic C#"/>
15+
</Folder>
1316
</Solution>

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ test:
55
dotnet test ./tests/Evently.Server.Test/VisualPatron.Server.Test.csproj
66

77
add-migration:
8-
dotnet ef migrations add RenameAccountId --project=src/Evently.Server --context=AppDbContext --output-dir=Common/Adapters/Data/Migrations
8+
dotnet ef migrations add ColCollation --project=src/Evently.Server --context=AppDbContext --output-dir=Common/Adapters/Data/Migrations
99

1010
update-migration:
1111
dotnet ef database update --project=src/Evently.Server --context=AppDbContext

src/Evently.Server/Common/Adapters/Data/Migrations/AppDbContextModelSnapshot.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
161161

162162
b.HasIndex("GatheringId");
163163

164-
b.ToTable("Bookings");
164+
b.ToTable("Bookings", (string)null);
165165

166166
b.HasData(
167167
new
@@ -199,7 +199,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
199199

200200
b.HasKey("CategoryId");
201201

202-
b.ToTable("Categories");
202+
b.ToTable("Categories", (string)null);
203203

204204
b.HasData(
205205
new
@@ -266,7 +266,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
266266

267267
b.HasKey("GatheringId");
268268

269-
b.ToTable("Gatherings");
269+
b.ToTable("Gatherings", (string)null);
270270

271271
b.HasData(
272272
new
@@ -448,7 +448,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
448448

449449
b.HasIndex("CategoryId");
450450

451-
b.ToTable("GatheringCategoryDetails");
451+
b.ToTable("GatheringCategoryDetails", (string)null);
452452

453453
b.HasData(
454454
new

src/Evently.Server/Common/Extensions/ServiceContainerExtensions.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
using Evently.Server.Common.Domains.Models;
22
using Microsoft.Extensions.Options;
3-
using System.Text.RegularExpressions;
43

54
namespace Evently.Server.Common.Extensions;
65

7-
public static partial class ServiceContainerExtensions {
6+
public static class ServiceContainerExtensions {
87
public static IOptions<Settings> LoadAppConfiguration(this IServiceCollection services,
98
ConfigurationManager configuration) {
109
// load .env variables, in addition to appsettings.json that is loaded by default
@@ -20,8 +19,4 @@ public static IOptions<Settings> LoadAppConfiguration(this IServiceCollection se
2019
IOptions<Settings> options = Options.Create(settings);
2120
return options;
2221
}
23-
24-
25-
[GeneratedRegex("postgres://(.*):(.*)@(.*):(.*)/(.*)")]
26-
private static partial Regex HerokuDbRegex();
2722
}

src/Evently.Server/Features/Bookings/Controllers/BookingsController.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,18 @@ public async Task<ActionResult<Booking>> CreateBooking([FromBody] BookingReqDto
6767
[HttpPut("{bookingId}", Name = "UpdateBooking")]
6868
public async Task<ActionResult> UpdateBooking(string bookingId,
6969
[FromBody] BookingReqDto bookingReqDto) {
70-
bool isExist = await bookingService.Exists(bookingId);
71-
if (!isExist) {
70+
Booking? booking = await bookingService.GetBooking(bookingId);
71+
if (booking is null) {
7272
return NotFound();
7373
}
7474

75-
Booking booking = await bookingService.UpdateBooking(bookingId, bookingReqDto);
75+
bool isAuth = await this.IsResourceOwner(booking.AttendeeId);
76+
logger.LogInformation("isAuth: {}", isAuth);
77+
if (!isAuth) {
78+
return Forbid();
79+
}
80+
81+
booking = await bookingService.UpdateBooking(bookingId, bookingReqDto);
7682
return Ok(booking);
7783
}
7884

src/evently.client/README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ This template provides a minimal setup to get React working in Vite with HMR and
44

55
Currently, two official plugins are available:
66

7-
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) for Fast Refresh
8-
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
7+
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react)
8+
uses [Babel](https://babeljs.io/) for Fast Refresh
9+
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc)
10+
uses [SWC](https://swc.rs/) for Fast Refresh
911

1012
## Expanding the ESLint configuration
1113

@@ -39,7 +41,10 @@ export default tseslint.config([
3941
]);
4042
```
4143

42-
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
44+
You can also
45+
install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x)
46+
and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom)
47+
for React-specific lint rules:
4348

4449
```js
4550
// eslint.config.js
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<Project Sdk="Microsoft.VisualStudio.JavaScript.Sdk/1.0.2125207">
2-
<Target Name="InstallWithPnpm" BeforeTargets="BeforeBuild">
3-
<Exec Command="pnpm install"/>
4-
</Target>
5-
<PropertyGroup>
6-
<ShouldRunNpmInstall>false</ShouldRunNpmInstall>
7-
<StartupCommand>pnpm run dev</StartupCommand>
8-
<JavaScriptTestRoot>src\</JavaScriptTestRoot>
9-
<JavaScriptTestFramework>Vitest</JavaScriptTestFramework>
10-
<!-- Allows the build (or compile) script located on package.json to run on Build -->
11-
<ShouldRunBuildScript>false</ShouldRunBuildScript>
12-
<!-- Must include BuildCommand - weird bug with msft where if wwwroot folder contains exisiting files, npm run build will not automatically run if <BuildCommand /> is excluded. -->
13-
<BuildCommand>pnpm run build</BuildCommand>
14-
<PublishCommand>pnpm run build</PublishCommand>
15-
<!-- Folder where production build objects will be placed -->
16-
<BuildOutputFolder>$(MSBuildProjectDirectory)\dist</BuildOutputFolder>
17-
</PropertyGroup>
2+
<Target Name="InstallWithPnpm" BeforeTargets="BeforeBuild">
3+
<Exec Command="pnpm install"/>
4+
</Target>
5+
<PropertyGroup>
6+
<ShouldRunNpmInstall>false</ShouldRunNpmInstall>
7+
<StartupCommand>pnpm run dev</StartupCommand>
8+
<JavaScriptTestRoot>src\</JavaScriptTestRoot>
9+
<JavaScriptTestFramework>Vitest</JavaScriptTestFramework>
10+
<!-- Allows the build (or compile) script located on package.json to run on Build -->
11+
<ShouldRunBuildScript>false</ShouldRunBuildScript>
12+
<!-- Must include BuildCommand - weird bug with msft where if wwwroot folder contains exisiting files, npm run build will not automatically run if <BuildCommand /> is excluded. -->
13+
<BuildCommand>pnpm run build</BuildCommand>
14+
<PublishCommand>pnpm run build</PublishCommand>
15+
<!-- Folder where production build objects will be placed -->
16+
<BuildOutputFolder>$(MSBuildProjectDirectory)\dist</BuildOutputFolder>
17+
</PropertyGroup>
1818
</Project>

src/evently.client/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<!doctype html>
2-
<html lang="en" data-theme="dark">
2+
<html data-theme="dark" lang="en">
33
<head>
44
<meta charset="UTF-8" />
5-
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
5+
<link href="/vite.svg" rel="icon" type="image/svg+xml" />
66
<meta
7-
name="viewport"
87
content="height=device-height, width=device-width, initial-scale=1.0, minimum-scale=1.0"
8+
name="viewport"
99
/>
1010
<title>Evently</title>
1111
</head>
1212
<body>
1313
<div id="root"></div>
14-
<script type="module" src="/src/main.tsx"></script>
14+
<script src="/src/main.tsx" type="module"></script>
1515
</body>
1616
</html>

src/evently.client/public/vite.svg

Lines changed: 18 additions & 1 deletion
Loading

0 commit comments

Comments
 (0)