integration/docker test changes

use env var for the docker password, run the tests, remove docker jschan-test (was broken)
some changes to test folder, to run the suites in order
merge-requests/341/head
Thomas Lynch 2 years ago
parent f41a84c944
commit 19dcab2016
  1. 8
      CONTRIBUTING.md
  2. 16
      docker-compose.yml
  3. 23
      docker/jschan/Dockerfile-test
  4. 4
      helpers/checks/captcha.js
  5. 5
      test/integration.test.js
  6. 2
      test/pages.js
  7. 2
      test/posting.js
  8. 41
      test/setup.js

@ -31,7 +31,7 @@ Read the code to understand, but basically:
* TAB for indentation.
* Please include comments.
## Running tests
## Running tests (WIP)
Make sure these still pass after your changes, or adjust them to meet the new expected results.
@ -40,12 +40,12 @@ There is a "jschan-test" service in the `docker-compose.yml` file that will run
You can also Run them locally if you have an instance setup (or for quickly running unit tests):
```bash
#unit tests only
#unit tests
npm run test
# OR npm run test:unit
#integration tests only
npm run test:integration
#integration tests
TEST_ADMIN_PASSWORD=<password from jschan-reset docker> npm run test:integration
#all tests
npm run test:all

@ -32,6 +32,7 @@ services:
environment:
- NODE_ENV=development
- JSCHAN_IP=0.0.0.0
- NO_CAPTCHA=1
- MONGO_USERNAME=jschan
- MONGO_PASSWORD=changeme
- REDIS_PASSWORD=changeme
@ -64,21 +65,6 @@ services:
- redis
- mongodb
jschan-test:
build:
context: .
dockerfile: ./docker/jschan/Dockerfile-test
network: jschan_default
environment:
- MONGO_USERNAME=jschan
- MONGO_PASSWORD=changeme
- REDIS_PASSWORD=changeme
volumes:
- ./docker/static:/opt/static/
depends_on:
- redis
- mongodb
networks:
default:
name: jschan_default

@ -1,23 +0,0 @@
FROM node:16
RUN apt-get update -y
RUN apt-get install ffmpeg imagemagick graphicsmagick -y
WORKDIR /opt
COPY . .
RUN npm install
RUN npm install -g pm2 gulp
COPY ./docker/jschan/secrets.js ./configs/secrets.js
#i fucking hate docker
ENV MONGO_USERNAME jschan
ENV MONGO_PASSWORD changeme
ENV REDIS_PASSWORD changeme
RUN gulp generate-favicon
CMD ["npm", "run", "test"]

@ -10,6 +10,10 @@ const { Captchas } = require(__dirname+'/../../db/')
module.exports = async (captchaInput, captchaId) => {
if (process.env.NO_CAPTCHA) {
return true;
}
const { captchaOptions } = config.get;
//check if captcha field in form is valid

@ -0,0 +1,5 @@
describe('run integration tests', () => {
require('./setup.js')();
require('./posting.js')();
require('./pages.js')();
})

@ -1,6 +1,6 @@
const fetch = require('node-fetch');
describe('Test loading dynamic pages', () => {
module.exports = () => describe('Test loading dynamic pages', () => {
test('/boards.html', async () => {
const response = await fetch('http://localhost/boards.html');

@ -1,6 +1,6 @@
const fetch = require('node-fetch');
describe('Test posting', () => {
module.exports = () => describe('Test posting', () => {
let threadId;
test('post new thread', async () => {

@ -0,0 +1,41 @@
const fetch = require('node-fetch');
module.exports = () => describe('login and create test board', () => {
let sessionCookie;
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];
});
test('create test board', async () => {
const params = new URLSearchParams();
params.append('uri', 'test');
params.append('name', 'test');
const response = await fetch('http://localhost/forms/create', {
headers: {
'x-using-xhr': 'true',
'cookie': sessionCookie,
},
method: 'POST',
body: params,
redirect: 'manual',
});
expect([302, 409]).toContain(response.status)
});
});
Loading…
Cancel
Save