async'ify avatar and apppassword code

This commit is contained in:
Girish Ramakrishnan
2021-06-25 22:11:17 -07:00
parent 31d742fa67
commit 147c8df6e3
11 changed files with 385 additions and 354 deletions

View File

@@ -258,65 +258,53 @@ describe('Profile API', function () {
});
});
describe('app password', function () {
it('cannot add app password with invalid token', async function () {
const response = await superagent.post(`${serverUrl}/api/v1/app_passwords`)
.query({ access_token: user.token + 'xx' })
.send({ name: 'my-device', identifier: 'someapp' })
describe('avatar', function () {
it('has no avatar by default (public route)', async function () {
const response = await superagent.get(`${serverUrl}/api/v1/profile`)
.query({ access_token: user.token });
expect(response.body.avatarUrl).to.contain('www.gravatar.com');
const response2 = await superagent.get(`${serverUrl}/api/v1/profile/avatar/${user.id}`)
.ok(() => true);
expect(response.statusCode).to.equal(401);
expect(response2.statusCode).to.equal(404);
});
it('cannot add app password without name', async function () {
const response = await superagent.post(`${serverUrl}/api/v1/app_passwords`)
it('can set avatar', async function () {
const response = await superagent.post(`${serverUrl}/api/v1/profile/avatar`)
.query({ access_token: user.token })
.send({ identifier: 'someapp' })
.attach('avatar', './logo.png');
expect(response.statusCode).to.be(202);
});
it('did set 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/');
const response2 = await superagent.get(`${serverUrl}/api/v1/profile/avatar/${user.id}`)
.ok(() => true);
expect(response.statusCode).to.equal(400);
expect(response2.statusCode).to.equal(200);
});
let pwd;
it('can add app password', async function () {
const response = await superagent.post(`${serverUrl}/api/v1/app_passwords`)
.query({ access_token: user.token })
.send({ name: 'my-device', identifier: 'someapp' });
expect(response.statusCode).to.equal(201);
expect(response.body.password).to.be.a('string');
pwd = response.body;
});
it('can get app passwords', async function () {
const response = await superagent.get(`${serverUrl}/api/v1/app_passwords`)
it('can clear avatar', async function () {
const response = await superagent.del(`${serverUrl}/api/v1/profile/avatar`)
.query({ access_token: user.token });
expect(response.statusCode).to.equal(200);
expect(response.body.appPasswords).to.be.an(Array);
expect(response.body.appPasswords.length).to.be(1);
expect(response.body.appPasswords[0].name).to.be('my-device');
expect(response.body.appPasswords[0].identifier).to.be('someapp');
expect(response.body.appPasswords[0].hashedPassword).to.be(undefined);
expect(response.body.appPasswords[0].password).to.be(undefined);
expect(response.statusCode).to.be(202);
});
it('can get app password', async function () {
const response = await superagent.get(`${serverUrl}/api/v1/app_passwords/${pwd.id}`)
it('did clear avatar', async function () {
const response = await superagent.get(`${serverUrl}/api/v1/profile`)
.query({ access_token: user.token });
expect(response.body.avatarUrl).to.contain('www.gravatar.com');
expect(response.statusCode).to.equal(200);
expect(response.body.name).to.be('my-device');
expect(response.body.identifier).to.be('someapp');
expect(response.body.hashedPassword).to.be(undefined);
expect(response.body.password).to.be(undefined);
});
const response2 = await superagent.get(`${serverUrl}/api/v1/profile/avatar/${user.id}`)
.ok(() => true);
it('can del app password', async function () {
const response = await superagent.del(`${serverUrl}/api/v1/app_passwords/${pwd.id}`)
.query({ access_token: user.token });
expect(response.statusCode).to.equal(204);
expect(response2.statusCode).to.equal(404);
});
});
});