delete file
unlink file
add/delete banner
add/delete flags
add/delete assets
indiachan-spamvector
Thomas Lynch 2 years ago
parent 7bc5e8485d
commit 8f34e9e362
  1. 34
      test/actions.js
  2. 159
      test/board.js
  3. 1
      test/integration.test.js
  4. 5
      test/setup.js

@ -374,6 +374,23 @@ int main() {...}
expect(response.ok).toBe(true);
});
test('unlink file', async () => {
const params = new URLSearchParams({
_csrf: csrfToken,
unlink_file: '1',
checkedposts: 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('make post with already spoilered image', async () => {
const threadParams = new FormData({
message: Math.random(),
@ -396,6 +413,23 @@ int main() {...}
postId = (await response.json()).postId;
});
test('delete file', async () => {
const params = new URLSearchParams({
_csrf: csrfToken,
delete_file: '1',
checkedposts: 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;

@ -0,0 +1,159 @@
const fetch = require('node-fetch');
const FormData = require('form-data');
const fs = require('fs-extra');
module.exports = () => describe('test some global form submissions', () => {
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);
});
let bannerId, assetId;
test('add banner', async () => {
const fileParams = new FormData();
const filePath = 'gulp/res/img/flags.png';
const fileSizeInBytes = fs.statSync(filePath).size;
const fileStream = fs.createReadStream(filePath);
fileParams.append('_csrf', csrfToken);
fileParams.append('file', fileStream, { knownLength: fileSizeInBytes });
const response = await fetch('http://localhost/forms/board/test/addbanners', {
headers: {
'x-using-xhr': 'true',
'cookie': sessionCookie,
...fileParams.getHeaders(),
},
method: 'POST',
body: fileParams
});
expect(response.ok).toBe(true);
const bannerPage = await fetch('http://localhost/test/manage/assets.html', {
headers: {
'cookie': sessionCookie,
},
}).then(res => res.text());
const checkString = 'name="checkedbanners" value="';
const checkIndex = bannerPage.indexOf(checkString);
const bannerSubstring = bannerPage.substring(checkIndex+checkString.length, checkIndex+checkString.length+70);
bannerId = bannerSubstring.substring(0, bannerSubstring.lastIndexOf('"'));
});
test('add flag', async () => {
const fileParams = new FormData();
const filePath = 'gulp/res/img/flags.png';
const fileSizeInBytes = fs.statSync(filePath).size;
const fileStream = fs.createReadStream(filePath);
fileParams.append('_csrf', csrfToken);
fileParams.append('file', fileStream, { knownLength: fileSizeInBytes });
const response = await fetch('http://localhost/forms/board/test/addflags', {
headers: {
'x-using-xhr': 'true',
'cookie': sessionCookie,
...fileParams.getHeaders(),
},
method: 'POST',
body: fileParams
});
expect(response.ok).toBe(true);
flagId = 'flags';
});
test('add asset', async () => {
const fileParams = new FormData();
const filePath = 'gulp/res/img/flags.png';
const fileSizeInBytes = fs.statSync(filePath).size;
const fileStream = fs.createReadStream(filePath);
fileParams.append('_csrf', csrfToken);
fileParams.append('file', fileStream, { knownLength: fileSizeInBytes });
const response = await fetch('http://localhost/forms/board/test/addassets', {
headers: {
'x-using-xhr': 'true',
'cookie': sessionCookie,
...fileParams.getHeaders(),
},
method: 'POST',
body: fileParams
});
expect(response.ok).toBe(true);
const assetPage = await fetch('http://localhost/test/manage/assets.html', {
headers: {
'cookie': sessionCookie,
},
}).then(res => res.text());
const checkString = 'name="checkedassets" value="';
const checkIndex = assetPage.indexOf(checkString);
const assetSubstring = assetPage.substring(checkIndex+checkString.length, checkIndex+checkString.length+70);
assetId = assetSubstring.substring(0, assetSubstring.lastIndexOf('"'));
});
test('delete banner', async () => {
const params = new URLSearchParams({
_csrf: csrfToken,
checkedbanners: bannerId,
});
const response = await fetch('http://localhost/forms/board/test/deletebanners', {
headers: {
'x-using-xhr': 'true',
'cookie': sessionCookie,
},
method: 'POST',
body: params,
redirect: 'manual',
})
expect(response.ok).toBe(true);
});
test('delete flag', async () => {
const params = new URLSearchParams({
_csrf: csrfToken,
checkedflags: flagId,
});
const response = await fetch('http://localhost/forms/board/test/deleteflags', {
headers: {
'x-using-xhr': 'true',
'cookie': sessionCookie,
},
method: 'POST',
body: params,
redirect: 'manual',
})
expect(response.ok).toBe(true);
});
test('delete asset', async () => {
const params = new URLSearchParams({
_csrf: csrfToken,
checkedassets: assetId,
});
const response = await fetch('http://localhost/forms/board/test/deleteassets', {
headers: {
'x-using-xhr': 'true',
'cookie': sessionCookie,
},
method: 'POST',
body: params,
redirect: 'manual',
})
expect(response.ok).toBe(true);
});
});

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

@ -184,9 +184,8 @@ module.exports = () => describe('login and create test board', () => {
global_limits_post_files_size_max: '10485760',
global_limits_custom_pages_max_length: '10000',
global_limits_custom_pages_max: '10',
global_limits_banner_files_width: '300',
global_limits_banner_files_height: '100',
global_limits_banner_files_force_aspect_ratio: 'true',
global_limits_banner_files_width: '500',
global_limits_banner_files_height: '500',
global_limits_banner_files_size_max: '10485760',
global_limits_banner_files_max: '10',
global_limits_banner_files_total: '100',

Loading…
Cancel
Save