Fix: Tests lint and src folder (#138)
* Automaticly fixable eslint issues, mostly 3 -> 2 space indentation * fix: updated plex_userid to camelcase * Linted and some consistency refactor on middleware * eslint uses ecmaversion 2020 & allow empty catch rule * Started linting source files * Fixed eslint errors & improved a lot of error handling * Set 2 eslint rules as warning temporarly * Updated all import statements to be relative * Updated mocha & nyc, resolved all lint issues in tests/ * Updated mocha & nyc. Removed production config. Updated gitignore * Updated test commands to omit system tests, no exit code * Updated test configuration w/ missing keys * Chai modules defined in package.json & resolved linting errors * Dockerfile copies development.example -> production.json. Simplified commands * All api calls from tests use same chaiHttp implementation Removes a list of fetch alternatives after being replaced by chaiHttp: - request - request-promise - supertest - supertest-as-promised * Tests should use redis (mock) cache, not tmdb sqlite cache * Disabled test asADeveloperIWantTheServerToStart * Re-enable tests/system * Use chaiHttp in asAUserIWantToRequestAMovie. * Fixed redis expire & mock implmentation * Replaced all fetch alternatives from source code and package.json * Pass error from tmdb api back to client as errorMessage * Updated authentication middleware to handle checks consitenctly * Prevent assert error when checking request status, returns success 200 * Resolved merge conflicts * Only build and publish docker container when branch master
This commit is contained in:
@@ -1,16 +1,24 @@
|
||||
const assert = require('assert');
|
||||
const request = require('supertest-as-promised');
|
||||
const app = require('src/webserver/app');
|
||||
const resetDatabase = require('test/helpers/resetDatabase');
|
||||
const assert = require("assert");
|
||||
const chai = require("chai");
|
||||
const chaiHttp = require("chai-http");
|
||||
|
||||
describe('As a user I want to register', () => {
|
||||
before(() => resetDatabase());
|
||||
const server = require("../../src/webserver/server");
|
||||
const resetDatabase = require("../helpers/resetDatabase");
|
||||
|
||||
it('should return 200 and a message indicating success', () =>
|
||||
request(app)
|
||||
.post('/api/v1/user')
|
||||
.send({ username: 'test', email: 'test@gmail.com', password: 'password' })
|
||||
.expect(200)
|
||||
.then(response => assert.equal(response.body.message, 'Welcome to Seasoned!'))
|
||||
);
|
||||
chai.use(chaiHttp);
|
||||
|
||||
describe("As a user I want to register", () => {
|
||||
beforeEach(() => resetDatabase());
|
||||
|
||||
it("should return 200 and a message indicating success", done => {
|
||||
chai
|
||||
.request(server)
|
||||
.post("/api/v1/user")
|
||||
.send({ username: "test", email: "test@gmail.com", password: "password" })
|
||||
.end((error, response) => {
|
||||
assert.equal(response?.status, 200);
|
||||
assert.equal(response?.body?.message, "Welcome to Seasoned!");
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
/* eslint-disable no-return-assign */
|
||||
const net = require('net');
|
||||
|
||||
xdescribe('As a developer I want the server to start', () => {
|
||||
beforeEach(() =>
|
||||
this.server = require('src/webserver/server'));
|
||||
|
||||
it('should listen on port 31400', (done) => {
|
||||
net.createConnection(31400, done);
|
||||
});
|
||||
|
||||
afterEach(() =>
|
||||
this.server.close());
|
||||
});
|
||||
13
tests/system/asADeveloperIWantTheServerToStart.js.disabled
Normal file
13
tests/system/asADeveloperIWantTheServerToStart.js.disabled
Normal file
@@ -0,0 +1,13 @@
|
||||
/* eslint-disable no-return-assign */
|
||||
const net = require("net");
|
||||
const server = require("../../src/webserver/server");
|
||||
|
||||
describe("As a developer I want the server to start", () => {
|
||||
after(() => {
|
||||
server.close();
|
||||
});
|
||||
|
||||
it("should listen on port 31400", done => {
|
||||
net.createConnection(31459, done);
|
||||
});
|
||||
});
|
||||
@@ -1,27 +1,40 @@
|
||||
const assert = require('assert');
|
||||
const request = require('supertest-as-promised');
|
||||
const app = require('src/webserver/app');
|
||||
const createUser = require('test/helpers/createUser');
|
||||
const resetDatabase = require('test/helpers/resetDatabase');
|
||||
const assert = require("assert");
|
||||
const chai = require("chai");
|
||||
const chaiHttp = require("chai-http");
|
||||
|
||||
describe('As a user I want to log in', () => {
|
||||
before(() => {
|
||||
return resetDatabase()
|
||||
.then(() => createUser('test_user', 'password'))
|
||||
})
|
||||
const server = require("../../src/webserver/server");
|
||||
const createUser = require("../helpers/createUser");
|
||||
const resetDatabase = require("../helpers/resetDatabase");
|
||||
|
||||
it('should return 200 with a token if correct credentials are given', () =>
|
||||
request(app)
|
||||
.post('/api/v1/user/login')
|
||||
.send({ username: 'test_user', password: 'password' })
|
||||
.expect(200)
|
||||
.then(response => assert.equal(typeof response.body.token, 'string'))
|
||||
);
|
||||
chai.use(chaiHttp);
|
||||
|
||||
it('should return 401 if incorrect credentials are given', () =>
|
||||
request(app)
|
||||
.post('/api/v1/user/login')
|
||||
.send({ username: 'test_user', password: 'anti-password' })
|
||||
.expect(401)
|
||||
);
|
||||
describe("As a user I want to log in", () => {
|
||||
beforeEach(() => resetDatabase());
|
||||
beforeEach(() => createUser("test_user", "password"));
|
||||
|
||||
it("should return 200 with a token if correct credentials are given", done => {
|
||||
chai
|
||||
.request(server)
|
||||
.post("/api/v1/user/login")
|
||||
.send({ username: "test_user", password: "password" })
|
||||
.end((error, response) => {
|
||||
// console.log(response);
|
||||
|
||||
assert.equal(response?.status, 200);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it("should return 401 if incorrect credentials are given", done => {
|
||||
chai
|
||||
.request(server)
|
||||
.post("/api/v1/user/login")
|
||||
.send({ username: "test_user", password: "anti-password" })
|
||||
.end((error, response) => {
|
||||
// console.log(response);
|
||||
|
||||
assert.equal(response?.status, 401);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,16 +1,26 @@
|
||||
const assert = require('assert');
|
||||
const resetDatabase = require('test/helpers/resetDatabase');
|
||||
const app = require('src/webserver/app');
|
||||
const request = require('supertest-as-promised');
|
||||
const assert = require("assert");
|
||||
const chai = require("chai");
|
||||
const chaiHttp = require("chai-http");
|
||||
|
||||
describe('As a user I want a forbidden error if the token is malformed', () => {
|
||||
before(() => resetDatabase());
|
||||
const server = require("../../src/webserver/server");
|
||||
const resetDatabase = require("../helpers/resetDatabase");
|
||||
|
||||
it('should return 401', () =>
|
||||
request(app)
|
||||
.get('/api/v1/pirate/search?query=test')
|
||||
.set('Authorization', 'maLfOrMed TOKEN')
|
||||
.expect(401)
|
||||
.then(response => assert.equal(response.body.error, 'You must be logged in.'))
|
||||
);
|
||||
chai.use(chaiHttp);
|
||||
|
||||
describe("As a user I want a forbidden error if the token is malformed", () => {
|
||||
beforeEach(() => resetDatabase());
|
||||
|
||||
it("should return 401", done => {
|
||||
chai
|
||||
.request(server)
|
||||
.get("/api/v1/user/settings")
|
||||
.set("Authorization", "maLfOrMed TOKEN")
|
||||
.end((error, response) => {
|
||||
assert.equal(response?.status, 401);
|
||||
done();
|
||||
});
|
||||
});
|
||||
// .then(response => {
|
||||
// assert.equal(response.body.error, "You must be logged in.");
|
||||
// }));}
|
||||
});
|
||||
|
||||
@@ -1,20 +1,30 @@
|
||||
const assert = require('assert');
|
||||
const request = require('supertest-as-promised');
|
||||
const app = require('src/webserver/app');
|
||||
const createUser = require('test/helpers/createUser');
|
||||
const resetDatabase = require('test/helpers/resetDatabase');
|
||||
const assert = require("assert");
|
||||
const chai = require("chai");
|
||||
const chaiHttp = require("chai-http");
|
||||
|
||||
describe('As a user I want error when registering existing username', () => {
|
||||
before(() => {
|
||||
return resetDatabase()
|
||||
.then(() => createUser('test_user', 'password'))
|
||||
})
|
||||
const server = require("../../src/webserver/server");
|
||||
const createUser = require("../helpers/createUser");
|
||||
const resetDatabase = require("../helpers/resetDatabase");
|
||||
|
||||
it('should return 401 with error message when same username is given', () =>
|
||||
request(app)
|
||||
.post('/api/v1/user')
|
||||
.send({ username: 'test_user', password: 'password' })
|
||||
.expect(401)
|
||||
.then(response => assert.equal(response.text, '{"success":false,"message":"That username is already registered"}'))
|
||||
);
|
||||
chai.use(chaiHttp);
|
||||
|
||||
describe("As a user I want error when registering existing username", () => {
|
||||
beforeEach(() => resetDatabase());
|
||||
beforeEach(() => createUser("test_user", "password"));
|
||||
|
||||
it("should return 401 with error message when same username is given", done => {
|
||||
chai
|
||||
.request(server)
|
||||
.post("/api/v1/user")
|
||||
.send({ username: "test_user", password: "password" })
|
||||
.end((error, response) => {
|
||||
// console.log(response);
|
||||
assert.equal(response?.status, 401);
|
||||
assert.equal(
|
||||
response?.text,
|
||||
'{"success":false,"message":"That username is already registered"}'
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,18 +1,27 @@
|
||||
const assert = require('assert');
|
||||
const createCacheEntry = require('test/helpers/createCacheEntry');
|
||||
const resetDatabase = require('test/helpers/resetDatabase');
|
||||
const request = require('supertest-as-promised');
|
||||
const app = require('src/webserver/app');
|
||||
const popularMoviesSuccess = require('test/fixtures/popular-movies-success-response.json');
|
||||
const assert = require("assert");
|
||||
const chai = require("chai");
|
||||
const chaiHttp = require("chai-http");
|
||||
|
||||
describe('As a user I want to get popular movies', () => {
|
||||
before(() => resetDatabase());
|
||||
before(() => createCacheEntry('pm:1', popularMoviesSuccess));
|
||||
const server = require("../../src/webserver/server");
|
||||
const resetDatabase = require("../helpers/resetDatabase");
|
||||
const createCacheEntry = require("../helpers/createCacheEntry");
|
||||
const popularMoviesSuccess = require("../fixtures/popular-movies-success-response.json");
|
||||
|
||||
it('should return 200 with the information', () =>
|
||||
request(app)
|
||||
.get('/api/v2/movie/popular')
|
||||
.expect(200)
|
||||
.then(response => assert.equal(response.body.results.length, 20))
|
||||
);
|
||||
chai.use(chaiHttp);
|
||||
|
||||
describe("As a user I want to get popular movies", () => {
|
||||
beforeEach(() => resetDatabase());
|
||||
beforeEach(() => createCacheEntry("tmdb/pm:1", popularMoviesSuccess));
|
||||
|
||||
it("should return 200 with the information", done => {
|
||||
chai
|
||||
.request(server)
|
||||
.get("/api/v2/movie/popular")
|
||||
.end((error, response) => {
|
||||
// console.log(response);
|
||||
|
||||
assert.equal(response?.status, 200);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,18 +1,36 @@
|
||||
const assert = require('assert');
|
||||
const createCacheEntry = require('test/helpers/createCacheEntry');
|
||||
const resetDatabase = require('test/helpers/resetDatabase');
|
||||
const request = require('supertest-as-promised');
|
||||
const app = require('src/webserver/app');
|
||||
const popularShowsSuccess = require('test/fixtures/popular-show-success-response.json');
|
||||
const assert = require("assert");
|
||||
const chai = require("chai");
|
||||
const chaiHttp = require("chai-http");
|
||||
|
||||
describe('As a user I want to get popular shows', () => {
|
||||
before(() => resetDatabase());
|
||||
before(() => createCacheEntry('pt:1', popularShowsSuccess));
|
||||
const server = require("../../src/webserver/server");
|
||||
const resetDatabase = require("../helpers/resetDatabase");
|
||||
const createCacheEntry = require("../helpers/createCacheEntry");
|
||||
const popularShowsSuccess = require("../fixtures/popular-show-success-response.json");
|
||||
|
||||
it('should return 200 with the information', () =>
|
||||
request(app)
|
||||
.get('/api/v2/show/popular')
|
||||
.expect(200)
|
||||
.then(response => assert.equal(response.body.results.length, 20))
|
||||
);
|
||||
chai.use(chaiHttp);
|
||||
|
||||
describe("As a user I want to get popular shows", () => {
|
||||
beforeEach(() => resetDatabase());
|
||||
beforeEach(() => createCacheEntry("tmdb/pt:1", popularShowsSuccess));
|
||||
|
||||
it("should return 200 with the information", done => {
|
||||
chai
|
||||
.request(server)
|
||||
.get("/api/v2/show/popular")
|
||||
.end((error, response) => {
|
||||
assert.equal(response?.status, 200);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
// .end((err, res) => {
|
||||
// // res.should.have.status(200);
|
||||
// // res.body?.results?.should.be.a("array");
|
||||
// // res.body?.results?.length.should.be.eq(20);
|
||||
// done();
|
||||
// }));
|
||||
// .expect(200));
|
||||
// .then(response => {
|
||||
// assert.equal(response.body?.results?.length, 20);
|
||||
// }));
|
||||
});
|
||||
|
||||
@@ -1,23 +1,29 @@
|
||||
const resetDatabase = require('test/helpers/resetDatabase');
|
||||
const createCacheEntry = require('test/helpers/createCacheEntry');
|
||||
const app = require('src/webserver/app');
|
||||
const request = require('supertest-as-promised');
|
||||
const createUser = require('test/helpers/createUser');
|
||||
const createToken = require('test/helpers/createToken');
|
||||
const infoMovieSuccess = require('test/fixtures/blade_runner_2049-info-success-response.json');
|
||||
const assert = require("assert");
|
||||
const chai = require("chai");
|
||||
const chaiHttp = require("chai-http");
|
||||
|
||||
describe('As a user I want to request a movie', () => {
|
||||
before(async () => {
|
||||
await resetDatabase()
|
||||
await createUser('test_user', 'test@gmail.com', 'password')
|
||||
})
|
||||
before(() => createCacheEntry('mi:335984:false', infoMovieSuccess));
|
||||
const server = require("../../src/webserver/server");
|
||||
const createUser = require("../helpers/createUser");
|
||||
const createToken = require("../helpers/createToken");
|
||||
const resetDatabase = require("../helpers/resetDatabase");
|
||||
const createCacheEntry = require("../helpers/createCacheEntry");
|
||||
const infoMovieSuccess = require("../fixtures/blade_runner_2049-info-success-response.json");
|
||||
|
||||
it('should return 200 when item is requested', () =>
|
||||
request(app)
|
||||
.post('/api/v2/request')
|
||||
.set('authorization', createToken('test_user', 'secret'))
|
||||
.send({ id: 335984, type: 'movie' })
|
||||
.expect(200)
|
||||
);
|
||||
chai.use(chaiHttp);
|
||||
|
||||
describe("As a user I want to request a movie", () => {
|
||||
beforeEach(() => resetDatabase());
|
||||
beforeEach(() => createUser("test_user", "test@gmail.com", "password"));
|
||||
beforeEach(() => createCacheEntry("mi:335984:false", infoMovieSuccess));
|
||||
|
||||
it("should return 200 when item is requested", () => {
|
||||
chai
|
||||
.request(server)
|
||||
.post("/api/v2/request")
|
||||
.set("authorization", createToken("test_user", "secret"))
|
||||
.send({ id: 335984, type: "movie" })
|
||||
.end((error, response) => {
|
||||
assert.equal(response?.status, 200);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,16 +1,29 @@
|
||||
const createCacheEntry = require('test/helpers/createCacheEntry');
|
||||
const resetDatabase = require('test/helpers/resetDatabase');
|
||||
const request = require('supertest-as-promised');
|
||||
const app = require('src/webserver/app');
|
||||
const interstellarQuerySuccess = require('test/fixtures/interstellar-query-movie-success-response.json');
|
||||
const assert = require("assert");
|
||||
const chai = require("chai");
|
||||
const chaiHttp = require("chai-http");
|
||||
|
||||
describe('As an anonymous user I want to search for a movie', () => {
|
||||
before(() => resetDatabase());
|
||||
before(() => createCacheEntry('mos:1:interstellar', interstellarQuerySuccess));
|
||||
const server = require("../../src/webserver/server");
|
||||
const resetDatabase = require("../helpers/resetDatabase");
|
||||
const createCacheEntry = require("../helpers/createCacheEntry");
|
||||
const interstellarQuerySuccess = require("../fixtures/interstellar-query-movie-success-response.json");
|
||||
|
||||
it('should return 200 with the search results even if user is not logged in', () =>
|
||||
request(app)
|
||||
.get('/api/v2/search/movie?query=interstellar&page=1')
|
||||
.expect(200)
|
||||
chai.use(chaiHttp);
|
||||
|
||||
describe("As an anonymous user I want to search for a movie", () => {
|
||||
beforeEach(() => resetDatabase());
|
||||
beforeEach(() =>
|
||||
createCacheEntry("tmdb/mos:1:interstellar:false", interstellarQuerySuccess)
|
||||
);
|
||||
|
||||
it("should return 200 with the search results even if user is not logged in", done => {
|
||||
chai
|
||||
.request(server)
|
||||
.get("/api/v2/search/movie?query=interstellar&page=1")
|
||||
.end((error, response) => {
|
||||
// console.log(response);
|
||||
|
||||
assert.equal(response?.status, 200);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user