add some more posting, cyclic test, moving, deleting, bans, range bans w/modlog records

indiachan-spamvector
Thomas Lynch 2 years ago
parent 40b514933c
commit bafecbd847
  1. 321
      test/actions.js

@ -26,59 +26,13 @@ module.exports = () => describe('Test post modactions', () => {
.then(json => json.token);
});
test('delete 5 random posts from /test/', async () => {
const threads = await fetch('http://localhost/test/catalog.json').then(res => res.json());
for (let i = 0; i < 5; i++) {
const thread = threads[Math.floor(Math.random() * threads.length)];
const params = new URLSearchParams({
_csrf: csrfToken,
delete: '1',
});
params.append('checkedposts', thread.postId);
const response = await fetch('http://localhost/forms/board/test/modactions', {
headers: {
'x-using-xhr': 'true',
'cookie': sessionCookie,
},
method: 'POST',
body: params,
});
expect(response.ok).toBe(true);
}
//this is scuffed but because the json could still be building async in the background this can break following tests
await new Promise((resolve) => { setTimeout(resolve, 1000) });
});
test('bumplock, lock, and sticky 5 random posts from /test/', async () => {
const threads = await fetch('http://localhost/test/catalog.json').then(res => res.json());
for (let i = 0; i < 5; i++) {
const thread = threads[Math.floor(Math.random() * threads.length)];
const params = new URLSearchParams({
_csrf: csrfToken,
sticky: i+1,
bumplock: '1',
lock: '1',
});
params.append('checkedposts', thread.postId);
const response = await fetch('http://localhost/forms/board/test/modactions', {
headers: {
'x-using-xhr': 'true',
'cookie': sessionCookie,
},
method: 'POST',
body: params,
});
expect(response.ok).toBe(true);
}
});
jest.setTimeout(5*60*1000); //give a generous timeout
test('make new 5 threads with 10 replies each', async () => {
test('make new 10 threads with 10 replies each', async () => {
const threadParams = new URLSearchParams();
threadParams.append('message', Math.random());
threadParams.append('captcha', '000000');
const promises = [];
for (let t = 0; t < 5; t++) {
for (let t = 0; t < 10; t++) {
const promise = fetch('http://localhost/forms/board/test/post', {
headers: {
'x-using-xhr': 'true',
@ -109,6 +63,31 @@ module.exports = () => describe('Test post modactions', () => {
}
await Promise.all(promises); //wait for all posts to go through
jest.setTimeout(5*1000); //back to normal timeout
await new Promise((resolve) => { setTimeout(resolve, 1000) }); //wait for async builds
});
test('bumplock, lock, and sticky 5 random posts from /test/', async () => {
const threads = await fetch('http://localhost/test/catalog.json').then(res => res.json());
const params = new URLSearchParams({
_csrf: csrfToken,
sticky: '1',
bumplock: '1',
lock: '1',
});
for (let i = 0; i < 5; i++) {
const thread = threads[Math.floor(Math.random() * threads.length)];
params.append('checkedposts', thread.postId);
}
const response = await fetch('http://localhost/forms/board/test/modactions', {
headers: {
'x-using-xhr': 'true',
'cookie': sessionCookie,
},
method: 'POST',
body: params,
});
expect(response.ok).toBe(true);
await new Promise((resolve) => { setTimeout(resolve, 1000) }); //wait for async builds
});
test('remove the bumplock, lock and sticky on any threads', async () => {
@ -120,7 +99,6 @@ module.exports = () => describe('Test post modactions', () => {
lock: '1',
});
threads.filter(t => t.locked).forEach(t => params.append('checkedposts', t.postId));
//this is a lot of threads per action, but its using admin account, and the globalsettings is set to allow 100 checkedposts
const response = await fetch('http://localhost/forms/board/test/modactions', {
headers: {
'x-using-xhr': 'true',
@ -132,4 +110,249 @@ module.exports = () => describe('Test post modactions', () => {
expect(response.ok).toBe(true);
});
test('delete 5 random posts from /test/', async () => {
const threads = await fetch('http://localhost/test/catalog.json').then(res => res.json());
const params = new URLSearchParams({
_csrf: csrfToken,
delete: '1',
});
for (let i = 0; i < 5; i++) {
const thread = threads[Math.floor(Math.random() * threads.length)];
params.append('checkedposts', thread.postId);
}
const response = await fetch('http://localhost/forms/board/test/modactions', {
headers: {
'x-using-xhr': 'true',
'cookie': sessionCookie,
},
method: 'POST',
body: params,
});
expect(response.ok).toBe(true);
});
test('lower reply limit', async () => {
const params = new URLSearchParams({
_csrf: csrfToken,
name: 'test',
description: '',
tags: '',
announcement: '',
theme: 'yotsuba-b',
code_theme: 'ir-black',
custom_css: '',
enable_tegaki: 'true',
max_files: '5',
files_allow_video: 'true',
files_allow_image: 'true',
files_allow_animated_image: 'true',
files_allow_audio: 'true',
user_post_spoiler: 'true',
user_post_unlink: 'true',
default_name: 'Anon',
user_post_delete: 'true',
min_thread_message_length: '0',
min_reply_message_length: '0',
max_thread_message_length: '20000',
max_reply_message_length: '20000',
thread_limit: '100',
reply_limit: '20',
bump_limit: '500',
file_r9k_mode: '0',
message_r9k_mode: '0',
delete_protection_count: '0',
delete_protection_age: '0',
lock_mode: '0',
captcha_mode: '2',
pph_trigger: '50',
pph_trigger_action: '2',
tph_trigger: '10',
tph_trigger_action: '1',
lock_reset: '0',
captcha_reset: '0',
filters: '',
filter_mode: '0',
ban_duration: '0'
});
const response = await fetch('http://localhost/forms/board/test/settings', {
headers: {
'x-using-xhr': 'true',
'cookie': sessionCookie,
},
method: 'POST',
body: params,
redirect: 'manual',
});
expect(response.status).toBe(200);
});
jest.setTimeout(5*60*1000); //give generous timeout
test('make new cyclic thread and check it prunes replies after the limit', async () => {
//new thread
const threadParams = new URLSearchParams();
threadParams.append('message', Math.random());
threadParams.append('captcha', '000000');
const response = await fetch('http://localhost/forms/board/test/post', {
headers: {
'x-using-xhr': 'true',
},
method: 'POST',
body: threadParams
});
expect(response.ok).toBe(true);
const thread = (await response.json()).postId;
//make it cyclic
const params = new URLSearchParams({
_csrf: csrfToken,
cyclic: '1',
checkedposts: thread,
});
const response2 = await fetch('http://localhost/forms/board/test/modactions', {
headers: {
'x-using-xhr': 'true',
'cookie': sessionCookie,
},
method: 'POST',
body: params,
});
expect(response2.ok).toBe(true);
//make the replies
const promises = [];
for (let r = 0; r < 25; r++) {
const replyParams = new URLSearchParams();
replyParams.append('message', Math.random());
replyParams.append('thread', thread);
replyParams.append('captcha', '000000');
const promise = await fetch('http://localhost/forms/board/test/post', {
headers: {
'x-using-xhr': 'true',
},
method: 'POST',
body: replyParams
}).then(response3 => {
expect(response3.ok).toBe(true);
});
promises.push(promise);
}
await Promise.all(promises); //wait for all posts to go through
//check the replies in json
const response3 = await fetch(`http://localhost/test/thread/${thread}.json`).then(res => res.json());
expect(response3.replies.length).toBe(20);
jest.setTimeout(5*1000); //back to normal timeout
});
test('move/merge a thread', async () => {
const threads = await fetch('http://localhost/test/catalog.json').then(res => res.json());
const params = new URLSearchParams({
_csrf: csrfToken,
checkedposts: threads[Math.floor(threads.length/2)].postId,
move: '1',
move_to_thread: threads[0].postId,
});
const response = await fetch('http://localhost/forms/board/test/modactions', {
headers: {
'x-using-xhr': 'true',
'cookie': sessionCookie,
},
method: 'POST',
body: params,
});
expect(response.ok).toBe(true);
});
test('test banning', async () => {
const threads = await fetch('http://localhost/test/catalog.json').then(res => res.json());
const randomThreadId = threads[Math.floor(Math.random() * threads.length)].postId;
const params = new URLSearchParams({
_csrf: csrfToken,
ban: '1',
checkedposts: randomThreadId,
});
const response = await fetch('http://localhost/forms/board/test/modactions', {
headers: {
'x-using-xhr': 'true',
'cookie': sessionCookie,
},
method: 'POST',
body: params,
});
expect(response.ok).toBe(true);
});
test('test ban + qrange + non-appealable + show post in ban + hide name in modlog + modlog message + ban reason', async () => {
const threads = await fetch('http://localhost/test/catalog.json').then(res => res.json());
const randomThreadId = threads[Math.floor(Math.random() * threads.length)].postId;
const params = new URLSearchParams({
_csrf: csrfToken,
ban: '1',
ban_q: '1',
ban_reason: 'test',
log_message: 'test',
preserve_post: '1',
hide_name: '1',
no_appeal: '1',
checkedposts: randomThreadId,
});
const response = await fetch('http://localhost/forms/board/test/modactions', {
headers: {
'x-using-xhr': 'true',
'cookie': sessionCookie,
},
method: 'POST',
body: params,
});
expect(response.ok).toBe(true);
});
test('delete_ip_thread test', async () => {
const threads = await fetch('http://localhost/test/catalog.json').then(res => res.json());
//delete a reply and check if the OP is deleted (ip is the same for all posts atm)
const randomThreadId = threads[Math.floor(Math.random() * threads.length)].postId;
const thread = await fetch(`http://localhost/test/thread/${randomThreadId}.json`).then(res => res.json());
const reply = thread.replies[Math.floor(Math.random() * thread.replies.length)];
const params = new URLSearchParams({
_csrf: csrfToken,
delete_ip_thread: '1',
checkedposts: reply.postId,
});
const response = await fetch('http://localhost/forms/board/test/modactions', {
headers: {
'x-using-xhr': 'true',
'cookie': sessionCookie,
},
method: 'POST',
body: params,
});
expect(response.ok).toBe(true);
const response2 = await fetch(`http://localhost/test/thread/${randomThreadId}.json`);
expect(response2.status).toBe(404);
});
test('delete_ip_board test', async () => {
const threads = await fetch('http://localhost/test/catalog.json').then(res => res.json());
const randomThreadId = threads[Math.floor(Math.random() * threads.length)].postId;
const params = new URLSearchParams({
_csrf: csrfToken,
delete_ip_board: '1',
checkedposts: randomThreadId,
});
const response = await fetch('http://localhost/forms/board/test/modactions', {
headers: {
'x-using-xhr': 'true',
'cookie': sessionCookie,
},
method: 'POST',
body: params,
});
expect(response.ok).toBe(true);
await new Promise((resolve) => { setTimeout(resolve, 1000) }); //wait for async builds
const response2 = await fetch('http://localhost/test/catalog.json').then(res => res.json());
expect(response2.length).toBe(0);
});
});

Loading…
Cancel
Save