Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: /cgi/suggest.pl + tests #8004

Merged
merged 7 commits into from
Jan 19, 2023
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
10 changes: 10 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,16 @@ auth:

autosuggest:
- cgi/suggest.pl
- tests/integration/api_cgi_suggest.t
- tests/integration/expected_test_results/api_cgi_suggest/**/*
- tests/integration/expected_test_results/api_cgi_suggest/categories-no-term.json
- tests/integration/expected_test_results/api_cgi_suggest/categories-string-strawberry.json
- tests/integration/expected_test_results/api_cgi_suggest/categories-term-fr-cafe-accent.json
- tests/integration/expected_test_results/api_cgi_suggest/categories-term-fr-frais.json
- tests/integration/expected_test_results/api_cgi_suggest/categories-term-fr-fraise.json
- tests/integration/expected_test_results/api_cgi_suggest/categories-term-fraise.json
- tests/integration/expected_test_results/api_cgi_suggest/categories-term-strawberry.json
- tests/integration/expected_test_results/api_cgi_suggest/no-tagtype.json

subdomains:
- scripts/list_subdomains.pl
Expand Down
18 changes: 13 additions & 5 deletions cgi/suggest.pl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use ProductOpener::Tags qw/:all/;
use ProductOpener::Lang qw/:all/;
use ProductOpener::PackagerCodes qw/:all/;
use ProductOpener::HTTP qw/:all/;

use CGI qw/:cgi :form escapeHTML/;
use URI::Escape::XS;
Expand Down Expand Up @@ -185,11 +186,18 @@ =head3 limit - max number of suggestions

# send response
write_cors_headers();
print header(
-type => 'application/json',
-charset => 'utf-8',
);

