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

Feature/workflowgroups #41

Merged
merged 7 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ bin
obj
.DS_STORE
src/Novu.sln.DotSettings.user
**/.vs
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,24 @@ var result = await client.Topic.RenameTopicAsync("my-topic", topicRequest);

```

## WorkflowGroups

```csharp
...
Using Novu.DTO.WorkflowGroup

// Create a new Workflow group
var request = new WorkflowGroupDto
{
WorkflowGroupName = "<name of workflow group to be created>"
}

var response = await client.WorkflowGroup.CreateWorkflowGroup(request);


// Get All Workflow groups
var response = await client.WorkflowGroup.GetWorkflowGroups();
```

## Repository Overview

Expand Down
2 changes: 1 addition & 1 deletion src/Novu.Tests/Novu.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
Expand Down
26 changes: 26 additions & 0 deletions src/Novu.Tests/WorkflowGroups/WorkflowGroupFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Novu.Models;

namespace Novu.Tests.WorkflowGroups
{
public class WorkflowGroupFixture : IDisposable
{
public NovuClient NovuClient { get; }

public WorkflowGroupFixture()
{
var novuConfiguration = new NovuClientConfiguration
{
ApiKey = Environment.GetEnvironmentVariable("NOVU_API_KEY") ?? throw new InvalidOperationException(),
};
var novu = new NovuClient(novuConfiguration);

NovuClient = novu;
}

public async void Dispose()
{
//Delete resources created
}

}
}
40 changes: 40 additions & 0 deletions src/Novu.Tests/WorkflowGroups/WorkflowGroupUnitTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Novu.DTO.WorkflowGroup;

namespace Novu.Tests.WorkflowGroups
{
public class WorkflowGroupUnitTests
{
public readonly WorkflowGroupFixture _fixture;

public WorkflowGroupUnitTests(WorkflowGroupFixture fixture)
{
_fixture = fixture;
}

[Fact]
public async void Should_Create_WorkflowGroup()
{
var client = _fixture.NovuClient;

var requestBody = new WorkflowGroupDto
{
WorkflowGroupName = "workflowGroup123"
};

var workflowGroup = await client.WorkflowGroup.CreateWorkflowGroup(requestBody);

Assert.Equal(requestBody.WorkflowGroupName, workflowGroup.PayloadDto.Name);
}

[Fact]
public async void Should_Return_WorkflowGroup_List()
{
var client = _fixture.NovuClient;

var listOfWorkflowGroups = await client.WorkflowGroup.GetWorkflowGroups();

Assert.NotNull(listOfWorkflowGroups);
Assert.NotEmpty(listOfWorkflowGroups.PayloadDtos);
}
}
}
10 changes: 10 additions & 0 deletions src/Novu/DTO/WorkflowGroup/WorkflowGroupDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Newtonsoft.Json;

namespace Novu.DTO.WorkflowGroup
{
public class WorkflowGroupDto
{
[JsonProperty("name")]
public string WorkflowGroupName { get; set; }
}
}
30 changes: 30 additions & 0 deletions src/Novu/DTO/WorkflowGroup/WorkflowGroupResponsePayloadDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Newtonsoft.Json;

namespace Novu.DTO.WorkflowGroup
{
public class WorkflowGroupResponsePayloadDto
{
[JsonProperty("_id")]
public string Id { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("_environmentId")]
public string EnvironmentId { get; set; }
[JsonProperty("_organizationId")]
public string OrganizationId { get; set; }
[JsonProperty("_parentId")]
public string ParentId { get; set; }
}

public class WorkflowGroupSingleResponseDto
{
[JsonProperty("data")]
public WorkflowGroupResponsePayloadDto PayloadDto { get; set; }
}

public class WorkflowGroupBulkResponseDto
{
[JsonProperty("data")]
public List<WorkflowGroupResponsePayloadDto> PayloadDtos { get; set; }
}
}
1 change: 1 addition & 0 deletions src/Novu/Interfaces/INovuClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ public interface INovuClient

public ITopicClient Topic { get; }
public INotificationTemplatesClient NotificationTemplates { get; }
public IWorkflowGroupClient WorkflowGroup { get; }
}
26 changes: 26 additions & 0 deletions src/Novu/Interfaces/IWorkflowGroupClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Novu.DTO.WorkflowGroup;
using Refit;

namespace Novu.Interfaces
{
public interface IWorkflowGroupClient
{
/// <summary>
/// Create a Workflow Group
/// </summary>
/// <param name="requestBody"></param>
/// <returns>
/// <see cref="WorkflowGroupSingleResponseDto"/> - The created workflow group
/// </returns>
[Post("/notification-groups")]
public Task<WorkflowGroupSingleResponseDto> CreateWorkflowGroup([Body] WorkflowGroupDto requestBody);
/// <summary>
/// Get All Workflow Groups
/// </summary>
/// <returns>
/// <see cref="WorkflowGroupBulkResponseDto"/> - List of workflow groups
/// </returns>
[Get("/notification-groups")]
public Task<WorkflowGroupBulkResponseDto> GetWorkflowGroups();
}
}
2 changes: 1 addition & 1 deletion src/Novu/Novu.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<!-- General Settings -->
<PropertyGroup>
Expand Down
5 changes: 5 additions & 0 deletions src/Novu/NovuClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public NovuClient(INovuClientConfiguration configuration,HttpClient? client = de
{
ContentSerializer = new NewtonsoftJsonContentSerializer(SerializerSettings)
});
WorkflowGroup = RestService.For<IWorkflowGroupClient>(httpClient, new RefitSettings
{
ContentSerializer = new NewtonsoftJsonContentSerializer(SerializerSettings)
});
}

public ISubscriberClient Subscriber { get; }
Expand All @@ -49,4 +53,5 @@ public NovuClient(INovuClientConfiguration configuration,HttpClient? client = de

public ITopicClient Topic { get; }
public INotificationTemplatesClient NotificationTemplates { get; }
public IWorkflowGroupClient WorkflowGroup { get; }
}