1
+ const chai = window . chai ;
2
+
3
+ describe ( "Sortable tests" , ( ) => {
4
+ const username0 = "test0" ;
5
+ const username1 = "test1" ;
6
+
7
+ const pw = "12345" ;
8
+
9
+ /** @type User */
10
+ let user0 , user1 ;
11
+
12
+ /** @type Group */
13
+ let group , group_for_user_1 ;
14
+
15
+ const sentc = window . Sentc . default ;
16
+
17
+ before ( async ( ) => {
18
+ await sentc . init ( {
19
+ app_token : "5zMb6zs3dEM62n+FxjBilFPp+j9e7YUFA+7pi6Hi" ,
20
+ base_url : "http://127.0.0.1:3002"
21
+ } ) ;
22
+
23
+ await sentc . register ( username0 , pw ) ;
24
+
25
+ user0 = await sentc . login ( username0 , pw ) ;
26
+
27
+ await sentc . register ( username1 , pw ) ;
28
+
29
+ user1 = await sentc . login ( username1 , pw ) ;
30
+ } ) ;
31
+
32
+ it ( "should create a group" , async function ( ) {
33
+ const group_id = await user0 . createGroup ( ) ;
34
+
35
+ group = await user0 . getGroup ( group_id ) ;
36
+
37
+ chai . assert . equal ( group . data . group_id , group_id ) ;
38
+ } ) ;
39
+
40
+ it ( "should invite the 2nd user in this group" , async function ( ) {
41
+ await group . inviteAuto ( user1 . user_data . user_id ) ;
42
+
43
+ group_for_user_1 = await user1 . getGroup ( group . data . group_id ) ;
44
+ } ) ;
45
+
46
+ let a , b , c ;
47
+
48
+ it ( "should encrypt a number" , function ( ) {
49
+ a = group . encryptSortableRawNumber ( 262 ) ;
50
+ b = group . encryptSortableRawNumber ( 263 ) ;
51
+ c = group . encryptSortableRawNumber ( 65321 ) ;
52
+
53
+ chai . assert . equal ( ( a < b ) , true ) ;
54
+ chai . assert . equal ( ( b < c ) , true ) ;
55
+ } ) ;
56
+
57
+ it ( "should get the same numbers as result back" , function ( ) {
58
+ const a1 = group_for_user_1 . encryptSortableRawNumber ( 262 ) ;
59
+ const b1 = group_for_user_1 . encryptSortableRawNumber ( 263 ) ;
60
+ const c1 = group_for_user_1 . encryptSortableRawNumber ( 65321 ) ;
61
+
62
+ chai . assert . equal ( ( a1 < b1 ) , true ) ;
63
+ chai . assert . equal ( ( b1 < c1 ) , true ) ;
64
+
65
+ chai . assert . equal ( a , a1 ) ;
66
+ chai . assert . equal ( b , b1 ) ;
67
+ chai . assert . equal ( c , c1 ) ;
68
+ } ) ;
69
+
70
+ after ( async ( ) => {
71
+ //clean up
72
+
73
+ await group . deleteGroup ( ) ;
74
+
75
+ await user0 . deleteUser ( pw ) ;
76
+ await user1 . deleteUser ( pw ) ;
77
+ } ) ;
78
+ } ) ;
0 commit comments