Use TypeScript for tests and fix semantic errors

This commit is contained in:
Aya Morisawa 2017-02-28 01:57:37 +09:00
parent 409964adcb
commit fedbe55e97
1 changed files with 166 additions and 167 deletions

View File

@ -91,7 +91,7 @@ describe('API', () => {
}); });
}); });
it('同じユーザー名のアカウントは作成できない', () => new Promise(async (done) => { it('同じユーザー名のアカウントは作成できない', () => async (done) => {
const user = await insertSakurako(); const user = await insertSakurako();
request('/signup', { request('/signup', {
username: user.username, username: user.username,
@ -100,11 +100,11 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
}); });
describe('signin', () => { describe('signin', () => {
it('間違ったパスワードでサインインできない', () => new Promise(async (done) => { it('間違ったパスワードでサインインできない', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
request('/signin', { request('/signin', {
username: me.username, username: me.username,
@ -114,9 +114,9 @@ describe('API', () => {
res.text.should.be.equal('incorrect password'); res.text.should.be.equal('incorrect password');
done(); done();
}); });
})); });
it('クエリをインジェクションできない', () => new Promise(async (done) => { it('クエリをインジェクションできない', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
request('/signin', { request('/signin', {
username: me.username, username: me.username,
@ -127,9 +127,9 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('正しい情報でサインインできる', () => new Promise(async (done) => { it('正しい情報でサインインできる', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
request('/signin', { request('/signin', {
username: me.username, username: me.username,
@ -138,11 +138,11 @@ describe('API', () => {
res.should.have.status(204); res.should.have.status(204);
done(); done();
}); });
})); });
}); });
describe('i/update', () => { describe('i/update', () => {
it('アカウント設定を更新できる', () => new Promise(async (done) => { it('アカウント設定を更新できる', () => async (done) => {
const me = await insertSakurako({ const me = await insertSakurako({
profile: { profile: {
gender: 'female' gender: 'female'
@ -167,9 +167,9 @@ describe('API', () => {
res.body.should.have.deep.property('profile.gender').eql('female'); res.body.should.have.deep.property('profile.gender').eql('female');
done(); done();
}); });
})); });
it('誕生日の設定を削除できる', () => new Promise(async (done) => { it('誕生日の設定を削除できる', () => async (done) => {
const me = await insertSakurako({ const me = await insertSakurako({
birthday: '2000-09-07' birthday: '2000-09-07'
}); });
@ -182,9 +182,9 @@ describe('API', () => {
res.body.should.have.deep.property('profile.birthday').eql(null); res.body.should.have.deep.property('profile.birthday').eql(null);
done(); done();
}); });
})); });
it('不正な誕生日の形式で怒られる', () => new Promise(async (done) => { it('不正な誕生日の形式で怒られる', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
request('/i/update', { request('/i/update', {
birthday: '2000/09/07' birthday: '2000/09/07'
@ -192,11 +192,11 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
}); });
describe('users/show', () => { describe('users/show', () => {
it('ユーザーが取得できる', () => new Promise(async (done) => { it('ユーザーが取得できる', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
request('/users/show', { request('/users/show', {
user_id: me._id.toString() user_id: me._id.toString()
@ -206,29 +206,29 @@ describe('API', () => {
res.body.should.have.property('id').eql(me._id.toString()); res.body.should.have.property('id').eql(me._id.toString());
done(); done();
}); });
})); });
it('ユーザーが存在しなかったら怒る', () => new Promise(async (done) => { it('ユーザーが存在しなかったら怒る', () => async (done) => {
request('/users/show', { request('/users/show', {
user_id: '000000000000000000000000' user_id: '000000000000000000000000'
}).then(res => { }).then(res => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('間違ったIDで怒られる', () => new Promise(async (done) => { it('間違ったIDで怒られる', () => async (done) => {
request('/users/show', { request('/users/show', {
user_id: 'kyoppie' user_id: 'kyoppie'
}).then(res => { }).then(res => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
}); });
describe('posts/create', () => { describe('posts/create', () => {
it('投稿できる', () => new Promise(async (done) => { it('投稿できる', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
const post = { const post = {
text: 'ひまわりー' text: 'ひまわりー'
@ -239,9 +239,9 @@ describe('API', () => {
res.body.should.have.property('text').eql(post.text); res.body.should.have.property('text').eql(post.text);
done(); done();
}); });
})); });
it('ファイルを添付できる', () => new Promise(async (done) => { it('ファイルを添付できる', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
const file = await insertDriveFile({ const file = await insertDriveFile({
user_id: me._id user_id: me._id
@ -254,9 +254,9 @@ describe('API', () => {
res.body.should.have.property('media_ids').eql([file._id.toString()]); res.body.should.have.property('media_ids').eql([file._id.toString()]);
done(); done();
}); });
})); });
it('他人のファイルは添付できない', () => new Promise(async (done) => { it('他人のファイルは添付できない', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
const hima = await insertHimawari(); const hima = await insertHimawari();
const file = await insertDriveFile({ const file = await insertDriveFile({
@ -268,9 +268,9 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('存在しないファイルは添付できない', () => new Promise(async (done) => { it('存在しないファイルは添付できない', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
request('/posts/create', { request('/posts/create', {
media_ids: ['000000000000000000000000'] media_ids: ['000000000000000000000000']
@ -278,9 +278,9 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('不正なファイルIDで怒られる', () => new Promise(async (done) => { it('不正なファイルIDで怒られる', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
request('/posts/create', { request('/posts/create', {
media_ids: ['kyoppie'] media_ids: ['kyoppie']
@ -288,9 +288,9 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('返信できる', () => new Promise(async (done) => { it('返信できる', () => async (done) => {
const hima = await insertHimawari(); const hima = await insertHimawari();
const himaPost = await db.get('posts').insert({ const himaPost = await db.get('posts').insert({
user_id: hima._id, user_id: hima._id,
@ -311,9 +311,9 @@ describe('API', () => {
res.body.reply_to.should.have.property('text').eql(himaPost.text); res.body.reply_to.should.have.property('text').eql(himaPost.text);
done(); done();
}); });
})); });
it('repostできる', () => new Promise(async (done) => { it('repostできる', () => async (done) => {
const hima = await insertHimawari(); const hima = await insertHimawari();
const himaPost = await db.get('posts').insert({ const himaPost = await db.get('posts').insert({
user_id: hima._id, user_id: hima._id,
@ -332,9 +332,9 @@ describe('API', () => {
res.body.repost.should.have.property('text').eql(himaPost.text); res.body.repost.should.have.property('text').eql(himaPost.text);
done(); done();
}); });
})); });
it('引用repostできる', () => new Promise(async (done) => { it('引用repostできる', () => async (done) => {
const hima = await insertHimawari(); const hima = await insertHimawari();
const himaPost = await db.get('posts').insert({ const himaPost = await db.get('posts').insert({
user_id: hima._id, user_id: hima._id,
@ -355,9 +355,9 @@ describe('API', () => {
res.body.repost.should.have.property('text').eql(himaPost.text); res.body.repost.should.have.property('text').eql(himaPost.text);
done(); done();
}); });
})); });
it('文字数ぎりぎりで怒られない', () => new Promise(async (done) => { it('文字数ぎりぎりで怒られない', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
const post = { const post = {
text: '!'.repeat(1000) text: '!'.repeat(1000)
@ -366,9 +366,9 @@ describe('API', () => {
res.should.have.status(200); res.should.have.status(200);
done(); done();
}); });
})); });
it('文字数オーバーで怒られる', () => new Promise(async (done) => { it('文字数オーバーで怒られる', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
const post = { const post = {
text: '!'.repeat(1001) text: '!'.repeat(1001)
@ -377,9 +377,9 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('存在しないリプライ先で怒られる', () => new Promise(async (done) => { it('存在しないリプライ先で怒られる', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
const post = { const post = {
text: 'さく', text: 'さく',
@ -389,9 +389,9 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('存在しないrepost対象で怒られる', () => new Promise(async (done) => { it('存在しないrepost対象で怒られる', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
const post = { const post = {
repost_id: '000000000000000000000000' repost_id: '000000000000000000000000'
@ -400,9 +400,9 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('不正なリプライ先IDで怒られる', () => new Promise(async (done) => { it('不正なリプライ先IDで怒られる', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
const post = { const post = {
text: 'さく', text: 'さく',
@ -412,9 +412,9 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('不正なrepost対象IDで怒られる', () => new Promise(async (done) => { it('不正なrepost対象IDで怒られる', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
const post = { const post = {
repost_id: 'kyoppie' repost_id: 'kyoppie'
@ -423,9 +423,9 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('投票を添付できる', () => new Promise(async (done) => { it('投票を添付できる', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
request('/posts/create', { request('/posts/create', {
text: 'インデントするなら?', text: 'インデントするなら?',
@ -438,9 +438,9 @@ describe('API', () => {
res.body.should.have.property('poll'); res.body.should.have.property('poll');
done(); done();
}); });
})); });
it('投票の選択肢が無くて怒られる', () => new Promise(async (done) => { it('投票の選択肢が無くて怒られる', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
request('/posts/create', { request('/posts/create', {
poll: {} poll: {}
@ -448,9 +448,9 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('投票の選択肢が無くて怒られる (空の配列)', () => new Promise(async (done) => { it('投票の選択肢が無くて怒られる (空の配列)', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
request('/posts/create', { request('/posts/create', {
poll: { poll: {
@ -460,9 +460,9 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('投票の選択肢が1つで怒られる', () => new Promise(async (done) => { it('投票の選択肢が1つで怒られる', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
request('/posts/create', { request('/posts/create', {
poll: { poll: {
@ -472,11 +472,11 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
}); });
describe('posts/show', () => { describe('posts/show', () => {
it('投稿が取得できる', () => new Promise(async (done) => { it('投稿が取得できる', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
const myPost = await db.get('posts').insert({ const myPost = await db.get('posts').insert({
user_id: me._id, user_id: me._id,
@ -490,29 +490,29 @@ describe('API', () => {
res.body.should.have.property('id').eql(myPost._id.toString()); res.body.should.have.property('id').eql(myPost._id.toString());
done(); done();
}); });
})); });
it('投稿が存在しなかったら怒る', () => new Promise(async (done) => { it('投稿が存在しなかったら怒る', () => async (done) => {
request('/posts/show', { request('/posts/show', {
post_id: '000000000000000000000000' post_id: '000000000000000000000000'
}).then(res => { }).then(res => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('間違ったIDで怒られる', () => new Promise(async (done) => { it('間違ったIDで怒られる', () => async (done) => {
request('/posts/show', { request('/posts/show', {
post_id: 'kyoppie' post_id: 'kyoppie'
}).then(res => { }).then(res => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
}); });
describe('posts/likes/create', () => { describe('posts/likes/create', () => {
it('いいねできる', () => new Promise(async (done) => { it('いいねできる', () => async (done) => {
const hima = await insertHimawari(); const hima = await insertHimawari();
const himaPost = await db.get('posts').insert({ const himaPost = await db.get('posts').insert({
user_id: hima._id, user_id: hima._id,
@ -526,9 +526,9 @@ describe('API', () => {
res.should.have.status(204); res.should.have.status(204);
done(); done();
}); });
})); });
it('自分の投稿にはいいねできない', () => new Promise(async (done) => { it('自分の投稿にはいいねできない', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
const myPost = await db.get('posts').insert({ const myPost = await db.get('posts').insert({
user_id: me._id, user_id: me._id,
@ -541,9 +541,9 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('二重にいいねできない', () => new Promise(async (done) => { it('二重にいいねできない', () => async (done) => {
const hima = await insertHimawari(); const hima = await insertHimawari();
const himaPost = await db.get('posts').insert({ const himaPost = await db.get('posts').insert({
user_id: hima._id, user_id: hima._id,
@ -562,9 +562,9 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('存在しない投稿にはいいねできない', () => new Promise(async (done) => { it('存在しない投稿にはいいねできない', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
request('/posts/likes/create', { request('/posts/likes/create', {
post_id: '000000000000000000000000' post_id: '000000000000000000000000'
@ -572,17 +572,17 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('空のパラメータで怒られる', () => new Promise(async (done) => { it('空のパラメータで怒られる', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
request('/posts/likes/create', {}, me).then(res => { request('/posts/likes/create', {}, me).then(res => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('間違ったIDで怒られる', () => new Promise(async (done) => { it('間違ったIDで怒られる', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
request('/posts/likes/create', { request('/posts/likes/create', {
post_id: 'kyoppie' post_id: 'kyoppie'
@ -590,11 +590,11 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
}); });
describe('posts/likes/delete', () => { describe('posts/likes/delete', () => {
it('いいね解除できる', () => new Promise(async (done) => { it('いいね解除できる', () => async (done) => {
const hima = await insertHimawari(); const hima = await insertHimawari();
const himaPost = await db.get('posts').insert({ const himaPost = await db.get('posts').insert({
user_id: hima._id, user_id: hima._id,
@ -613,9 +613,9 @@ describe('API', () => {
res.should.have.status(204); res.should.have.status(204);
done(); done();
}); });
})); });
it('いいねしていない投稿はいいね解除できない', () => new Promise(async (done) => { it('いいねしていない投稿はいいね解除できない', () => async (done) => {
const hima = await insertHimawari(); const hima = await insertHimawari();
const himaPost = await db.get('posts').insert({ const himaPost = await db.get('posts').insert({
user_id: hima._id, user_id: hima._id,
@ -629,9 +629,9 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('存在しない投稿はいいね解除できない', () => new Promise(async (done) => { it('存在しない投稿はいいね解除できない', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
request('/posts/likes/delete', { request('/posts/likes/delete', {
post_id: '000000000000000000000000' post_id: '000000000000000000000000'
@ -639,17 +639,17 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('空のパラメータで怒られる', () => new Promise(async (done) => { it('空のパラメータで怒られる', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
request('/posts/likes/delete', {}, me).then(res => { request('/posts/likes/delete', {}, me).then(res => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('間違ったIDで怒られる', () => new Promise(async (done) => { it('間違ったIDで怒られる', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
request('/posts/likes/delete', { request('/posts/likes/delete', {
post_id: 'kyoppie' post_id: 'kyoppie'
@ -657,11 +657,11 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
}); });
describe('following/create', () => { describe('following/create', () => {
it('フォローできる', () => new Promise(async (done) => { it('フォローできる', () => async (done) => {
const hima = await insertHimawari(); const hima = await insertHimawari();
const me = await insertSakurako(); const me = await insertSakurako();
request('/following/create', { request('/following/create', {
@ -670,9 +670,9 @@ describe('API', () => {
res.should.have.status(204); res.should.have.status(204);
done(); done();
}); });
})); });
it('過去にフォロー歴があった状態でフォローできる', () => new Promise(async (done) => { it('過去にフォロー歴があった状態でフォローできる', () => async (done) => {
const hima = await insertHimawari(); const hima = await insertHimawari();
const me = await insertSakurako(); const me = await insertSakurako();
await db.get('following').insert({ await db.get('following').insert({
@ -686,9 +686,9 @@ describe('API', () => {
res.should.have.status(204); res.should.have.status(204);
done(); done();
}); });
})); });
it('既にフォローしている場合は怒る', () => new Promise(async (done) => { it('既にフォローしている場合は怒る', () => async (done) => {
const hima = await insertHimawari(); const hima = await insertHimawari();
const me = await insertSakurako(); const me = await insertSakurako();
await db.get('following').insert({ await db.get('following').insert({
@ -701,9 +701,9 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('存在しないユーザーはフォローできない', () => new Promise(async (done) => { it('存在しないユーザーはフォローできない', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
request('/following/create', { request('/following/create', {
user_id: '000000000000000000000000' user_id: '000000000000000000000000'
@ -711,9 +711,9 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('自分自身はフォローできない', () => new Promise(async (done) => { it('自分自身はフォローできない', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
request('/following/create', { request('/following/create', {
user_id: me._id.toString() user_id: me._id.toString()
@ -721,17 +721,17 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('空のパラメータで怒られる', () => new Promise(async (done) => { it('空のパラメータで怒られる', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
request('/following/create', {}, me).then(res => { request('/following/create', {}, me).then(res => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('間違ったIDで怒られる', () => new Promise(async (done) => { it('間違ったIDで怒られる', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
request('/following/create', { request('/following/create', {
user_id: 'kyoppie' user_id: 'kyoppie'
@ -739,11 +739,11 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
}); });
describe('following/delete', () => { describe('following/delete', () => {
it('フォロー解除できる', () => new Promise(async (done) => { it('フォロー解除できる', () => async (done) => {
const hima = await insertHimawari(); const hima = await insertHimawari();
const me = await insertSakurako(); const me = await insertSakurako();
await db.get('following').insert({ await db.get('following').insert({
@ -756,9 +756,9 @@ describe('API', () => {
res.should.have.status(204); res.should.have.status(204);
done(); done();
}); });
})); });
it('過去にフォロー歴があった状態でフォロー解除できる', () => new Promise(async (done) => { it('過去にフォロー歴があった状態でフォロー解除できる', () => async (done) => {
const hima = await insertHimawari(); const hima = await insertHimawari();
const me = await insertSakurako(); const me = await insertSakurako();
await db.get('following').insert({ await db.get('following').insert({
@ -776,9 +776,9 @@ describe('API', () => {
res.should.have.status(204); res.should.have.status(204);
done(); done();
}); });
})); });
it('フォローしていない場合は怒る', () => new Promise(async (done) => { it('フォローしていない場合は怒る', () => async (done) => {
const hima = await insertHimawari(); const hima = await insertHimawari();
const me = await insertSakurako(); const me = await insertSakurako();
request('/following/delete', { request('/following/delete', {
@ -787,9 +787,9 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('存在しないユーザーはフォロー解除できない', () => new Promise(async (done) => { it('存在しないユーザーはフォロー解除できない', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
request('/following/delete', { request('/following/delete', {
user_id: '000000000000000000000000' user_id: '000000000000000000000000'
@ -797,9 +797,9 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('自分自身はフォロー解除できない', () => new Promise(async (done) => { it('自分自身はフォロー解除できない', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
request('/following/delete', { request('/following/delete', {
user_id: me._id.toString() user_id: me._id.toString()
@ -807,17 +807,17 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('空のパラメータで怒られる', () => new Promise(async (done) => { it('空のパラメータで怒られる', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
request('/following/delete', {}, me).then(res => { request('/following/delete', {}, me).then(res => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('間違ったIDで怒られる', () => new Promise(async (done) => { it('間違ったIDで怒られる', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
request('/following/delete', { request('/following/delete', {
user_id: 'kyoppie' user_id: 'kyoppie'
@ -825,11 +825,11 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
}); });
describe('drive', () => { describe('drive', () => {
it('ドライブ情報を取得できる', () => new Promise(async (done) => { it('ドライブ情報を取得できる', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
await insertDriveFile({ await insertDriveFile({
user_id: me._id, user_id: me._id,
@ -849,11 +849,11 @@ describe('API', () => {
res.body.should.have.property('usage').eql(1792); res.body.should.have.property('usage').eql(1792);
done(); done();
}); });
})); });
}); });
describe('drive/files/create', () => { describe('drive/files/create', () => {
it('ファイルを作成できる', () => new Promise(async (done) => { it('ファイルを作成できる', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
_chai.request(server) _chai.request(server)
.post('/drive/files/create') .post('/drive/files/create')
@ -866,19 +866,19 @@ describe('API', () => {
res.body.should.have.property('name').eql('Lenna.png'); res.body.should.have.property('name').eql('Lenna.png');
done(); done();
}); });
})); });
it('ファイル無しで怒られる', () => new Promise(async (done) => { it('ファイル無しで怒られる', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
request('/drive/files/create', {}, me).then(res => { request('/drive/files/create', {}, me).then(res => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
}); });
describe('drive/files/update', () => { describe('drive/files/update', () => {
it('名前を更新できる', () => new Promise(async (done) => { it('名前を更新できる', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
const file = await insertDriveFile({ const file = await insertDriveFile({
user_id: me._id user_id: me._id
@ -893,9 +893,9 @@ describe('API', () => {
res.body.should.have.property('name').eql(newName); res.body.should.have.property('name').eql(newName);
done(); done();
}); });
})); });
it('他人のファイルは更新できない', () => new Promise(async (done) => { it('他人のファイルは更新できない', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
const hima = await insertHimawari(); const hima = await insertHimawari();
const file = await insertDriveFile({ const file = await insertDriveFile({
@ -908,9 +908,9 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('親フォルダを更新できる', () => new Promise(async (done) => { it('親フォルダを更新できる', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
const file = await insertDriveFile({ const file = await insertDriveFile({
user_id: me._id user_id: me._id
@ -927,9 +927,9 @@ describe('API', () => {
res.body.should.have.property('folder_id').eql(folder._id.toString()); res.body.should.have.property('folder_id').eql(folder._id.toString());
done(); done();
}); });
})); });
it('親フォルダを無しにできる', () => new Promise(async (done) => { it('親フォルダを無しにできる', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
const file = await insertDriveFile({ const file = await insertDriveFile({
user_id: me._id, user_id: me._id,
@ -944,9 +944,9 @@ describe('API', () => {
res.body.should.have.property('folder_id').eql(null); res.body.should.have.property('folder_id').eql(null);
done(); done();
}); });
})); });
it('他人のフォルダには入れられない', () => new Promise(async (done) => { it('他人のフォルダには入れられない', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
const hima = await insertHimawari(); const hima = await insertHimawari();
const file = await insertDriveFile({ const file = await insertDriveFile({
@ -962,9 +962,9 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('存在しないフォルダで怒られる', () => new Promise(async (done) => { it('存在しないフォルダで怒られる', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
const file = await insertDriveFile({ const file = await insertDriveFile({
user_id: me._id user_id: me._id
@ -976,9 +976,9 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('不正なフォルダIDで怒られる', () => new Promise(async (done) => { it('不正なフォルダIDで怒られる', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
const file = await insertDriveFile({ const file = await insertDriveFile({
user_id: me._id user_id: me._id
@ -990,9 +990,9 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('ファイルが存在しなかったら怒る', () => new Promise(async (done) => { it('ファイルが存在しなかったら怒る', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
request('/drive/files/update', { request('/drive/files/update', {
file_id: '000000000000000000000000', file_id: '000000000000000000000000',
@ -1001,9 +1001,9 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('間違ったIDで怒られる', () => new Promise(async (done) => { it('間違ったIDで怒られる', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
request('/drive/files/update', { request('/drive/files/update', {
file_id: 'kyoppie', file_id: 'kyoppie',
@ -1012,11 +1012,11 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
}); });
describe('drive/folders/create', () => { describe('drive/folders/create', () => {
it('フォルダを作成できる', () => new Promise(async (done) => { it('フォルダを作成できる', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
request('/drive/folders/create', { request('/drive/folders/create', {
name: 'my folder' name: 'my folder'
@ -1026,11 +1026,11 @@ describe('API', () => {
res.body.should.have.property('name').eql('my folder'); res.body.should.have.property('name').eql('my folder');
done(); done();
}); });
})); });
}); });
describe('drive/folders/update', () => { describe('drive/folders/update', () => {
it('名前を更新できる', () => new Promise(async (done) => { it('名前を更新できる', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
const folder = await insertDriveFolder({ const folder = await insertDriveFolder({
user_id: me._id user_id: me._id
@ -1044,9 +1044,9 @@ describe('API', () => {
res.body.should.have.property('name').eql('new name'); res.body.should.have.property('name').eql('new name');
done(); done();
}); });
})); });
it('他人のフォルダを更新できない', () => new Promise(async (done) => { it('他人のフォルダを更新できない', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
const hima = await insertHimawari(); const hima = await insertHimawari();
const folder = await insertDriveFolder({ const folder = await insertDriveFolder({
@ -1059,9 +1059,9 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('親フォルダを更新できる', () => new Promise(async (done) => { it('親フォルダを更新できる', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
const folder = await insertDriveFolder({ const folder = await insertDriveFolder({
user_id: me._id user_id: me._id
@ -1078,9 +1078,9 @@ describe('API', () => {
res.body.should.have.property('parent_id').eql(parentFolder._id.toString()); res.body.should.have.property('parent_id').eql(parentFolder._id.toString());
done(); done();
}); });
})); });
it('親フォルダを無しに更新できる', () => new Promise(async (done) => { it('親フォルダを無しに更新できる', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
const folder = await insertDriveFolder({ const folder = await insertDriveFolder({
user_id: me._id, user_id: me._id,
@ -1095,9 +1095,9 @@ describe('API', () => {
res.body.should.have.property('parent_id').eql(null); res.body.should.have.property('parent_id').eql(null);
done(); done();
}); });
})); });
it('他人のフォルダを親フォルダに設定できない', () => new Promise(async (done) => { it('他人のフォルダを親フォルダに設定できない', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
const hima = await insertHimawari(); const hima = await insertHimawari();
const folder = await insertDriveFolder({ const folder = await insertDriveFolder({
@ -1113,9 +1113,9 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('フォルダが循環するような構造にできない', () => new Promise(async (done) => { it('フォルダが循環するような構造にできない', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
const folder = await insertDriveFolder(); const folder = await insertDriveFolder();
const parentFolder = await insertDriveFolder({ const parentFolder = await insertDriveFolder({
@ -1128,9 +1128,9 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('フォルダが循環するような構造にできない(再帰的)', () => new Promise(async (done) => { it('フォルダが循環するような構造にできない(再帰的)', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
const folderA = await insertDriveFolder(); const folderA = await insertDriveFolder();
const folderB = await insertDriveFolder({ const folderB = await insertDriveFolder({
@ -1146,9 +1146,9 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('存在しない親フォルダを設定できない', () => new Promise(async (done) => { it('存在しない親フォルダを設定できない', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
const folder = await insertDriveFolder(); const folder = await insertDriveFolder();
request('/drive/folders/update', { request('/drive/folders/update', {
@ -1158,9 +1158,9 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('不正な親フォルダIDで怒られる', () => new Promise(async (done) => { it('不正な親フォルダIDで怒られる', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
const folder = await insertDriveFolder(); const folder = await insertDriveFolder();
request('/drive/folders/update', { request('/drive/folders/update', {
@ -1170,9 +1170,9 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('存在しないフォルダを更新できない', () => new Promise(async (done) => { it('存在しないフォルダを更新できない', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
request('/drive/folders/update', { request('/drive/folders/update', {
folder_id: '000000000000000000000000' folder_id: '000000000000000000000000'
@ -1180,9 +1180,9 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('不正なフォルダIDで怒られる', () => new Promise(async (done) => { it('不正なフォルダIDで怒られる', () => async (done) => {
const me = await insertSakurako(); const me = await insertSakurako();
request('/drive/folders/update', { request('/drive/folders/update', {
folder_id: 'kyoppie' folder_id: 'kyoppie'
@ -1190,11 +1190,11 @@ describe('API', () => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
}); });
describe('auth/session/generate', () => { describe('auth/session/generate', () => {
it('認証セッションを作成できる', () => new Promise(async (done) => { it('認証セッションを作成できる', () => async (done) => {
const app = await insertApp(); const app = await insertApp();
request('/auth/session/generate', { request('/auth/session/generate', {
app_secret: app.secret app_secret: app.secret
@ -1205,23 +1205,23 @@ describe('API', () => {
res.body.should.have.property('url'); res.body.should.have.property('url');
done(); done();
}); });
})); });
it('app_secret 無しで怒られる', () => new Promise(async (done) => { it('app_secret 無しで怒られる', () => async (done) => {
request('/auth/session/generate', {}).then(res => { request('/auth/session/generate', {}).then(res => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
it('誤った app secret で怒られる', () => new Promise(async (done) => { it('誤った app secret で怒られる', () => async (done) => {
request('/auth/session/generate', { request('/auth/session/generate', {
app_secret: 'kyoppie' app_secret: 'kyoppie'
}).then(res => { }).then(res => {
res.should.have.status(400); res.should.have.status(400);
done(); done();
}); });
})); });
}); });
}); });
@ -1264,4 +1264,3 @@ async function insertApp(opts?) {
secret: 'mysecret' secret: 'mysecret'
}, opts)); }, opts));
} }