move some delete actions and delete board to after the pages test, so stuff likeoverboard has some content

indiachan-spamvector
Thomas Lynch 2 years ago
parent 2d37b00dae
commit 7bc5e8485d
  1. 46
      test/actions.js
  2. 92
      test/cleanup.js
  3. 3
      test/integration.test.js

@ -440,50 +440,4 @@ int main() {...}
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);
});
});

@ -0,0 +1,92 @@
const fetch = require('node-fetch');
module.exports = () => describe('delete testa and cleanup', () => {
let sessionCookie
, csrfToken;
test('login as admin', async () => {
const params = new URLSearchParams();
params.append('username', 'admin');
params.append('password', process.env.TEST_ADMIN_PASSWORD);
const response = await fetch('http://localhost/forms/login', {
headers: {
'x-using-xhr': 'true',
},
method: 'POST',
body: params,
redirect: 'manual',
});
const rawHeaders = response.headers.raw();
expect(rawHeaders['set-cookie']).toBeDefined();
expect(rawHeaders['set-cookie'][0]).toMatch(/^connect\.sid/);
sessionCookie = rawHeaders['set-cookie'][0];
csrfToken = await fetch('http://localhost/csrf.json', { headers: { 'cookie': sessionCookie }})
.then(res => res.json())
.then(json => json.token);
});
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);
});
test('delete test board', async () => {
const params = new URLSearchParams();
params.append('_csrf', csrfToken);
params.append('uri', 'test');
params.append('confirm', 'true');
const response = await fetch('http://localhost/forms/board/test/deleteboard', {
headers: {
'x-using-xhr': 'true',
'cookie': sessionCookie,
},
method: 'POST',
body: params,
redirect: 'manual',
});
expect([200, 404]).toContain(response.status)
});
});

@ -1,7 +1,8 @@
describe('run integration tests', () => {
require('./setup.js')();
require('./posting.js')();
require('./actions.js')();
require('./global.js')();
require('./actions.js')();
require('./pages.js')();
require('./cleanup.js')();
})

Loading…
Cancel
Save