Initial commit.
This commit is contained in:
commit
b48a4e92e1
169 changed files with 7538 additions and 0 deletions
33
test/api/auth.spec.js
Normal file
33
test/api/auth.spec.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
import { agent } from 'supertest';
|
||||
import app from '../../api/app';
|
||||
|
||||
const request = agent(app.listen());
|
||||
|
||||
describe('hostr-api auth', function(){
|
||||
|
||||
describe('with no credentials', function(){
|
||||
it('should `throw` 401', function(done){
|
||||
request
|
||||
.get('/user')
|
||||
.expect(401, done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with invalid credentials', function(){
|
||||
it('should `throw` 401', function(done){
|
||||
request
|
||||
.get('/user')
|
||||
.auth('user', 'invalid password')
|
||||
.expect(401, done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with valid credentials', function(){
|
||||
it('should call the next middleware', function(done){
|
||||
request
|
||||
.get('/')
|
||||
.auth('test@hostr.co', 'test-password')
|
||||
.expect(200, done);
|
||||
});
|
||||
});
|
||||
});
|
68
test/api/file.spec.js
Normal file
68
test/api/file.spec.js
Normal file
|
@ -0,0 +1,68 @@
|
|||
import assert from 'assert';
|
||||
import { agent } from 'supertest';
|
||||
import app from '../../api/app';
|
||||
|
||||
const request = agent(app.listen());
|
||||
|
||||
describe('hostr-api file', function() {
|
||||
|
||||
let id;
|
||||
|
||||
describe('when GET /file', function() {
|
||||
it('should receive a list of file objects', function(done) {
|
||||
request
|
||||
.get('/file')
|
||||
.auth('test@hostr.co', 'test-password')
|
||||
.expect(200)
|
||||
.expect(function(response) {
|
||||
assert(response.body instanceof Array);
|
||||
})
|
||||
.end(done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when POSTing a file to /file', function() {
|
||||
it('should receive a new file object', function(done) {
|
||||
this.timeout(30000);
|
||||
request
|
||||
.post('/file')
|
||||
.attach('file', 'test/fixtures/utah-arches.jpg')
|
||||
.auth('test@hostr.co', 'test-password')
|
||||
.expect(201)
|
||||
.expect(function(response) {
|
||||
assert(response.body.name === 'utah-arches.jpg');
|
||||
id = response.body.id;
|
||||
})
|
||||
.end(done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when GET /file/:id', function() {
|
||||
it('should receive the file object', function(done) {
|
||||
request
|
||||
.get('/file/' + id)
|
||||
.expect(200)
|
||||
.expect(function(response) {
|
||||
assert(response.body.name === 'utah-arches.jpg');
|
||||
})
|
||||
.end(done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when DELETE /file/:id', function() {
|
||||
it('should delete the file object', function(done) {
|
||||
request
|
||||
.delete('/file/' + id)
|
||||
.auth('test@hostr.co', 'test-password')
|
||||
.expect(200, done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when GET deleted /file/:id', function() {
|
||||
it('should not receive the file object', function(done) {
|
||||
request
|
||||
.get('/file/' + id)
|
||||
.expect(404, done);
|
||||
});
|
||||
});
|
||||
});
|
62
test/api/user.spec.js
Normal file
62
test/api/user.spec.js
Normal file
|
@ -0,0 +1,62 @@
|
|||
import assert from 'assert';
|
||||
import { agent } from 'supertest';
|
||||
import app from '../../api/app';
|
||||
|
||||
const request = agent(app.listen());
|
||||
|
||||
describe('hostr-api user', function() {
|
||||
|
||||
describe('when GET /user', function() {
|
||||
it('should receive a user object', function(done) {
|
||||
request
|
||||
.get('/user')
|
||||
.auth('test@hostr.co', 'test-password')
|
||||
.expect(function(response) {
|
||||
assert(response.body.id === '54fd04a37675bcd06213eac8');
|
||||
})
|
||||
.expect(200)
|
||||
.end(done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when GET /user/token', function() {
|
||||
it('should receive a user token object', function(done) {
|
||||
request
|
||||
.get('/user/token')
|
||||
.auth('test@hostr.co', 'test-password')
|
||||
.expect(function(response) {
|
||||
assert(response.body.token);
|
||||
})
|
||||
.expect(200)
|
||||
.end(done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when GET /user/transaction', function() {
|
||||
it('should receive a user transactions object', function(done) {
|
||||
request
|
||||
.get('/user/transaction')
|
||||
.auth('test@hostr.co', 'test-password')
|
||||
.expect(200)
|
||||
.expect(function(response) {
|
||||
assert(response.body instanceof Array);
|
||||
})
|
||||
.end(done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when GET /user/settings', function() {
|
||||
it('should update user password', function(done) {
|
||||
request
|
||||
.post('/user/settings')
|
||||
.send({'current_password': 'test-password', 'new_password': 'test-password' })
|
||||
.auth('test@hostr.co', 'test-password')
|
||||
.expect(200)
|
||||
.expect(function(response) {
|
||||
assert(response.body instanceof Object);
|
||||
})
|
||||
.end(done);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue