From 556e6a2bda50453acfdbaad13c46247ee7f38b39 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 18 Jan 2017 06:33:33 +0900 Subject: [PATCH] test --- test/api.js | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/test/api.js b/test/api.js index 7058f5394..120f3b775 100644 --- a/test/api.js +++ b/test/api.js @@ -15,10 +15,13 @@ const server = require('../built/api/server'); const db = require('../built/db/mongodb').default; const request = (endpoint, params, me) => new Promise((ok, ng) => { + const auth = me ? { + i: me.token + } : {}; chai.request(server) .post(endpoint) .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) => { 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', () => { it('投稿できる', () => new Promise(async (done) => { const me = await insertSakurako(); @@ -291,7 +326,6 @@ describe('API', () => { user_id: hima._id.toString() }, me).then(res => { res.should.have.status(204); - res.body.should.be.a('object'); done(); }); }));