File indexing completed on 2024-12-01 04:35:27

0001 /*
0002    SPDX-FileCopyrightText: 2017-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "rocketchatmessagetest.h"
0008 #include "rocketchatmessage.h"
0009 #include "ruqola_autotest_helper.h"
0010 
0011 QTEST_GUILESS_MAIN(RocketChatMessageTest)
0012 
0013 RocketChatMessageTest::RocketChatMessageTest(QObject *parent)
0014     : QObject(parent)
0015 {
0016 }
0017 
0018 void RocketChatMessageTest::compareFile(const QString &data, const QString &name)
0019 {
0020     AutoTestHelper::compareFile(QStringLiteral("/method/"), data.toUtf8(), name);
0021 }
0022 
0023 void RocketChatMessageTest::shouldJoinRoom()
0024 {
0025     RocketChatMessage m;
0026     m.setJsonFormat(QJsonDocument::Indented);
0027     RocketChatMessage::RocketChatMessageResult r = m.joinRoom(QStringLiteral("foo"), QStringLiteral("access_code"), 43);
0028     compareFile(r.result, QStringLiteral("joinroom"));
0029 }
0030 
0031 void RocketChatMessageTest::shouldSetDefaultStatus()
0032 {
0033     RocketChatMessage m;
0034     m.setJsonFormat(QJsonDocument::Indented);
0035     RocketChatMessage::RocketChatMessageResult r = m.setDefaultStatus(User::PresenceStatus::PresenceBusy, 42);
0036     compareFile(r.result, QStringLiteral("defaultstatusbusy"));
0037 
0038     r = m.setDefaultStatus(User::PresenceStatus::PresenceAway, 43);
0039     compareFile(r.result, QStringLiteral("defaultstatusaway"));
0040 
0041     r = m.setDefaultStatus(User::PresenceStatus::PresenceOffline, 44);
0042     compareFile(r.result, QStringLiteral("defaultstatusoffline"));
0043 
0044     r = m.setDefaultStatus(User::PresenceStatus::PresenceOnline, 45);
0045     compareFile(r.result, QStringLiteral("defaultstatusonline"));
0046 }
0047 
0048 void RocketChatMessageTest::shouldInformTypingStatus()
0049 {
0050     RocketChatMessage m;
0051     m.setJsonFormat(QJsonDocument::Indented);
0052     RocketChatMessage::RocketChatMessageResult r = m.informTypingStatus(QStringLiteral("roomId"), QStringLiteral("user1"), false, 42);
0053     compareFile(r.result, QStringLiteral("informtypingstatusfalse"));
0054 
0055     r = m.informTypingStatus(QStringLiteral("roomId2"), QStringLiteral("user2"), true, 43);
0056     compareFile(r.result, QStringLiteral("informtypingstatustrue"));
0057 }
0058 
0059 void RocketChatMessageTest::shouldUserAutoComplete()
0060 {
0061     RocketChatMessage m;
0062     m.setJsonFormat(QJsonDocument::Indented);
0063     RocketChatMessage::RocketChatMessageResult r = m.userAutocomplete(QStringLiteral("foo"), QStringLiteral("exception"), 43);
0064     compareFile(r.result, QStringLiteral("userAutocomplete"));
0065 
0066     r = m.userAutocomplete(QStringLiteral("foo"), QStringLiteral("foo,bla,bli"), 43);
0067     compareFile(r.result, QStringLiteral("userAutocomplete-exceptions"));
0068 }
0069 
0070 // TODO fix me
0071 void RocketChatMessageTest::shouldSendFileMessage()
0072 {
0073     RocketChatMessage m;
0074     m.setJsonFormat(QJsonDocument::Indented);
0075     // FIXME
0076     // RocketChatMessage::RocketChatMessageResult r = m.sendFileMessage(43);
0077     // compareFile(r.result, QStringLiteral("sendFileMessage"));
0078 }
0079 
0080 void RocketChatMessageTest::shouldSplotlightWithoutUsers()
0081 {
0082     RocketChatMessage m;
0083     m.setJsonFormat(QJsonDocument::Indented);
0084     RocketChatMessage::RocketChatMessageResult r = m.searchRoomUsers(QString(), QStringLiteral("room"), QStringLiteral("foo,bla"), false, true, 43);
0085     compareFile(r.result, QStringLiteral("spotlight-without-users"));
0086 }
0087 
0088 void RocketChatMessageTest::shouldSplotlightWithoutRooms()
0089 {
0090     RocketChatMessage m;
0091     m.setJsonFormat(QJsonDocument::Indented);
0092     RocketChatMessage::RocketChatMessageResult r = m.searchRoomUsers(QString(), QStringLiteral("room"), QStringLiteral("foo,bla"), true, false, 43);
0093     compareFile(r.result, QStringLiteral("spotlight-without-rooms"));
0094 }
0095 
0096 void RocketChatMessageTest::inputChannelAutocomplete()
0097 {
0098     RocketChatMessage m;
0099     m.setJsonFormat(QJsonDocument::Indented);
0100     RocketChatMessage::RocketChatMessageResult r = m.inputChannelAutocomplete(QString(), QStringLiteral("pattern"), QStringLiteral("exception"), 43);
0101     compareFile(r.result, QStringLiteral("inputChannelAutocomplete"));
0102 }
0103 
0104 void RocketChatMessageTest::inputUserAutocomplete()
0105 {
0106     RocketChatMessage m;
0107     m.setJsonFormat(QJsonDocument::Indented);
0108     RocketChatMessage::RocketChatMessageResult r = m.inputUserAutocomplete(QString(), QStringLiteral("pattern"), QStringLiteral("exception"), 43);
0109     compareFile(r.result, QStringLiteral("inputUserAutocomplete"));
0110 }
0111 
0112 void RocketChatMessageTest::inputUserWithRoomIdAutocomplete()
0113 {
0114     RocketChatMessage m;
0115     m.setJsonFormat(QJsonDocument::Indented);
0116     RocketChatMessage::RocketChatMessageResult r =
0117         m.inputUserAutocomplete(QStringLiteral("RoomId25"), QStringLiteral("pattern"), QStringLiteral("exception"), 43);
0118     compareFile(r.result, QStringLiteral("inputUserWithRoomIdAutocomplete"));
0119 }
0120 
0121 void RocketChatMessageTest::blockUser()
0122 {
0123     RocketChatMessage m;
0124     m.setJsonFormat(QJsonDocument::Indented);
0125     RocketChatMessage::RocketChatMessageResult r = m.blockUser(QStringLiteral("rid"), QStringLiteral("userId"), 43);
0126     compareFile(r.result, QStringLiteral("blockUser"));
0127 }
0128 
0129 void RocketChatMessageTest::setAdminStatus()
0130 {
0131     {
0132         RocketChatMessage m;
0133         m.setJsonFormat(QJsonDocument::Indented);
0134         RocketChatMessage::RocketChatMessageResult r = m.setAdminStatus(QStringLiteral("userId"), false, 43);
0135         compareFile(r.result, QStringLiteral("setAdminStatusFalse"));
0136     }
0137     {
0138         RocketChatMessage m;
0139         m.setJsonFormat(QJsonDocument::Indented);
0140         RocketChatMessage::RocketChatMessageResult r = m.setAdminStatus(QStringLiteral("userId"), false, 43);
0141         compareFile(r.result, QStringLiteral("setAdminStatusTrue"));
0142     }
0143 }
0144 
0145 void RocketChatMessageTest::deleteOAuthApp()
0146 {
0147     RocketChatMessage m;
0148     m.setJsonFormat(QJsonDocument::Indented);
0149     RocketChatMessage::RocketChatMessageResult r = m.deleteOAuthApp(QStringLiteral("oauthappid"), 43);
0150     compareFile(r.result, QStringLiteral("deleteOAuthApp"));
0151 }
0152 
0153 void RocketChatMessageTest::addOAuthApp()
0154 {
0155     {
0156         RocketChatMessage m;
0157         m.setJsonFormat(QJsonDocument::Indented);
0158         RocketChatMessage::RocketChatMessageResult r = m.addOAuthApp(QStringLiteral("oauthappname"), true, QStringLiteral("url"), 43);
0159         compareFile(r.result, QStringLiteral("addOAuthApp"));
0160     }
0161     {
0162         RocketChatMessage m;
0163         m.setJsonFormat(QJsonDocument::Indented);
0164         RocketChatMessage::RocketChatMessageResult r = m.addOAuthApp(QStringLiteral("oauthappname"), false, QStringLiteral("url"), 43);
0165         compareFile(r.result, QStringLiteral("addOAuthApp-disabled"));
0166     }
0167 }
0168 
0169 void RocketChatMessageTest::updateOAuthApp()
0170 {
0171     // TODO
0172     {
0173         RocketChatMessage m;
0174         m.setJsonFormat(QJsonDocument::Indented);
0175         RocketChatMessage::RocketChatMessageResult r = m.addOAuthApp(QStringLiteral("updateoauthappname"), true, QStringLiteral("url"), 43);
0176         compareFile(r.result, QStringLiteral("updateOAuthApp"));
0177     }
0178 }
0179 
0180 void RocketChatMessageTest::unBlockUser()
0181 {
0182     RocketChatMessage m;
0183     m.setJsonFormat(QJsonDocument::Indented);
0184     RocketChatMessage::RocketChatMessageResult r = m.unblockUser(QStringLiteral("rid"), QStringLiteral("userId"), 43);
0185     compareFile(r.result, QStringLiteral("unBlockUser"));
0186 }
0187 
0188 void RocketChatMessageTest::streamNotifyUserOtrEnd()
0189 {
0190     RocketChatMessage m;
0191     m.setJsonFormat(QJsonDocument::Indented);
0192     RocketChatMessage::RocketChatMessageResult r = m.streamNotifyUserOtrEnd(QStringLiteral("userFrom"), QStringLiteral("userTo"), 43);
0193     compareFile(r.result, QStringLiteral("streamNotifyUserOtrEnd"));
0194 }
0195 
0196 void RocketChatMessageTest::streamNotifyUserOtrHandshake()
0197 {
0198     RocketChatMessage m;
0199     m.setJsonFormat(QJsonDocument::Indented);
0200     RocketChatMessage::RocketChatMessageResult r =
0201         m.streamNotifyUserOtrHandshake(QStringLiteral("userFrom"), QStringLiteral("userTo"), QStringLiteral("publickeys"), 43);
0202     compareFile(r.result, QStringLiteral("streamNotifyUserOtrHandshake"));
0203 }
0204 
0205 void RocketChatMessageTest::streamNotifyUserOtrAcknowledge()
0206 {
0207     RocketChatMessage m;
0208     m.setJsonFormat(QJsonDocument::Indented);
0209     RocketChatMessage::RocketChatMessageResult r =
0210         m.streamNotifyUserOtrAcknowledge(QStringLiteral("userFrom"), QStringLiteral("userTo"), QStringLiteral("publickeys"), 43);
0211     compareFile(r.result, QStringLiteral("streamNotifyUserOtrAcknowledge"));
0212 }
0213 
0214 void RocketChatMessageTest::listCustomSounds()
0215 {
0216     RocketChatMessage m;
0217     m.setJsonFormat(QJsonDocument::Indented);
0218     RocketChatMessage::RocketChatMessageResult r = m.listCustomSounds(43);
0219     compareFile(r.result, QStringLiteral("listCustomSounds"));
0220 }
0221 
0222 void RocketChatMessageTest::deleteFileMessage()
0223 {
0224     RocketChatMessage m;
0225     m.setJsonFormat(QJsonDocument::Indented);
0226     RocketChatMessage::RocketChatMessageResult r = m.deleteFileMessage(QStringLiteral("fileid"), 43);
0227     compareFile(r.result, QStringLiteral("deleteFileMessage"));
0228 }
0229 
0230 void RocketChatMessageTest::deleteCustomSound()
0231 {
0232     RocketChatMessage m;
0233     m.setJsonFormat(QJsonDocument::Indented);
0234     RocketChatMessage::RocketChatMessageResult r = m.deleteCustomSound(QStringLiteral("identifier"), 43);
0235     compareFile(r.result, QStringLiteral("deleteCustomSound"));
0236 }
0237 
0238 void RocketChatMessageTest::enable2fa()
0239 {
0240     RocketChatMessage m;
0241     m.setJsonFormat(QJsonDocument::Indented);
0242     RocketChatMessage::RocketChatMessageResult r = m.enable2fa(43);
0243     compareFile(r.result, QStringLiteral("enable2fa"));
0244 }
0245 
0246 void RocketChatMessageTest::disable2fa()
0247 {
0248     RocketChatMessage m;
0249     m.setJsonFormat(QJsonDocument::Indented);
0250     RocketChatMessage::RocketChatMessageResult r = m.disable2fa(QStringLiteral("bla"), 43);
0251     compareFile(r.result, QStringLiteral("disable2fa"));
0252 }
0253 
0254 void RocketChatMessageTest::validateTempToken2fa()
0255 {
0256     RocketChatMessage m;
0257     m.setJsonFormat(QJsonDocument::Indented);
0258     RocketChatMessage::RocketChatMessageResult r = m.validateTempToken2fa(QStringLiteral("bla"), 43);
0259     compareFile(r.result, QStringLiteral("validateTempToken2fa"));
0260 }
0261 
0262 void RocketChatMessageTest::regenerateCodes2fa()
0263 {
0264     RocketChatMessage m;
0265     m.setJsonFormat(QJsonDocument::Indented);
0266     RocketChatMessage::RocketChatMessageResult r = m.regenerateCodes2fa(QStringLiteral("bla"), 43);
0267     compareFile(r.result, QStringLiteral("regenerateCodes2fa"));
0268 }
0269 
0270 void RocketChatMessageTest::openRoom()
0271 {
0272     RocketChatMessage m;
0273     m.setJsonFormat(QJsonDocument::Indented);
0274     RocketChatMessage::RocketChatMessageResult r = m.openRoom(QStringLiteral("bla"), 43);
0275     compareFile(r.result, QStringLiteral("openroom"));
0276 }
0277 
0278 void RocketChatMessageTest::getroombyid()
0279 {
0280     RocketChatMessage m;
0281     m.setJsonFormat(QJsonDocument::Indented);
0282     RocketChatMessage::RocketChatMessageResult r = m.getRoomById(QStringLiteral("bla"), 43);
0283     compareFile(r.result, QStringLiteral("getroombyid"));
0284 }
0285 
0286 void RocketChatMessageTest::bannerDismiss()
0287 {
0288     RocketChatMessage m;
0289     m.setJsonFormat(QJsonDocument::Indented);
0290     RocketChatMessage::RocketChatMessageResult r = m.bannerDismiss(QStringLiteral("banner_read"), 43);
0291     compareFile(r.result, QStringLiteral("bannerDismiss"));
0292 }
0293 
0294 void RocketChatMessageTest::licenseGetModules()
0295 {
0296     RocketChatMessage m;
0297     m.setJsonFormat(QJsonDocument::Indented);
0298     RocketChatMessage::RocketChatMessageResult r = m.licenseGetModules(43);
0299     compareFile(r.result, QStringLiteral("licenseGetModules"));
0300 }
0301 
0302 void RocketChatMessageTest::videoConferenceAccepted()
0303 {
0304     RocketChatMessage m;
0305     m.setJsonFormat(QJsonDocument::Indented);
0306 
0307     RocketChatMessage::RocketChatMessageResult r = m.videoConferenceAccepted(QStringLiteral("YbwG4T2uB3wZSZSKBxkNpoB3T98EEPCj2K"),
0308                                                                              QStringLiteral("639976cb31e2ca494753c439"),
0309                                                                              QStringLiteral("YbwG4T2uB3wZSZSKB"),
0310                                                                              43);
0311     compareFile(r.result, QStringLiteral("videoConferenceAccepted"));
0312 }
0313 
0314 void RocketChatMessageTest::videoConferenceRejected()
0315 {
0316     RocketChatMessage m;
0317     m.setJsonFormat(QJsonDocument::Indented);
0318 
0319     RocketChatMessage::RocketChatMessageResult r = m.videoConferenceRejected(QStringLiteral("YbwG4T2uB3wZSZSKBxkNpoB3T98EEPCj2K"),
0320                                                                              QStringLiteral("639976cb31e2ca494753c439"),
0321                                                                              QStringLiteral("YbwG4T2uB3wZSZSKB"),
0322                                                                              43);
0323     compareFile(r.result, QStringLiteral("videoConferenceRejected"));
0324 }
0325 
0326 void RocketChatMessageTest::videoConferenceCall()
0327 {
0328     RocketChatMessage m;
0329     m.setJsonFormat(QJsonDocument::Indented);
0330 
0331     RocketChatMessage::RocketChatMessageResult r = m.videoConferenceCall(QStringLiteral("YbwG4T2uB3wZSZSKBxkNpoB3T98EEPCj2K"),
0332                                                                          QStringLiteral("639976cb31e2ca494753c439"),
0333                                                                          QStringLiteral("YbwG4T2uB3wZSZSKB"),
0334                                                                          43);
0335     compareFile(r.result, QStringLiteral("videoConferenceCall"));
0336 }
0337 
0338 void RocketChatMessageTest::videoConferenceConfirmed()
0339 {
0340     RocketChatMessage m;
0341     m.setJsonFormat(QJsonDocument::Indented);
0342 
0343     RocketChatMessage::RocketChatMessageResult r = m.videoConferenceConfirmed(QStringLiteral("YbwG4T2uB3wZSZSKBxkNpoB3T98EEPCj2K"),
0344                                                                               QStringLiteral("639976cb31e2ca494753c439"),
0345                                                                               QStringLiteral("YbwG4T2uB3wZSZSKB"),
0346                                                                               43);
0347     compareFile(r.result, QStringLiteral("videoConferenceConfirmed"));
0348 }
0349 
0350 #include "moc_rocketchatmessagetest.cpp"