This commit is contained in:
syuilo 2017-01-18 06:33:33 +09:00
parent 2f596948f3
commit 4059e3b504

View file

@ -15,10 +15,13 @@ const server = require('../built/api/server');
const db = require('../built/db/mongodb').default; const db = require('../built/db/mongodb').default;
const request = (endpoint, params, me) => new Promise((ok, ng) => { const request = (endpoint, params, me) => new Promise((ok, ng) => {
const auth = me ? {
i: me.token
} : {};
chai.request(server) chai.request(server)
.post(endpoint) .post(endpoint)
.set('content-type', 'application/x-www-form-urlencoded') .set('content-type', 'application/x-www-form-urlencoded')
.send(Object.assign({ i: (me || { token: null }).token }, params)) .send(Object.assign(auth, params))
.end((err, res) => { .end((err, res) => {
ok(res); ok(res);
}); });
@ -133,6 +136,38 @@ describe('API', () => {
}); });
})); }));
describe('users/show', () => {
it('ユーザーが取得できる', () => new Promise(async (done) => {
const me = await insertSakurako();
request('/users/show', {
user_id: me._id.toString()
}, me).then(res => {
res.should.have.status(200);
res.body.should.be.a('object');
res.body.should.have.property('id').eql(me._id.toString());
done();
});
}));
it('ユーザーが存在しなかったら怒る', () => new Promise(async (done) => {
request('/users/show', {
user_id: '000000000000000000000000'
}).then(res => {
res.should.have.status(400);
done();
});
}));
it('間違ったIDで怒られる', () => new Promise(async (done) => {
request('/users/show', {
user_id: 'kyoppie'
}).then(res => {
res.should.have.status(400);
done();
});
}));
});
describe('posts/create', () => { describe('posts/create', () => {
it('投稿できる', () => new Promise(async (done) => { it('投稿できる', () => new Promise(async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
@ -291,7 +326,6 @@ describe('API', () => {
user_id: hima._id.toString() user_id: hima._id.toString()
}, me).then(res => { }, me).then(res => {
res.should.have.status(204); res.should.have.status(204);
res.body.should.be.a('object');
done(); done();
}); });
})); }));