diff --git a/test/raven-integration/EventLog/EventLog.cs b/test/raven-integration/EventLog/EventLog.cs index 5858700e..2c3b8f73 100644 --- a/test/raven-integration/EventLog/EventLog.cs +++ b/test/raven-integration/EventLog/EventLog.cs @@ -20,7 +20,7 @@ namespace raven_integration public async void ObjectLogWorks() { //CRUD a widget and confirm it logs properly - //http://localhost:7575/api/v8.0/EventLog/UserLog?AyType=3&AyId=1 + //http://localhost:7575/api/v8.0/EventLog/UserLog?AyType=3&AyId=1 //http://localhost:7575/api/v8.0/EventLog/ObjectLog?AyType=2&AyId=242 //http://localhost:7575/api/v8.0/EventLog/UserLog?AyType=3&AyId=1&StartDate=2018-08-23&EndDate=2018-08-24 @@ -35,6 +35,13 @@ namespace raven_integration Util.ValidateDataReturnResponseOk(r2); long w2Id = r2.ObjectResponse["result"]["id"].Value(); + ApiResponse EventLogResponse = await Util.GetAsync($"EventLog/ObjectLog?AyType=2&AyId={w2Id}", await Util.GetTokenAsync("BizAdminFull")); + Util.ValidateHTTPStatusCode(EventLogResponse, 200); + ((JArray)EventLogResponse.ObjectResponse["result"]).Count.Should().Be(1);//only one event so far + EventLogResponse.ObjectResponse["result"][0]["date"].Value().Should().BeLessThan(new TimeSpan(1, 0, 0)).Before(DateTime.UtcNow);//should be less than one hour before now + EventLogResponse.ObjectResponse["result"][0]["userId"].Should().NotBeNull(); + EventLogResponse.ObjectResponse["result"][0]["event"].Value().Should().Be(1);//AyEvent 1 = created + EventLogResponse.ObjectResponse["result"][0]["textra"].Should().BeNullOrEmpty(); //RETRIEVE @@ -43,13 +50,21 @@ namespace raven_integration Util.ValidateDataReturnResponseOk(r3); r3.ObjectResponse["result"]["name"].Value().Should().Be(w.name.ToString()); + EventLogResponse = await Util.GetAsync($"EventLog/ObjectLog?AyType=2&AyId={w2Id}", await Util.GetTokenAsync("BizAdminFull")); + Util.ValidateHTTPStatusCode(EventLogResponse, 200); + ((JArray)EventLogResponse.ObjectResponse["result"]).Count.Should().Be(2); + EventLogResponse.ObjectResponse["result"][1]["date"].Value().Should().BeLessThan(new TimeSpan(1, 0, 0)).Before(DateTime.UtcNow);//should be less than one hour before now + EventLogResponse.ObjectResponse["result"][1]["userId"].Should().NotBeNull(); + EventLogResponse.ObjectResponse["result"][1]["event"].Value().Should().Be(2);//AyEvent 2 = retrieved + EventLogResponse.ObjectResponse["result"][1]["textra"].Should().BeNullOrEmpty(); + //UPDATE //PUT //update w2id - w.name = Util.Uniquify("UPDATED VIA PUT SECOND TEST WIDGET"); + w.name = Util.Uniquify("UPDATED VIA PUT EVENTLOG TEST WIDGET"); w.OwnerId = 1; w.concurrencyToken = r2.ObjectResponse["result"]["concurrencyToken"].Value(); ApiResponse PUTTestResponse = await Util.PutAsync("Widget/" + w2Id.ToString(), await Util.GetTokenAsync("InventoryFull"), w.ToString()); @@ -61,29 +76,29 @@ namespace raven_integration checkPUTWorked.ObjectResponse["result"]["name"].Value().Should().Be(w.name.ToString()); uint concurrencyToken = PUTTestResponse.ObjectResponse["result"]["concurrencyToken"].Value(); - //PATCH - var newName = Util.Uniquify("UPDATED VIA PATCH SECOND TEST WIDGET"); - string patchJson = "[{\"value\": \"" + newName + "\",\"path\": \"/name\",\"op\": \"replace\"}]"; - ApiResponse PATCHTestResponse = await Util.PatchAsync("Widget/" + w2Id.ToString() + "/" + concurrencyToken.ToString(), await Util.GetTokenAsync("InventoryFull"), patchJson); - Util.ValidateHTTPStatusCode(PATCHTestResponse, 200); + EventLogResponse = await Util.GetAsync($"EventLog/ObjectLog?AyType=2&AyId={w2Id}", await Util.GetTokenAsync("BizAdminFull")); + Util.ValidateHTTPStatusCode(EventLogResponse, 200); + ((JArray)EventLogResponse.ObjectResponse["result"]).Count.Should().Be(4); + EventLogResponse.ObjectResponse["result"][2]["date"].Value().Should().BeLessThan(new TimeSpan(1, 0, 0)).Before(DateTime.UtcNow);//should be less than one hour before now + EventLogResponse.ObjectResponse["result"][2]["userId"].Should().NotBeNull(); + EventLogResponse.ObjectResponse["result"][2]["event"].Value().Should().Be(3);//AyEvent 3 = Modified + EventLogResponse.ObjectResponse["result"][2]["textra"].Should().BeNullOrEmpty(); - //check PATCH worked - ApiResponse checkPATCHWorked = await Util.GetAsync("Widget/" + w2Id.ToString(), await Util.GetTokenAsync("InventoryFull")); - Util.ValidateNoErrorInResponse(checkPATCHWorked); - checkPATCHWorked.ObjectResponse["result"]["name"].Value().Should().Be(newName); //DELETE ApiResponse DELETETestResponse = await Util.DeleteAsync("Widget/" + w2Id.ToString(), await Util.GetTokenAsync("InventoryFull")); Util.ValidateHTTPStatusCode(DELETETestResponse, 204); + //All events should be cleared up on deletion with the sole exception of the deleted event + EventLogResponse = await Util.GetAsync($"EventLog/ObjectLog?AyType=2&AyId={w2Id}", await Util.GetTokenAsync("BizAdminFull")); + Util.ValidateHTTPStatusCode(EventLogResponse, 200); + ((JArray)EventLogResponse.ObjectResponse["result"]).Count.Should().Be(1); + EventLogResponse.ObjectResponse["result"][0]["date"].Value().Should().BeLessThan(new TimeSpan(1, 0, 0)).Before(DateTime.UtcNow);//should be less than one hour before now + EventLogResponse.ObjectResponse["result"][0]["userId"].Should().NotBeNull(); + EventLogResponse.ObjectResponse["result"][0]["event"].Value().Should().Be(0);//AyEvent 0 = deleted + EventLogResponse.ObjectResponse["result"][0]["textra"].Value().Should().Be(w.name.ToString()); - - - ApiTextResponse t = await Util.GetTextResultAsync("EventLog/", await Util.GetTokenAsync("BizAdminFull")); - Util.ValidateHTTPStatusCode(t, 200); - t.TextResponse.Should().Contain("|INFO|");//assumes any log will have at least one INFO log item in it - } //==================================================