-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add admin_logs_streaming support (#797)
- Loading branch information
Showing
4 changed files
with
95 additions
and
2 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
Box.V2.Test.IntegrationNew/BoxEventsManagerIntegrationTest.cs
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,32 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Box.V2.Models; | ||
using Box.V2.Test.IntegrationNew.Configuration; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace Box.V2.Test.IntegrationNew | ||
{ | ||
[TestClass] | ||
public class BoxEventsManagerIntegrationTest : TestInFolder | ||
{ | ||
[TestMethod] | ||
public async Task EnterpriseEventsStreamingAsync_ForNewFile_ShouldReturnUploadFileEvent() | ||
{ | ||
var uploadedFile = await CreateSmallFile(FolderId); | ||
|
||
var events = await AdminClient.EventsManager.EnterpriseEventsStreamingAsync(); | ||
BoxEnterpriseEvent uploadedFileEvent = null; | ||
while (events.ChunkSize == 500 || uploadedFileEvent == null) | ||
{ | ||
events = await AdminClient.EventsManager.EnterpriseEventsStreamingAsync(500, events.NextStreamPosition, new List<string>() { "UPLOAD" }); | ||
uploadedFileEvent = events.Entries.FirstOrDefault(x => x.Source?.Id == uploadedFile.Id); | ||
} | ||
|
||
Assert.IsNotNull(uploadedFileEvent); | ||
Assert.AreEqual("UPLOAD", uploadedFileEvent.EventType); | ||
Assert.AreEqual(uploadedFile.Id, uploadedFileEvent.Source.Id); | ||
Assert.AreEqual("file", uploadedFileEvent.Source.Type); | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -213,5 +213,32 @@ public async Task GetWebLinkEvents_ValidResponse() | |
Assert.AreEqual(webLinkEventSource.Type, "web_link"); | ||
Assert.AreEqual(webLinkEventSource.Parent.Id, "22222"); | ||
} | ||
|
||
[TestMethod] | ||
[TestCategory("CI-UNIT-TEST")] | ||
public async Task EnterpriseEventsStreamingAsync_ValidResponse() | ||
{ | ||
var responseString = "{\"chunk_size\": 1, \"next_stream_position\": 123, \"entries\": [{\"source\":{\"group_id\":\"942617509\",\"group_name\":\"Groupies\"},\"created_by\":{\"type\":\"user\",\"id\":\"11111\",\"name\":\"Test User\",\"login\":\"[email protected]\"},\"action_by\":{\"type\":\"user\",\"id\":\"12345\",\"name\":\"Test User\",\"login\":\"[email protected]\"},\"created_at\":\"2018-03-16T15:12:52-07:00\",\"event_id\":\"85c57bf3-bc15-4d24-93bc-955c796217c8\",\"event_type\":\"GROUP_EDITED\",\"ip_address\":\"UnknownIP\",\"type\":\"event\",\"session_id\":null,\"additional_details\":null}]}"; | ||
IBoxRequest boxRequest = null; | ||
Handler.Setup(h => h.ExecuteAsync<BoxEventCollection<BoxEnterpriseEvent>>(It.IsAny<IBoxRequest>())) | ||
.Returns(Task.FromResult<IBoxResponse<BoxEventCollection<BoxEnterpriseEvent>>>(new BoxResponse<BoxEventCollection<BoxEnterpriseEvent>>() | ||
{ | ||
Status = ResponseStatus.Success, | ||
ContentString = responseString | ||
})).Callback<IBoxRequest>(r => boxRequest = r); | ||
|
||
/*** Act ***/ | ||
var events = await _eventsManager.EnterpriseEventsStreamingAsync(); | ||
var firstEvent = events.Entries.First<BoxEnterpriseEvent>(); | ||
|
||
/*** Assert ***/ | ||
Assert.AreEqual("stream_type=admin_logs_streaming&limit=500", boxRequest.GetQueryString()); | ||
Assert.AreEqual("12345", firstEvent.ActionBy.Id); | ||
Assert.AreEqual("user", firstEvent.ActionBy.Type); | ||
Assert.AreEqual("Test User", firstEvent.ActionBy.Name); | ||
Assert.AreEqual("[email protected]", firstEvent.ActionBy.Login); | ||
Assert.AreEqual("942617509", firstEvent.Source.Id); | ||
Assert.AreEqual("85c57bf3-bc15-4d24-93bc-955c796217c8", firstEvent.EventId); | ||
} | ||
} | ||
} |
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