Skip to content

Commit

Permalink
Merge pull request #192 from SaintAngeLs/posts_service_tests
Browse files Browse the repository at this point in the history
(#149) posts service tests
  • Loading branch information
SaintAngeLs authored May 26, 2024
2 parents 33bbee9 + 487c62a commit 344a763
Show file tree
Hide file tree
Showing 88 changed files with 1,770 additions and 526 deletions.
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

0 comments on commit 344a763

Please sign in to comment.