<commit_before>=head1 NAME

t/integration/ajax.t - Integration tests for AJAXy stuff

=head1 DESCRIPTION

Tests for AJAXy stuff.

=head1 AUTHORS

Jonathan "Duke" Leto

=cut

use strict;
use Test::More;
use Test::JSON;
use Test::WWW::Mechanize;
BAIL_OUT "Need to set the SGN_TEST_SERVER environment variable" unless $ENV{SGN_TEST_SERVER};

my $base_url = $ENV{SGN_TEST_SERVER};
my $mech = Test::WWW::Mechanize->new;

my $ajax_urls = {
    "/image/ajax/image_ajax_form.pl?action=view" => '{"is_owner":0,"user_type":"user","html":" <table> <tr><td>Image Name:</td><td width=\"20\">&nbsp;</td><td><b>\n</b></td></tr>\n<tr><td>Image Description: </td><td width=\"20\">&nbsp;</td><td><b>\n</b></td></tr>\n<tr><td>Uploaded by: </td><td width=\"20\">&nbsp;</td><td><b><a href=\"/solpeople/personal-info.pl?sp_person_id=\">  </a> </b></td></tr>\n </table> ","editable_form_id":null,"error":"No object_id provided"}',
    "/image/ajax/image_ajax_form.pl?action=edit" => '{"is_owner":0,"user_type":"user","html":"<form id =\"image_form\" method=\"get\" action=\"\"> <table> <tr><td>Image Name:</td><td width=\"20\">&nbsp;</td><td> <input type=\"text\" id=\"\" name=\"name\" value=\"\" size=\"15\" />\n</td></tr>\n<tr><td>Image Description: </td><td width=\"20\">&nbsp;</td><td> <input type=\"text\" id=\"\" name=\"description\" value=\"\" size=\"40\" />\n</td></tr>\n<tr><td>Uploaded by: </td><td width=\"20\">&nbsp;</td><td><a href=\"/solpeople/personal-info.pl?sp_person_id=\">  </a> </td></tr>\n <tr><td colspan=\"3\" align=\"center\">  <input type=\"hidden\" id=\"\" name=\"object_id\" value=\"\" />  <input type=\"hidden\" id=\"\" name=\"action\" value=\"store\" />  </td></tr></table> ","editable_form_id":"image_form","error":"No object_id provided"}'
};

plan( tests => 3*(scalar keys %$ajax_urls));

while( my ($url, $json) = each %$ajax_urls) {
    $mech->get_ok("$base_url/$url");
    is_valid_json($mech->content, "$url is valid JSON");
    is_json($mech->content, $ajax_urls->{$url}, "$url has the expected JSON");
}<commit_msg>Add some more tests for image_ajax_form.pl<commit_after>=head1 NAME

t/integration/ajax.t - Integration tests for AJAXy stuff

=head1 DESCRIPTION

Tests for AJAXy stuff.

=head1 AUTHORS

Jonathan "<NAME>

=cut

use strict;
use Test::More;
use Test::JSON;
use Test::WWW::Mechanize;
BAIL_OUT "Need to set the SGN_TEST_SERVER environment variable" unless $ENV{SGN_TEST_SERVER};

my $base_url = $ENV{SGN_TEST_SERVER};
my $mech = Test::WWW::Mechanize->new;

my $ajax_urls = {
    "/image/ajax/image_ajax_form.pl?action=view" => '{"is_owner":0,"user_type":"user","html":" <table> <tr><td>Image Name:</td><td width=\"20\">&nbsp;</td><td><b>\n</b></td></tr>\n<tr><td>Image Description: </td><td width=\"20\">&nbsp;</td><td><b>\n</b></td></tr>\n<tr><td>Uploaded by: </td><td width=\"20\">&nbsp;</td><td><b><a href=\"/solpeople/personal-info.pl?sp_person_id=\">  </a> </b></td></tr>\n </table> ","editable_form_id":null,"error":"No object_id provided"}',
    "/image/ajax/image_ajax_form.pl?action=" => '{"is_owner":0,"user_type":"user","html":" <table> <tr><td>Image Name:</td><td width=\"20\">&nbsp;</td><td><b>\n</b></td></tr>\n<tr><td>Image Description: </td><td width=\"20\">&nbsp;</td><td><b>\n</b></td></tr>\n<tr><td>Uploaded by: </td><td width=\"20\">&nbsp;</td><td><b><a href=\"/solpeople/personal-info.pl?sp_person_id=\">  </a> </b></td></tr>\n </table> ","editable_form_id":null,"error":"No object_id provided"}',
    "/image/ajax/image_ajax_form.pl" => '{"is_owner":0,"user_type":"user","html":" <table> <tr><td>Image Name:</td><td width=\"20\">&nbsp;</td><td><b>\n</b></td></tr>\n<tr><td>Image Description: </td><td width=\"20\">&nbsp;</td><td><b>\n</b></td></tr>\n<tr><td>Uploaded by: </td><td width=\"20\">&nbsp;</td><td><b><a href=\"/solpeople/personal-info.pl?sp_person_id=\">  </a> </b></td></tr>\n </table> ","editable_form_id":null,"error":"No object_id provided"}',
    "/image/ajax/image_ajax_form.pl?action=edit" => '{"is_owner":0,"user_type":"user","html":"<form id =\"image_form\" method=\"get\" action=\"\"> <table> <tr><td>Image Name:</td><td width=\"20\">&nbsp;</td><td> <input type=\"text\" id=\"\" name=\"name\" value=\"\" size=\"15\" />\n</td></tr>\n<tr><td>Image Description: </td><td width=\"20\">&nbsp;</td><td> <input type=\"text\" id=\"\" name=\"description\" value=\"\" size=\"40\" />\n</td></tr>\n<tr><td>Uploaded by: </td><td width=\"20\">&nbsp;</td><td><a href=\"/solpeople/personal-info.pl?sp_person_id=\">  </a> </td></tr>\n <tr><td colspan=\"3\" align=\"center\">  <input type=\"hidden\" id=\"\" name=\"object_id\" value=\"\" />  <input type=\"hidden\" id=\"\" name=\"action\" value=\"store\" />  </td></tr></table> ","editable_form_id":"image_form","error":"No object_id provided"}',
    "/image/ajax/image_ajax_form.pl?object_id=0" => '{"is_owner":0,"user_type":"user","html":" <table> <tr><td>Image Name:</td><td width=\"20\">&nbsp;</td><td><b>\n</b></td></tr>\n<tr><td>Image Description: </td><td width=\"20\">&nbsp;</td><td><b>\n</b></td></tr>\n<tr><td>Uploaded by: </td><td width=\"20\">&nbsp;</td><td><b><a href=\"/solpeople/personal-info.pl?sp_person_id=\">  </a> </b></td></tr>\n </table> ","editable_form_id":null}',
};

plan( tests => 3*(scalar keys %$ajax_urls));

while( my ($url, $json) = each %$ajax_urls) {
    $mech->get_ok("$base_url/$url");
    is_valid_json($mech->content, "$url is valid JSON");
    is_json($mech->content, $ajax_urls->{$url}, "$url has the expected JSON");
}
{'fraction_non_alphanumeric': 0.29743589743589743, 'fraction_numerical': 0.012454212454212455, 'mean_word_length': 5.49346016646849, 'pattern_counts': {'":': 34, '<': 248, '<?xml version=': 0, '>': 267, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5750302', 'n_tokens_mistral': 2093, 'n_tokens_neox': 2057, 'n_words': 337}