Skip to content

Commit 32c3092

Browse files
committed
added new tests for helpers spec
1 parent 8cbdfbf commit 32c3092

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

samples/chat/js/dialogs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ function retrieveChatDialogs() {
5757
if (item.type != 3) {
5858
QB.chat.muc.join(item.xmpp_room_jid, function() {
5959
console.log("Joined dialog "+dialogId);
60+
console.log(item)
6061
});
6162
}
6263

spec/QB-HelpersSpec.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
var LOGIN_TIMEOUT = 10000;
2+
13
describe('Helpers', function() {
24

35
// beforeAll
@@ -9,11 +11,13 @@ describe('Helpers', function() {
911
it("can generate user's jid", function() {
1012
var userJid = QB.chat.helpers.getUserJid(5, 29650);
1113
expect(userJid).toEqual("5-29650@chat.quickblox.com");
14+
console.info("can generate user's jid");
1215
});
1316

1417
it("can return jid from jid or from user's id", function() {
1518
var jid = QB.chat.helpers.jidOrUserId(100500);
1619
expect(jid).toEqual("100500-29650@chat.quickblox.com");
20+
console.info("can return jid from jid or from user's id");
1721
});
1822

1923
it("can get type chat from jid or from user's id", function() {
@@ -23,14 +27,71 @@ describe('Helpers', function() {
2327
expect(jid).toEqual("chat");
2428
var room = QB.chat.helpers.typeChat("29650_562f271ba28f9aa53e004788@muc.chat.quickblox.com");
2529
expect(room).toEqual("groupchat");
30+
console.info("can get type chat from jid or from user's id");
2631
});
2732

2833
it("can get recipient id from privat chat", function() {
2934
var occupantsIds = [100500, 707070];
3035
var userId = 100500;
3136
var recipientId = QB.chat.helpers.getRecipientId(occupantsIds, userId);
3237
expect(recipientId).toEqual(707070);
38+
console.info("can get recipient id from privat chat");
39+
});
40+
41+
it("can get user nick with muc domain", function() {
42+
var userNick = QB.chat.helpers.getUserNickWithMucDomain(100500);
43+
expect(userNick).toEqual("muc.chat.quickblox.com/100500");
44+
console.info("can get user nick with muc domain");
3345
});
3446

47+
it("can get id from node", function() {
48+
var userId = QB.chat.helpers.getIdFromNode("100500-29650@chat.quickblox.com");
49+
expect(userId).toEqual(100500);
50+
console.info("can get id from node");
51+
});
52+
53+
it("can get dialog id from node", function() {
54+
var dialogId = QB.chat.helpers.getDialogIdFromNode("28287_5640ada2a28f9a76540006b6@muc.chat.quickblox.com");
55+
expect(dialogId).toEqual("5640ada2a28f9a76540006b6");
56+
console.info("can get dialog id from node");
57+
});
58+
59+
it("can get roomJid from jid", function(done) {
60+
QB.chat.connect({userId: QBUser1.id, password: QBUser1.password}, function(err, roster) {
61+
if (err) {
62+
done.fail("Connection to chat error: " + JSON.stringify(err));
63+
} else {
64+
var roomJid = QB.chat.helpers.getRoomJid("28287_5640ada2a28f9a76540006b6@muc.chat.quickblox.com");
65+
expect(roomJid).toEqual("28287_5640ada2a28f9a76540006b6@muc.chat.quickblox.com/6126733");
66+
console.info("can get roomJid from jid");
67+
done();
68+
}
69+
});
70+
}, LOGIN_TIMEOUT);
71+
72+
it("can get id from resource", function() {
73+
var userId = QB.chat.helpers.getIdFromResource("28287_5640ada2a28f9a76540006b6@muc.chat.quickblox.com/6126733");
74+
expect(userId).toEqual(6126733);
75+
console.info("can get id from resource");
76+
});
77+
78+
it("can get unique id", function() {
79+
var uniqueId = QB.chat.helpers.getUniqueId();
80+
expect(uniqueId).toEqual(jasmine.any(String));
81+
console.info("can get unique id");
82+
});
83+
84+
it("can get bson object id", function() {
85+
var ObjectId = QB.chat.helpers.getBsonObjectId();
86+
expect(ObjectId).toEqual(jasmine.any(String));
87+
console.info("can get bson object id");
88+
});
89+
90+
it("can get user id from roomJid", function() {
91+
var userId = QB.chat.helpers.getUserIdFromRoomJid("28287_5640ada2a28f9a76540006b6@muc.chat.quickblox.com/6126733");
92+
expect(userId).toEqual("6126733");
93+
console.info("can get user id from roomJid");
94+
});
95+
3596
});
3697

0 commit comments

Comments
 (0)