Skip to content

Commit

Permalink
Enable monitoring of deleted generic content
Browse files Browse the repository at this point in the history
  • Loading branch information
dtvalk-ov committed Nov 24, 2021
1 parent 1ac15cb commit 541f076
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 4 deletions.
3 changes: 2 additions & 1 deletion content/genericContent.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type GenericContent struct {
UUID string `json:"uuid"`
Type string `json:"-"` //This field is for internal application usage
BinaryContent []byte `json:"-"` //This field is for internal application usage
Deleted bool `json:"deleted,omitempty"`
}

func (gc GenericContent) Initialize(binaryContent []byte) Content {
Expand Down Expand Up @@ -55,5 +56,5 @@ func (gc GenericContent) isValid(status int) bool {
}

func (gc GenericContent) isMarkedDeleted(status ...int) bool {
return false
return gc.Deleted
}
24 changes: 21 additions & 3 deletions content/genericContent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ func TestGenericContent_Validate(t *testing.T) {
}{
"valid generic content": {
Content: GenericContent{
UUID: "077f5ac2-0491-420e-a5d0-982e0f86204b",
Type: "application/vnd.ft-upp-article-internal",
UUID: "077f5ac2-0491-420e-a5d0-982e0f86204b",
Type: "application/vnd.ft-upp-article-internal",
Deleted: false,
BinaryContent: []byte(`{
"uuid": "077f5ac2-0491-420e-a5d0-982e0f86204b",
"title": "A title",
Expand All @@ -31,12 +32,28 @@ func TestGenericContent_Validate(t *testing.T) {
"editorialDesk": "some string editorial desk identifier",
"description": "Some descriptive explanation for this content",
"mainImage": "0000aa3c-0056-506b-2b73-ed90e21b3e64",
"someUnknownProperty" : " is totally fine, we don't validate for unknown fields/properties"
"someUnknownProperty" : " is totally fine, we don't validate for unknown fields/properties",
"deleted": false
}`),
},
ExternalValidationResponseCode: http.StatusOK,
Expected: ValidationResponse{IsValid: true, IsMarkedDeleted: false},
},
"valid deleted generic content": {
Content: GenericContent{
UUID: "077f5ac2-0491-420e-a5d0-982e0f86204b",
Type: "application/vnd.ft-upp-article-internal",
Deleted: true,
BinaryContent: []byte(`{
"uuid": "077f5ac2-0491-420e-a5d0-982e0f86204b",
"title": "A title",
"type": "Article",
"deleted": true
}`),
},
ExternalValidationResponseCode: http.StatusOK,
Expected: ValidationResponse{IsValid: true, IsMarkedDeleted: true},
},
"generic content with missing uuid is invalid": {
Content: GenericContent{
UUID: "",
Expand Down Expand Up @@ -79,6 +96,7 @@ func TestGenericContent_Validate(t *testing.T) {
}))

validationResponse := test.Content.Validate(testServer.URL+"/validate", txID, "", "")
assert.Equal(t, test.Content.isMarkedDeleted(), validationResponse.IsMarkedDeleted)
assert.Equal(t, test.Expected, validationResponse)
})
}
Expand Down
44 changes: 44 additions & 0 deletions messageHandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,22 @@ func TestUnmarshalContent_GenericContent(t *testing.T) {
assert.Equal(t, "077f5ac2-0491-420e-a5d0-982e0f86204b", genericContent.UUID)
assert.Equal(t, validGenericContentMessage.Headers["Content-Type"], genericContent.Type)
assert.Equal(t, []byte(validGenericContentMessage.Body), genericContent.BinaryContent)
assert.False(t, genericContent.Deleted)
}

func TestUnmarshalContent_DeletedGenericContent(t *testing.T) {
h := kafkaMessageHandler{}

resultContent, err := h.unmarshalContent(validDeletedGenericContentMessage)
assert.NoError(t, err)

genericContent, ok := resultContent.(content.GenericContent)
assert.True(t, ok)

assert.Equal(t, "077f5ac2-0491-420e-a5d0-982e0f86204b", genericContent.GetUUID())
assert.Equal(t, validDeletedGenericContentMessage.Headers["Content-Type"], genericContent.GetType())
assert.Equal(t, []byte(validDeletedGenericContentMessage.Body), genericContent.BinaryContent)
assert.True(t, genericContent.Deleted)
}

func TestUnmarshalContent_GenericContent_Audio(t *testing.T) {
Expand Down Expand Up @@ -435,6 +451,34 @@ var validGenericContentMessage = consumer.Message{
}`,
}

var validDeletedGenericContentMessage = consumer.Message{
Headers: map[string]string{
"Origin-System-Id": "http://cmdb.ft.com/systems/cct",
"X-Request-Id": "tid_0123wxyz",
"Content-Type": "application/vnd.ft-upp-article-internal",
},
Body: `{
"uuid": "077f5ac2-0491-420e-a5d0-982e0f86204b",
"title": "A title",
"type": "Article",
"byline": "A byline",
"identifiers": [
{
"authority": "an authority",
"identifierValue": "some identifier value"
},
{
"authority": "another authority",
"identifierValue": "some other identifier value"
}
],
"publishedDate": "2014-12-23T20:45:54.000Z",
"firstPublishedDate": "2014-12-22T20:45:54.000Z",
"bodyXML": "<body>Lorem ipsum</body>",
"deleted": true
}`,
}

var validGenericAudioMessage = consumer.Message{
Headers: map[string]string{
"Origin-System-Id": "http://cmdb.ft.com/systems/next-video-editor",
Expand Down

0 comments on commit 541f076

Please sign in to comment.