Skip to content

Commit

Permalink
Updated error boundary for prompt generation endpoint and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
clpetersonucf committed Sep 17, 2024
1 parent 53addd4 commit 7f63e1f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
2 changes: 1 addition & 1 deletion fuel/app/classes/materia/api/v1.php
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ static public function question_set_generate($inst_id, $widget_id, $topic, $incl

static public function widget_prompt_generate($prompt)
{
if ( ! Widget_Question_Generator::is_enabled()) throw new \HttpNotFoundException;
if ( ! Widget_Question_Generator::is_enabled()) return Msg::failure();
if (\Service_User::verify_session() !== true) return Msg::no_login();

$result = Widget_Question_Generator::generate_from_prompt($prompt);
Expand Down
22 changes: 4 additions & 18 deletions fuel/app/tests/api/v1.php
Original file line number Diff line number Diff line change
Expand Up @@ -1174,28 +1174,14 @@ public function test_widget_prompt_generate()
{
if ( ! \Materia\Widget_Question_Generator::is_enabled())
{
try
{
$output = Api_V1::widget_prompt_generate('Provide a background story for Kogneato, the robot mascot of Materia, a platform for educational tools and games.');
$this->fail('Expected exception HttpNotFoundException not thrown');
}
catch (\Exception $e)
{
$this->assertInstanceOf('HttpNotFoundException', $e);
}
$output = Api_V1::widget_prompt_generate('Provide a background story for Kogneato, the robot mascot of Materia, a platform for educational tools and games.');
$this->assert_failure_message($output);
}
else
{
// ======= AS NO ONE ========
try
{
$output = Api_V1::widget_prompt_generate('Provide a background story for Kogneato, the robot mascot of Materia, a platform for educational tools and games.');
$this->fail('Expected exception HttpNotFoundException not thrown');
}
catch (\Exception $e)
{
$this->assertInstanceOf('HttpNotFoundException', $e);
}
$output = Api_V1::widget_prompt_generate('Provide a background story for Kogneato, the robot mascot of Materia, a platform for educational tools and games.');
$this->assert_invalid_login_message($output);
}
}

Expand Down

0 comments on commit 7f63e1f

Please sign in to comment.