#!/usr/local/cpanel/3rdparty/bin/perl -w

# cpanel - t/medium/Cpanel-Template-Plugin-SQM.t   Copyright 2024 cPanel, L.L.C.
#                                                           All rights reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited

package t::medium::Cpanel::Template::Plugin::SQM;

use cPstrict;
use Test::Cpanel::Policy;
use Test::Cpanel::Logger;
use Test::MockModule;
use Test::MockObject;

use Test2::V0;
use Test2::Plugin::NoWarnings;

use Cpanel::Template::Plugin::SQM ();

use base qw(Test::Class);

__PACKAGE__->new()->runtests() if !caller;

sub test_new : Tests(1) {
    my $obj = Cpanel::Template::Plugin::SQM->new();
    isa_ok( $obj, 'Cpanel::Template::Plugin::SQM' );
    return;
}

sub test_health_check : Tests(2) {

    my $mock_api_obj = Test::MockObject->new();
    $mock_api_obj->set_true('base_url')->set_true('endpoint');
    $mock_api_obj->set_always( 'run', '{ "status":"foo", "message":"a message"}' );

    my $mock_api_module = Test::MockModule->new('Cpanel::Plugins::RestApiClient');
    $mock_api_module->redefine( 'new', sub { return $mock_api_obj } );

    my $obj                   = Cpanel::Template::Plugin::SQM->new();
    my $health_check_response = $obj->health_check();

    is( $health_check_response->{status},  'foo',       "Got the expected status." );
    is( $health_check_response->{message}, 'a message', "Got the expected message." );

    return;
}

1;
