Skip to content

Commit

Permalink
fix+ops(enki): prepare test environment for ci pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
WarriorsSami committed Jun 21, 2024
1 parent 9b20b22 commit 602918b
Show file tree
Hide file tree
Showing 26 changed files with 290 additions and 307 deletions.
18 changes: 10 additions & 8 deletions .github/workflows/enki-problems-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Setup dotnet
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: '7.0.x'
- name: Cd into the project directory
run: cd enki-problems
- name: Install dependencies
run: dotnet restore
- name: Build
run: dotnet build
- name: Test with the dotnet CLI
run: dotnet test
run: |
dotnet restore "enki-problems/src/EnkiProblems.HttpApi.Host/EnkiProblems.HttpApi.Host.csproj"
dotnet restore "enki-problems/test/EnkiProblems.Application.Tests/EnkiProblems.Application.Tests.csproj"
cd enki-problems
dotnet build --no-restore
- name: Test
run: |
cd enki-problems
dotnet test -e DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false
2 changes: 1 addition & 1 deletion .github/workflows/quetzalcoatl-auth-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Setup dotnet
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: '7.0.x'
- name: Build
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ public static class EnkiProblemsDtoExtensions

public static void Configure()
{
OneTimeRunner.Run(() =>
{
OneTimeRunner.Run(() => {
/* You can add extension properties to DTOs
* defined in the depended modules.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ public class ProblemEvalMetadataUpsertedEvent : EntityDto<Guid>
public IoTypeEnum IoType { get; set; }

public IEnumerable<TestDto> Tests { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ namespace EnkiProblems.Problems.Events;
public class TestDeletedEvent : EntityDto<int>
{
public Guid ProblemId { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ public class TestUpsertedEvent : EntityDto<int>
public string InputDownloadUrl { get; set; }

public string OutputDownloadUrl { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ public async Task<ProblemDto> CreateAsync(CreateProblemDto input)

problem = await _problemRepository.InsertAsync(problem);

var problemEvalMetadataUpsertedEvent = ObjectMapper.Map<Problem, ProblemEvalMetadataUpsertedEvent>(problem);
var problemEvalMetadataUpsertedEvent = ObjectMapper.Map<
Problem,
ProblemEvalMetadataUpsertedEvent
>(problem);

await _daprClient.PublishEventAsync(
EnkiProblemsConsts.PubSubName,
Expand Down Expand Up @@ -121,7 +124,9 @@ public async Task<PagedResultDto<ProblemDto>> GetListAsync(ProblemListFilterDto
}

[Authorize]
public async Task<PagedResultDto<ProblemWithTestsDto>> GetListUnpublishedAsync(ProblemListFilterDto input)
public async Task<PagedResultDto<ProblemWithTestsDto>> GetListUnpublishedAsync(
ProblemListFilterDto input
)
{
_logger.LogInformation(
"Getting unpublished problems list for user {UserId}",
Expand All @@ -142,8 +147,9 @@ public async Task<PagedResultDto<ProblemWithTestsDto>> GetListUnpublishedAsync(P

var problemQueryable = await _problemRepository.GetQueryableAsync();

problemQueryable = problemQueryable
.Where(p => !p.IsPublished && p.ProposerId == CurrentUser.Id);
problemQueryable = problemQueryable.Where(p =>
!p.IsPublished && p.ProposerId == CurrentUser.Id
);

if (!string.IsNullOrEmpty(input.Name))
{
Expand Down Expand Up @@ -273,18 +279,23 @@ public async Task<ProblemDto> UpdateAsync(Guid id, UpdateProblemDto input)

updatedProblem = await _problemRepository.UpdateAsync(updatedProblem);

var problemEvalMetadataUpsertedEvent = ObjectMapper.Map<Problem, ProblemEvalMetadataUpsertedEvent>(updatedProblem);
_logger.LogInformation("Publishing ProblemEvalMetadataUpsertedEvent for problem {ProblemId}: {Event}", id, problemEvalMetadataUpsertedEvent);
var problemEvalMetadataUpsertedEvent = ObjectMapper.Map<
Problem,
ProblemEvalMetadataUpsertedEvent
>(updatedProblem);
_logger.LogInformation(
"Publishing ProblemEvalMetadataUpsertedEvent for problem {ProblemId}: {Event}",
id,
problemEvalMetadataUpsertedEvent
);

await _daprClient.PublishEventAsync(
EnkiProblemsConsts.PubSubName,
EnkiProblemsConsts.ProblemEvalMetadataUpsertedTopic,
problemEvalMetadataUpsertedEvent
);

return ObjectMapper.Map<Problem, ProblemDto>(
updatedProblem
);
return ObjectMapper.Map<Problem, ProblemDto>(updatedProblem);
}

[Authorize]
Expand All @@ -304,19 +315,31 @@ public async Task DeleteAsync(Guid id)
}

// TODO: convert to permission
if (problem.IsPublished && CurrentUser.Roles.All(r => r != EnkiProblemsConsts.AdminRoleName))
if (
problem.IsPublished && CurrentUser.Roles.All(r => r != EnkiProblemsConsts.AdminRoleName)
)
{
_logger.LogError("User {UserId} is not allowed to delete problem {ProblemId}", CurrentUser.Id, id);
_logger.LogError(
"User {UserId} is not allowed to delete problem {ProblemId}",
CurrentUser.Id,
id
);
throw new AbpAuthorizationException(
EnkiProblemsDomainErrorCodes.NotAllowedToDeletePublishedProblem
);
}

// TODO: convert to permission
if (CurrentUser.Roles.All(r => r != EnkiProblemsConsts.AdminRoleName) &&
CurrentUser.Id != id)
if (
CurrentUser.Roles.All(r => r != EnkiProblemsConsts.AdminRoleName)
&& CurrentUser.Id != id
)
{
_logger.LogError("User {UserId} is not allowed to delete problem {ProblemId}", CurrentUser.Id, id);
_logger.LogError(
"User {UserId} is not allowed to delete problem {ProblemId}",
CurrentUser.Id,
id
);
throw new AbpAuthorizationException(
EnkiProblemsDomainErrorCodes.ProblemCannotBeDeleted
);
Expand All @@ -327,7 +350,11 @@ public async Task DeleteAsync(Guid id)
foreach (var problemTest in problemTests)
{
var deleteResponse = await _testService.DeleteTestAsync(
new DeleteTestRequest { ProblemId = id.ToString(), TestId = problemTest.Id.ToString() }
new DeleteTestRequest
{
ProblemId = id.ToString(),
TestId = problemTest.Id.ToString()
}
);

if (deleteResponse.Status.Code != StatusCode.Ok)
Expand All @@ -338,9 +365,9 @@ public async Task DeleteAsync(Guid id)
deleteResponse.Status.Message
);
throw new BusinessException(
EnkiProblemsDomainErrorCodes.TestDeleteFailed,
$"Test delete failed with status code {deleteResponse.Status.Code}: {deleteResponse.Status.Message}."
)
EnkiProblemsDomainErrorCodes.TestDeleteFailed,
$"Test delete failed with status code {deleteResponse.Status.Code}: {deleteResponse.Status.Message}."
)
.WithData("id", problem.Id)
.WithData("testId", problemTest.Id);
}
Expand Down Expand Up @@ -632,11 +659,7 @@ public async Task<ProblemWithTestsDto> DeleteTestAsync(Guid id, int testId)
await _daprClient.PublishEventAsync(
EnkiProblemsConsts.PubSubName,
EnkiProblemsConsts.TestDeletedTopic,
new TestDeletedEvent
{
Id = testId,
ProblemId = id,
}
new TestDeletedEvent { Id = testId, ProblemId = id, }
);

return ObjectMapper.Map<Problem, ProblemWithTestsDto>(updatedProblem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public async Task<DownloadTestStreamDto> DownloadTestAsync(DownloadRequest input
}
}

response:
response:
return new DownloadTestStreamDto
{
ProblemId = metadata.ProblemId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ public override void ConfigureServices(ServiceConfigurationContext context)
Configure<AbpLocalizationOptions>(options =>
{
options
.Resources
.Add<EnkiProblemsResource>("en")
.Resources.Add<EnkiProblemsResource>("en")
.AddBaseTypes(typeof(AbpValidationResource))
.AddVirtualJson("/Localization/EnkiProblems");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ public static class EnkiProblemsGlobalFeatureConfigurator

public static void Configure()
{
OneTimeRunner.Run(() =>
{
OneTimeRunner.Run(() => {
/* You can configure (enable/disable) global features of the used modules here.
*
* YOU CAN SAFELY DELETE THIS CLASS AND REMOVE ITS USAGES IF YOU DON'T NEED TO IT!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ public async Task MigrateAsync()
if (tenant.ConnectionStrings.Any())
{
var tenantConnectionStrings = tenant
.ConnectionStrings
.Select(x => x.Value)
.ConnectionStrings.Select(x => x.Value)
.ToList();

if (!migratedDatabaseSchemas.IsSupersetOf(tenantConnectionStrings))
Expand Down
Loading

0 comments on commit 602918b

Please sign in to comment.