Added unit tests for API and Web App
Also updated backend to use .NET6
This commit is contained in:
@ -13,7 +13,7 @@
|
|||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.13" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.13" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.14" />
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.14" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.0.0" />
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.0.0" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.17">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.14">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netstandard2.1</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|||||||
@ -12,6 +12,7 @@ namespace YABA.Data.Context
|
|||||||
{
|
{
|
||||||
public class YABABaseContext : DbContext
|
public class YABABaseContext : DbContext
|
||||||
{
|
{
|
||||||
|
public YABABaseContext() : base() { }
|
||||||
public YABABaseContext(DbContextOptions<YABABaseContext> options) : base(options) { }
|
public YABABaseContext(DbContextOptions<YABABaseContext> options) : base(options) { }
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
@ -47,10 +48,10 @@ namespace YABA.Data.Context
|
|||||||
.IsUnique();
|
.IsUnique();
|
||||||
}
|
}
|
||||||
|
|
||||||
public DbSet<Bookmark> Bookmarks { get; set; }
|
public virtual DbSet<Bookmark> Bookmarks { get; set; }
|
||||||
public DbSet<Tag> Tags { get; set; }
|
public virtual DbSet<Tag> Tags { get; set; }
|
||||||
public DbSet<BookmarkTag> BookmarkTags { get; set; }
|
public virtual DbSet<BookmarkTag> BookmarkTags { get; set; }
|
||||||
public DbSet<User> Users { get; set; }
|
public virtual DbSet<User> Users { get; set; }
|
||||||
|
|
||||||
private static LambdaExpression ConvertFilterExpression<TInterface>(
|
private static LambdaExpression ConvertFilterExpression<TInterface>(
|
||||||
Expression<Func<TInterface, bool>> filterExpression,
|
Expression<Func<TInterface, bool>> filterExpression,
|
||||||
|
|||||||
@ -4,6 +4,7 @@ namespace YABA.Data.Context
|
|||||||
{
|
{
|
||||||
public class YABAReadOnlyContext : YABABaseContext
|
public class YABAReadOnlyContext : YABABaseContext
|
||||||
{
|
{
|
||||||
|
public YABAReadOnlyContext() : base() { }
|
||||||
public YABAReadOnlyContext(DbContextOptions<YABABaseContext> options) : base(options)
|
public YABAReadOnlyContext(DbContextOptions<YABABaseContext> options) : base(options)
|
||||||
{
|
{
|
||||||
ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
|
ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
|
||||||
|
|||||||
@ -9,6 +9,8 @@ namespace YABA.Data.Context
|
|||||||
{
|
{
|
||||||
public class YABAReadWriteContext : YABABaseContext
|
public class YABAReadWriteContext : YABABaseContext
|
||||||
{
|
{
|
||||||
|
public YABAReadWriteContext() : base() { }
|
||||||
|
|
||||||
public YABAReadWriteContext(DbContextOptions<YABABaseContext> options) : base(options)
|
public YABAReadWriteContext(DbContextOptions<YABABaseContext> options) : base(options)
|
||||||
{
|
{
|
||||||
ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.TrackAll;
|
ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.TrackAll;
|
||||||
|
|||||||
@ -1,20 +1,20 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netstandard2.1</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="EFCore.NamingConventions" Version="5.0.2" />
|
<PackageReference Include="EFCore.NamingConventions" Version="6.0.0" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.17" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.14" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.17">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.14">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
|
||||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.10" />
|
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.8" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netstandard2.1</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|||||||
67
YABA.Service.Tests/UserServiceTests/IsUserRegisteredTests.cs
Normal file
67
YABA.Service.Tests/UserServiceTests/IsUserRegisteredTests.cs
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Moq;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Xunit;
|
||||||
|
using YABA.Data.Context;
|
||||||
|
using YABA.Models;
|
||||||
|
|
||||||
|
namespace YABA.Service.Tests
|
||||||
|
{
|
||||||
|
public partial class UserServiceTests
|
||||||
|
{
|
||||||
|
[Theory]
|
||||||
|
[ClassData(typeof(IsUserRegistedTestData))]
|
||||||
|
public void IsUserRegistedTests(IsUserRegisteredScenario scenario)
|
||||||
|
{
|
||||||
|
var usersDbSet = new Mock<DbSet<User>>();
|
||||||
|
usersDbSet.As<IQueryable<User>>().Setup(m => m.Provider).Returns(scenario.Users.Provider);
|
||||||
|
usersDbSet.As<IQueryable<User>>().Setup(m => m.Expression).Returns(scenario.Users.Expression);
|
||||||
|
usersDbSet.As<IQueryable<User>>().Setup(m => m.ElementType).Returns(scenario.Users.ElementType);
|
||||||
|
usersDbSet.As<IQueryable<User>>().Setup(m => m.GetEnumerator()).Returns(() => scenario.Users.GetEnumerator());
|
||||||
|
|
||||||
|
var mockContext = new Mock<YABAReadOnlyContext>();
|
||||||
|
mockContext.Setup(x => x.Users).Returns(usersDbSet.Object);
|
||||||
|
|
||||||
|
var userService = new UserService(mockContext.Object, null, null, null);
|
||||||
|
var actualIsUserRegistered = userService.IsUserRegistered(scenario.AuthProviderId);
|
||||||
|
Assert.Equal(scenario.ExpectedResult, actualIsUserRegistered);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class IsUserRegistedTestData : TheoryData<IsUserRegisteredScenario>
|
||||||
|
{
|
||||||
|
public IsUserRegistedTestData()
|
||||||
|
{
|
||||||
|
Add(new IsUserRegisteredScenario
|
||||||
|
{
|
||||||
|
Users = new List<User>
|
||||||
|
{
|
||||||
|
new User { Id = 1, Auth0Id = "auth0|TestId1" },
|
||||||
|
}.AsQueryable(),
|
||||||
|
AuthProviderId = "auth0|TestId1",
|
||||||
|
ExpectedResult = true
|
||||||
|
});
|
||||||
|
|
||||||
|
// Not Found
|
||||||
|
Add(new IsUserRegisteredScenario
|
||||||
|
{
|
||||||
|
Users = new List<User>
|
||||||
|
{
|
||||||
|
new User { Id = 1, Auth0Id = "auth0|TestId1" },
|
||||||
|
}.AsQueryable(),
|
||||||
|
AuthProviderId = "auth0|TestId2",
|
||||||
|
ExpectedResult = false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class IsUserRegisteredScenario
|
||||||
|
{
|
||||||
|
public IQueryable<User> Users { get; set; }
|
||||||
|
public string AuthProviderId { get; set; }
|
||||||
|
public bool ExpectedResult { get; set; }
|
||||||
|
public bool ActualResult { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
27
YABA.Service.Tests/YABA.Service.Tests.csproj
Normal file
27
YABA.Service.Tests/YABA.Service.Tests.csproj
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
|
||||||
|
<PackageReference Include="Moq" Version="4.18.4" />
|
||||||
|
<PackageReference Include="xunit" Version="2.4.2" />
|
||||||
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="coverlet.collector" Version="3.1.2">
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\YABA.Service\YABA.Service.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netstandard2.1</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|||||||
20
YABA.sln
20
YABA.sln
@ -11,7 +11,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YABA.Data", "YABA.Data\YABA
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YABA.Service", "YABA.Service\YABA.Service.csproj", "{0098D0A8-0273-46F1-9FE7-B0409442251A}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YABA.Service", "YABA.Service\YABA.Service.csproj", "{0098D0A8-0273-46F1-9FE7-B0409442251A}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YABA.Common", "YABA.Common\YABA.Common.csproj", "{CA107B5D-4B8E-4515-8380-CB474C57F79C}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YABA.Common", "YABA.Common\YABA.Common.csproj", "{CA107B5D-4B8E-4515-8380-CB474C57F79C}"
|
||||||
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{17A95D6E-D7F8-40F0-A140-1556492495DB}"
|
||||||
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{0CA49C56-9635-4BA7-A88A-DA16264E2ED2}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YABA.Service.Tests", "YABA.Service.Tests\YABA.Service.Tests.csproj", "{00E8AC4F-B7B3-4DC5-8BA1-BB7DDC4A9071}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -39,10 +45,22 @@ Global
|
|||||||
{CA107B5D-4B8E-4515-8380-CB474C57F79C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{CA107B5D-4B8E-4515-8380-CB474C57F79C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{CA107B5D-4B8E-4515-8380-CB474C57F79C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{CA107B5D-4B8E-4515-8380-CB474C57F79C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{CA107B5D-4B8E-4515-8380-CB474C57F79C}.Release|Any CPU.Build.0 = Release|Any CPU
|
{CA107B5D-4B8E-4515-8380-CB474C57F79C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{00E8AC4F-B7B3-4DC5-8BA1-BB7DDC4A9071}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{00E8AC4F-B7B3-4DC5-8BA1-BB7DDC4A9071}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{00E8AC4F-B7B3-4DC5-8BA1-BB7DDC4A9071}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{00E8AC4F-B7B3-4DC5-8BA1-BB7DDC4A9071}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
|
GlobalSection(NestedProjects) = preSolution
|
||||||
|
{97FC2A4F-B663-43B0-987D-DC3EA7ADD66C} = {17A95D6E-D7F8-40F0-A140-1556492495DB}
|
||||||
|
{DDA30925-F844-426B-8B90-3E6E258BD407} = {17A95D6E-D7F8-40F0-A140-1556492495DB}
|
||||||
|
{461E9D5A-3C06-4CCB-A466-76BBB9BB7BF5} = {17A95D6E-D7F8-40F0-A140-1556492495DB}
|
||||||
|
{0098D0A8-0273-46F1-9FE7-B0409442251A} = {17A95D6E-D7F8-40F0-A140-1556492495DB}
|
||||||
|
{CA107B5D-4B8E-4515-8380-CB474C57F79C} = {17A95D6E-D7F8-40F0-A140-1556492495DB}
|
||||||
|
{00E8AC4F-B7B3-4DC5-8BA1-BB7DDC4A9071} = {0CA49C56-9635-4BA7-A88A-DA16264E2ED2}
|
||||||
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {8B677B7D-5CF6-460E-B4F6-7AF3BD655B12}
|
SolutionGuid = {8B677B7D-5CF6-460E-B4F6-7AF3BD655B12}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
|
|||||||
1056
yaba-web/package-lock.json
generated
1056
yaba-web/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -43,5 +43,8 @@
|
|||||||
"last 1 firefox version",
|
"last 1 firefox version",
|
||||||
"last 1 safari version"
|
"last 1 safari version"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"jest": "^27.5.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
30
yaba-web/src/tests/utils/arrayHelper.test.js
Normal file
30
yaba-web/src/tests/utils/arrayHelper.test.js
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import { isSubset } from "../../utils/arrayHelper";
|
||||||
|
|
||||||
|
describe("utils/arrayHelper", () => {
|
||||||
|
describe("isSubset", () => {
|
||||||
|
const testCases = [
|
||||||
|
{
|
||||||
|
parentArray: ["test1", "test2", "test3", "test4"],
|
||||||
|
subsetArray: ["test1"],
|
||||||
|
expected: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
parentArray: ["test1", "test2", "test3", "test4"],
|
||||||
|
subsetArray: ["test5"],
|
||||||
|
expected: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
parentArray: ["test1", "test2", "test3", "test4"],
|
||||||
|
subsetArray: ["test2", "test4"],
|
||||||
|
expected: true
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
testCases.forEach(test => {
|
||||||
|
it(`[${test.subsetArray.join(", ")}] should be a subset of [${test.parentArray.join(", ")}] which is ${test.expected}`, () => {
|
||||||
|
const actual = isSubset(test.parentArray, test.subsetArray);
|
||||||
|
expect(actual).toEqual(test.expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user