64 lines
2.7 KiB
C#
64 lines
2.7 KiB
C#
using Socialize.Api.Modules.CalendarIntegrations.Services;
|
|
|
|
namespace Socialize.Tests.CalendarIntegrations;
|
|
|
|
public class CalendarExportFeedTests
|
|
{
|
|
[Fact]
|
|
public void Token_regeneration_changes_private_feed_secret()
|
|
{
|
|
string firstToken = CalendarExportFeedTokenService.GenerateToken();
|
|
string secondToken = CalendarExportFeedTokenService.GenerateToken();
|
|
|
|
Assert.NotEqual(firstToken, secondToken);
|
|
Assert.NotEqual(
|
|
CalendarExportFeedTokenService.HashToken(firstToken),
|
|
CalendarExportFeedTokenService.HashToken(secondToken));
|
|
}
|
|
|
|
[Fact]
|
|
public void HashToken_allows_token_authorization_boundary_checks_without_plaintext_comparison()
|
|
{
|
|
string token = CalendarExportFeedTokenService.GenerateToken();
|
|
string storedHash = CalendarExportFeedTokenService.HashToken(token);
|
|
|
|
Assert.Equal(storedHash, CalendarExportFeedTokenService.HashToken(token));
|
|
Assert.NotEqual(storedHash, CalendarExportFeedTokenService.HashToken(CalendarExportFeedTokenService.GenerateToken()));
|
|
}
|
|
|
|
[Fact]
|
|
public void Build_emits_valid_ics_for_user_work_without_sensitive_discussion_details()
|
|
{
|
|
CalendarExportFeedBuilder builder = new();
|
|
string ics = builder.Build(
|
|
"Socialize my work",
|
|
[
|
|
new CalendarExportFeedEvent(
|
|
"content-1@socialize",
|
|
"Launch reel",
|
|
new DateTimeOffset(2026, 5, 10, 9, 0, 0, TimeSpan.Zero),
|
|
new DateTimeOffset(2026, 5, 10, 9, 30, 0, TimeSpan.Zero),
|
|
IsAllDay: false,
|
|
"Status: Draft\nWorkspace: Brand A\nClient: Client\nCampaign: Spring launch",
|
|
"https://app.test/app/content/content-1"),
|
|
new CalendarExportFeedEvent(
|
|
"approval-1@socialize",
|
|
"Approval due: Launch reel",
|
|
new DateTimeOffset(2026, 5, 12, 0, 0, 0, TimeSpan.Zero),
|
|
new DateTimeOffset(2026, 5, 13, 0, 0, 0, TimeSpan.Zero),
|
|
IsAllDay: true,
|
|
"Stage: Client review\nState: Pending\nWorkspace: Brand A",
|
|
"https://app.test/app/content/content-1"),
|
|
]);
|
|
|
|
Assert.StartsWith("BEGIN:VCALENDAR", ics);
|
|
Assert.Contains("SUMMARY:Launch reel", ics);
|
|
Assert.Contains("SUMMARY:Approval due: Launch reel", ics);
|
|
Assert.Contains("DTSTART:20260510T090000Z", ics);
|
|
Assert.Contains("DTSTART;VALUE=DATE:20260512", ics);
|
|
Assert.DoesNotContain("approval-token", ics);
|
|
Assert.DoesNotContain("Mother's Day", ics);
|
|
Assert.EndsWith("END:VCALENDAR" + Environment.NewLine, ics);
|
|
}
|
|
}
|