@@ -107,13 +107,13 @@ async function testStory(akun, storyId) {
107
107
} ) ;
108
108
client . storyThread . on ( 'subscriptionSucceeded' , onSubscriptionSucceeded ) ;
109
109
110
- // const resTestPost1 = await client.post ('Test post 1');
110
+ // const resTestPost1 = await client.postChat ('Test post 1');
111
111
// console.log(`post response: ${resTestPost1}`);
112
112
113
113
const resLogin = await akun . login ( credentials [ 'username' ] , credentials [ 'password' ] ) ;
114
114
console . log ( `Logged in as ${ resLogin [ 'username' ] } !` ) ;
115
115
116
- // const resTestPost2 = await client.post ('Test post 2');
116
+ // const resTestPost2 = await client.postChat ('Test post 2');
117
117
// console.log(`post response: ${resTestPost2}`);
118
118
119
119
// console.log(client.latestChapter());
@@ -125,7 +125,7 @@ async function testStory(akun, storyId) {
125
125
// });
126
126
127
127
return new Promise ( res => {
128
- client . storyThread . on ( 'chat' , ( node ) => {
128
+ client . chatThread . on ( 'chat' , ( node ) => {
129
129
if ( node . body === 'exit' ) {
130
130
res ( ) ;
131
131
}
@@ -174,7 +174,7 @@ async function testPut(akun, chatId) {
174
174
const postData = await client . post ( 'Test post' ) ;
175
175
const data = await akun . getNode ( postData [ '_id' ] ) ;
176
176
data . b = 'edited text' ;
177
- console . log ( await akun . put ( '/api/node' , { data } ) ) ;
177
+ console . log ( await akun . put ( '/api/node' , { data} ) ) ;
178
178
}
179
179
180
180
async function testAnonToggle ( akun , chatId ) {
@@ -201,21 +201,65 @@ async function testBan(akun) {
201
201
let res ;
202
202
res = await akun . login ( credentials [ 'username' ] , credentials [ 'password' ] ) ;
203
203
console . log ( res ) ;
204
- res = await akun . unban ( 'iRoYFFCDCZnB2QvEq' , '53zAELYaC8RkkMpcn' ) ;
204
+ res = await akun . ban ( 'iRoYFFCDCZnB2QvEq' , '53zAELYaC8RkkMpcn' ) ;
205
205
console . log ( res ) ;
206
206
res = await akun . unban ( 'iRoYFFCDCZnB2QvEq' , 'B5cqvTk3kMgRNPesr' ) ;
207
207
console . log ( res ) ;
208
208
}
209
209
210
+ async function testPollOpenClose ( akun ) {
211
+ await akun . login ( credentials [ 'username' ] , credentials [ 'password' ] ) ;
212
+
213
+ while ( true ) {
214
+ console . log ( await akun . closeChoice ( '58BfMER3GZg48LbYm' ) ) ;
215
+ await setTimeoutPromise ( 1000 ) ;
216
+ console . log ( await akun . openChoice ( '58BfMER3GZg48LbYm' ) ) ;
217
+ await setTimeoutPromise ( 1000 ) ;
218
+ }
219
+ }
220
+
221
+ async function testPollChoiceRemoval ( akun ) {
222
+ let res ;
223
+ res = await akun . login ( credentials [ 'username' ] , credentials [ 'password' ] ) ;
224
+ console . log ( res ) ;
225
+ const client = await akun . join ( 'vhHhMfskRnNDbxwzo' ) ;
226
+ client . storyThread . on ( 'choice' , ( node ) => {
227
+ onChoice ( akun , client , node ) ;
228
+ for ( let choiceId = 0 ; choiceId < node . choiceValues . length ; choiceId ++ ) {
229
+ if ( node . choiceValues [ choiceId ] === 'test' ) {
230
+ akun . removeChoiceNodeChoice ( node . id , choiceId ) . then ( res => console . log ( res ) )
231
+ }
232
+ }
233
+ } ) ;
234
+ client . storyThread . on ( 'choiceUpdated' , ( node ) => {
235
+ onChoiceUpdated ( akun , client , node ) ;
236
+ for ( let choiceId = 0 ; choiceId < node . choiceValues . length ; choiceId ++ ) {
237
+ if ( node . choiceValues [ choiceId ] === 'test' ) {
238
+ akun . removeChoiceNodeChoice ( node . id , choiceId , 'sample reason' ) . then ( res => console . log ( res ) )
239
+ }
240
+ }
241
+ } ) ;
242
+
243
+ return new Promise ( res => {
244
+ client . chatThread . on ( 'chat' , ( node ) => {
245
+ if ( node . body === 'exit' ) {
246
+ res ( ) ;
247
+ }
248
+ } ) ;
249
+ } )
250
+ }
251
+
210
252
async function runTests ( akun ) {
211
253
// await testAnonToggle(akun, 'vhHhMfskRnNDbxwzo');
212
254
// await testPost(akun, 'vhHhMfskRnNDbxwzo');
213
255
await testStory ( akun , 'vhHhMfskRnNDbxwzo' ) ;
214
- // await testChat(akun, 'oQ2fkvRS4nxjLfSmA');
256
+ // await testChat(akun, 'oQ2fkvRS4nxjLfSmA');
215
257
// await testChat(akun, 'oWC3WhFDMXqZkAG69');
216
258
// await testPut(akun, 'vhHhMfskRnNDbxwzo');
217
259
// await testVote(akun, 'TziTddJsppEfr82nh');
260
+ // await testPollOpenClose(akun);
218
261
// await testBan(akun);
262
+ // await testPollChoiceRemoval(akun);
219
263
}
220
264
221
265
async function setup ( withRealtime = true ) {
0 commit comments