1 /*
2  * Unit tests for libkvkontakte.
3  * Copyright (C) 2015  Alexander Potashev <aspotashev@gmail.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #include "test_userinfo.h"
21 
22 #include "userinfojob.h"
23 
24 #include <QtTest/QtTest>
25 #include <QtCore/QList>
26 
27 using namespace Vkontakte;
28 
TestUserInfo()29 TestUserInfo::TestUserInfo()
30     : VkTestBase()
31 {
32 }
33 
initTestCase()34 void TestUserInfo::initTestCase()
35 {
36     authenticate(AppPermissions::NoPermissions);
37 }
38 
testUserInfoJob()39 void TestUserInfo::testUserInfoJob()
40 {
41     Vkontakte::UserInfoJob* const job = new Vkontakte::UserInfoJob(
42         accessToken(), 1);
43     job->exec();
44     QVERIFY(!job->error());
45 
46     QList<UserInfo> res = job->userInfo();
47     QCOMPARE(res.size(), 1);
48 
49     const UserInfo user = res.at(0);
50     QCOMPARE(user.userId(), 1);
51     QCOMPARE(user.firstName(), QString::fromUtf8("Павел"));
52     QCOMPARE(user.lastName(), QString::fromUtf8("Дуров"));
53     QCOMPARE(user.nickName(), QString::fromUtf8(""));
54     QCOMPARE(user.sex(), 2);
55     // TODO: verify that "online" status is received from server
56 //     QCOMPARE(user.birthday(), QDate(1984, 10, 10));
57 //     QCOMPARE(user.countryId(), 1); // Russia
58 //     QCOMPARE(user.countryString(), QString::fromUtf8("Россия"));
59 //     QCOMPARE(user.cityId(), 2); // Saint-Petersburg
60 //     QCOMPARE(user.cityString(), QString::fromUtf8("Санкт-Петербург"));
61     QCOMPARE(user.domain(), QStringLiteral("durov"));
62 //     QCOMPARE(user.hasMobile(), true);
63 //     QCOMPARE(user.homePhone(), QString(""));
64 //     QCOMPARE(user.mobilePhone(), QString(""));
65 //     QCOMPARE(user.university(), 1); // SPbSU
66 //     QCOMPARE(user.universityName(), QString::fromUtf8("СПбГУ")); // SPbSU
67 //     QCOMPARE(user.faculty(), 0);
68 //     QCOMPARE(user.facultyName(), QString(""));
69 //     QCOMPARE(user.graduation(), 2006); // graduation year
70 //     QCOMPARE(user.canPost(), false);
71 //     QCOMPARE(user.canWritePrivateMessage(), false);
72     // Timezone is returned only for the current user
73 //     QCOMPARE(user.timezone(), static_cast<int>(UserInfo::INVALID_TIMEZONE));
74 }
75 
testSelfUserInfoJob()76 void TestUserInfo::testSelfUserInfoJob()
77 {
78     Vkontakte::UserInfoJob* const job = new Vkontakte::UserInfoJob(accessToken());
79     job->exec();
80     QVERIFY(!job->error());
81 
82     QList<UserInfo> res = job->userInfo();
83     QCOMPARE(res.size(), 1);
84 
85     const UserInfo user = res.at(0);
86     QVERIFY(user.userId() > 0);
87     QVERIFY(!user.domain().isEmpty());
88     // Timezone is returned only for the current user
89 //     QVERIFY(user.timezone() != static_cast<int>(UserInfo::INVALID_TIMEZONE));
90 }
91 
92 QTEST_MAIN(TestUserInfo)
93