|
1 | 1 | using System.IO.Abstractions.TestingHelpers;
|
2 | 2 | using Sentry.Internal.Http;
|
| 3 | +using Sentry.Protocol; |
3 | 4 | using Sentry.Tests.Internals;
|
4 | 5 |
|
5 | 6 | namespace Sentry.Tests;
|
@@ -1742,7 +1743,7 @@ public void CaptureUserFeedback_HubEnabled(bool enabled)
|
1742 | 1743 | hub.Dispose();
|
1743 | 1744 | }
|
1744 | 1745 |
|
1745 |
| - var feedback = new UserFeedback(SentryId.Create(), "foo", "bar", "baz"); |
| 1746 | + var feedback = new UserFeedback(SentryId.Create(), "foo", "bar@example.com", "baz"); |
1746 | 1747 |
|
1747 | 1748 | // Act
|
1748 | 1749 | hub.CaptureUserFeedback(feedback);
|
@@ -1890,6 +1891,103 @@ await transport.Received(1)
|
1890 | 1891 | }
|
1891 | 1892 |
|
1892 | 1893 | private static Scope GetCurrentScope(Hub hub) => hub.ScopeManager.GetCurrent().Key;
|
| 1894 | + |
| 1895 | + [Theory] |
| 1896 | + [InlineData(null)] |
| 1897 | + [InlineData("")] |
| 1898 | + [InlineData(" ")] |
| 1899 | + [InlineData("test@example.com")] |
| 1900 | + [InlineData("user.name@domain.com")] |
| 1901 | + [InlineData("user+tag@example.com")] |
| 1902 | + public void CaptureFeedback_ValidEmail_FeedbackRegistered(string email) |
| 1903 | + { |
| 1904 | + // Arrange |
| 1905 | + var hub = _fixture.GetSut(); |
| 1906 | + var feedback = new SentryFeedback("Test feedback", email); |
| 1907 | + |
| 1908 | + // Act |
| 1909 | + hub.CaptureFeedback(feedback); |
| 1910 | + |
| 1911 | + // Assert |
| 1912 | + _fixture.Client.Received(1).CaptureFeedback(Arg.Any<SentryFeedback>(), Arg.Any<Scope>(), Arg.Any<SentryHint>()); |
| 1913 | + } |
| 1914 | + |
| 1915 | + [Theory] |
| 1916 | + [InlineData("invalid-email")] |
| 1917 | + [InlineData("missing@domain")] |
| 1918 | + [InlineData("@missing-local.com")] |
| 1919 | + [InlineData("spaces in@email.com")] |
| 1920 | + public void CaptureFeedback_InvalidEmail_FeedbackDropped(string email) |
| 1921 | + { |
| 1922 | + // Arrange |
| 1923 | + _fixture.Options.Debug = true; |
| 1924 | + _fixture.Options.DiagnosticLogger = Substitute.For<IDiagnosticLogger>(); |
| 1925 | + _fixture.Options.DiagnosticLogger!.IsEnabled(Arg.Any<SentryLevel>()).Returns(true); |
| 1926 | + var hub = _fixture.GetSut(); |
| 1927 | + var feedback = new SentryFeedback("Test feedback", email); |
| 1928 | + |
| 1929 | + // Act |
| 1930 | + hub.CaptureFeedback(feedback); |
| 1931 | + |
| 1932 | + // Assert |
| 1933 | + _fixture.Options.DiagnosticLogger.Received(1).Log( |
| 1934 | + SentryLevel.Warning, |
| 1935 | + Arg.Is<string>(s => s.Contains("invalid email format")), |
| 1936 | + null, |
| 1937 | + Arg.Any<object[]>()); |
| 1938 | + _fixture.Client.Received(1).CaptureFeedback(Arg.Is<SentryFeedback>(f => f.ContactEmail.IsNull()), |
| 1939 | + Arg.Any<Scope>(), Arg.Any<SentryHint>()); |
| 1940 | + } |
| 1941 | + |
| 1942 | + [Theory] |
| 1943 | + [InlineData(null)] |
| 1944 | + [InlineData("")] |
| 1945 | + [InlineData(" ")] |
| 1946 | + [InlineData("test@example.com")] |
| 1947 | + [InlineData("user.name@domain.com")] |
| 1948 | + [InlineData("user+tag@example.com")] |
| 1949 | + public void CaptureUserFeedback_ValidEmail_FeedbackRegistered(string email) |
| 1950 | + { |
| 1951 | +#pragma warning disable CS0618 // Type or member is obsolete |
| 1952 | + // Arrange |
| 1953 | + var hub = _fixture.GetSut(); |
| 1954 | + var feedback = new UserFeedback(SentryId.Create(), "Test name", email, "Test comment"); |
| 1955 | + |
| 1956 | + // Act |
| 1957 | + hub.CaptureUserFeedback(feedback); |
| 1958 | + |
| 1959 | + // Assert |
| 1960 | + _fixture.Client.Received(1).CaptureUserFeedback(Arg.Any<UserFeedback>()); |
| 1961 | +#pragma warning restore CS0618 // Type or member is obsolete |
| 1962 | + } |
| 1963 | + |
| 1964 | + [Theory] |
| 1965 | + [InlineData("invalid-email")] |
| 1966 | + [InlineData("missing@domain")] |
| 1967 | + [InlineData("@missing-local.com")] |
| 1968 | + [InlineData("spaces in@email.com")] |
| 1969 | + public void CaptureUserFeedback_InvalidEmail_FeedbackDropped(string email) |
| 1970 | + { |
| 1971 | +#pragma warning disable CS0618 // Type or member is obsolete |
| 1972 | + // Arrange |
| 1973 | + _fixture.Options.Debug = true; |
| 1974 | + _fixture.Options.DiagnosticLogger = Substitute.For<IDiagnosticLogger>(); |
| 1975 | + _fixture.Options.DiagnosticLogger!.IsEnabled(Arg.Any<SentryLevel>()).Returns(true); |
| 1976 | + var hub = _fixture.GetSut(); |
| 1977 | + var feedback = new UserFeedback(SentryId.Create(), "Test name", email, "Test comment"); |
| 1978 | + |
| 1979 | + // Act |
| 1980 | + hub.CaptureUserFeedback(feedback); |
| 1981 | + |
| 1982 | + // Assert |
| 1983 | + _fixture.Options.DiagnosticLogger.Received(1).Log( |
| 1984 | + SentryLevel.Warning, |
| 1985 | + Arg.Is<string>(s => s.Contains("invalid email format")), |
| 1986 | + null, |
| 1987 | + Arg.Any<object[]>()); |
| 1988 | + _fixture.Client.Received(1).CaptureUserFeedback(Arg.Is<UserFeedback>(f => f.Email.IsNull())); |
| 1989 | +#pragma warning restore CS0618 // Type or member is obsolete |
| 1990 | + } |
1893 | 1991 | }
|
1894 | 1992 |
|
1895 | 1993 | #if NET6_0_OR_GREATER
|
|
0 commit comments