File indexing completed on 2024-05-12 05:09:55

0001 /***************************************************************************
0002     Copyright (C) 2019-2020 Robby Stephenson <robby@periapsis.org>
0003  ***************************************************************************/
0004 
0005 /***************************************************************************
0006  *                                                                         *
0007  *   This program is free software; you can redistribute it and/or         *
0008  *   modify it under the terms of the GNU General Public License as        *
0009  *   published by the Free Software Foundation; either version 2 of        *
0010  *   the License or (at your option) version 3 or any later version        *
0011  *   accepted by the membership of KDE e.V. (or its successor approved     *
0012  *   by the membership of KDE e.V.), which shall act as a proxy            *
0013  *   defined in Section 14 of version 3 of the license.                    *
0014  *                                                                         *
0015  *   This program is distributed in the hope that it will be useful,       *
0016  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0017  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0018  *   GNU General Public License for more details.                          *
0019  *                                                                         *
0020  *   You should have received a copy of the GNU General Public License     *
0021  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
0022  *                                                                         *
0023  ***************************************************************************/
0024 
0025 #undef QT_NO_CAST_FROM_ASCII
0026 
0027 #include "colnectfetchertest.h"
0028 
0029 #include "../fetch/colnectfetcher.h"
0030 #include "../entry.h"
0031 #include "../collections/coincollection.h"
0032 #include "../collections/comicbookcollection.h"
0033 #include "../collectionfactory.h"
0034 #include "../images/imagefactory.h"
0035 
0036 #include <KSharedConfig>
0037 
0038 #include <QTest>
0039 
0040 QTEST_GUILESS_MAIN( ColnectFetcherTest )
0041 
0042 ColnectFetcherTest::ColnectFetcherTest() : AbstractFetcherTest() {
0043 }
0044 
0045 void ColnectFetcherTest::initTestCase() {
0046   Tellico::ImageFactory::init();
0047   Tellico::RegisterCollection<Tellico::Data::CoinCollection> registerMe(Tellico::Data::Collection::Coin, "coin");
0048   Tellico::RegisterCollection<Tellico::Data::ComicBookCollection> registerComic(Tellico::Data::Collection::ComicBook, "comic");
0049 
0050   m_config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)->group(QStringLiteral("colnect"));
0051   m_config.writeEntry("Custom Fields", QStringLiteral("obverse,reverse,series,mintage,description"));
0052 }
0053 
0054 void ColnectFetcherTest::testSlug() {
0055   // test the implementation of the Colnect slug derivation
0056   QFETCH(QString, input);
0057   QFETCH(QString, slug);
0058 
0059   QCOMPARE(Tellico::Fetch::ColnectFetcher::URLize(input), slug);
0060 }
0061 
0062 void ColnectFetcherTest::testSlug_data() {
0063   QTest::addColumn<QString>("input");
0064   QTest::addColumn<QString>("slug");
0065 
0066   QTest::newRow("basic") << QStringLiteral("input") << QStringLiteral("input");
0067   QTest::newRow("Aus1$") << QStringLiteral("1 Dollar (50 Years Moonlanding)") << QStringLiteral("1_Dollar_50_Years_Moonlanding");
0068 }
0069 
0070 void ColnectFetcherTest::testRaw() {
0071   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Coin,
0072                                        Tellico::Fetch::Raw,
0073                                        QStringLiteral("147558"));
0074   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::ColnectFetcher(this));
0075   fetcher->readConfig(m_config);
0076 
0077   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
0078 
0079   QCOMPARE(results.size(), 1);
0080   Tellico::Data::EntryPtr entry = results.at(0);
0081 
0082   QCOMPARE(entry->field(QStringLiteral("year")), QStringLiteral("2019"));
0083   QCOMPARE(entry->field(QStringLiteral("country")), QStringLiteral("Australia"));
0084   QCOMPARE(entry->field(QStringLiteral("denomination")), QStringLiteral("$1.00"));
0085   QCOMPARE(entry->field(QStringLiteral("currency")), QStringLiteral("$ - Australian dollar"));
0086   QCOMPARE(entry->field(QStringLiteral("series")), QStringLiteral("1970~Today - Numismatic Products"));
0087   QCOMPARE(entry->field(QStringLiteral("mintage")), QStringLiteral("25000"));
0088   QVERIFY(!entry->field(QStringLiteral("description")).isEmpty());
0089   QVERIFY(!entry->field(QStringLiteral("obverse")).isEmpty());
0090   QVERIFY(!entry->field(QStringLiteral("obverse")).contains(QLatin1Char('/')));
0091   QVERIFY(!entry->field(QStringLiteral("reverse")).isEmpty());
0092   QVERIFY(!entry->field(QStringLiteral("reverse")).contains(QLatin1Char('/')));
0093 }
0094 
0095 void ColnectFetcherTest::testSacagawea() {
0096   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Coin,
0097                                        Tellico::Fetch::Keyword,
0098                                        QStringLiteral("2007 Sacagawea"));
0099   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::ColnectFetcher(this));
0100   fetcher->readConfig(m_config);
0101   QVERIFY(fetcher->canSearch(request.key()));
0102 
0103   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
0104 
0105   QCOMPARE(results.size(), 1);
0106   Tellico::Data::EntryPtr entry = results.at(0);
0107 
0108   QCOMPARE(entry->field(QStringLiteral("year")), QStringLiteral("2007"));
0109   QCOMPARE(entry->field(QStringLiteral("country")), QStringLiteral("United States of America"));
0110   QCOMPARE(entry->field(QStringLiteral("denomination")), QStringLiteral("$1.00"));
0111   QCOMPARE(entry->field(QStringLiteral("currency")), QStringLiteral("$ - United States dollar"));
0112   QCOMPARE(entry->field(QStringLiteral("series")), QStringLiteral("B06a - Eisenhower, Anthony & Sacagawea Dollar"));
0113   QCOMPARE(entry->field(QStringLiteral("mintage")), QStringLiteral("1497251077"));
0114   QVERIFY(!entry->field(QStringLiteral("description")).isEmpty());
0115   QVERIFY(!entry->field(QStringLiteral("obverse")).isEmpty());
0116   QVERIFY(!entry->field(QStringLiteral("obverse")).contains(QLatin1Char('/')));
0117   QVERIFY(!entry->field(QStringLiteral("reverse")).isEmpty());
0118   QVERIFY(!entry->field(QStringLiteral("reverse")).contains(QLatin1Char('/')));
0119 }
0120 
0121 void ColnectFetcherTest::testSkylab() {
0122   KConfigGroup cg = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)->group(QStringLiteral("colnect stamps"));
0123   cg.writeEntry("Custom Fields", QStringLiteral("series,description,stanley-gibbons,michel,colnect"));
0124 
0125   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Stamp,
0126                                        Tellico::Fetch::Title,
0127                                        QStringLiteral("2013 Skylab"));
0128   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::ColnectFetcher(this));
0129   fetcher->readConfig(cg);
0130   QVERIFY(fetcher->canSearch(request.key()));
0131 
0132   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
0133 
0134   QCOMPARE(results.size(), 1);
0135   Tellico::Data::EntryPtr entry = results.at(0);
0136 
0137   QCOMPARE(entry->field(QStringLiteral("year")), QStringLiteral("2013"));
0138   QCOMPARE(entry->field(QStringLiteral("country")), QStringLiteral("Papua New Guinea"));
0139   QCOMPARE(entry->field(QStringLiteral("stanley-gibbons")), QStringLiteral("PG 1638"));
0140   QCOMPARE(entry->field(QStringLiteral("michel")), QStringLiteral("PG 1902"));
0141   QCOMPARE(entry->field(QStringLiteral("series")), QStringLiteral("15th Anniversary of Launch of International Space Station"));
0142   QCOMPARE(entry->field(QStringLiteral("gummed")), QStringLiteral("PVA (Polyvinyl Alcohol)"));
0143   QCOMPARE(entry->field(QStringLiteral("denomination")), QStringLiteral("K1.30"));
0144   QCOMPARE(entry->field(QStringLiteral("currency")), QStringLiteral("K - Papua New Guinean kina"));
0145   QCOMPARE(entry->field(QStringLiteral("color")), QStringLiteral("Multicolor"));
0146   QVERIFY(!entry->field(QStringLiteral("description")).isEmpty());
0147   QCOMPARE(entry->field(QStringLiteral("colnect")), QStringLiteral("https://colnect.com/en/stamps/stamp/717470-Skylab_space_station_1"));
0148   QVERIFY(!entry->field(QStringLiteral("image")).isEmpty());
0149   QVERIFY(!entry->field(QStringLiteral("image")).contains(QLatin1Char('/')));
0150 }
0151 
0152 void ColnectFetcherTest::testComic() {
0153   KConfigGroup cg = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)->group(QStringLiteral("colnect comics"));
0154   cg.writeEntry("Custom Fields", QStringLiteral("series,colnect"));
0155 
0156   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::ComicBook,
0157                                        Tellico::Fetch::Title,
0158                                        QStringLiteral("Destiny's Hand: Finale"));
0159   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::ColnectFetcher(this));
0160   fetcher->readConfig(cg);
0161   QVERIFY(fetcher->canSearch(request.key()));
0162 
0163   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
0164 
0165   QCOMPARE(results.size(), 1);
0166   Tellico::Data::EntryPtr entry = results.at(0);
0167 
0168   QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("Destiny's Hand: Finale"));
0169   QCOMPARE(entry->field(QStringLiteral("pub_year")), QStringLiteral("1993"));
0170   QCOMPARE(entry->field(QStringLiteral("series")), QStringLiteral("Justice League America (JLA)"));
0171   QCOMPARE(entry->field(QStringLiteral("writer")), QStringLiteral("Jurgens Dan"));
0172   QCOMPARE(entry->field(QStringLiteral("artist")), QStringLiteral("Jurgens Dan; Giordano Dick"));
0173   QCOMPARE(entry->field(QStringLiteral("issue")), QStringLiteral("75"));
0174   QCOMPARE(entry->field(QStringLiteral("publisher")), QStringLiteral("DC Comics"));
0175   QCOMPARE(entry->field(QStringLiteral("edition")), QStringLiteral("First edition"));
0176   QCOMPARE(entry->field(QStringLiteral("genre")), QStringLiteral("Superhero"));
0177   QCOMPARE(entry->field(QStringLiteral("colnect")), QStringLiteral("https://colnect.com/en/comics/comic/16515-Destinys_Hand_Finale"));
0178   QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty());
0179   QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/')));
0180 }
0181 
0182 void ColnectFetcherTest::testBaseballCard() {
0183   KConfigGroup cg = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)->group(QStringLiteral("colnect cards"));
0184   cg.writeEntry("Custom Fields", QStringLiteral("series,colnect"));
0185 
0186   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Card,
0187                                        Tellico::Fetch::Title,
0188                                        QStringLiteral("1991 Chipper Jones"));
0189   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::ColnectFetcher(this));
0190   fetcher->readConfig(cg);
0191   QVERIFY(fetcher->canSearch(request.key()));
0192 
0193   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
0194 
0195   QCOMPARE(results.size(), 1);
0196   Tellico::Data::EntryPtr entry = results.at(0);
0197 
0198   QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("1991 Upper Deck Chipper Jones"));
0199   QCOMPARE(entry->field(QStringLiteral("year")), QStringLiteral("1991"));
0200   QCOMPARE(entry->field(QStringLiteral("brand")), QStringLiteral("Upper Deck"));
0201   QCOMPARE(entry->field(QStringLiteral("team")), QStringLiteral("Atlanta Braves"));
0202   QCOMPARE(entry->field(QStringLiteral("number")), QStringLiteral("55"));
0203   QCOMPARE(entry->field(QStringLiteral("series")), QStringLiteral("Base Set"));
0204   QCOMPARE(entry->field(QStringLiteral("type")), QStringLiteral("Major League Baseball"));
0205   QCOMPARE(entry->field(QStringLiteral("colnect")), QStringLiteral("https://colnect.com/en/sports_cards/sports_card/67064-55_Chipper_Jones_1991"));
0206   QVERIFY(!entry->field(QStringLiteral("front")).isEmpty());
0207   QVERIFY(!entry->field(QStringLiteral("front")).contains(QLatin1Char('/')));
0208 }
0209 
0210 void ColnectFetcherTest::testGoldeneye() {
0211   KConfigGroup cg = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)->group(QStringLiteral("colnect games"));
0212   cg.writeEntry("Custom Fields", QStringLiteral("pegi"));
0213 
0214   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Game,
0215                                        Tellico::Fetch::Title,
0216                                        QStringLiteral("Goldeneye 007"));
0217   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::ColnectFetcher(this));
0218   fetcher->readConfig(cg);
0219   QVERIFY(fetcher->canSearch(request.key()));
0220 
0221   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 2);
0222 
0223   QVERIFY(results.size() > 1);
0224   Tellico::Data::EntryPtr entry = results.at(0);
0225 
0226   QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("GoldenEye 007"));
0227   QCOMPARE(entry->field(QStringLiteral("year")), QStringLiteral("1997"));
0228   QCOMPARE(entry->field(QStringLiteral("publisher")), QStringLiteral("Nintendo"));
0229   QCOMPARE(entry->field(QStringLiteral("platform")), QStringLiteral("Nintendo 64"));
0230   QCOMPARE(entry->field(QStringLiteral("genre")), QStringLiteral("FPS"));
0231   QCOMPARE(entry->field(QStringLiteral("pegi")), QStringLiteral("PEGI 16"));
0232   QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty());
0233   QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/')));
0234 
0235   // test against the Japanese version, which is result #2
0236   entry = results.at(1);
0237 
0238   QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("GoldenEye 007"));
0239   QCOMPARE(entry->field(QStringLiteral("year")), QStringLiteral("1997"));
0240   QCOMPARE(entry->field(QStringLiteral("publisher")), QStringLiteral("Nintendo"));
0241   QCOMPARE(entry->field(QStringLiteral("platform")), QStringLiteral("Nintendo 64"));
0242   QCOMPARE(entry->field(QStringLiteral("genre")), QStringLiteral("Shooter"));
0243   QCOMPARE(entry->field(QStringLiteral("certification")), QStringLiteral("Teen"));
0244   QVERIFY(!entry->field(QStringLiteral("description")).isEmpty());
0245   QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty());
0246   QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/')));
0247 }