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

Failing Notification Template tests fix #33

Merged
merged 1 commit into from
Jun 2, 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
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using FluentAssertions;
using Novu.Models;
using Novu.NotificationTemplates;

namespace Novu.Tests;

public class NotificationTemplatesTests
public class NotificationTemplatesTest
{
private readonly NovuClient _client;

public NotificationTemplatesTests()
public NotificationTemplatesTest()
{
_client = new NovuClient(new NovuClientConfiguration
{
Expand All @@ -23,18 +24,18 @@
templates.Data.Should().NotBeEmpty();
}
[Fact]
public async Task Should_Get_Notification_Template()

Check warning on line 27 in src/Novu.Tests/NotificationTemplatesTest.cs

View workflow job for this annotation

GitHub Actions / build_and_test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
// TODO:
}

[Fact]
public async Task Should_Create_Notification_Template()

Check warning on line 33 in src/Novu.Tests/NotificationTemplatesTest.cs

View workflow job for this annotation

GitHub Actions / build_and_test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
// TODO:
}
[Fact]
public async Task Should_Delete_Notification_Template()

Check warning on line 38 in src/Novu.Tests/NotificationTemplatesTest.cs

View workflow job for this annotation

GitHub Actions / build_and_test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
// TODO:
}
Expand All @@ -44,7 +45,10 @@
{
var templates = await _client.NotificationTemplates.GetTemplates();
var template = templates.Data.First();
var result = await _client.NotificationTemplates.UpdateStatus(template.Id, new(!template.Active));
var result = await _client.NotificationTemplates.UpdateStatus(template.Id, new UpdateTemplateStatusRequest
{
Active = !template.Active
});
result.Data.Should().NotBeNull();
result.Data.Active.Should().Be(!template.Active);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Novu.Tests/Novu.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="FluentAssertions" Version="6.11.0"/>
<PackageReference Include="FluentAssertions" Version="6.11.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
237 changes: 178 additions & 59 deletions src/Novu/NotificationTemplates/Types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,70 +3,189 @@

namespace Novu.NotificationTemplates;

public record PreferenceSettings(
bool Email,
bool Sms,
bool Chat,
bool Push,
[property: JsonProperty("in_app")] bool InApp);
public class PreferenceSettings
{
[JsonProperty("email")]
public bool Email { get; set; }

[JsonProperty("sms")]
public bool Sms { get; set; }

[JsonProperty("chat")]
public bool Chat { get; set; }

[JsonProperty("push")]
public bool Push { get; set; }

[JsonProperty("in_app")]
public bool InApp { get; set; }
}

public record Child(string Field,
string Value,
string Operator,
string On);
public class Child
{
[JsonProperty("field")]
public string Field { get; set; }

[JsonProperty("value")]
public string Value { get; set; }

[JsonProperty("operator")]
public string Operator { get; set; }

[JsonProperty("on")]
public string On { get; set; }
}

public record Filter(
bool IsNegated,
string Type,
string Value,
Child[] Children);
public class Filter
{
[JsonProperty("isNegated")]
public bool IsNegated { get; set; }

[JsonProperty("type")]
public string Type { get; set; }

[JsonProperty("value")]
public string Value { get; set; }

[JsonProperty("children")]
public Child[] Children { get; set; }
}

public record Variable(string Name);
public class Variable
{
[JsonProperty("name")]
public string Name { get; set; }
}

public record Trigger(
string Type,
string Identifier,
Variable[] Variables,
Variable[] SubscriberVariables);
public class Trigger
{
[JsonProperty("type")]
public string Type { get; set; }

[JsonProperty("identifier")]
public string Identifier { get; set; }

[JsonProperty("variables")]
public Variable[] Variables { get; set; }

[JsonProperty("subscriberVariables")]
public Variable[] SubscriberVariables { get; set; }
}

public record NotificationGroup(
[property: JsonProperty("_id")] string Id,
[property: JsonProperty("_organizationId")] string OrganizationId,
[property: JsonProperty("_environmentId")] string EnvironmentId,
[property: JsonProperty("_parentId")] string ParentId,
string Name);
public class NotificationGroup
{
[JsonProperty("_id")]
public string Id { get; set; }

[JsonProperty("_organizationId")]
public string OrganizationId { get; set; }

[JsonProperty("_environmentId")]
public string EnvironmentId { get; set; }

[JsonProperty("_parentId")]
public string ParentId { get; set; }

[JsonProperty("name")]
public string Name { get; set; }
}

public record Step(
[property: JsonProperty("_id")]string Id,
string Name,
[property: JsonProperty("_templateId")]string TemplateId,
bool Active,
bool ShouldStopOnFail,
object Template,
Filter[] Filters,
[property: JsonProperty("_parentId")]JObject ParentId,
JObject Metadata,
JObject ReplyCallback); // TODO: Metadata is a JObject, but it can be anything. Need to figure out how to handle this.
public class Step
{
[JsonProperty("_id")]
public string Id { get; set; }

[JsonProperty("name")]
public string Name { get; set; }

[JsonProperty("_templateId")]
public string TemplateId { get; set; }

[JsonProperty("active")]
public bool Active { get; set; }

[JsonProperty("shouldStopOnFail")]
public bool ShouldStopOnFail { get; set; }

[JsonProperty("template")]
public object Template { get; set; }

public record NotificationTemplate(
[property: JsonProperty("_id")]string Id,
[property: JsonProperty("_organizationId")]string OrganizationId,
[property: JsonProperty("_creatorId")]string CreatorId,
[property: JsonProperty("_environmentId")]string EnvironmentId,
[property: JsonProperty("_notificationGroupId")] string NotificationGroupId,
[property: JsonProperty("_parentId")] string ParentId,
string Name,
string Description,
bool Active,
bool Draft,
bool Critical,
string[] Tags,
PreferenceSettings PreferenceSettings,
Step[] Steps,
Trigger[] Triggers,
bool Deleted,
DateTime DeletedAt,
string DeletedBy,
NotificationGroup NotificationGroup);
[JsonProperty("filters")]
public Filter[] Filters { get; set; }

[JsonProperty("_parentId")]
public string ParentId { get; set; }

[JsonProperty("metadata")]
public object Metadata { get; set; }

[JsonProperty("replyCallback")]
public object ReplyCallback { get; set; }

}

public record UpdateTemplateStatusRequest(bool Active);
public class NotificationTemplate
{
[JsonProperty("_id")]
public string Id { get; set; }

[JsonProperty("_organizationId")]
public string OrganizationId { get; set; }

[JsonProperty("_creatorId")]
public string CreatorId { get; set; }

[JsonProperty("_environmentId")]
public string EnvironmentId { get; set; }

[JsonProperty("_notificationGroupId")]
public string NotificationGroupId { get; set; }

[JsonProperty("_parentId")]
public string ParentId { get; set; }

[JsonProperty("name")]
public string Name { get; set; }

[JsonProperty("description")]
public string Description { get; set; }

[JsonProperty("active")]
public bool Active { get; set; }

[JsonProperty("draft")]
public bool Draft { get; set; }

[JsonProperty("critical")]
public bool Critical { get; set; }

[JsonProperty("tags")]
public string[] Tags { get; set; }

[JsonProperty("preferenceSettings")]
public PreferenceSettings PreferenceSettings { get; set; }

[JsonProperty("steps")]
public Step[] Steps { get; set; }

[JsonProperty("triggers")]
public Trigger[] Triggers { get; set; }

[JsonProperty("deleted")]
public bool Deleted { get; set; }

[JsonProperty("deletedAt")]
public DateTime DeletedAt { get; set; }

[JsonProperty("deletedBy")]
public string DeletedBy { get; set; }

[JsonProperty("notificationGroup")]
public NotificationGroup NotificationGroup { get; set; }
}

public class UpdateTemplateStatusRequest
{
[JsonProperty("active")]
public bool Active { get; set; }
}
Loading