rimashah25 commented on code in PR #6746:
URL: https://github.com/apache/trafficcontrol/pull/6746#discussion_r856409538


##########
traffic_ops/testing/api/v3/tc-fixtures.json:
##########
@@ -281,16 +281,20 @@
     ],
     "deliveryServiceRequestComments": [
         {
-            "value": "this is comment one"
+            "value": "this is comment one",
+            "xmlId": "test-ds1"

Review Comment:
   Don't we need `xmlId` to be unique?



##########
traffic_ops/testing/api/v4/tc-fixtures.json:
##########
@@ -310,16 +310,20 @@
     ],
     "deliveryServiceRequestComments": [
         {
-            "value": "this is comment one"
+            "value": "this is comment one",
+            "xmlId": "test-ds1"

Review Comment:
   Don't we need `xmlId` to be unique?



##########
traffic_ops/testing/api/v3/deliveryservice_request_comments_test.go:
##########
@@ -16,189 +16,178 @@ package v3
 */
 
 import (
+       "encoding/json"
        "net/http"
        "sort"
        "testing"
        "time"
 
        "github.com/apache/trafficcontrol/lib/go-rfc"
        "github.com/apache/trafficcontrol/lib/go-tc"
+       "github.com/apache/trafficcontrol/traffic_ops/testing/api/assert"
+       "github.com/apache/trafficcontrol/traffic_ops/testing/api/utils"
+       "github.com/apache/trafficcontrol/traffic_ops/toclientlib"
 )
 
 func TestDeliveryServiceRequestComments(t *testing.T) {
        WithObjs(t, []TCObj{CDNs, Types, Parameters, Tenants, 
DeliveryServiceRequests, DeliveryServiceRequestComments}, func() {
-               GetTestDeliveryServiceRequestCommentsIMS(t)
-               currentTime := time.Now().UTC().Add(-5 * time.Second)
-               time := currentTime.Format(time.RFC1123)
-               var header http.Header
-               header = make(map[string][]string)
-               header.Set(rfc.IfUnmodifiedSince, time)
-               header.Set(rfc.IfModifiedSince, time)
-               SortTestDeliveryServiceRequestComments(t)
-               UpdateTestDeliveryServiceRequestComments(t)
-               UpdateTestDeliveryServiceRequestCommentsWithHeaders(t, header)
-               header = make(map[string][]string)
-               etag := rfc.ETag(currentTime)
-               header.Set(rfc.IfMatch, etag)
-               UpdateTestDeliveryServiceRequestCommentsWithHeaders(t, header)
-               GetTestDeliveryServiceRequestComments(t)
-               GetTestDeliveryServiceRequestCommentsIMSAfterChange(t, header)
-       })
-}
-
-func UpdateTestDeliveryServiceRequestCommentsWithHeaders(t *testing.T, header 
http.Header) {
-       comments, _, _ := 
TOSession.GetDeliveryServiceRequestCommentsWithHdr(header)
 
-       if len(comments) > 0 {
-               firstComment := comments[0]
-               newFirstCommentValue := "new comment value"
-               firstComment.Value = newFirstCommentValue
-
-               _, reqInf, err := 
TOSession.UpdateDeliveryServiceRequestCommentByIDWithHdr(firstComment.ID, 
firstComment, header)
-               if err == nil {
-                       t.Errorf("expected precondition failed error, but got 
none")
-               }
-               if reqInf.StatusCode != http.StatusPreconditionFailed {
-                       t.Errorf("Expected status code 412, got %v", 
reqInf.StatusCode)
+               currentTime := time.Now().UTC().Add(-15 * time.Second)
+               currentTimeRFC := currentTime.Format(time.RFC1123)
+               tomorrow := currentTime.AddDate(0, 0, 1).Format(time.RFC1123)
+
+               methodTests := utils.V3TestCase{
+                       "GET": {
+                               "NOT MODIFIED when NO CHANGES made": {
+                                       ClientSession: TOSession, 
RequestHeaders: http.Header{rfc.IfModifiedSince: {tomorrow}},
+                                       Expectations: 
utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusNotModified)),
+                               },
+                               "OK when VALID request": {
+                                       ClientSession: TOSession, Expectations: 
utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
+                               },
+                               "OK when VALID ID parameter": {
+                                       EndpointId: GetDSRequestCommentId(t), 
ClientSession: TOSession,
+                                       Expectations: 
utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK), 
utils.ResponseHasLength(1)),
+                               },
+                               "VALIDATE SORT when DEFAULT is ASC ORDER": {
+                                       ClientSession: TOSession,
+                                       Expectations:  
utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK), 
validateSortedDSRequestComments()),
+                               },
+                       },
+                       "PUT": {
+                               "OK when VALID request": {
+                                       EndpointId: GetDSRequestCommentId(t), 
ClientSession: TOSession,
+                                       RequestBody: map[string]interface{}{
+                                               "deliveryServiceRequestId": 
GetDSRequestId(t, "test-ds1")(),
+                                               "value":                    
"updated comment",
+                                       },
+                                       Expectations: 
utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
+                               },
+                               "PRECONDITION FAILED when updating with 
IF-UNMODIFIED-SINCE Header": {
+                                       EndpointId: GetDSRequestCommentId(t), 
ClientSession: TOSession,
+                                       RequestHeaders: 
http.Header{rfc.IfUnmodifiedSince: {currentTimeRFC}},
+                                       RequestBody:    
map[string]interface{}{},
+                                       Expectations:   
utils.CkRequest(utils.HasError(), 
utils.HasStatus(http.StatusPreconditionFailed)),
+                               },
+                               "PRECONDITION FAILED when updating with IFMATCH 
ETAG Header": {
+                                       EndpointId: GetDSRequestCommentId(t), 
ClientSession: TOSession,
+                                       RequestBody:    
map[string]interface{}{},
+                                       RequestHeaders: 
http.Header{rfc.IfMatch: {rfc.ETag(currentTime)}},
+                                       Expectations:   
utils.CkRequest(utils.HasError(), 
utils.HasStatus(http.StatusPreconditionFailed)),
+                               },
+                       },
+                       "GET AFTER CHANGES": {
+                               "OK when CHANGES made": {
+                                       ClientSession:  TOSession,
+                                       RequestHeaders: 
http.Header{rfc.IfModifiedSince: {currentTimeRFC}},
+                                       Expectations:   
utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),

Review Comment:
   Do we check for http code 200 or 304 `StatusNotModified`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to