Add more avatar tests
This commit is contained in:
@@ -259,6 +259,8 @@ describe('Profile API', function () {
|
||||
});
|
||||
|
||||
describe('avatar', function () {
|
||||
let customAvatarSize = 0;
|
||||
|
||||
it('has no avatar by default (public route)', async function () {
|
||||
const response = await superagent.get(`${serverUrl}/api/v1/profile`)
|
||||
.query({ access_token: user.token });
|
||||
@@ -266,15 +268,17 @@ describe('Profile API', function () {
|
||||
expect(response.body.avatarUrl).to.contain('/img/');
|
||||
});
|
||||
|
||||
it('can set avatar', async function () {
|
||||
it('can set custom avatar', async function () {
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/profile/avatar`)
|
||||
.query({ access_token: user.token })
|
||||
.attach('avatar', './logo.png');
|
||||
|
||||
customAvatarSize = require('fs').readFileSync('./logo.png').length;
|
||||
|
||||
expect(response.statusCode).to.be(202);
|
||||
});
|
||||
|
||||
it('did set avatar', async function () {
|
||||
it('did set custom avatar', async function () {
|
||||
const response = await superagent.get(`${serverUrl}/api/v1/profile`)
|
||||
.query({ access_token: user.token });
|
||||
expect(response.body.avatarUrl).to.contain('/api/v1/profile/avatar/');
|
||||
@@ -282,7 +286,38 @@ describe('Profile API', function () {
|
||||
const response2 = await superagent.get(`${serverUrl}/api/v1/profile/avatar/${user.id}`)
|
||||
.ok(() => true);
|
||||
|
||||
expect(parseInt(response2.headers['content-length'])).to.equal(customAvatarSize);
|
||||
expect(response2.statusCode).to.equal(200);
|
||||
});
|
||||
|
||||
it('can set gravatar', async function () {
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/profile/avatar`)
|
||||
.query({ access_token: user.token })
|
||||
.send({ avatar: 'gravatar' });
|
||||
|
||||
expect(response.statusCode).to.be(202);
|
||||
});
|
||||
|
||||
it('did set gravatar', async function () {
|
||||
const response = await superagent.get(`${serverUrl}/api/v1/profile`)
|
||||
.query({ access_token: user.token });
|
||||
|
||||
expect(response.body.avatarUrl).to.contain('https://www.gravatar.com/avatar/');
|
||||
});
|
||||
|
||||
it('can unset avatar', async function () {
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/profile/avatar`)
|
||||
.query({ access_token: user.token })
|
||||
.send({ avatar: '' });
|
||||
|
||||
expect(response.statusCode).to.be(202);
|
||||
});
|
||||
|
||||
it('did unset avatar', async function () {
|
||||
const response = await superagent.get(`${serverUrl}/api/v1/profile`)
|
||||
.query({ access_token: user.token });
|
||||
|
||||
expect(response.body.avatarUrl).to.contain('/img/');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user