Add some tests and some fixes

This commit is contained in:
syuilo 2018-10-16 08:54:36 +09:00
parent 88664486af
commit 99da4f9839
No known key found for this signature in database
GPG key ID: BDC4C49D06AB9D69
3 changed files with 69 additions and 10 deletions

View file

@ -101,7 +101,7 @@ export const meta = {
export default async (params: any, user: ILocalUser, app: IApp) => new Promise(async (res, rej) => { export default async (params: any, user: ILocalUser, app: IApp) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params); const [ps, psErr] = getParams(meta, params);
if (psErr) throw psErr; if (psErr) return rej(psErr);
const isSecure = user != null && app == null; const isSecure = user != null && app == null;

View file

@ -132,6 +132,12 @@ export default async (ctx: Koa.Context) => {
updateUserStats(account, true); updateUserStats(account, true);
// Response const res = await pack(account, account, {
ctx.body = await pack(account); detail: true,
includeSecrets: true
});
res.token = secret;
ctx.body = res;
}; };

View file

@ -75,7 +75,7 @@ describe('API', () => {
username: 'test.', username: 'test.',
password: 'test' password: 'test'
}); });
expect(res).to.have.status(400); expect(res).have.status(400);
})); }));
it('空のパスワードでアカウントが作成できない', async(async () => { it('空のパスワードでアカウントが作成できない', async(async () => {
@ -83,7 +83,7 @@ describe('API', () => {
username: 'test', username: 'test',
password: '' password: ''
}); });
expect(res).to.have.status(400); expect(res).have.status(400);
})); }));
it('正しくアカウントが作成できる', async(async () => { it('正しくアカウントが作成できる', async(async () => {
@ -92,7 +92,7 @@ describe('API', () => {
password: 'test' password: 'test'
}; };
const res = await request('/signup', me); const res = await request('/signup', me);
expect(res).to.have.status(200); expect(res).have.status(200);
expect(res.body).be.a('object'); expect(res.body).be.a('object');
expect(res.body).have.property('username').eql(me.username); expect(res.body).have.property('username').eql(me.username);
})); }));
@ -105,7 +105,7 @@ describe('API', () => {
username: 'test', username: 'test',
password: 'test' password: 'test'
}); });
expect(res).to.have.status(400); expect(res).have.status(400);
})); }));
}); });
@ -119,7 +119,7 @@ describe('API', () => {
username: 'test', username: 'test',
password: 'bar' password: 'bar'
}); });
expect(res).to.have.status(403); expect(res).have.status(403);
})); }));
it('クエリをインジェクションできない', async(async () => { it('クエリをインジェクションできない', async(async () => {
@ -132,7 +132,7 @@ describe('API', () => {
$gt: '' $gt: ''
} }
}); });
expect(res).to.have.status(400); expect(res).have.status(400);
})); }));
it('正しい情報でサインインできる', async(async () => { it('正しい情報でサインインできる', async(async () => {
@ -144,7 +144,60 @@ describe('API', () => {
username: 'test', username: 'test',
password: 'foo' password: 'foo'
}); });
expect(res).to.have.status(204); expect(res).have.status(204);
}));
});
describe('i/update', () => {
it('アカウント設定を更新できる', async(async () => {
const me = await signup();
const myName = '大室櫻子';
const myLocation = '七森中';
const myBirthday = '2000-09-07';
const res = await request('/i/update', {
name: myName,
location: myLocation,
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);
}));
it('名前を空白にできない', async(async () => {
const me = await signup();
const res = await request('/i/update', {
name: ' '
}, me);
expect(res).have.status(400);
}));
it('誕生日の設定を削除できる', async(async () => {
const me = await signup();
await request('/i/update', {
birthday: '2000-09-07'
}, me);
const res = await request('/i/update', {
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);
}));
it('不正な誕生日の形式で怒られる', async(async () => {
const me = await signup();
const res = await request('/i/update', {
birthday: '2000/09/07'
}, me);
expect(res).have.status(400);
})); }));
}); });
}); });