Skip to content
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
50 changes: 50 additions & 0 deletions SlackNet.Tests/MemberChannelEventTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using EasyAssertions;
using Newtonsoft.Json;
using NUnit.Framework;
using SlackNet.Events;

namespace SlackNet.Tests;

public class MemberChannelEventTests
{
private JsonSerializerSettings _sut;

[SetUp]
public void SetUp()
{
_sut = Default.JsonSettings(Default.SlackTypeResolver(Default.AssembliesContainingSlackTypes)).SerializerSettings;
}

[Test]
public void MemberJoinedChannel_HasTeamAndEnterprise()
{
var result = Deserialize<Event>(@"{ ""type"": ""member_joined_channel"", ""user"": ""W123ABC456"", ""channel"": ""C123ABC456"", ""channel_type"": ""C"", ""team"": ""T123ABC456"", ""inviter"": ""U123456789"", ""enterprise"": ""E123456789"" }");

var joined = result.ShouldBeA<MemberJoinedChannel>().And;
joined.Team.ShouldBe("T123ABC456");
joined.Enterprise.ShouldBe("E123456789");
joined.ExtraProperties.ShouldBeEmpty();
}

[Test]
public void MemberJoinedChannel_WithoutTeamOrEnterprise_HasNeither()
{
var result = Deserialize<Event>(@"{ ""type"": ""member_joined_channel"", ""user"": ""W123ABC456"", ""channel"": ""C123ABC456"", ""channel_type"": ""C"" }");

var joined = result.ShouldBeA<MemberJoinedChannel>().And;
joined.Team.ShouldBeNull();
joined.Enterprise.ShouldBeNull();
}

[Test]
public void MemberLeftChannel_HasTeam()
{
var result = Deserialize<Event>(@"{ ""type"": ""member_left_channel"", ""user"": ""W123ABC456"", ""channel"": ""C123ABC456"", ""channel_type"": ""C"", ""team"": ""T123ABC456"" }");

var left = result.ShouldBeA<MemberLeftChannel>().And;
left.Team.ShouldBe("T123ABC456");
left.ExtraProperties.ShouldBeEmpty();
}

private T Deserialize<T>(string json) => JsonConvert.DeserializeObject<T>(json, _sut);
}
8 changes: 8 additions & 0 deletions SlackNet/Events/MemberJoinedChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ public class MemberJoinedChannel : Event
public string Channel { get; set; }
public ChannelType ChannelType { get; set; }
/// <summary>
/// Team ID, identifying which workspace the user is from.
/// </summary>
public string Team { get; set; }
/// <summary>
/// If the user was invited, the user ID of the inviting user.
/// </summary>
public string Inviter { get; set; }
/// <summary>
/// Enterprise ID, identifying which org the user is from. The value will be blank if the user's team is not an Enterprise organization.
/// </summary>
public string Enterprise { get; set; }
}
4 changes: 4 additions & 0 deletions SlackNet/Events/MemberLeftChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ public class MemberLeftChannel : Event
public string User { get; set; }
public string Channel { get; set; }
public ChannelType ChannelType { get; set; }
/// <summary>
/// Team ID, identifying which workspace the user is from.
/// </summary>
public string Team { get; set; }
}
Loading