~ps-jenkins/unity-scope-click/ubuntu-rtm-14.09-proposed

« back to all changes in this revision

Viewing changes to scope/tests/test_query.cpp

  • Committer: CI bot
  • Author(s): Rodney Dawes
  • Date: 2014-10-02 19:21:07 UTC
  • mfrom: (279.1.10 multi-currency)
  • Revision ID: ps-jenkins@lists.canonical.com-20141002192107-5m6ddk56kpi5ijd0
Add support for multiple currencies based on GeoIP suggestion from the server. Fixes: 1375281
Approved by: Alejandro J. Cura, PS Jenkins bot

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
#include "click/application.h"
44
44
#include "click/departments-db.h"
45
45
#include "test_helpers.h"
 
46
#include "click/package.h"
46
47
 
 
48
#include <tests/fake_json.h>
47
49
#include <tests/mock_network_access_manager.h>
48
50
 
49
51
#include <unity/scopes/CategoryRenderer.h>
555
557
    EXPECT_CALL(q, push_result(_, HasAttributes(true)));
556
558
    q.wrap_add_available_apps(reply, no_installed_packages, FAKE_CATEGORY_TEMPLATE);
557
559
}
 
560
 
 
561
MATCHER_P(HasPrice, price, "") { return arg["price"].get_double() == price; }
 
562
 
 
563
TEST(QueryTest, testPushPackagePushesPriceUSD)
 
564
{
 
565
    ASSERT_EQ(unsetenv(Configuration::CURRENCY_ENVVAR), 0);
 
566
    ASSERT_EQ(setenv(Configuration::PURCHASES_ENVVAR, "1", 1), 0);
 
567
 
 
568
    Json::Value root;
 
569
    Json::Reader().parse(FAKE_JSON_SEARCH_RESULT_ONE, root);
 
570
    auto const embedded = root[Package::JsonKeys::embedded];
 
571
    auto const ci_package = embedded[Package::JsonKeys::ci_package];
 
572
 
 
573
    Packages packages = package_list_from_json_node(ci_package);
 
574
 
 
575
    MockIndex mock_index(packages);
 
576
    scopes::SearchMetadata metadata("en_EN", "phone");
 
577
    PackageSet no_installed_packages;
 
578
    DepartmentLookup dept_lookup;
 
579
    HighlightList highlights;
 
580
    MockPayPackage pay_pkg;
 
581
    const unity::scopes::CannedQuery query("foo.scope", "", "");
 
582
    MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg);
 
583
 
 
584
    scopes::CategoryRenderer renderer("{}");
 
585
    auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer);
 
586
 
 
587
    scopes::testing::MockSearchReply mock_reply;
 
588
    scopes::SearchReplyProxy reply(&mock_reply, [](unity::scopes::SearchReply*){});
 
589
    EXPECT_CALL(q, push_result(reply, HasPrice(1.99)));
 
590
    q.push_package(reply, ptrCat, no_installed_packages, packages[0]);
 
591
 
 
592
    ASSERT_EQ(unsetenv(Configuration::PURCHASES_ENVVAR), 0);
 
593
}
 
594
 
 
595
TEST(QueryTest, testPushPackagePushesPriceEUR)
 
596
{
 
597
    ASSERT_EQ(setenv(Configuration::CURRENCY_ENVVAR, "EUR", 1), 0);
 
598
    ASSERT_EQ(setenv(Configuration::PURCHASES_ENVVAR, "1", 1), 0);
 
599
 
 
600
    Json::Value root;
 
601
    Json::Reader().parse(FAKE_JSON_SEARCH_RESULT_ONE, root);
 
602
    auto const embedded = root[Package::JsonKeys::embedded];
 
603
    auto const ci_package = embedded[Package::JsonKeys::ci_package];
 
604
 
 
605
    Packages packages = package_list_from_json_node(ci_package);
 
606
 
 
607
    MockIndex mock_index(packages);
 
608
    scopes::SearchMetadata metadata("en_EN", "phone");
 
609
    PackageSet no_installed_packages;
 
610
    DepartmentLookup dept_lookup;
 
611
    HighlightList highlights;
 
612
    MockPayPackage pay_pkg;
 
613
    const unity::scopes::CannedQuery query("foo.scope", "", "");
 
614
    MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg);
 
615
 
 
616
    scopes::CategoryRenderer renderer("{}");
 
617
    auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer);
 
618
 
 
619
    scopes::testing::MockSearchReply mock_reply;
 
620
    scopes::SearchReplyProxy reply(&mock_reply, [](unity::scopes::SearchReply*){});
 
621
    EXPECT_CALL(q, push_result(reply, HasPrice(1.69)));
 
622
    q.push_package(reply, ptrCat, no_installed_packages, packages[0]);
 
623
 
 
624
    ASSERT_EQ(unsetenv(Configuration::CURRENCY_ENVVAR), 0);
 
625
    ASSERT_EQ(unsetenv(Configuration::PURCHASES_ENVVAR), 0);
 
626
}