-
-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Manually capturing user feedback (#559)
- Loading branch information
1 parent
038e6de
commit 0c2f718
Showing
15 changed files
with
329 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System.IO; | ||
using System.Runtime.Serialization; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Sentry.Internal; | ||
using Sentry.Protocol; | ||
using ISerializable = Sentry.Protocol.ISerializable; | ||
|
||
namespace Sentry | ||
{ | ||
/// <summary> | ||
/// Sentry User Feedback. | ||
/// </summary> | ||
[DataContract] | ||
public class UserFeedback : ISerializable | ||
{ | ||
[DataMember(Name = "event_id", EmitDefaultValue = false)] | ||
private string _serializableEventId => EventId.ToString(); | ||
|
||
/// <summary> | ||
/// The eventId of the event to which the user feedback is associated. | ||
/// </summary> | ||
public SentryId EventId { get; } | ||
|
||
/// <summary> | ||
/// The name of the user. | ||
/// </summary> | ||
[DataMember(Name = "name", EmitDefaultValue = false)] | ||
public string? Name { get; } | ||
|
||
/// <summary> | ||
/// The name of the user. | ||
/// </summary> | ||
[DataMember(Name = "email", EmitDefaultValue = false)] | ||
public string Email { get; } | ||
|
||
/// <summary> | ||
/// Comments of the user about what happened. | ||
/// </summary> | ||
[DataMember(Name = "comments", EmitDefaultValue = false)] | ||
public string Comments { get; } | ||
|
||
/// <summary> | ||
/// Initializes an instance of <see cref="UserFeedback"/>. | ||
/// </summary> | ||
public UserFeedback(SentryId eventId, string email, string comments, string? name = null) | ||
{ | ||
EventId = eventId; | ||
Name = name; | ||
Email = email; | ||
Comments = comments; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task SerializeAsync(Stream stream, CancellationToken cancellationToken = default) | ||
=> await Json.SerializeToStreamAsync(this, stream, cancellationToken).ConfigureAwait(false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using System.IO; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Sentry.Protocol; | ||
using Xunit; | ||
|
||
namespace Sentry.Tests.Protocol | ||
{ | ||
public class UserFeedbackTests | ||
{ | ||
[Fact] | ||
public async Task Serialization_SentryUserFeedbacks_Success() | ||
{ | ||
// Arrange | ||
var eventId = new SentryId(Guid.Parse("acbe351c61494e7b807fd7e82a435ffc")); | ||
var userFeedback = new UserFeedback(eventId, "[email protected]", "my comment", "myName"); | ||
using var stream = new MemoryStream(); | ||
|
||
// Act | ||
await userFeedback.SerializeAsync(stream, default); | ||
var serializedContent = Encoding.UTF8.GetString(stream.ToArray()); | ||
|
||
// Assert | ||
var assertExpected = "{\"event_id\":\"acbe351c61494e7b807fd7e82a435ffc\",\"name\":\"myName\",\"email\":\"[email protected]\",\"comments\":\"my comment\"}"; | ||
Assert.Equal(assertExpected, serializedContent); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,5 +82,22 @@ public void CaptureMessage_NullMessage_DoesNotCapturesEventWithMessage() | |
_ = _sut.DidNotReceive().CaptureEvent(Arg.Any<SentryEvent>()); | ||
Assert.Equal(default, id); | ||
} | ||
|
||
[Fact] | ||
public void CaptureUserFeedback_EnabledClient_CapturesUserFeedback() | ||
{ | ||
_ = _sut.IsEnabled.Returns(true); | ||
_sut.CaptureUserFeedback(Guid.Parse("1ec19311a7c048818de80b18dcc43eaa"), "[email protected]", "comments"); | ||
_sut.Received(1).CaptureUserFeedback(Arg.Any<UserFeedback>()); | ||
} | ||
|
||
[Fact] | ||
public void CaptureUserFeedback_DisabledClient_DoesNotCaptureUserFeedback() | ||
{ | ||
_ = _sut.IsEnabled.Returns(false); | ||
_sut.CaptureUserFeedback(Guid.Parse("1ec19311a7c048818de80b18dcc43eea"), "[email protected]", "comments"); | ||
|
||
_sut.DidNotReceive().CaptureUserFeedback(Arg.Any<UserFeedback>()); | ||
} | ||
} | ||
} |
Oops, something went wrong.