Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ on:
- rpc_v2
- legacy
push:
branches: [ main, next ]
branches: [ main, develop, next ]
pull_request:
branches: [ main, next ]
branches: [ main, develop, next ]
Comment thread
swethasukumarr marked this conversation as resolved.

defaults:
run:
Expand Down
13 changes: 8 additions & 5 deletions include/firebolt/actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,34 @@
#ifndef FIREBOLT_ACTIONS_H
#define FIREBOLT_ACTIONS_H

#include <firebolt/types.h>
#include <functional>
#include <optional>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#include <firebolt/types.h>

namespace Firebolt::Actions {
namespace Firebolt::Actions
{

class IActions {
class IActions
{
public:
virtual ~IActions() = default;

virtual Result<std::string> intent() const = 0;

virtual Result<SubscriptionId> subscribeOnIntent(std::function<void(const std::string&)>&& notification) = 0;
virtual Result<SubscriptionId> subscribeOnIntentChanged(std::function<void(const std::string&)>&& notification) {
virtual Result<SubscriptionId> subscribeOnIntentChanged(std::function<void(const std::string&)>&& notification)
{
return subscribeOnIntent(std::move(notification));
}

virtual Result<void> unsubscribe(SubscriptionId id) = 0;
virtual void unsubscribeAll() = 0;

}; // class IActions
}; // class IActions

} // namespace Firebolt::Actions

Expand Down
22 changes: 14 additions & 8 deletions src/actions_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,32 @@
#include "json_types/actions.h"
#include <firebolt/json_types.h>

namespace Firebolt::Actions {
namespace Firebolt::Actions
{

ActionsImpl::ActionsImpl(Firebolt::Helpers::IHelper& helper)
: helper_(helper)
, subscriptionManager_(helper, this)
{}
: helper_(helper),
subscriptionManager_(helper, this)
{
}

Result<std::string> ActionsImpl::intent() const {
Result<std::string> ActionsImpl::intent() const
{
return helper_.get<Firebolt::JSON::String, std::string>("Actions.intent");
}

Result<SubscriptionId> ActionsImpl::subscribeOnIntent(std::function<void(const std::string&)>&& notification) {
Result<SubscriptionId> ActionsImpl::subscribeOnIntent(std::function<void(const std::string&)>&& notification)
{
return subscriptionManager_.subscribe<Firebolt::JSON::String>("Actions.onIntent", std::move(notification));
}

Result<void> ActionsImpl::unsubscribe(SubscriptionId id) {
Result<void> ActionsImpl::unsubscribe(SubscriptionId id)
{
return subscriptionManager_.unsubscribe(id);
}

void ActionsImpl::unsubscribeAll() {
void ActionsImpl::unsubscribeAll()
{
subscriptionManager_.unsubscribeAll();
}

Expand Down
6 changes: 4 additions & 2 deletions src/actions_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
#include "firebolt/actions.h"
#include <firebolt/helpers.h>

namespace Firebolt::Actions {
namespace Firebolt::Actions
{

class ActionsImpl : public IActions {
class ActionsImpl : public IActions
{
public:
explicit ActionsImpl(Firebolt::Helpers::IHelper& helper);
ActionsImpl(const ActionsImpl&) = delete;
Expand Down
12 changes: 7 additions & 5 deletions src/json_types/actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@
#define FIREBOLT_ACTIONS_JSON_H

#pragma once
#include <type_traits>
#include <nlohmann/json.hpp>
#include <firebolt/json_types.h>
#include "firebolt/actions.h"
#include <firebolt/json_types.h>
#include <nlohmann/json.hpp>
#include <type_traits>

namespace Firebolt::Actions {
namespace Firebolt::Actions
{

namespace JsonData {
namespace JsonData
{

} // namespace JsonData

Expand Down
1 change: 0 additions & 1 deletion test/component/actionsGeneratedTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,3 @@ TEST_F(ActionsGeneratedCTest, SubscribeOnIntent)
auto result = Firebolt::IFireboltAccessor::Instance().ActionsInterface().unsubscribe(id.value());
verifyUnsubscribeResult(result);
}

19 changes: 9 additions & 10 deletions test/unit/actionsGeneratedTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include "mock_helper.h"
#include "actions_impl.h"
#include "mock_helper.h"
#include <gtest/gtest.h>

class ActionsGeneratedUTest : public ::testing::Test
Expand All @@ -34,24 +34,23 @@ TEST_F(ActionsGeneratedUTest, Constructs)

TEST_F(ActionsGeneratedUTest, UnsubscribeForwardsToHelper)
{
EXPECT_CALL(mockHelper, unsubscribe(7))
.WillOnce(::testing::Return(Firebolt::Result<void>{Firebolt::Error::None}));
EXPECT_CALL(mockHelper, unsubscribe(7)).WillOnce(::testing::Return(Firebolt::Result<void>{Firebolt::Error::None}));

auto result = impl.unsubscribe(7);
ASSERT_TRUE(result) << "unsubscribe should return success when helper succeeds";
}


TEST_F(ActionsGeneratedUTest, ForwardsIntentTransportErrors)
{
EXPECT_CALL(mockHelper, getJson("Actions.intent", ::testing::_))
.WillOnce(::testing::Invoke([](const std::string& /*method*/, const nlohmann::json& params) {
EXPECT_TRUE(params.is_null() || (params.is_object() && params.empty()))
<< "Actions.intent getter should not send request params";
return Firebolt::Result<nlohmann::json>{Firebolt::Error::General};
}));
.WillOnce(::testing::Invoke(
[](const std::string& /*method*/, const nlohmann::json& params)
{
EXPECT_TRUE(params.is_null() || (params.is_object() && params.empty()))
<< "Actions.intent getter should not send request params";
return Firebolt::Result<nlohmann::json>{Firebolt::Error::General};
}));

auto result = impl.intent();
EXPECT_FALSE(result) << "Expected error propagation when helper getJson fails";
}

Loading