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

(#149) Posts service tests #165

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7a78361
(#149) Create the test project
olegkiprik May 18, 2024
83ddce6
(#149) Delete .vscode directory
olegkiprik May 18, 2024
5001127
(#149) Update the project structure
olegkiprik May 19, 2024
6a6bd7f
(#149) Prepare the project for implementing tests
olegkiprik May 19, 2024
d3fc2ed
(#149) Add the first test
olegkiprik May 19, 2024
4dd08e2
(#149) Add tests for command and event handlers
olegkiprik May 20, 2024
faa4595
(#149) Add test that checks repo update
olegkiprik May 20, 2024
7809d99
(#149) udpat the test-build script
SaintAngeLs May 20, 2024
f0b78c9
(#149) udpdate the deployment script
SaintAngeLs May 20, 2024
60d80bd
Merge remote-tracking branch 'remotes/origin/dev' into posts_service_…
SaintAngeLs May 22, 2024
38f67b3
(#149) conflics resolve
SaintAngeLs May 26, 2024
310d4e6
(#149) Application: add Queries and Extensions test coverage exclusions
olegkiprik May 26, 2024
d462141
(#149) Core: test InvalidAggregatedException, InvalidPostPublishDateE…
olegkiprik May 26, 2024
ee15935
(#149) Infrastructure: add extension test coverage exclusion
olegkiprik May 26, 2024
52c9cd0
(#149) Infrastructure: add Context test coverage exclusions
olegkiprik May 26, 2024
c88b7b7
(#149) Infrastructure: remove IdentityContext test coverage exclusion
olegkiprik May 26, 2024
e878579
(#149) Delete draft comments
olegkiprik May 26, 2024
cf80f06
(#149) conflics resolve
olegkiprik May 25, 2024
0cf9568
(#149) exclude logger related files from Infrastructure
olegkiprik May 25, 2024
17f4fa7
(#149) Add additional test coverage exclusions
olegkiprik May 25, 2024
560d174
(#149) Add additional test coverage exclusions
olegkiprik May 25, 2024
bbde623
(#149) Add event rejected test coverage exclusions
olegkiprik May 26, 2024
663ca7d
(#149) Add post state updater worker tests
olegkiprik May 26, 2024
3d235b6
(#149) Add UpdatePostsStateHandlerTest
olegkiprik May 26, 2024
ae72fe1
(#149) Add ChangePostStateHandler message broker test
olegkiprik May 26, 2024
4b8ca3c
(#149) Update tests
olegkiprik May 26, 2024
487c62a
Merge pull request #191 from SaintAngeLs/posts_service_tests_2
SaintAngeLs May 26, 2024
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
4 changes: 3 additions & 1 deletion .github/workflows/build_microservices.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jobs:
- project: 'MiniSpace.APIGateway/src/MiniSpace.APIGateway'
- project: 'MiniSpace.Services.Identity/src/MiniSpace.Services.Identity.Api'
test_dir: 'MiniSpace.Services.Identity/tests'
- project: 'MiniSpace.Services.Posts/src/MiniSpace.Services.Posts.Api'
test_dir: 'MiniSpace.Services.Posts/tests'
- project: 'MiniSpace.Services.Comments/src/MiniSpace.Services.Comments.Api'
test_dir: 'MiniSpace.Services.Comments/tests'
- project: 'MiniSpace.Web/src/MiniSpace.Web'
Expand Down Expand Up @@ -53,6 +55,6 @@ jobs:
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: '**/coverage.cobertura.xml'
slug: SaintAngeLs/p_software_engineering_2
slug: SaintAngeLs/distributed_minispace
commit: ${{ github.event.pull_request.base.sha }}
# fail_ci_if_error: true
4 changes: 2 additions & 2 deletions .github/workflows/cloud_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: Deploy to Cloud
on:
push:
branches:
- dev
- main
pull_request:
branches:
- dev
- main

jobs:
deploy:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
[assembly: System.Reflection.AssemblyCompanyAttribute("MiniSpace.Services.Notifications.Api")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+e469fbdaa8f94ad32f18bc8ef20510fd62b15985")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+60d80bd60074e10f1cb39a7857095b65f8213b6b")]
[assembly: System.Reflection.AssemblyProductAttribute("MiniSpace.Services.Notifications.Api")]
[assembly: System.Reflection.AssemblyTitleAttribute("MiniSpace.Services.Notifications.Api")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2d6a02b206ac77283cc075e6254c51c91df1cc844dbe932e799219bd1858d708
31d3d94a6fa27c086d9707313d1f0be1fb13fd6bcd249b38361e7fac38610470
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
[assembly: System.Reflection.AssemblyCompanyAttribute("MiniSpace.Services.Notifications.Application")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+e469fbdaa8f94ad32f18bc8ef20510fd62b15985")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+60d80bd60074e10f1cb39a7857095b65f8213b6b")]
[assembly: System.Reflection.AssemblyProductAttribute("MiniSpace.Services.Notifications.Application")]
[assembly: System.Reflection.AssemblyTitleAttribute("MiniSpace.Services.Notifications.Application")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
72ac1d3825741bd508e9ff6ffaf58fa81268523d2a753710d887fc83a9d80b9a
8b3e043d4a8610c77bcbe2160d6b95b7942634686dac3d3841cdef59e617bd04
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
[assembly: System.Reflection.AssemblyCompanyAttribute("MiniSpace.Services.Notifications.Core")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+e469fbdaa8f94ad32f18bc8ef20510fd62b15985")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+60d80bd60074e10f1cb39a7857095b65f8213b6b")]
[assembly: System.Reflection.AssemblyProductAttribute("MiniSpace.Services.Notifications.Core")]
[assembly: System.Reflection.AssemblyTitleAttribute("MiniSpace.Services.Notifications.Core")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
af7e27a1b036cf20b19f769f736410eb4de82166981876644172854c53396ed6
5dd7b0640cf1bb26d53f06d7da4a1fccb31b33f3ce01be304f8a958930eaee66
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
[assembly: System.Reflection.AssemblyCompanyAttribute("MiniSpace.Services.Notifications.Infrastructure")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+e469fbdaa8f94ad32f18bc8ef20510fd62b15985")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+60d80bd60074e10f1cb39a7857095b65f8213b6b")]
[assembly: System.Reflection.AssemblyProductAttribute("MiniSpace.Services.Notifications.Infrastructure")]
[assembly: System.Reflection.AssemblyTitleAttribute("MiniSpace.Services.Notifications.Infrastructure")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
06935d4026aba0069abdca20ba9959a7f7e14e8e87a965f3b7301324f870eec5
1cdfc024d737e449203c0f0f3550021dfc68bcff58a6f7d5947cc08a0083e939
Binary file not shown.
3 changes: 3 additions & 0 deletions MiniSpace.Services.Posts/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore

# VSCode
.vscode/

# User-specific files
*.suo
*.user
Expand Down
21 changes: 21 additions & 0 deletions MiniSpace.Services.Posts/MiniSpace.Services.Posts.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MiniSpace.Services.Posts.Co
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MiniSpace.Services.Posts.Infrastructure", "src\MiniSpace.Services.Posts.Infrastructure\MiniSpace.Services.Posts.Infrastructure.csproj", "{515F6D6B-FB63-40F7-8173-2B94031F29B1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MiniSpace.Services.Posts.Application.UnitTests", "tests\MiniSpace.Services.Posts.Application.UnitTests\MiniSpace.Services.Posts.Application.UnitTests.csproj", "{63DF71AF-1D31-4A4D-8127-9B8EB359889D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MiniSpace.Services.Posts.Core.UnitTests", "tests\MiniSpace.Services.Posts.Core.UnitTests\MiniSpace.Services.Posts.Core.UnitTests.csproj", "{38556B4C-90E1-453F-8BA7-C0699577A521}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MiniSpace.Services.Posts.Infrastructure.UnitTests", "tests\MiniSpace.Services.Posts.Infrastructure.UnitTests\MiniSpace.Services.Posts.Infrastructure.UnitTests.csproj", "{641E0BF5-8BAA-4ECC-9EA7-18CA3D763166}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -38,11 +44,26 @@ Global
{515F6D6B-FB63-40F7-8173-2B94031F29B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{515F6D6B-FB63-40F7-8173-2B94031F29B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{515F6D6B-FB63-40F7-8173-2B94031F29B1}.Release|Any CPU.Build.0 = Release|Any CPU
{63DF71AF-1D31-4A4D-8127-9B8EB359889D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{63DF71AF-1D31-4A4D-8127-9B8EB359889D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{63DF71AF-1D31-4A4D-8127-9B8EB359889D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{63DF71AF-1D31-4A4D-8127-9B8EB359889D}.Release|Any CPU.Build.0 = Release|Any CPU
{38556B4C-90E1-453F-8BA7-C0699577A521}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{38556B4C-90E1-453F-8BA7-C0699577A521}.Debug|Any CPU.Build.0 = Debug|Any CPU
{38556B4C-90E1-453F-8BA7-C0699577A521}.Release|Any CPU.ActiveCfg = Release|Any CPU
{38556B4C-90E1-453F-8BA7-C0699577A521}.Release|Any CPU.Build.0 = Release|Any CPU
{641E0BF5-8BAA-4ECC-9EA7-18CA3D763166}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{641E0BF5-8BAA-4ECC-9EA7-18CA3D763166}.Debug|Any CPU.Build.0 = Debug|Any CPU
{641E0BF5-8BAA-4ECC-9EA7-18CA3D763166}.Release|Any CPU.ActiveCfg = Release|Any CPU
{641E0BF5-8BAA-4ECC-9EA7-18CA3D763166}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{5D62C437-6137-4000-A90A-6549835F593B} = {16C8A8E2-B637-4A8B-828F-876523BCC79F}
{A17406AF-E11D-421B-9913-9512BB9B3333} = {16C8A8E2-B637-4A8B-828F-876523BCC79F}
{0FD8C55D-00F5-4059-889A-D223C7D1275C} = {16C8A8E2-B637-4A8B-828F-876523BCC79F}
{515F6D6B-FB63-40F7-8173-2B94031F29B1} = {16C8A8E2-B637-4A8B-828F-876523BCC79F}
{63DF71AF-1D31-4A4D-8127-9B8EB359889D} = {16C8A8E2-B637-4A8B-828F-876523BCC79F}
{38556B4C-90E1-453F-8BA7-C0699577A521} = {16C8A8E2-B637-4A8B-828F-876523BCC79F}
{641E0BF5-8BAA-4ECC-9EA7-18CA3D763166} = {16C8A8E2-B637-4A8B-828F-876523BCC79F}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
using Convey;
using Convey.Logging;
Expand All @@ -13,11 +15,11 @@
using MiniSpace.Services.Posts.Application.Commands;
using MiniSpace.Services.Posts.Application.Dto;
using MiniSpace.Services.Posts.Application.Queries;
using MiniSpace.Services.Posts.Application.Services;
using MiniSpace.Services.Posts.Infrastructure;

namespace MiniSpace.Services.Posts.Api
{
[ExcludeFromCodeCoverage]
public class Program
{
public static async Task Main(string[] args)
Expand All @@ -30,12 +32,6 @@ public static async Task Main(string[] args)
.Build())
.Configure(app => app
.UseInfrastructure()
.UseEndpoints(endpoints => endpoints
.Post<SearchPosts>("posts/search", async (cmd, ctx) =>
{
var pagedResult = await ctx.RequestServices.GetService<IPostsService>().BrowsePostsAsync(cmd);
await ctx.Response.WriteJsonAsync(pagedResult);
}))
.UseDispatcherEndpoints(endpoints => endpoints
.Get("", ctx => ctx.Response.WriteAsync(ctx.RequestServices.GetService<AppOptions>().Name))
.Get<GetPost, PostDto>("posts/{postId}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
"httpClient": {
"type": "fabio",
"retries": 3,
"services": {
"students": "students-service"
}
"services": {}
},
"jwt": {
"certificate": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@
"service": "posts-service"
},
"httpClient": {
"type": "direct",
"type": "fabio",
"retries": 3,
"services": {
"students": "http://localhost:5007"
},
"services": {},
"requestMasking": {
"enabled": true,
"maskTemplate": "*****"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ public class CreatePost : ICommand
public Guid EventId { get; }
public Guid OrganizerId { get; }
public string TextContent { get; }
public IEnumerable<Guid> MediaFiles { get; }
public string MediaContent { get; }
public string State { get; }
public DateTime? PublishDate { get; }

public CreatePost(Guid postId, Guid eventId, Guid organizerId, string textContent,
IEnumerable<Guid> mediaFiles, string state, DateTime? publishDate)
string mediaContent, string state, DateTime? publishDate)
{
PostId = postId;
PostId = postId == Guid.Empty ? Guid.NewGuid() : postId;
EventId = eventId;
OrganizerId = organizerId;
TextContent = textContent;
MediaFiles = mediaFiles;
MediaContent = mediaContent;
State = state;
PublishDate = publishDate;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,11 @@ public async Task HandleAsync(CreatePost command, CancellationToken cancellation
{
throw new UnauthorizedPostCreationAttemptException(identity.Id, command.EventId);
}

if(command.PostId == Guid.Empty || await _postRepository.ExistsAsync(command.PostId))
{
throw new InvalidPostIdException(command.PostId);
}

if (!Enum.TryParse<State>(command.State, true, out var newState))
{
throw new InvalidPostStateException(command.State);
}

var mediaFiles = command.MediaFiles.ToList();
if(mediaFiles.Count > 3)
{
throw new InvalidNumberOfPostMediaFilesException(command.PostId, mediaFiles.Count);
}

switch (newState)
{
Expand All @@ -65,10 +54,10 @@ public async Task HandleAsync(CreatePost command, CancellationToken cancellation
}

var post = Post.Create(command.PostId, command.EventId, command.OrganizerId, command.TextContent,
command.MediaFiles, _dateTimeProvider.Now, newState, command.PublishDate);
command.MediaContent, _dateTimeProvider.Now, newState, command.PublishDate);
await _postRepository.AddAsync(post);

await _messageBroker.PublishAsync(new PostCreated(command.PostId, post.MediaFiles));
await _messageBroker.PublishAsync(new PostCreated(command.PostId));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,10 @@ public async Task HandleAsync(UpdatePost command, CancellationToken cancellation
throw new UnauthorizedPostOperationException(command.PostId, identity.Id);
}

var mediaFiles = command.MediaFiles.ToList();
if(mediaFiles.Count > 3)
{
throw new InvalidNumberOfPostMediaFilesException(post.Id, mediaFiles.Count);
}

post.Update(command.TextContent, command.MediaFiles, _dateTimeProvider.Now);
post.Update(command.TextContent, command.MediaContent, _dateTimeProvider.Now);
await _postRepository.UpdateAsync(post);

await _messageBroker.PublishAsync(new PostUpdated(command.PostId, post.MediaFiles));
await _messageBroker.PublishAsync(new PostUpdated(command.PostId));
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ public class UpdatePost : ICommand
{
public Guid PostId { get; }
public string TextContent { get; }
public IEnumerable<Guid> MediaFiles { get; }
public string MediaContent { get; }

public UpdatePost(Guid postId, string textContent, IEnumerable<Guid> mediaFiles)
public UpdatePost(Guid postId, string textContent, string mediaContent)
{
PostId = postId;
TextContent = textContent;
MediaFiles = mediaFiles;
MediaContent = mediaContent;
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,34 +1,18 @@
using MiniSpace.Services.Posts.Core.Entities;
using System.Diagnostics.CodeAnalysis;

namespace MiniSpace.Services.Posts.Application.Dto
{
[ExcludeFromCodeCoverage]
public class PostDto
{
public Guid Id { get; set; }
public Guid EventId { get; set; }
public Guid OrganizerId { get; set; }
public string TextContent { get; set; }
public IEnumerable<Guid> MediaFiles { get; set; }
public string MediaContent { get; set; }
public string State { get; set; }
public DateTime? PublishDate { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime? UpdatedAt { get; set; }

public PostDto()
{
}

public PostDto(Post post)
{
Id = post.Id;
EventId = post.EventId;
OrganizerId = post.OrganizerId;
TextContent = post.TextContent;
MediaFiles = post.MediaFiles;
State = post.State.ToString();
PublishDate = post.PublishDate;
CreatedAt = post.CreatedAt;
UpdatedAt = post.UpdatedAt;
}
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading