Bläddra i källkod

Fix group state field default (#475)

* Add failing test for group state field default

* set default
Chris Mullins 6 år sedan
förälder
incheckning
197253c7ba
2 ändrade filer med 26 tillägg och 2 borttagningar
  1. 3 2
      lib/Settings/Settings.h
  2. 23 0
      test/remote/spec/settings_spec.rb

+ 3 - 2
lib/Settings/Settings.h

@@ -58,14 +58,14 @@ enum RadioInterfaceType {
   LT8900 = 1,
 };
 
-static const GroupStateField DEFAULT_GROUP_STATE_FIELDS[] = {
+static const std::vector<GroupStateField> DEFAULT_GROUP_STATE_FIELDS({
   GroupStateField::STATE,
   GroupStateField::BRIGHTNESS,
   GroupStateField::COMPUTED_COLOR,
   GroupStateField::MODE,
   GroupStateField::COLOR_TEMP,
   GroupStateField::BULB_MODE
-};
+});
 
 struct GatewayConfig {
   GatewayConfig(uint16_t deviceId, uint16_t port, uint8_t protocolVersion);
@@ -105,6 +105,7 @@ public:
     hostname("milight-hub"),
     rf24PowerLevel(RF24PowerLevelHelpers::defaultValue()),
     rf24Channels(RF24ChannelHelpers::allValues()),
+    groupStateFields(DEFAULT_GROUP_STATE_FIELDS),
     rf24ListenChannel(RF24Channel::RF24_LOW),
     _autoRestartPeriod(0)
   { }

+ 23 - 0
test/remote/spec/settings_spec.rb

@@ -165,4 +165,27 @@ RSpec.describe 'Settings' do
       expect(ping_test.ping?).to be(true)
     end
   end
+
+  context 'defaults' do
+    before(:all) do
+      # Clobber all settings
+      file = Tempfile.new('espmh-settings.json')
+      file.close
+
+      @client.upload_json('/settings', file.path)
+    end
+
+    it 'should have some group state fields defined' do
+      settings = @client.get('/settings')
+
+      expect(settings['group_state_fields']).to_not be_empty
+    end
+
+    it 'should allow for empty group state fields if set' do
+      @client.patch_settings(group_state_fields: [])
+      settings = @client.get('/settings')
+
+      expect(settings['group_state_fields']).to eq([])
+    end
+  end
 end