github.com/Financial-Times/publish-availability-monitor@v1.12.0/checks/publishCheck_content_neo4j_test.go (about) 1 package checks 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/Financial-Times/go-logger/v2" 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func TestIsCurrentOperationFinished_ContentNeo4jCheck_InvalidContent(t *testing.T) { 12 currentTid := "tid_1234" 13 testResponse := `{ "uuid" : "1234-1234"` 14 response := buildResponse(200, testResponse) 15 defer response.Body.Close() 16 contentCheck := &ContentNeo4jCheck{ 17 mockHTTPCaller(t, "tid_pam_1234", response), 18 } 19 log := logger.NewUPPLogger("test", "PANIC") 20 21 pm := newPublishMetricBuilder().withTID(currentTid).build() 22 finished, _ := contentCheck.isCurrentOperationFinished(NewPublishCheck(pm, "", "", 0, 0, nil, nil, log)) 23 assert.False(t, finished, "Expected error.") 24 } 25 26 func TestIsCurrentOperationFinished_ContentNeo4jCheck_InvalidUUID(t *testing.T) { 27 currentTid := "tid_1234" 28 testResponse := `{ "uuid" : "1234-1235"}` 29 response := buildResponse(200, testResponse) 30 defer response.Body.Close() 31 contentCheck := &ContentNeo4jCheck{ 32 mockHTTPCaller(t, "tid_pam_1234", response), 33 } 34 log := logger.NewUPPLogger("test", "PANIC") 35 36 pm := newPublishMetricBuilder().withTID(currentTid).build() 37 finished, _ := contentCheck.isCurrentOperationFinished(NewPublishCheck(pm, "", "", 0, 0, nil, nil, log)) 38 assert.False(t, finished, "Expected error.") 39 } 40 41 func TestIsCurrentOperationFinished_ContentNeo4jCheck_Finished(t *testing.T) { 42 currentTid := "tid_1234" 43 testResponse := fmt.Sprintf(`{ "uuid" : "1234-1234", "publishReference" : "%s"}`, currentTid) 44 response := buildResponse(200, testResponse) 45 defer response.Body.Close() 46 contentCheck := &ContentNeo4jCheck{ 47 mockHTTPCaller(t, "tid_pam_1234", response), 48 } 49 log := logger.NewUPPLogger("test", "PANIC") 50 51 pm := newPublishMetricBuilder().withUUID("1234-1234").withTID(currentTid).build() 52 finished, _ := contentCheck.isCurrentOperationFinished(NewPublishCheck(pm, "", "", 0, 0, nil, nil, log)) 53 assert.True(t, finished, "operation should have finished successfully") 54 } 55 56 func TestIsCurrentOperationFinished_ContentNeo4jCheck_WithAuthentication(t *testing.T) { 57 currentTid := "tid_5678" 58 testResponse := fmt.Sprintf(`{ "uuid" : "1234-1234", "publishReference" : "%s"}`, currentTid) 59 username := "jdoe" 60 password := "frodo" 61 response := buildResponse(200, testResponse) 62 defer response.Body.Close() 63 contentCheck := &ContentNeo4jCheck{ 64 mockAuthenticatedHTTPCaller(t, "tid_pam_5678", username, password, response), 65 } 66 log := logger.NewUPPLogger("test", "PANIC") 67 68 pm := newPublishMetricBuilder().withUUID("1234-1234").withTID(currentTid).build() 69 finished, _ := contentCheck.isCurrentOperationFinished(NewPublishCheck(pm, username, password, 0, 0, nil, nil, log)) 70 assert.True(t, finished, "operation should have finished successfully") 71 } 72 73 func TestIsCurrentOperationFinished_ContentNeo4jCheck_NotFinished(t *testing.T) { 74 currentTid := "tid_1234" 75 testResponse := `{ "uuid" : "1234-1234", "publishReference" : "tid_1235"}` 76 response := buildResponse(200, testResponse) 77 defer response.Body.Close() 78 contentCheck := &ContentNeo4jCheck{ 79 mockHTTPCaller(t, "tid_pam_1234", response), 80 } 81 log := logger.NewUPPLogger("test", "PANIC") 82 83 pm := newPublishMetricBuilder().withTID(currentTid).build() 84 finished, _ := contentCheck.isCurrentOperationFinished(NewPublishCheck(pm, "", "", 0, 0, nil, nil, log)) 85 assert.False(t, finished, "Expected failure.") 86 } 87 88 func TestIsCurrentOperationFinished_ContentNeo4jCheck_MarkedDeleted_Finished(t *testing.T) { 89 currentTid := "tid_1234" 90 testResponse := fmt.Sprintf(`{ "uuid" : "1234-1234", "publishReference" : "%s"}`, currentTid) 91 response := buildResponse(404, testResponse) 92 defer response.Body.Close() 93 contentCheck := &ContentNeo4jCheck{ 94 mockHTTPCaller(t, "tid_pam_1234", response), 95 } 96 log := logger.NewUPPLogger("test", "PANIC") 97 98 pm := newPublishMetricBuilder().withTID(currentTid).withMarkedDeleted(true).build() 99 finished, _ := contentCheck.isCurrentOperationFinished(NewPublishCheck(pm, "", "", 0, 0, nil, nil, log)) 100 assert.True(t, finished, "operation should have finished successfully.") 101 } 102 103 func TestIsCurrentOperationFinished_ContentNeo4jCheck_MarkedDeleted_NotFinished(t *testing.T) { 104 currentTid := "tid_1234" 105 testResponse := fmt.Sprintf(`{ "uuid" : "1234-1234", "publishReference" : "%s"}`, currentTid) 106 response := buildResponse(200, testResponse) 107 defer response.Body.Close() 108 contentCheck := &ContentNeo4jCheck{ 109 mockHTTPCaller(t, "tid_pam_1234", response), 110 } 111 log := logger.NewUPPLogger("test", "PANIC") 112 113 pm := newPublishMetricBuilder().withTID(currentTid).withMarkedDeleted(true).build() 114 finished, _ := contentCheck.isCurrentOperationFinished(NewPublishCheck(pm, "", "", 0, 0, nil, nil, log)) 115 assert.False(t, finished, "operation should not have finished") 116 }