buffet: Add GCD device draft record to device registration

Use the command definitions provided by Command Manager in
device registration record sent to GCD server.

BUG=chromium:396716
TEST=USE=buffet P2_TEST_FILTER="buffet::*" FEATURES=test emerge-link platform2

Change-Id: If9109bfee8862d9252cdb03301a4362492064809
Reviewed-on: https://chromium-review.googlesource.com/210146
Reviewed-by: Christopher Wiley <wiley@chromium.org>
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/buffet/commands/command_dictionary_unittest.cc b/buffet/commands/command_dictionary_unittest.cc
index 0aeab50..30d185f 100644
--- a/buffet/commands/command_dictionary_unittest.cc
+++ b/buffet/commands/command_dictionary_unittest.cc
@@ -165,3 +165,46 @@
             error->GetFirstError()->GetMessage());
   error.reset();
 }
+
+TEST(CommandDictionary, GetCommandsAsJson) {
+  auto json_base = CreateDictionaryValue(R"({
+    'base': {
+      'reboot': {
+        'parameters': {'delay': {'maximum': 100}}
+      },
+      'shutdown': {
+        'parameters': {}
+      }
+    }
+  })");
+  buffet::CommandDictionary base_dict;
+  base_dict.LoadCommands(*json_base, "base", nullptr, nullptr);
+
+  auto json = buffet::unittests::CreateDictionaryValue(R"({
+    'base': {
+      'reboot': {
+        'parameters': {'delay': {'minimum': 10}}
+      }
+    },
+    'robot': {
+      '_jump': {
+        'parameters': {'_height': 'integer'}
+      }
+    }
+  })");
+  buffet::CommandDictionary dict;
+  dict.LoadCommands(*json, "device", &base_dict, nullptr);
+
+  json = dict.GetCommandsAsJson(false, nullptr);
+  EXPECT_NE(nullptr, json.get());
+  EXPECT_EQ("{'base':{'reboot':{'parameters':{'delay':{'minimum':10}}}},"
+            "'robot':{'_jump':{'parameters':{'_height':'integer'}}}}",
+            buffet::unittests::ValueToString(json.get()));
+
+  json = dict.GetCommandsAsJson(true, nullptr);
+  EXPECT_NE(nullptr, json.get());
+  EXPECT_EQ("{'base':{'reboot':{'parameters':{'delay':{"
+            "'maximum':100,'minimum':10,'type':'integer'}}}},"
+            "'robot':{'_jump':{'parameters':{'_height':{'type':'integer'}}}}}",
+            buffet::unittests::ValueToString(json.get()));
+}