if ($cache_max_age) {
print header(-cache_control => 'public, max-age=' . $cache_max_age,);
print header(
-type => 'application/json',
-charset => 'utf-8',
-cache_control => 'public, max-age=' . $cache_max_age,
);
}
else {
print header(
-type => 'application/json',
-charset => 'utf-8',
);
}
print $data;
14 changes: 8 additions & 6 deletions lib/ProductOpener/APITest.pm
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ sub execute_api_tests ($file, $tests_ref, $ua = undef) {

my ($test_id, $test_dir, $expected_result_dir, $update_expected_results) = (init_expected_results($file));

my $ua = $ua // LWP::UserAgent->new();
$ua = $ua // LWP::UserAgent->new();

foreach my $test_ref (@$tests_ref) {
my $test_case = $test_ref->{test_case};
Expand Down Expand Up @@ -500,11 +500,13 @@ sub execute_api_tests ($file, $tests_ref, $ua = undef) {
};

# normalize for comparison
if (defined $decoded_json->{'products'}) {
normalize_products_for_test_comparison($decoded_json->{'products'});
}
if (defined $decoded_json->{'product'}) {
normalize_product_for_test_comparison($decoded_json->{'product'});
if (ref($decoded_json) eq 'HASH') {
if (defined $decoded_json->{'products'}) {
normalize_products_for_test_comparison($decoded_json->{'products'});
}
if (defined $decoded_json->{'product'}) {
normalize_product_for_test_comparison($decoded_json->{'product'});
}
}

is(
Expand Down
79 changes: 79 additions & 0 deletions tests/integration/api_cgi_suggest.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/perl -w

use ProductOpener::PerlStandards;

use Test::More;
use ProductOpener::APITest qw/:all/;
use ProductOpener::Test qw/:all/;
use ProductOpener::TestDefaults qw/:all/;

use File::Basename "dirname";

use Storable qw(dclone);

remove_all_users();

remove_all_products();

wait_application_ready();

# Note: expected results are stored in json files, see execute_api_tests
my $tests_ref = [
{
test_case => 'no-tagtype',
method => 'GET',
path => '/cgi/suggest.pl',
},
{
test_case => 'categories-no-term',
method => 'GET',
path => '/cgi/suggest.pl?tagtype=categories',
expected_status_code => 200,
},
{
test_case => 'categories-term-strawberry',
method => 'GET',
path => '/cgi/suggest.pl?tagtype=categories&term=strawberry',
expected_status_code => 200,
},
{
test_case => 'categories-string-strawberry',
method => 'GET',
path => '/cgi/suggest.pl?tagtype=categories&string=strawberry',
expected_status_code => 200,
},
{
test_case => 'categories-term-fraise',
method => 'GET',
path => '/cgi/suggest.pl?tagtype=categories&term=fraise',
expected_status_code => 200,
},
{
test_case => 'categories-term-fr-fraise',
method => 'GET',
path => '/cgi/suggest.pl?tagtype=categories&term=fraise&lc=fr',
expected_status_code => 200,
},
{
test_case => 'categories-term-fr-frais',
method => 'GET',
path => '/cgi/suggest.pl?tagtype=categories&term=frais&lc=fr',
expected_status_code => 200,
},
{
test_case => 'categories-term-fr-frais',
method => 'GET',
path => '/cgi/suggest.pl?tagtype=categories&term=frais&lc=fr',
expected_status_code => 200,
},
{
test_case => 'categories-term-fr-cafe-accent',
method => 'GET',
path => '/cgi/suggest.pl?tagtype=categories&term=Café&lc=fr',
expected_status_code => 200,
},
];

execute_api_tests(__FILE__, $tests_ref);

done_testing();
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[
"10% red wine",
"11% dry white wine",
"11% red wine",
"11% rosé wine",
"11% white wine",
"12% red wine",
"13% red wine",
"2-3% fat Petit-Suisse",
"2-3% fat Petit-Suisse fruits flavoured fortified with calcium and vitamin D",
"2-3% fat Petit-Suisse with fruits",
"2-3% fat Petit-Suisse with fruits fortified with calcium and vitamin D",
"30-40% blended fat with vegetable and animal origins",
"30-40% fat lightly salted vegetable fat",
"30-40% fat unsalted vegetable fat",
"Asenovgrad",
"Fruit brandy",
"Goat's Haymilk",
"Haymilk",
"Limoncello",
"Peza",
"Pieria",
"Pisatis",
"Pylia",
"Rapsani",
"Sheep's Haymilk"
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[
"Strawberry and blueberry compotes",
"Strawberry applesauces",
"Strawberry biscuits",
"Strawberry cereal bars",
"Strawberry cheesecakes",
"Strawberry compotes",
"Strawberry coulis",
"Strawberry ice cream tubs",
"Strawberry in-season raw",
"Strawberry jams",
"Strawberry juice",
"Strawberry milks",
"Strawberry nectars",
"Strawberry off-season raw",
"Strawberry pies",
"Strawberry sorbets",
"Strawberry soy yogurts",
"Strawberry syrups",
"Strawberry tartlets",
"Strawberry yogurt drinks",
"Strawberry yogurts",
"Strawberry-Vanilla ice cream cones",
"Partially skimmed strawberry flavoured milk with sugar fortified with vitamins D"
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[
"Café Arabica",
"Café Arabica moulu",
"Café au lait non sucré",
"Café au lait sucré",
"Café brésilien",
"Café d'Ouganda",
"Café d'Éthiopie",
"Café de Colombie",
"Café de Côte d'Ivoire",
"Café de Madagascar",
"Café de Tanzanie",
"Café du Costa Rica",
"Café du Guatemala",
"Café du Laos",
"Café du Nicaragua",
"Café décaféiné non sucré",
"Café expresso non sucré",
"Café non sucré",
"Cafés",
"Cafés de céréales",
"Cafés de république dominicaine",
"Cafés décaféinés",
"Cafés en dosettes",
"Cafés en dosettes compatible Dolce Gusto",
"Cafés en poudre décaféinés"
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[
"Frais",
"Fraise de saison crue",
"Fraise du Périgord",
"Fraise hors saison crue",
"Fraises",
"Fraises de Nîmes",
"Fraises de jardin",
"Fraises fraîches",
"Fraises gélifiées",
"Fraises surgelées",
"Fraises séchées",
"Fraisier",
"Fromage frais aromatisé aux fruits à 2-3% de matières grasses enrichi en calcium et vitamine D",
"Fromage frais aux fruits à 2-3% de matières grasses enrichi en calcium et vitamine D",
"Viandes et abats frais belges",
"Fromage de chèvre frais au lait pasteurisé ou cru",
"Fromage de chèvre frais au lait cru",
"Barre de chocolat au lait frais",
"Barre de chocolat au lait frais avec génoise",
"Crêpes fourrées aux fraises",
"Abricots frais",
"Artichauts frais",
"Laurier frais",
"Radis noirs frais",
"Cassis frais"
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[
"Fraise de saison crue",
"Fraise du Périgord",
"Fraise hors saison crue",
"Fraises",
"Fraises de Nîmes",
"Fraises de jardin",
"Fraises fraîches",
"Fraises gélifiées",
"Fraises surgelées",
"Fraises séchées",
"Crêpes fourrées aux fraises",
"Boisson lactée aromatisée à la fraise sucrée au lait partiellement écrémé enrichie à la vitamine D",
"Compotes fraise myrtille",
"Compotes pommes fraise",
"Biscuits à la fraise",
"Barres de céréales aux fraises",
"Cheesecakes à la fraise",
"Compotes de fraise",
"Coulis de fraise",
"Glaces à la fraise",
"Confitures de fraises",
"Jus de fraise",
"Laits aromatisés à la fraise",
"Nectars de fraise",
"Tartes aux fraises"
]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[
"Strawberry and blueberry compotes",
"Strawberry applesauces",
"Strawberry biscuits",
"Strawberry cereal bars",
"Strawberry cheesecakes",
"Strawberry compotes",
"Strawberry coulis",
"Strawberry ice cream tubs",
"Strawberry in-season raw",
"Strawberry jams",
"Strawberry juice",
"Strawberry milks",
"Strawberry nectars",
"Strawberry off-season raw",
"Strawberry pies",
"Strawberry sorbets",
"Strawberry soy yogurts",
"Strawberry syrups",
"Strawberry tartlets",
"Strawberry yogurt drinks",
"Strawberry yogurts",
"Strawberry-Vanilla ice cream cones",
"Partially skimmed strawberry flavoured milk with sugar fortified with vitamins D"
]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]