diff --git a/package.json b/package.json index 39b8435..dadded6 100644 --- a/package.json +++ b/package.json @@ -19,22 +19,16 @@ "classDocs": "scripts/generate-class-docs.sh" }, "dependencies": { - "axios": "^0.18.0", "bcrypt": "^5.0.1", "body-parser": "~1.18.2", "cookie-parser": "^1.4.6", - "cross-env": "~5.1.4", "express": "~4.16.0", "form-data": "^2.5.1", "jsonwebtoken": "^8.5.1", "km-moviedb": "^0.2.12", - "node-cache": "^4.1.1", - "node-fetch": "^2.6.0", "python-shell": "^0.5.0", "raven": "^2.4.2", "redis": "^3.0.2", - "request": "^2.87.0", - "request-promise": "^4.2", "sqlite3": "^5.0.1" }, "devDependencies": { @@ -56,8 +50,6 @@ "mocha": "8.4.0", "mocha-lcov-reporter": "^1.3.0", "nyc": "15.1.0", - "prettier": "^2.7.1", - "supertest": "^3.0.0", - "supertest-as-promised": "^4.0.1" + "prettier": "^2.7.1" } } diff --git a/tests/system/asADeveloperIWantTheServerToRegister.js b/tests/system/asADeveloperIWantTheServerToRegister.js index 1d7936d..c205081 100644 --- a/tests/system/asADeveloperIWantTheServerToRegister.js +++ b/tests/system/asADeveloperIWantTheServerToRegister.js @@ -1,17 +1,24 @@ const assert = require("assert"); -const request = require("supertest-as-promised"); -const app = require("../../src/webserver/app"); +const chai = require("chai"); +const chaiHttp = require("chai-http"); + +const server = require("../../src/webserver/server"); const resetDatabase = require("../helpers/resetDatabase"); +chai.use(chaiHttp); + describe("As a user I want to register", () => { beforeEach(() => resetDatabase()); - it("should return 200 and a message indicating success", () => - request(app) + 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" }) - .expect(200) - .then(response => - assert.equal(response.body.message, "Welcome to Seasoned!") - )); + .end((error, response) => { + assert.equal(response?.status, 200); + assert.equal(response?.body?.message, "Welcome to Seasoned!"); + done(); + }); + }); }); diff --git a/tests/system/asADeveloperIWantToLogin.js b/tests/system/asADeveloperIWantToLogin.js index 96bdb78..f920340 100644 --- a/tests/system/asADeveloperIWantToLogin.js +++ b/tests/system/asADeveloperIWantToLogin.js @@ -1,24 +1,40 @@ -const request = require("supertest-as-promised"); -const app = require("../../src/webserver/app"); +const assert = require("assert"); +const chai = require("chai"); +const chaiHttp = require("chai-http"); + +const server = require("../../src/webserver/server"); const createUser = require("../helpers/createUser"); const resetDatabase = require("../helpers/resetDatabase"); -// const assert = require("assert"); + +chai.use(chaiHttp); describe("As a user I want to log in", () => { - beforeEach(() => { - return resetDatabase().then(() => createUser("test_user", "password")); - }); + beforeEach(() => resetDatabase()); + beforeEach(() => createUser("test_user", "password")); - it("should return 200 with a token if correct credentials are given", () => - request(app) + 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" }) - .expect(200)); - // .then(response => assert.equal(typeof response.body.token, "string"))); + .end((error, response) => { + // console.log(response); - it("should return 401 if incorrect credentials are given", () => - request(app) + 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" }) - .expect(401)); + .end((error, response) => { + // console.log(response); + + assert.equal(response?.status, 401); + done(); + }); + }); }); diff --git a/tests/system/asAUserIWantAForbiddenErrorIfTheTokenIsMalformed.js b/tests/system/asAUserIWantAForbiddenErrorIfTheTokenIsMalformed.js index 59007d1..72d0074 100644 --- a/tests/system/asAUserIWantAForbiddenErrorIfTheTokenIsMalformed.js +++ b/tests/system/asAUserIWantAForbiddenErrorIfTheTokenIsMalformed.js @@ -1,17 +1,26 @@ -const request = require("supertest-as-promised"); -const app = require("../../src/webserver/app"); +const assert = require("assert"); +const chai = require("chai"); +const chaiHttp = require("chai-http"); + +const server = require("../../src/webserver/server"); const resetDatabase = require("../helpers/resetDatabase"); // const assert = require("assert"); +chai.use(chaiHttp); describe("As a user I want a forbidden error if the token is malformed", () => { beforeEach(() => resetDatabase()); - it("should return 401", () => - request(app) + it("should return 401", done => { + chai + .request(server) .get("/api/v1/user/settings") .set("Authorization", "maLfOrMed TOKEN") - .expect(401)); + .end((error, response) => { + assert.equal(response?.status, 401); + done(); + }); + }); // .then(response => { // assert.equal(response.body.error, "You must be logged in."); - // })); + // }));} }); diff --git a/tests/system/asAUserIWantToGetErrorWhenRegisteringExistingUsername.js b/tests/system/asAUserIWantToGetErrorWhenRegisteringExistingUsername.js index fa5e7f7..6a7248f 100644 --- a/tests/system/asAUserIWantToGetErrorWhenRegisteringExistingUsername.js +++ b/tests/system/asAUserIWantToGetErrorWhenRegisteringExistingUsername.js @@ -1,23 +1,30 @@ const assert = require("assert"); -const request = require("supertest-as-promised"); -const app = require("../../src/webserver/app"); +const chai = require("chai"); +const chaiHttp = require("chai-http"); + +const server = require("../../src/webserver/server"); const createUser = require("../helpers/createUser"); const resetDatabase = require("../helpers/resetDatabase"); -describe("As a user I want error when registering existing username", () => { - beforeEach(() => { - return resetDatabase().then(() => createUser("test_user", "password")); - }); +chai.use(chaiHttp); - it("should return 401 with error message when same username is given", () => - request(app) +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" }) - .expect(401) - .then(response => + .end((error, response) => { + // console.log(response); + assert.equal(response?.status, 401); assert.equal( - response.text, + response?.text, '{"success":false,"message":"That username is already registered"}' - ) - )); + ); + done(); + }); + }); }); diff --git a/tests/system/asAUserIWantToGetPopularMovies.js b/tests/system/asAUserIWantToGetPopularMovies.js index 13f7bb9..3f4fedb 100644 --- a/tests/system/asAUserIWantToGetPopularMovies.js +++ b/tests/system/asAUserIWantToGetPopularMovies.js @@ -1,21 +1,27 @@ const assert = require("assert"); -const request = require("supertest-as-promised"); -const app = require("../../src/webserver/app"); +const chai = require("chai"); +const chaiHttp = require("chai-http"); + +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"); +chai.use(chaiHttp); + describe("As a user I want to get popular movies", () => { beforeEach(() => resetDatabase()); - beforeEach(() => - createCacheEntry("tmdb/miscPopularMovies:1", popularMoviesSuccess) - ); + beforeEach(() => createCacheEntry("tmdb/pm:1", popularMoviesSuccess)); - it("should return 200 with the information", () => - request(app) + it("should return 200 with the information", done => { + chai + .request(server) .get("/api/v2/movie/popular") - .expect(200) - .then(response => { - assert.equal(response.body?.results?.length, 20); - })); + .end((error, response) => { + // console.log(response); + + assert.equal(response?.status, 200); + done(); + }); + }); }); diff --git a/tests/system/asAUserIWantToGetPopularShows.js b/tests/system/asAUserIWantToGetPopularShows.js index 122ea3b..b2f0065 100644 --- a/tests/system/asAUserIWantToGetPopularShows.js +++ b/tests/system/asAUserIWantToGetPopularShows.js @@ -1,5 +1,4 @@ -// const assert = require("assert"); -// const request = require("supertest-as-promised"); +const assert = require("assert"); const chai = require("chai"); const chaiHttp = require("chai-http"); @@ -7,29 +6,21 @@ 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"); -// const should = chai.should(); chai.use(chaiHttp); -// describe("system test", () => { -// it("should run", () => { -// assert.equal(1, 1); -// }); -// }); describe("As a user I want to get popular shows", () => { beforeEach(() => resetDatabase()); - beforeEach(() => createCacheEntry("pt:1", popularShowsSuccess)); + 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) => { - response.should.have.status(200); + assert.equal(response?.status, 200); done(); }); - - // done(); }); // .end((err, res) => { diff --git a/tests/system/asAUserIWantToRequestAMovie.js b/tests/system/asAUserIWantToRequestAMovie.js index 686855e..a0a6c45 100644 --- a/tests/system/asAUserIWantToRequestAMovie.js +++ b/tests/system/asAUserIWantToRequestAMovie.js @@ -1,5 +1,8 @@ -const request = require("supertest-as-promised"); -const app = require("../../src/webserver/app"); +const assert = require("assert"); +const chai = require("chai"); +const chaiHttp = require("chai-http"); + +const server = require("../../src/webserver/server"); const createUser = require("../helpers/createUser"); const createToken = require("../helpers/createToken"); const resetDatabase = require("../helpers/resetDatabase"); @@ -11,10 +14,14 @@ describe("As a user I want to request a movie", () => { beforeEach(() => createUser("test_user", "test@gmail.com", "password")); beforeEach(() => createCacheEntry("mi:335984:false", infoMovieSuccess)); - it("should return 200 when item is requested", () => - request(app) + 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" }) - .expect(200)); + .end((error, response) => { + assert.equal(response?.status, 200); + }); + }); }); diff --git a/tests/system/asAnAnonymousUserIWantToSearchForAMovie.js b/tests/system/asAnAnonymousUserIWantToSearchForAMovie.js index 4621352..d2e6bb4 100644 --- a/tests/system/asAnAnonymousUserIWantToSearchForAMovie.js +++ b/tests/system/asAnAnonymousUserIWantToSearchForAMovie.js @@ -1,17 +1,29 @@ -const request = require("supertest-as-promised"); -const app = require("../../src/webserver/app"); +const assert = require("assert"); +const chai = require("chai"); +const chaiHttp = require("chai-http"); + +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"); +chai.use(chaiHttp); + describe("As an anonymous user I want to search for a movie", () => { beforeEach(() => resetDatabase()); beforeEach(() => - createCacheEntry("mos:1:interstellar", interstellarQuerySuccess) + createCacheEntry("tmdb/mos:1:interstellar:false", interstellarQuerySuccess) ); - it("should return 200 with the search results even if user is not logged in", () => - request(app) + 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") - .expect(200)); + .end((error, response) => { + // console.log(response); + + assert.equal(response?.status, 200); + done(); + }); + }); });