buffet: Fix command progress update JSON for GCD server

GCD server expects command progress updates to contain a device-specific
JSON object, while buffet was providing just an integer. Make GCD server
happy by creating an object instead by sticking another "progress" property
as in {"progress":{"progress":100}}.

Also added some unit tests to cover the rest of UpdateCommand notifications.

BUG=brillo:779
TEST=`FEATURES=test emerge-link libchromeos buffet`

Change-Id: I210de62abae7fa1c357449b0c07b5298e8606ec0
Reviewed-on: https://chromium-review.googlesource.com/264867
Reviewed-by: Vitaly Buka <vitalybuka@chromium.org>
Trybot-Ready: Alex Vakulenko <avakulenko@chromium.org>
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/buffet/commands/command_instance.cc b/buffet/commands/command_instance.cc
index c12f1ed..c67411f 100644
--- a/buffet/commands/command_instance.cc
+++ b/buffet/commands/command_instance.cc
@@ -152,7 +152,8 @@
             TypedValueToJson(parameters_, nullptr).release());
   json->Set(commands::attributes::kCommand_Results,
             TypedValueToJson(results_, nullptr).release());
-  json->SetInteger(commands::attributes::kCommand_Progress, progress_);
+  json->Set(commands::attributes::kCommand_Progress,
+            GetProgressJson().release());
   json->SetString(commands::attributes::kCommand_State, status_);
 
   return json;
@@ -219,5 +220,15 @@
     queue_->DelayedRemove(GetID());
 }
 
+std::unique_ptr<base::Value> CommandInstance::GetProgressJson() const {
+  // GCD server requires "progress" to be a JSON object. We will just make
+  // an object with a single field, "progress", so the patch request will
+  // look like this: {"progress": {"progress":100}}.
+  std::unique_ptr<base::DictionaryValue> progress_object{
+      new base::DictionaryValue};
+  progress_object->SetInteger(commands::attributes::kCommand_Progress,
+                              progress_);
+  return std::move(progress_object);
+}
 
 }  // namespace buffet