@@ -9,8 +9,10 @@ describe("postWarning", () => {
9
9
const endpoint = "/api/warnUser" ;
10
10
const getWarning = ( userID : string , type = 0 ) => db . prepare ( "get" , `SELECT "userID", "issueTime", "issuerUserID", enabled, "reason" FROM warnings WHERE "userID" = ? AND "type" = ?` , [ userID , type ] ) ;
11
11
12
- const warneduserID = "warning-0" ;
13
- const warnedUserPublicID = getHash ( warneduserID ) ;
12
+ const warneduserOneID = "warning-0" ;
13
+ const warnedUserTwoID = "warning-1" ;
14
+ const warnedUserOnePublicID = getHash ( warneduserOneID ) ;
15
+ const warnedUserTwoPublicID = getHash ( warnedUserTwoID ) ;
14
16
const warningVipOne = "warning-vip-1" ;
15
17
const warningVipTwo = "warning-vip-2" ;
16
18
const nonVipUser = "warning-non-vip" ;
@@ -23,7 +25,7 @@ describe("postWarning", () => {
23
25
it ( "Should be able to create warning if vip (exp 200)" , ( done ) => {
24
26
const json = {
25
27
issuerUserID : warningVipOne ,
26
- userID : warnedUserPublicID ,
28
+ userID : warnedUserOnePublicID ,
27
29
reason : "warning-reason-0"
28
30
} ;
29
31
client . post ( endpoint , json )
@@ -44,7 +46,7 @@ describe("postWarning", () => {
44
46
it ( "Should be not be able to create a duplicate warning if vip" , ( done ) => {
45
47
const json = {
46
48
issuerUserID : warningVipOne ,
47
- userID : warnedUserPublicID ,
49
+ userID : warnedUserOnePublicID ,
48
50
} ;
49
51
50
52
client . post ( endpoint , json )
@@ -64,7 +66,7 @@ describe("postWarning", () => {
64
66
it ( "Should be able to remove warning if vip" , ( done ) => {
65
67
const json = {
66
68
issuerUserID : warningVipOne ,
67
- userID : warnedUserPublicID ,
69
+ userID : warnedUserOnePublicID ,
68
70
enabled : false
69
71
} ;
70
72
@@ -84,7 +86,7 @@ describe("postWarning", () => {
84
86
it ( "Should not be able to create warning if not vip (exp 403)" , ( done ) => {
85
87
const json = {
86
88
issuerUserID : nonVipUser ,
87
- userID : warnedUserPublicID ,
89
+ userID : warnedUserOnePublicID ,
88
90
} ;
89
91
90
92
client . post ( endpoint , json )
@@ -107,7 +109,7 @@ describe("postWarning", () => {
107
109
it ( "Should re-enable disabled warning" , ( done ) => {
108
110
const json = {
109
111
issuerUserID : warningVipOne ,
110
- userID : warnedUserPublicID ,
112
+ userID : warnedUserOnePublicID ,
111
113
enabled : true
112
114
} ;
113
115
@@ -126,14 +128,14 @@ describe("postWarning", () => {
126
128
127
129
it ( "Should be able to remove your own warning" , ( done ) => {
128
130
const json = {
129
- userID : warneduserID ,
131
+ userID : warneduserOneID ,
130
132
enabled : false
131
133
} ;
132
134
133
135
client . post ( endpoint , json )
134
136
. then ( async res => {
135
137
assert . strictEqual ( res . status , 200 ) ;
136
- const data = await getWarning ( warnedUserPublicID ) ;
138
+ const data = await getWarning ( warnedUserOnePublicID ) ;
137
139
const expected = {
138
140
enabled : 0
139
141
} ;
@@ -145,14 +147,14 @@ describe("postWarning", () => {
145
147
146
148
it ( "Should not be able to add your own warning" , ( done ) => {
147
149
const json = {
148
- userID : warneduserID ,
150
+ userID : warneduserOneID ,
149
151
enabled : true
150
152
} ;
151
153
152
154
client . post ( endpoint , json )
153
155
. then ( async res => {
154
156
assert . strictEqual ( res . status , 403 ) ;
155
- const data = await getWarning ( warnedUserPublicID ) ;
157
+ const data = await getWarning ( warnedUserOnePublicID ) ;
156
158
const expected = {
157
159
enabled : 0
158
160
} ;
@@ -161,4 +163,39 @@ describe("postWarning", () => {
161
163
} )
162
164
. catch ( err => done ( err ) ) ;
163
165
} ) ;
166
+
167
+ it ( "Should not be able to warn a user without reason" , ( done ) => {
168
+ const json = {
169
+ issuerUserID : warningVipOne ,
170
+ userID : warnedUserTwoPublicID ,
171
+ enabled : true
172
+ } ;
173
+
174
+ client . post ( endpoint , json )
175
+ . then ( res => {
176
+ assert . strictEqual ( res . status , 400 ) ;
177
+ done ( ) ;
178
+ } )
179
+ . catch ( err => done ( err ) ) ;
180
+ } ) ;
181
+
182
+ it ( "Should be able to re-warn a user without reason" , ( done ) => {
183
+ const json = {
184
+ issuerUserID : warningVipOne ,
185
+ userID : warnedUserOnePublicID ,
186
+ enabled : true
187
+ } ;
188
+
189
+ client . post ( endpoint , json )
190
+ . then ( async res => {
191
+ assert . strictEqual ( res . status , 200 ) ;
192
+ const data = await getWarning ( warnedUserOnePublicID ) ;
193
+ const expected = {
194
+ enabled : 1
195
+ } ;
196
+ assert . ok ( partialDeepEquals ( data , expected ) ) ;
197
+ done ( ) ;
198
+ } )
199
+ . catch ( err => done ( err ) ) ;
200
+ } ) ;
164
201
} ) ;
0 commit comments