Skip to content

Commit

Permalink
Merge branch 'feature/refactor-tests' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
gocreating committed Nov 5, 2016
2 parents 4e773ca + 0185dc7 commit c6a4172
Show file tree
Hide file tree
Showing 16 changed files with 454 additions and 256 deletions.
61 changes: 24 additions & 37 deletions specs/endToEnd/apis/locale.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import chai from 'chai';
import request from 'superagent';
import { apiEngine } from '../../utils';
import localeAPI from '../../../build/common/api/locale';
import async from 'async';
import constants from '../../constants';
import Errors from '../../../build/common/constants/Errors';
let expect = chai.expect;

describe('#locale', () => {
describe('#localeAPI', () => {
let validLocales = [
'en-us',
'zh-tw',
Expand All @@ -17,42 +17,29 @@ describe('#locale', () => {
'fuck you',
];

describe('#Unauthorized User', () => {
// GET /api/locale/{validLocaleName}
describe('GET /api/locales/{validLocaleName}', () => {
it('should download valid locale', (done) => {
async.eachSeries(validLocales, (validLocale, cb) => {
request
.get(constants.BASE + '/api/locales/' + validLocale)
.end((err, res) => {
expect(err).to.equal(null);
expect(res).to.not.be.undefined;
expect(res.status).to.equal(200);
expect(res.body.errors).to.be.undefined;
expect(res.body.locale).to.equal(validLocale);
expect(res.body.messages).to.be.an('object');
cb();
});
}, done);
});
describe('#read()', () => {
it('should download valid locale', (done) => {
async.eachSeries(validLocales, (validLocale, cb) => {
localeAPI(apiEngine)
.read(validLocale)
.then((json) => {
expect(json.locale).to.equal(validLocale);
expect(json.messages).to.be.an('object');
cb();
});
}, done);
});

// GET /api/locale/{invalidLocaleName}
describe('GET /api/locales/{invalidLocaleName}', () => {
it('should reject invalid locale', (done) => {
async.eachSeries(invalidLocales, (invalidLocale, cb) => {
request
.get(constants.BASE + '/api/locales/' + invalidLocale)
.end((err, res) => {
expect(err).to.equal(null);
expect(res).to.not.be.undefined;
expect(res.status).to.equal(200);
expect(res.body.errors[0].code)
.to.equal(Errors.LOCALE_NOT_SUPPORTED.code);
cb();
});
}, done);
});
it('should reject invalid locale', (done) => {
async.eachSeries(invalidLocales, (invalidLocale, cb) => {
localeAPI(apiEngine)
.read(invalidLocale)
.catch((err) => {
expect(err[0].code)
.to.equal(Errors.LOCALE_NOT_SUPPORTED.code);
cb();
});
}, done);
});
});
});
63 changes: 24 additions & 39 deletions specs/endToEnd/apis/todo.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,46 @@
import chai from 'chai';
import request from 'superagent';
import { apiEngine } from '../../utils';
import todoAPI from '../../../build/common/api/todo';
import async from 'async';
import constants from '../../constants';
import Todo from '../../../build/server/models/Todo';
let expect = chai.expect;

describe('#todo', () => {
describe('#todoAPI', () => {
let fakeTodos = [{
text: 'this is a fake todo text',
}, {
text: 'foo',
}, {
text: '~bar~',
}];
let resTodos = [];

before((done) => {
Todo.remove({}, done);
});

describe('#Unauthorized User', () => {
// POST /api/todo
describe('POST /api/todos', () => {
it('should create todo', (done) => {
async.eachSeries(fakeTodos, (fakeTodo, cb) => {
request
.post(constants.BASE + '/api/todos')
.send(fakeTodo)
.end((err, res) => {
expect(err).to.equal(null);
expect(res).to.not.be.undefined;
expect(res.status).to.equal(200);
expect(res.body.errors).to.be.undefined;
expect(res.body.todo).to.be.an('object');
expect(res.body.todo.text).to.equal(fakeTodo.text);
resTodos.push(res.body.todo);
cb();
});
}, done);
});
describe('#create()', () => {
it('should create todo', (done) => {
async.eachSeries(fakeTodos, (fakeTodo, cb) => {
todoAPI(apiEngine)
.create(fakeTodo)
.then((json) => {
expect(json.todo).to.be.an('object');
expect(json.todo.text).to.equal(fakeTodo.text);
cb();
});
}, done);
});
});

// GET /api/todo
describe('GET /api/todos', () => {
it('should list todos', (done) => {
request
.get(constants.BASE + '/api/todos')
.end((err, res) => {
expect(err).to.equal(null);
expect(res).to.not.be.undefined;
expect(res.status).to.equal(200);
expect(res.body.errors).to.be.undefined;
expect(res.body.todos).to.be.an('array');
expect(res.body.todos.length).to.equal(fakeTodos.length);
done();
});
});
describe('#list()', () => {
it('should list todos', (done) => {
todoAPI(apiEngine)
.list({ page: 1 })
.then((json) => {
expect(json.todos).to.be.an('array');
expect(json.todos).to.have.lengthOf(fakeTodos.length);
done();
});
});
});

Expand Down
Loading

0 comments on commit c6a4172

Please sign in to comment.