Moved contents of seasoned_api up to root folder
This commit is contained in:
16
tests/system/asADeveloperIWantTheServerToRegister.js
Normal file
16
tests/system/asADeveloperIWantTheServerToRegister.js
Normal file
@@ -0,0 +1,16 @@
|
||||
const assert = require('assert');
|
||||
const request = require('supertest-as-promised');
|
||||
const app = require('src/webserver/app');
|
||||
const resetDatabase = require('test/helpers/resetDatabase');
|
||||
|
||||
describe('As a user I want to register', () => {
|
||||
before(() => 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!'))
|
||||
);
|
||||
});
|
||||
14
tests/system/asADeveloperIWantTheServerToStart.js
Normal file
14
tests/system/asADeveloperIWantTheServerToStart.js
Normal file
@@ -0,0 +1,14 @@
|
||||
/* 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());
|
||||
});
|
||||
27
tests/system/asADeveloperIWantToLogin.js
Normal file
27
tests/system/asADeveloperIWantToLogin.js
Normal file
@@ -0,0 +1,27 @@
|
||||
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');
|
||||
|
||||
describe('As a user I want to log in', () => {
|
||||
before(() => {
|
||||
return resetDatabase()
|
||||
.then(() => createUser('test_user', 'password'))
|
||||
})
|
||||
|
||||
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'))
|
||||
);
|
||||
|
||||
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)
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,16 @@
|
||||
const assert = require('assert');
|
||||
const resetDatabase = require('test/helpers/resetDatabase');
|
||||
const app = require('src/webserver/app');
|
||||
const request = require('supertest-as-promised');
|
||||
|
||||
describe('As a user I want a forbidden error if the token is malformed', () => {
|
||||
before(() => 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.'))
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
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');
|
||||
|
||||
describe('As a user I want error when registering existing username', () => {
|
||||
before(() => {
|
||||
return resetDatabase()
|
||||
.then(() => createUser('test_user', 'password'))
|
||||
})
|
||||
|
||||
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"}'))
|
||||
);
|
||||
});
|
||||
18
tests/system/asAUserIWantToGetPopularMovies.js
Normal file
18
tests/system/asAUserIWantToGetPopularMovies.js
Normal file
@@ -0,0 +1,18 @@
|
||||
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');
|
||||
|
||||
describe('As a user I want to get popular movies', () => {
|
||||
before(() => resetDatabase());
|
||||
before(() => createCacheEntry('pm:1', popularMoviesSuccess));
|
||||
|
||||
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))
|
||||
);
|
||||
});
|
||||
18
tests/system/asAUserIWantToGetPopularShows.js
Normal file
18
tests/system/asAUserIWantToGetPopularShows.js
Normal file
@@ -0,0 +1,18 @@
|
||||
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');
|
||||
|
||||
describe('As a user I want to get popular shows', () => {
|
||||
before(() => resetDatabase());
|
||||
before(() => createCacheEntry('pt:1', popularShowsSuccess));
|
||||
|
||||
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))
|
||||
);
|
||||
});
|
||||
23
tests/system/asAUserIWantToRequestAMovie.js
Normal file
23
tests/system/asAUserIWantToRequestAMovie.js
Normal file
@@ -0,0 +1,23 @@
|
||||
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');
|
||||
|
||||
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));
|
||||
|
||||
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)
|
||||
);
|
||||
});
|
||||
16
tests/system/asAnAnonymousUserIWantToSearchForAMovie.js
Normal file
16
tests/system/asAnAnonymousUserIWantToSearchForAMovie.js
Normal file
@@ -0,0 +1,16 @@
|
||||
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');
|
||||
|
||||
describe('As an anonymous user I want to search for a movie', () => {
|
||||
before(() => resetDatabase());
|
||||
before(() => createCacheEntry('mos:1:interstellar', interstellarQuerySuccess));
|
||||
|
||||
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)
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user