-
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.
* Add `KycWebHook` lambda * - install KYC.DataBase package - add input model for lambda - cw input * update lambda function * add tests * fix test, cleanup tests * Create nuget.config (#38)
- Loading branch information
Showing
9 changed files
with
182 additions
and
0 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
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,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<packageSources> | ||
<add key="NuGet official package source" value="https://api.nuget.org/v3/index.json" /> | ||
<add key="Github" value="https://nuget.pkg.github.com/The-Poolz/index.json" /> | ||
</packageSources> | ||
<packageSourceCredentials> | ||
<Github> | ||
<add key="Username" value="%GITHUB_PACKAGE_USER_NAME%" /> | ||
<add key="ClearTextPassword" value="%GITHUB_PACKAGE_TOKEN%" /> | ||
</Github> | ||
</packageSourceCredentials> | ||
</configuration> |
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 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> | ||
<AWSProjectType>Lambda</AWSProjectType> | ||
<!-- This property makes the build directory similar to a publish directory and helps the AWS .NET Lambda Mock Test Tool find project dependencies. --> | ||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> | ||
<!-- Generate ready to run images during publishing to improve cold start time. --> | ||
<PublishReadyToRun>true</PublishReadyToRun> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Amazon.Lambda.Core" Version="2.1.0" /> | ||
<PackageReference Include="Amazon.Lambda.Serialization.Json" Version="2.1.0" /> | ||
<PackageReference Include="KYC.DataBase" Version="1.0.2" /> | ||
</ItemGroup> | ||
</Project> |
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,41 @@ | ||
using System.Net; | ||
using KYC.DataBase; | ||
using KycWebHook.Models; | ||
using Amazon.Lambda.Core; | ||
using Newtonsoft.Json.Linq; | ||
|
||
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))] | ||
|
||
namespace KycWebHook; | ||
|
||
public class LambdaFunction | ||
{ | ||
private readonly KycDbContext context; | ||
|
||
public LambdaFunction() | ||
: this(new KycDbContext()) | ||
{ } | ||
|
||
public LambdaFunction(KycDbContext context) | ||
{ | ||
this.context = context; | ||
} | ||
|
||
public async Task<int> RunAsync(HttpResponse httpResponse) | ||
{ | ||
Console.WriteLine(JToken.FromObject(httpResponse)); | ||
|
||
var user = context.Users.FirstOrDefault(x => x.RecordId == httpResponse.RecordId); | ||
if (user == null) | ||
{ | ||
context.Users.Add(httpResponse); | ||
} | ||
else | ||
{ | ||
context.Users.Update(httpResponse); | ||
} | ||
await context.SaveChangesAsync(); | ||
|
||
return (int)HttpStatusCode.OK; | ||
} | ||
} |
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,8 @@ | ||
using KYC.DataBase.Models; | ||
|
||
namespace KycWebHook.Models; | ||
|
||
public class HttpResponse : User | ||
{ | ||
public string Event { get; set; } = null!; | ||
} |
10 changes: 10 additions & 0 deletions
10
src/KYC.DataBase/KycWebHook/Properties/launchSettings.json
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,10 @@ | ||
{ | ||
"profiles": { | ||
"Mock Lambda Test Tool": { | ||
"commandName": "Executable", | ||
"commandLineArgs": "--port 5050", | ||
"workingDirectory": ".\\bin\\$(Configuration)\\net6.0", | ||
"executablePath": "%USERPROFILE%\\.dotnet\\tools\\dotnet-lambda-test-tool-6.0.exe" | ||
} | ||
} | ||
} |
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,2 @@ | ||
# KycWebHook | ||
|
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,31 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<RootNamespace>KycWebHook.Tests</RootNamespace> | ||
<AssemblyName>KycWebHook.Tests</AssemblyName> | ||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="FluentAssertions" Version="6.11.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" /> | ||
<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.2.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\KYC.DataBase\KycWebHook\KycWebHook.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,45 @@ | ||
using ConfiguredSqlConnection.Extensions; | ||
using Xunit; | ||
using FluentAssertions; | ||
using KYC.DataBase; | ||
using KycWebHook.Models; | ||
using System.Net; | ||
|
||
namespace KycWebHook.Tests; | ||
|
||
public class LambdaFunctionTests | ||
{ | ||
private readonly HttpResponse httpResponse = new() | ||
{ | ||
Guid = "614967cde3227d00125ebc4f", | ||
Status = "deleted", | ||
ClientId = "client_id", | ||
Event = "user.deleted", | ||
RecordId = "5ffffb44baaaaf001236b1d1", | ||
RefId = null | ||
}; | ||
|
||
[Fact] | ||
public async Task RunAsync_WhenUserNotExist() | ||
{ | ||
var context = new DbContextFactory<KycDbContext>().Create(ContextOption.InMemory, Guid.NewGuid().ToString()); | ||
|
||
var result = await new LambdaFunction(context).RunAsync(httpResponse); | ||
|
||
result.Should().Be((int)HttpStatusCode.OK); | ||
context.Users.Should().HaveCount(1); | ||
} | ||
|
||
[Fact] | ||
public async Task RunAsync_WhenUserExist() | ||
{ | ||
var context = new DbContextFactory<KycDbContext>().Create(ContextOption.InMemory, Guid.NewGuid().ToString()); | ||
context.Users.Add(httpResponse); | ||
await context.SaveChangesAsync(); | ||
|
||
var result = await new LambdaFunction(context).RunAsync(httpResponse); | ||
|
||
result.Should().Be((int)HttpStatusCode.OK); | ||
context.Users.First().Should().BeEquivalentTo(httpResponse); | ||
} | ||
} |