#!/usr/local/cpanel/3rdparty/bin/perl -w
#                                      Copyright 2025 WebPros International, LLC
#                                                           All rights reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited

use cPstrict;

use Test2::V0;
use Test2::Tools::Explain;
use Test2::Plugin::NoWarnings;
use Test2::Tools::Subtest;
use Test2::Tools::Exception;

use Test::MockModule qw/strict/;

use Test::Cpanel::Policy testing => 'Cpanel::Plugins::Components::Rules::FeatureFlag';
use Capture::Tiny;

use Cpanel::Plugins::Components::Rules::FeatureFlag;

subtest 'Check when feature flag is enabled on the system' => sub {

    my $mock = Test::MockModule->new('Cpanel::FeatureFlags');
    $mock->redefine( is_feature_enabled => sub { 1 } );

    my $got = Cpanel::Plugins::Components::Rules::FeatureFlag->new('test.flag')->is_allowed();
    is $got, !!1, "got true value when feature flag is present on the system.";
};

subtest 'Check when feature flag is not enabled on the system' => sub {
    my $mock = Test::MockModule->new('Cpanel::FeatureFlags');
    $mock->redefine( is_feature_enabled => sub { 0 } );

    my $got = Cpanel::Plugins::Components::Rules::FeatureFlag->new('test.flag')->is_allowed();
    is $got, !!0, "got false value when feature flag is NOT present on the system.";
};

done_testing;
