Repository: washingtonpost/ans-schema (js)

Issue:
Proposal: Comments Config
## Problem

Comments can be configured on a per-page basis, and some comment metadata is useful when rendering.

## Proposal

A `comments` object with the following properties (suggested by @StephanieDClark )

* `comments_period` - integer indicating how long (in days) until comments are closed
* `allow_comments` - boolean
* `display_comments` - boolean
* `moderation_required` - boolean

## Example

```
comments: {
  allow_comments: true,
  comments_period: 14,
  display_comments: true,
  moderation_required: false,
}
```



Pull request description:
92 comments
Fixes #92 

Patch:
diff --git a/lib/upvert/0.5.7.js b/lib/upvert/0.5.7.js
index 7b4d6f6..5f91237 100644
--- a/lib/upvert/0.5.7.js
+++ b/lib/upvert/0.5.7.js
@@ -73,15 +73,20 @@ var convertLabel = function convertLabel(old_label) {
 
 };
 
-
 // Move source from undefined object to new format
 var convertSource = function convertSource(old_source) {
   var source = limitFields(['source_id', 'source_type', 'name', 'system', 'additional_properties'], old_source);
-
   return source;
 };
 
 
+// Move comments from undefined object to new format
+var convertComments = function convertComments(old_comments) {
+  var comments = limitFields(['comments_period', 'allow_comments', 'display_comments', 'moderation_required',
+                              'additional_properties'], old_comments);
+  return comments;
+};
+
 // Convert a top-level ANS document and recur at known points
 var convertDocument = function convertDocument(doc) {
   return _.transform(doc, function(result, value, key, object) {
@@ -96,6 +101,9 @@ var convertDocument = function convertDocument(doc) {
     else if (key === 'source') {
       result[key] = convertSource(value);
     }
+    else if (key === 'comments') {
+      result[key] = convertComments(value);
+    }
     else if (_.includes(recursion_keys, key)) {
       result[key] = convert(value);
     }
diff --git a/package.json b/package.json
index 2efb4cc..9c3c614 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
 {
   "name": "ans-schema",
   "description": "The Washington Post's Arc Native Specification",
-  "version": "1.2.9",
+  "version": "1.2.10",
   "homepage": "https://github.com/washingtonpost/ans-schema",
   "repository": {
     "type": "git",
diff --git a/src/main/resources/schema/ans/0.5.8/traits/trait_comments.json b/src/main/resources/schema/ans/0.5.8/traits/trait_comments.json
index c162737..0140dad 100644
--- a/src/main/resources/schema/ans/0.5.8/traits/trait_comments.json
+++ b/src/main/resources/schema/ans/0.5.8/traits/trait_comments.json
@@ -4,5 +4,28 @@
   "title": "Comments",
   "description": "Comment configuration data",
   "type": "object",
-  "additionalProperties": {}
+  "additionalProperties": false,
+  "properties": {
+    "comments_period": {
+      "type": "integer",
+      "description": "How long (in days) after publish date until comments are closed."
+    },
+    "allow_comments": {
+      "type": "boolean",
+      "description": "If false, commenting is disabled on this content."
+    },
+    "display_comments": {
+      "type": "boolean",
+      "description": "If false, do not render comments on this content."
+    },
+    "moderation_required": {
+      "type": "boolean",
+      "description": "If true, comments must be moderator-approved before being displayed."
+    },
+
+    "additional_properties": {
+      "$ref": "https://raw.githubusercontent.com/washingtonpost/ans-schema/master/src/main/resources/schema/ans/0.5.8/traits/trait_additional_properties.json"
+    }
+
+  }
 }


Test patch:
diff --git a/tests/fixtures/schema/0.5.8/story-fixture-good.json b/tests/fixtures/schema/0.5.8/story-fixture-good.json
index fba8b1e..80a410d 100644
--- a/tests/fixtures/schema/0.5.8/story-fixture-good.json
+++ b/tests/fixtures/schema/0.5.8/story-fixture-good.json
@@ -423,6 +423,17 @@
     "search": true
   },
 
+  "comments": {
+    "comments_period": 14,
+    "allow_comments": true,
+    "display_comments": true,
+    "moderation_required": false,
+
+    "additional_properties": {
+      "favorite_comment": "All work and no play makes Jack a dull boy."
+    }
+  },
+
   "additional_properties": {
     "foo": "bar"
   }
diff --git a/tests/fixtures/transforms/0.5.7/story-fixture-good.json b/tests/fixtures/transforms/0.5.7/story-fixture-good.json
index dc73d41..7e5f97b 100644
--- a/tests/fixtures/transforms/0.5.7/story-fixture-good.json
+++ b/tests/fixtures/transforms/0.5.7/story-fixture-good.json
@@ -292,5 +292,13 @@
         "provider": "https://api.twitter.com/1/statuses/oembed.json"
       }
     }
-  ]
+  ],
+
+  "comments": {
+    "comments_period": 14,
+    "allow_comments": true,
+    "display_comments": true,
+    "moderation_required": false,
+    "favorite_comment": "All work and no play makes Jack a dull boy."
+  }
 }
diff --git a/tests/transform-tests.js b/tests/transform-tests.js
index 6dc386d..b0d8714 100644
--- a/tests/transform-tests.js
+++ b/tests/transform-tests.js
@@ -587,6 +587,20 @@ describe("Transformations: ", function() {
         });
       });
 
+      describe("Comments", function() {
+        it("should leave valid comments fields alone", function() {
+          var result = transforms.upvert(fixtures['0.5.7']['story-fixture-good'], '0.5.8');
+          result.comments.comments_period.should.eql(14);
+          result.comments.moderation_required.should.eql(false);
+        });
+
+        it("should move invalid comments fields to additional_properties", function() {
+          var result = transforms.upvert(fixtures['0.5.7']['story-fixture-good'], '0.5.8');
+          result.comments.additional_properties.favorite_comment.should.eql("All work and no play makes Jack a dull boy.");
+        });
+      });
+
+
     });
   });