diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2019-04-07 21:50:36 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-04-07 21:50:36 +0900 |
| commit | f0a29721c9fb10f97faf386bc9d6b1b2fad97895 (patch) | |
| tree | b5c1d38d698589bb444c0881a431391db91eb5bc /test/api.ts | |
| parent | Update README.md [AUTOGEN] (#4639) (diff) | |
| download | misskey-f0a29721c9fb10f97faf386bc9d6b1b2fad97895.tar.gz misskey-f0a29721c9fb10f97faf386bc9d6b1b2fad97895.tar.bz2 misskey-f0a29721c9fb10f97faf386bc9d6b1b2fad97895.zip | |
Use PostgreSQL instead of MongoDB (#4572)
* wip
* Update note.ts
* Update timeline.ts
* Update core.ts
* wip
* Update generate-visibility-query.ts
* wip
* wip
* wip
* wip
* wip
* Update global-timeline.ts
* wip
* wip
* wip
* Update vote.ts
* wip
* wip
* Update create.ts
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* Update files.ts
* wip
* wip
* Update CONTRIBUTING.md
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* Update read-notification.ts
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* Update cancel.ts
* wip
* wip
* wip
* Update show.ts
* wip
* wip
* Update gen-id.ts
* Update create.ts
* Update id.ts
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* Docker: Update files about Docker (#4599)
* Docker: Use cache if files used by `yarn install` was not updated
This patch reduces the number of times to installing node_modules.
For example, `yarn install` step will be skipped when only ".config/default.yml" is updated.
* Docker: Migrate MongoDB to Postgresql
Misskey uses Postgresql as a database instead of Mongodb since version 11.
* Docker: Uncomment about data persistence
This patch will save a lot of databases.
* wip
* wip
* wip
* Update activitypub.ts
* wip
* wip
* wip
* Update logs.ts
* wip
* Update drive-file.ts
* Update register.ts
* wip
* wip
* Update mentions.ts
* wip
* wip
* wip
* Update recommendation.ts
* wip
* Update index.ts
* wip
* Update recommendation.ts
* Doc: Update docker.ja.md and docker.en.md (#1) (#4608)
Update how to set up misskey.
* wip
* :v:
* wip
* Update note.ts
* Update postgre.ts
* wip
* wip
* wip
* wip
* Update add-file.ts
* wip
* wip
* wip
* Clean up
* Update logs.ts
* wip
* :pizza:
* wip
* Ad notes
* wip
* Update api-visibility.ts
* Update note.ts
* Update add-file.ts
* tests
* tests
* Update postgre.ts
* Update utils.ts
* wip
* wip
* Refactor
* wip
* Refactor
* wip
* wip
* Update show-users.ts
* Update update-instance.ts
* wip
* Update feed.ts
* Update outbox.ts
* Update outbox.ts
* Update user.ts
* wip
* Update list.ts
* Update update-hashtag.ts
* wip
* Update update-hashtag.ts
* Refactor
* Update update.ts
* wip
* wip
* :v:
* clean up
* docs
* Update push.ts
* wip
* Update api.ts
* wip
* :v:
* Update make-pagination-query.ts
* :v:
* Delete hashtags.ts
* Update instances.ts
* Update instances.ts
* Update create.ts
* Update search.ts
* Update reversi-game.ts
* Update signup.ts
* Update user.ts
* id
* Update example.yml
* :art:
* objectid
* fix
* reversi
* reversi
* Fix bug of chart engine
* Add test of chart engine
* Improve test
* Better testing
* Improve chart engine
* Refactor
* Add test of chart engine
* Refactor
* Add chart test
* Fix bug
* コミットし忘れ
* Refactoring
* :v:
* Add tests
* Add test
* Extarct note tests
* Refactor
* 存在しないユーザーにメンションできなくなっていた問題を修正
* Fix bug
* Update update-meta.ts
* Fix bug
* Update mention.vue
* Fix bug
* Update meta.ts
* Update CONTRIBUTING.md
* Fix bug
* Fix bug
* Fix bug
* Clean up
* Clean up
* Update notification.ts
* Clean up
* Add mute tests
* Add test
* Refactor
* Add test
* Fix test
* Refactor
* Refactor
* Add tests
* Update utils.ts
* Update utils.ts
* Fix test
* Update package.json
* Update update.ts
* Update manifest.ts
* Fix bug
* Fix bug
* Add test
* :art:
* Update endpoint permissions
* Updaye permisison
* Update person.ts
#4299
* データベースと同期しないように
* Fix bug
* Fix bug
* Update reversi-game.ts
* Use a feature of Node v11.7.0 to extract a public key (#4644)
* wip
* wip
* :v:
* Refactoring
#1540
* test
* test
* test
* test
* test
* test
* test
* Fix bug
* Fix test
* :sushi:
* wip
* #4471
* Add test for #4335
* Refactor
* Fix test
* Add tests
* :clock4:
* Fix bug
* Add test
* Add test
* rename
* Fix bug
Diffstat (limited to 'test/api.ts')
| -rw-r--r-- | test/api.ts | 635 |
1 files changed, 138 insertions, 497 deletions
diff --git a/test/api.ts b/test/api.ts index cc4521d3dc..71443c5730 100644 --- a/test/api.ts +++ b/test/api.ts @@ -6,44 +6,35 @@ * * To specify test: * > mocha test/api.ts --require ts-node/register -g 'test name' + * + * If the tests not start, try set following enviroment variables: + * TS_NODE_FILES=true and TS_NODE_TRANSPILE_ONLY=true + * for more details, please see: https://github.com/TypeStrong/ts-node/issues/754 */ -import * as http from 'http'; -import * as fs from 'fs'; -import * as assert from 'chai'; -import { async, _signup, _request, _uploadFile, _post, _react, resetDb } from './utils'; - -const expect = assert.expect; - -//#region process -Error.stackTraceLimit = Infinity; - -// During the test the env variable is set to test process.env.NODE_ENV = 'test'; -// Display detail of unhandled promise rejection -process.on('unhandledRejection', console.dir); -//#endregion - -const app = require('../built/server/api').default; -const db = require('../built/db/mongodb').default; - -const server = http.createServer(app.callback()); - -//#region Utilities -const request = _request(server); -const signup = _signup(request); -const post = _post(request); -const react = _react(request); -const uploadFile = _uploadFile(server); -//#endregion +import * as assert from 'assert'; +import * as childProcess from 'child_process'; +import { async, signup, request, post, react, uploadFile } from './utils'; describe('API', () => { - // Reset database each test - beforeEach(resetDb(db)); + let p: childProcess.ChildProcess; - after(() => { - server.close(); + beforeEach(done => { + p = childProcess.spawn('node', [__dirname + '/../index.js'], { + stdio: ['inherit', 'inherit', 'ipc'], + env: { NODE_ENV: 'test' } + }); + p.on('message', message => { + if (message === 'ok') { + done(); + } + }); + }); + + afterEach(() => { + p.kill(); }); describe('signup', () => { @@ -52,7 +43,7 @@ describe('API', () => { username: 'test.', password: 'test' }); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); it('空のパスワードでアカウントが作成できない', async(async () => { @@ -60,7 +51,7 @@ describe('API', () => { username: 'test', password: '' }); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); it('正しくアカウントが作成できる', async(async () => { @@ -71,9 +62,9 @@ describe('API', () => { const res = await request('/signup', me); - expect(res).have.status(200); - expect(res.body).be.a('object'); - expect(res.body).have.property('username').eql(me.username); + assert.strictEqual(res.status, 200); + assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true); + assert.strictEqual(res.body.username, me.username); })); it('同じユーザー名のアカウントは作成できない', async(async () => { @@ -86,7 +77,7 @@ describe('API', () => { password: 'test' }); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); }); @@ -102,7 +93,7 @@ describe('API', () => { password: 'bar' }); - expect(res).have.status(403); + assert.strictEqual(res.status, 403); })); it('クエリをインジェクションできない', async(async () => { @@ -117,7 +108,7 @@ describe('API', () => { } }); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); it('正しい情報でサインインできる', async(async () => { @@ -131,7 +122,7 @@ describe('API', () => { password: 'foo' }); - expect(res).have.status(200); + assert.strictEqual(res.status, 200); })); }); @@ -149,12 +140,11 @@ describe('API', () => { birthday: myBirthday }, me); - expect(res).have.status(200); - expect(res.body).be.a('object'); - expect(res.body).have.property('name').eql(myName); - expect(res.body).have.nested.property('profile').a('object'); - expect(res.body).have.nested.property('profile.location').eql(myLocation); - expect(res.body).have.nested.property('profile.birthday').eql(myBirthday); + assert.strictEqual(res.status, 200); + assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true); + assert.strictEqual(res.body.name, myName); + assert.strictEqual(res.body.location, myLocation); + assert.strictEqual(res.body.birthday, myBirthday); })); it('名前を空白にできない', async(async () => { @@ -162,7 +152,7 @@ describe('API', () => { const res = await request('/i/update', { name: ' ' }, me); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); it('誕生日の設定を削除できる', async(async () => { @@ -175,10 +165,9 @@ describe('API', () => { birthday: null }, me); - expect(res).have.status(200); - expect(res.body).be.a('object'); - expect(res.body).have.nested.property('profile').a('object'); - expect(res.body).have.nested.property('profile.birthday').eql(null); + assert.strictEqual(res.status, 200); + assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true); + assert.strictEqual(res.body.birthday, null); })); it('不正な誕生日の形式で怒られる', async(async () => { @@ -186,7 +175,7 @@ describe('API', () => { const res = await request('/i/update', { birthday: '2000/09/07' }, me); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); }); @@ -198,365 +187,23 @@ describe('API', () => { userId: me.id }, me); - expect(res).have.status(200); - expect(res.body).be.a('object'); - expect(res.body).have.property('id').eql(me.id); + assert.strictEqual(res.status, 200); + assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true); + assert.strictEqual(res.body.id, me.id); })); it('ユーザーが存在しなかったら怒る', async(async () => { const res = await request('/users/show', { userId: '000000000000000000000000' }); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); it('間違ったIDで怒られる', async(async () => { const res = await request('/users/show', { userId: 'kyoppie' }); - expect(res).have.status(400); - })); - }); - - describe('notes/create', () => { - it('投稿できる', async(async () => { - const me = await signup(); - const post = { - text: 'test' - }; - - const res = await request('/notes/create', post, me); - - expect(res).have.status(200); - expect(res.body).be.a('object'); - expect(res.body).have.property('createdNote'); - expect(res.body.createdNote).have.property('text').eql(post.text); - })); - - it('ファイルを添付できる', async(async () => { - const me = await signup(); - const file = await uploadFile(me); - - const res = await request('/notes/create', { - fileIds: [file.id] - }, me); - - expect(res).have.status(200); - expect(res.body).be.a('object'); - expect(res.body).have.property('createdNote'); - expect(res.body.createdNote).have.property('fileIds').eql([file.id]); - })); - - it('他人のファイルは無視', async(async () => { - const me = await signup({ username: 'alice' }); - const bob = await signup({ username: 'bob' }); - const file = await uploadFile(bob); - - const res = await request('/notes/create', { - text: 'test', - fileIds: [file.id] - }, me); - - expect(res).have.status(200); - expect(res.body).be.a('object'); - expect(res.body).have.property('createdNote'); - expect(res.body.createdNote).have.property('fileIds').eql([]); - })); - - it('存在しないファイルは無視', async(async () => { - const me = await signup(); - - const res = await request('/notes/create', { - text: 'test', - fileIds: ['000000000000000000000000'] - }, me); - - expect(res).have.status(200); - expect(res.body).be.a('object'); - expect(res.body).have.property('createdNote'); - expect(res.body.createdNote).have.property('fileIds').eql([]); - })); - - it('不正なファイルIDで怒られる', async(async () => { - const me = await signup(); - const res = await request('/notes/create', { - fileIds: ['kyoppie'] - }, me); - expect(res).have.status(400); - })); - - it('返信できる', async(async () => { - const bob = await signup({ username: 'bob' }); - const bobPost = await post(bob); - - const alice = await signup({ username: 'alice' }); - const alicePost = { - text: 'test', - replyId: bobPost.id - }; - - const res = await request('/notes/create', alicePost, alice); - - expect(res).have.status(200); - expect(res.body).be.a('object'); - expect(res.body).have.property('createdNote'); - expect(res.body.createdNote).have.property('text').eql(alicePost.text); - expect(res.body.createdNote).have.property('replyId').eql(alicePost.replyId); - expect(res.body.createdNote).have.property('reply'); - expect(res.body.createdNote.reply).have.property('text').eql(alicePost.text); - })); - - it('renoteできる', async(async () => { - const bob = await signup({ username: 'bob' }); - const bobPost = await post(bob, { - text: 'test' - }); - - const alice = await signup({ username: 'alice' }); - const alicePost = { - renoteId: bobPost.id - }; - - const res = await request('/notes/create', alicePost, alice); - - expect(res).have.status(200); - expect(res.body).be.a('object'); - expect(res.body).have.property('createdNote'); - expect(res.body.createdNote).have.property('renoteId').eql(alicePost.renoteId); - expect(res.body.createdNote).have.property('renote'); - expect(res.body.createdNote.renote).have.property('text').eql(bobPost.text); - })); - - it('引用renoteできる', async(async () => { - const bob = await signup({ username: 'bob' }); - const bobPost = await post(bob, { - text: 'test' - }); - - const alice = await signup({ username: 'alice' }); - const alicePost = { - text: 'test', - renoteId: bobPost.id - }; - - const res = await request('/notes/create', alicePost, alice); - - expect(res).have.status(200); - expect(res.body).be.a('object'); - expect(res.body).have.property('createdNote'); - expect(res.body.createdNote).have.property('text').eql(alicePost.text); - expect(res.body.createdNote).have.property('renoteId').eql(alicePost.renoteId); - expect(res.body.createdNote).have.property('renote'); - expect(res.body.createdNote.renote).have.property('text').eql(bobPost.text); - })); - - it('文字数ぎりぎりで怒られない', async(async () => { - const me = await signup(); - const post = { - text: '!'.repeat(1000) - }; - const res = await request('/notes/create', post, me); - expect(res).have.status(200); - })); - - it('文字数オーバーで怒られる', async(async () => { - const me = await signup(); - const post = { - text: '!'.repeat(1001) - }; - const res = await request('/notes/create', post, me); - expect(res).have.status(400); - })); - - it('存在しないリプライ先で怒られる', async(async () => { - const me = await signup(); - const post = { - text: 'test', - replyId: '000000000000000000000000' - }; - const res = await request('/notes/create', post, me); - expect(res).have.status(400); - })); - - it('存在しないrenote対象で怒られる', async(async () => { - const me = await signup(); - const post = { - renoteId: '000000000000000000000000' - }; - const res = await request('/notes/create', post, me); - expect(res).have.status(400); - })); - - it('不正なリプライ先IDで怒られる', async(async () => { - const me = await signup(); - const post = { - text: 'test', - replyId: 'foo' - }; - const res = await request('/notes/create', post, me); - expect(res).have.status(400); - })); - - it('不正なrenote対象IDで怒られる', async(async () => { - const me = await signup(); - const post = { - renoteId: 'foo' - }; - const res = await request('/notes/create', post, me); - expect(res).have.status(400); - })); - - it('投票を添付できる', async(async () => { - const me = await signup(); - - const res = await request('/notes/create', { - text: 'test', - poll: { - choices: ['foo', 'bar'] - } - }, me); - - expect(res).have.status(200); - expect(res.body).be.a('object'); - expect(res.body).have.property('createdNote'); - expect(res.body.createdNote).have.property('poll'); - })); - - it('投票の選択肢が無くて怒られる', async(async () => { - const me = await signup(); - const res = await request('/notes/create', { - poll: {} - }, me); - expect(res).have.status(400); - })); - - it('投票の選択肢が無くて怒られる (空の配列)', async(async () => { - const me = await signup(); - const res = await request('/notes/create', { - poll: { - choices: [] - } - }, me); - expect(res).have.status(400); - })); - - it('投票の選択肢が1つで怒られる', async(async () => { - const me = await signup(); - const res = await request('/notes/create', { - poll: { - choices: ['Strawberry Pasta'] - } - }, me); - expect(res).have.status(400); - })); - - it('投票できる', async(async () => { - const me = await signup(); - - const { body } = await request('/notes/create', { - text: 'test', - poll: { - choices: ['sakura', 'izumi', 'ako'] - } - }, me); - - const res = await request('/notes/polls/vote', { - noteId: body.createdNote.id, - choice: 1 - }, me); - - expect(res).have.status(204); - })); - - it('複数投票できない', async(async () => { - const me = await signup(); - - const { body } = await request('/notes/create', { - text: 'test', - poll: { - choices: ['sakura', 'izumi', 'ako'] - } - }, me); - - await request('/notes/polls/vote', { - noteId: body.createdNote.id, - choice: 0 - }, me); - - const res = await request('/notes/polls/vote', { - noteId: body.createdNote.id, - choice: 2 - }, me); - - expect(res).have.status(400); - })); - - it('許可されている場合は複数投票できる', async(async () => { - const me = await signup(); - - const { body } = await request('/notes/create', { - text: 'test', - poll: { - choices: ['sakura', 'izumi', 'ako'], - multiple: true - } - }, me); - - await request('/notes/polls/vote', { - noteId: body.createdNote.id, - choice: 0 - }, me); - - await request('/notes/polls/vote', { - noteId: body.createdNote.id, - choice: 1 - }, me); - - const res = await request('/notes/polls/vote', { - noteId: body.createdNote.id, - choice: 2 - }, me); - - expect(res).have.status(204); - })); - - it('締め切られている場合は投票できない', async(async () => { - const me = await signup(); - - const { body } = await request('/notes/create', { - text: 'test', - poll: { - choices: ['sakura', 'izumi', 'ako'], - expiredAfter: 1 - } - }, me); - - await new Promise(x => setTimeout(x, 2)); - - const res = await request('/notes/polls/vote', { - noteId: body.createdNote.id, - choice: 1 - }, me); - - expect(res).have.status(400); - })); - - it('同じユーザーに複数メンションしても内部的にまとめられる', async(async () => { - const alice = await signup({ username: 'alice' }); - const bob = await signup({ username: 'bob' }); - const post = { - text: '@bob @bob @bob yo' - }; - - const res = await request('/notes/create', post, alice); - - expect(res).have.status(200); - expect(res.body).be.a('object'); - expect(res.body).have.property('createdNote'); - expect(res.body.createdNote).have.property('text').eql(post.text); - - const noteDoc = await db.get('notes').findOne({ _id: res.body.createdNote.id }); - expect(noteDoc.mentions.map((id: any) => id.toString())).eql([bob.id.toString()]); + assert.strictEqual(res.status, 400); })); }); @@ -571,24 +218,24 @@ describe('API', () => { noteId: myPost.id }, me); - expect(res).have.status(200); - expect(res.body).be.a('object'); - expect(res.body).have.property('id').eql(myPost.id); - expect(res.body).have.property('text').eql(myPost.text); + assert.strictEqual(res.status, 200); + assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true); + assert.strictEqual(res.body.id, myPost.id); + assert.strictEqual(res.body.text, myPost.text); })); it('投稿が存在しなかったら怒る', async(async () => { const res = await request('/notes/show', { noteId: '000000000000000000000000' }); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); it('間違ったIDで怒られる', async(async () => { const res = await request('/notes/show', { noteId: 'kyoppie' }); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); }); @@ -603,7 +250,7 @@ describe('API', () => { reaction: 'like' }, alice); - expect(res).have.status(204); + assert.strictEqual(res.status, 204); })); it('自分の投稿にはリアクションできない', async(async () => { @@ -615,7 +262,7 @@ describe('API', () => { reaction: 'like' }, me); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); it('二重にリアクションできない', async(async () => { @@ -630,7 +277,7 @@ describe('API', () => { reaction: 'like' }, alice); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); it('存在しない投稿にはリアクションできない', async(async () => { @@ -641,7 +288,7 @@ describe('API', () => { reaction: 'like' }, me); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); it('空のパラメータで怒られる', async(async () => { @@ -649,7 +296,7 @@ describe('API', () => { const res = await request('/notes/reactions/create', {}, me); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); it('間違ったIDで怒られる', async(async () => { @@ -660,7 +307,7 @@ describe('API', () => { reaction: 'like' }, me); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); }); @@ -673,7 +320,7 @@ describe('API', () => { userId: alice.id }, bob); - expect(res).have.status(200); + assert.strictEqual(res.status, 200); })); it('既にフォローしている場合は怒る', async(async () => { @@ -687,7 +334,7 @@ describe('API', () => { userId: alice.id }, bob); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); it('存在しないユーザーはフォローできない', async(async () => { @@ -697,7 +344,7 @@ describe('API', () => { userId: '000000000000000000000000' }, alice); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); it('自分自身はフォローできない', async(async () => { @@ -707,7 +354,7 @@ describe('API', () => { userId: alice.id }, alice); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); it('空のパラメータで怒られる', async(async () => { @@ -715,7 +362,7 @@ describe('API', () => { const res = await request('/following/create', {}, alice); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); it('間違ったIDで怒られる', async(async () => { @@ -725,7 +372,7 @@ describe('API', () => { userId: 'foo' }, alice); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); }); @@ -741,7 +388,7 @@ describe('API', () => { userId: alice.id }, bob); - expect(res).have.status(200); + assert.strictEqual(res.status, 200); })); it('フォローしていない場合は怒る', async(async () => { @@ -752,7 +399,7 @@ describe('API', () => { userId: alice.id }, bob); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); it('存在しないユーザーはフォロー解除できない', async(async () => { @@ -762,7 +409,7 @@ describe('API', () => { userId: '000000000000000000000000' }, alice); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); it('自分自身はフォロー解除できない', async(async () => { @@ -772,7 +419,7 @@ describe('API', () => { userId: alice.id }, alice); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); it('空のパラメータで怒られる', async(async () => { @@ -780,7 +427,7 @@ describe('API', () => { const res = await request('/following/delete', {}, alice); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); it('間違ったIDで怒られる', async(async () => { @@ -790,7 +437,7 @@ describe('API', () => { userId: 'kyoppie' }, alice); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); }); @@ -799,20 +446,20 @@ describe('API', () => { it('ドライブ情報を取得できる', async(async () => { const bob = await signup({ username: 'bob' }); await uploadFile({ - userId: me._id, - datasize: 256 + userId: me.id, + size: 256 }); await uploadFile({ - userId: me._id, - datasize: 512 + userId: me.id, + size: 512 }); await uploadFile({ - userId: me._id, - datasize: 1024 + userId: me.id, + size: 1024 }); const res = await request('/drive', {}, me); - expect(res).have.status(200); - expect(res.body).be.a('object'); + assert.strictEqual(res.status, 200); + assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true); expect(res.body).have.property('usage').eql(1792); }));*/ }); @@ -821,14 +468,11 @@ describe('API', () => { it('ファイルを作成できる', async(async () => { const alice = await signup({ username: 'alice' }); - const res = await assert.request(server) - .post('/drive/files/create') - .field('i', alice.token) - .attach('file', fs.readFileSync(__dirname + '/resources/Lenna.png'), 'Lenna.png'); + const res = await uploadFile(alice); - expect(res).have.status(200); - expect(res.body).be.a('object'); - expect(res.body).have.property('name').eql('Lenna.png'); + assert.strictEqual(res.status, 200); + assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true); + assert.strictEqual(res.body.name, 'Lenna.png'); })); it('ファイル無しで怒られる', async(async () => { @@ -836,21 +480,18 @@ describe('API', () => { const res = await request('/drive/files/create', {}, alice); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); it('SVGファイルを作成できる', async(async () => { const izumi = await signup({ username: 'izumi' }); - const res = await assert.request(server) - .post('/drive/files/create') - .field('i', izumi.token) - .attach('file', fs.readFileSync(__dirname + '/resources/image.svg'), 'image.svg'); + const res = await uploadFile(izumi, __dirname + '/resources/image.svg'); - expect(res).have.status(200); - expect(res.body).be.a('object'); - expect(res.body).have.property('name').eql('image.svg'); - expect(res.body).have.property('type').eql('image/svg+xml'); + assert.strictEqual(res.status, 200); + assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true); + assert.strictEqual(res.body.name, 'image.svg'); + assert.strictEqual(res.body.type, 'image/svg+xml'); })); }); @@ -865,9 +506,9 @@ describe('API', () => { name: newName }, alice); - expect(res).have.status(200); - expect(res.body).be.a('object'); - expect(res.body).have.property('name').eql(newName); + assert.strictEqual(res.status, 200); + assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true); + assert.strictEqual(res.body.name, newName); })); it('他人のファイルは更新できない', async(async () => { @@ -880,7 +521,7 @@ describe('API', () => { name: 'いちごパスタ.png' }, alice); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); it('親フォルダを更新できる', async(async () => { @@ -895,9 +536,9 @@ describe('API', () => { folderId: folder.id }, alice); - expect(res).have.status(200); - expect(res.body).be.a('object'); - expect(res.body).have.property('folderId').eql(folder.id); + assert.strictEqual(res.status, 200); + assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true); + assert.strictEqual(res.body.folderId, folder.id); })); it('親フォルダを無しにできる', async(async () => { @@ -918,9 +559,9 @@ describe('API', () => { folderId: null }, alice); - expect(res).have.status(200); - expect(res.body).be.a('object'); - expect(res.body).have.property('folderId').eql(null); + assert.strictEqual(res.status, 200); + assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true); + assert.strictEqual(res.body.folderId, null); })); it('他人のフォルダには入れられない', async(async () => { @@ -936,7 +577,7 @@ describe('API', () => { folderId: folder.id }, alice); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); it('存在しないフォルダで怒られる', async(async () => { @@ -948,7 +589,7 @@ describe('API', () => { folderId: '000000000000000000000000' }, alice); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); it('不正なフォルダIDで怒られる', async(async () => { @@ -960,7 +601,7 @@ describe('API', () => { folderId: 'foo' }, alice); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); it('ファイルが存在しなかったら怒る', async(async () => { @@ -971,7 +612,7 @@ describe('API', () => { name: 'いちごパスタ.png' }, alice); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); it('間違ったIDで怒られる', async(async () => { @@ -982,7 +623,7 @@ describe('API', () => { name: 'いちごパスタ.png' }, alice); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); }); @@ -994,9 +635,9 @@ describe('API', () => { name: 'test' }, alice); - expect(res).have.status(200); - expect(res.body).be.a('object'); - expect(res.body).have.property('name').eql('test'); + assert.strictEqual(res.status, 200); + assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true); + assert.strictEqual(res.body.name, 'test'); })); }); @@ -1012,9 +653,9 @@ describe('API', () => { name: 'new name' }, alice); - expect(res).have.status(200); - expect(res.body).be.a('object'); - expect(res.body).have.property('name').eql('new name'); + assert.strictEqual(res.status, 200); + assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true); + assert.strictEqual(res.body.name, 'new name'); })); it('他人のフォルダを更新できない', async(async () => { @@ -1029,7 +670,7 @@ describe('API', () => { name: 'new name' }, alice); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); it('親フォルダを更新できる', async(async () => { @@ -1046,9 +687,9 @@ describe('API', () => { parentId: parentFolder.id }, alice); - expect(res).have.status(200); - expect(res.body).be.a('object'); - expect(res.body).have.property('parentId').eql(parentFolder.id); + assert.strictEqual(res.status, 200); + assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true); + assert.strictEqual(res.body.parentId, parentFolder.id); })); it('親フォルダを無しに更新できる', async(async () => { @@ -1069,9 +710,9 @@ describe('API', () => { parentId: null }, alice); - expect(res).have.status(200); - expect(res.body).be.a('object'); - expect(res.body).have.property('parentId').eql(null); + assert.strictEqual(res.status, 200); + assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true); + assert.strictEqual(res.body.parentId, null); })); it('他人のフォルダを親フォルダに設定できない', async(async () => { @@ -1089,7 +730,7 @@ describe('API', () => { parentId: parentFolder.id }, alice); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); it('フォルダが循環するような構造にできない', async(async () => { @@ -1110,7 +751,7 @@ describe('API', () => { parentId: parentFolder.id }, alice); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); it('フォルダが循環するような構造にできない(再帰的)', async(async () => { @@ -1138,7 +779,7 @@ describe('API', () => { parentId: folderC.id }, alice); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); it('フォルダが循環するような構造にできない(自身)', async(async () => { @@ -1166,7 +807,7 @@ describe('API', () => { parentId: '000000000000000000000000' }, alice); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); it('不正な親フォルダIDで怒られる', async(async () => { @@ -1180,7 +821,7 @@ describe('API', () => { parentId: 'foo' }, alice); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); it('存在しないフォルダを更新できない', async(async () => { @@ -1190,7 +831,7 @@ describe('API', () => { folderId: '000000000000000000000000' }, alice); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); it('不正なフォルダIDで怒られる', async(async () => { @@ -1200,7 +841,7 @@ describe('API', () => { folderId: 'foo' }, alice); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); }); @@ -1214,9 +855,9 @@ describe('API', () => { text: 'test' }, alice); - expect(res).have.status(200); - expect(res.body).be.a('object'); - expect(res.body).have.property('text').eql('test'); + assert.strictEqual(res.status, 200); + assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true); + assert.strictEqual(res.body.text, 'test'); })); it('自分自身にはメッセージを送信できない', async(async () => { @@ -1227,7 +868,7 @@ describe('API', () => { text: 'Yo' }, alice); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); it('存在しないユーザーにはメッセージを送信できない', async(async () => { @@ -1238,7 +879,7 @@ describe('API', () => { text: 'test' }, alice); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); it('不正なユーザーIDで怒られる', async(async () => { @@ -1249,7 +890,7 @@ describe('API', () => { text: 'test' }, alice); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); it('テキストが無くて怒られる', async(async () => { @@ -1260,7 +901,7 @@ describe('API', () => { userId: bob.id }, alice); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); it('文字数オーバーで怒られる', async(async () => { @@ -1272,7 +913,7 @@ describe('API', () => { text: '!'.repeat(1001) }, alice); - expect(res).have.status(400); + assert.strictEqual(res.status, 400); })); }); @@ -1297,9 +938,9 @@ describe('API', () => { noteId: alicePost.id }, carol); - expect(res).have.status(200); - expect(res.body).be.a('array'); - expect(res.body).length(0); + assert.strictEqual(res.status, 200); + assert.strictEqual(Array.isArray(res.body), true); + assert.strictEqual(res.body.length, 0); })); }); @@ -1319,10 +960,10 @@ describe('API', () => { const res = await request('/notes/timeline', {}, bob); - expect(res).have.status(200); - expect(res.body).be.a('array'); - expect(res.body).length(1); - expect(res.body[0].id).equals(alicePost.id); + assert.strictEqual(res.status, 200); + assert.strictEqual(Array.isArray(res.body), true); + assert.strictEqual(res.body.length, 1); + assert.strictEqual(res.body[0].id, alicePost.id); })); }); }); |