replace with custom superagent based on fetch API
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
const common = require('./common.js'),
|
||||
expect = require('expect.js'),
|
||||
speakeasy = require('speakeasy'),
|
||||
superagent = require('superagent'),
|
||||
superagent = require('../../superagent.js'),
|
||||
fs = require('fs'),
|
||||
path = require('path'),
|
||||
paths = require('../../paths.js'),
|
||||
@@ -26,7 +26,7 @@ describe('Profile API', function () {
|
||||
const response = await superagent.get(`${serverUrl}/api/v1/profile`)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(401);
|
||||
expect(response.status).to.equal(401);
|
||||
});
|
||||
|
||||
it('fails with empty token', async function () {
|
||||
@@ -34,7 +34,7 @@ describe('Profile API', function () {
|
||||
.query({ access_token: '' })
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(401);
|
||||
expect(response.status).to.equal(401);
|
||||
});
|
||||
|
||||
it('fails with invalid token', async function () {
|
||||
@@ -42,14 +42,14 @@ describe('Profile API', function () {
|
||||
.query({ access_token: 'some token' })
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(401);
|
||||
expect(response.status).to.equal(401);
|
||||
});
|
||||
|
||||
it('succeeds', async function () {
|
||||
const response = await superagent.get(`${serverUrl}/api/v1/profile`)
|
||||
.query({ access_token: owner.token });
|
||||
|
||||
expect(response.statusCode).to.equal(200);
|
||||
expect(response.status).to.equal(200);
|
||||
expect(response.body.username).to.equal(owner.username.toLowerCase());
|
||||
expect(response.body.email).to.equal(owner.email.toLowerCase());
|
||||
expect(response.body.fallbackEmail).to.equal('');
|
||||
@@ -67,7 +67,7 @@ describe('Profile API', function () {
|
||||
.query({ access_token: token.accessToken })
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(401);
|
||||
expect(response.status).to.equal(401);
|
||||
});
|
||||
|
||||
it('fails with invalid token in auth header', async function () {
|
||||
@@ -75,13 +75,13 @@ describe('Profile API', function () {
|
||||
.set('Authorization', 'Bearer ' + 'x' + owner.token)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(401);
|
||||
expect(response.status).to.equal(401);
|
||||
});
|
||||
|
||||
it('succeeds with token in auth header', async function () {
|
||||
const response = await superagent.get(`${serverUrl}/api/v1/profile`).set('Authorization', 'Bearer ' + owner.token);
|
||||
|
||||
expect(response.statusCode).to.equal(200);
|
||||
expect(response.status).to.equal(200);
|
||||
expect(response.body.username).to.equal(owner.username.toLowerCase());
|
||||
expect(response.body.email).to.equal(owner.email.toLowerCase());
|
||||
expect(response.body.displayName).to.be.a('string');
|
||||
@@ -96,7 +96,7 @@ describe('Profile API', function () {
|
||||
.send({ email: 'newemail@example.com' })
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(401);
|
||||
expect(response.status).to.equal(401);
|
||||
});
|
||||
|
||||
it('change email fails due to missing password', async function () {
|
||||
@@ -105,7 +105,7 @@ describe('Profile API', function () {
|
||||
.send({ email: 'newemail@example.com' })
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
expect(response.status).to.equal(400);
|
||||
});
|
||||
|
||||
it('change email fails due to invalid password', async function () {
|
||||
@@ -114,7 +114,7 @@ describe('Profile API', function () {
|
||||
.send({ email: 'foo@bar.com', password: 'this is wrong' })
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(412);
|
||||
expect(response.status).to.equal(412);
|
||||
});
|
||||
|
||||
it('change email fails due to invalid email', async function () {
|
||||
@@ -123,7 +123,7 @@ describe('Profile API', function () {
|
||||
.send({ email: 'foo@bar' })
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
expect(response.status).to.equal(400);
|
||||
});
|
||||
|
||||
it('change email succeeds', async function () {
|
||||
@@ -131,12 +131,12 @@ describe('Profile API', function () {
|
||||
.query({ access_token: owner.token })
|
||||
.send({ email: 'newemail@example.Com', password: owner.password });
|
||||
|
||||
expect(response.statusCode).to.equal(204);
|
||||
expect(response.status).to.equal(204);
|
||||
|
||||
const response2 = await superagent.get(`${serverUrl}/api/v1/profile`)
|
||||
.query({ access_token: owner.token });
|
||||
|
||||
expect(response2.statusCode).to.equal(200);
|
||||
expect(response2.status).to.equal(200);
|
||||
expect(response2.body.username).to.equal(owner.username);
|
||||
expect(response2.body.email).to.equal('newemail@example.com'); // lower cased
|
||||
expect(response2.body.displayName).to.equal('');
|
||||
@@ -150,7 +150,7 @@ describe('Profile API', function () {
|
||||
.send({ fallbackEmail: 'newemail@example.com' })
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
expect(response.status).to.equal(400);
|
||||
});
|
||||
|
||||
it('change fallback email fails due to invalid password', async function () {
|
||||
@@ -159,7 +159,7 @@ describe('Profile API', function () {
|
||||
.send({ fallbackEmail: 'foo@bar.com', password: 'this is wrong' })
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(412);
|
||||
expect(response.status).to.equal(412);
|
||||
});
|
||||
|
||||
it('change fallback email succeeds', async function () {
|
||||
@@ -167,12 +167,12 @@ describe('Profile API', function () {
|
||||
.query({ access_token: owner.token })
|
||||
.send({ fallbackEmail: 'NewFallbackemail@example.com', password: owner.password });
|
||||
|
||||
expect(response.statusCode).to.equal(204);
|
||||
expect(response.status).to.equal(204);
|
||||
|
||||
const response2 = await superagent.get(`${serverUrl}/api/v1/profile`)
|
||||
.query({ access_token: owner.token });
|
||||
|
||||
expect(response2.statusCode).to.equal(200);
|
||||
expect(response2.status).to.equal(200);
|
||||
expect(response2.body.username).to.equal(owner.username);
|
||||
expect(response2.body.fallbackEmail).to.equal('newfallbackemail@example.com'); // lowercase
|
||||
});
|
||||
@@ -184,11 +184,11 @@ describe('Profile API', function () {
|
||||
.query({ access_token: owner.token })
|
||||
.send({ displayName: 'Agent Smith' });
|
||||
|
||||
expect(response.statusCode).to.equal(204);
|
||||
expect(response.status).to.equal(204);
|
||||
|
||||
const response2 = await superagent.get(`${serverUrl}/api/v1/profile`)
|
||||
.query({ access_token: owner.token });
|
||||
expect(response2.statusCode).to.equal(200);
|
||||
expect(response2.status).to.equal(200);
|
||||
expect(response2.body.username).to.equal(owner.username);
|
||||
expect(response2.body.email).to.equal('newemail@example.com'); // lower cased
|
||||
expect(response2.body.displayName).to.equal('Agent Smith');
|
||||
@@ -202,7 +202,7 @@ describe('Profile API', function () {
|
||||
.send({ newPassword: 'some wrong password' })
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
expect(response.status).to.equal(400);
|
||||
});
|
||||
|
||||
it('fails due to missing new password', async function () {
|
||||
@@ -211,7 +211,7 @@ describe('Profile API', function () {
|
||||
.send({ password: owner.password })
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
expect(response.status).to.equal(400);
|
||||
});
|
||||
|
||||
it('fails due to wrong password', async function () {
|
||||
@@ -220,7 +220,7 @@ describe('Profile API', function () {
|
||||
.send({ password: 'some wrong password', newPassword: 'MOre#$%34' })
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(412);
|
||||
expect(response.status).to.equal(412);
|
||||
});
|
||||
|
||||
it('fails due to invalid password', async function () {
|
||||
@@ -229,7 +229,7 @@ describe('Profile API', function () {
|
||||
.send({ password: owner.password, newPassword: 'five' })
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
expect(response.status).to.equal(400);
|
||||
});
|
||||
|
||||
it('succeeds', async function () {
|
||||
@@ -237,7 +237,7 @@ describe('Profile API', function () {
|
||||
.query({ access_token: owner.token })
|
||||
.send({ password: owner.password, newPassword: 'MOre#$%34' });
|
||||
|
||||
expect(response.statusCode).to.equal(204);
|
||||
expect(response.status).to.equal(204);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -264,7 +264,7 @@ describe('Profile API', function () {
|
||||
.send({ username: user.username, password: user.password })
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(401);
|
||||
expect(response.status).to.equal(401);
|
||||
});
|
||||
|
||||
it('fails due to wrong token', async function () {
|
||||
@@ -272,7 +272,7 @@ describe('Profile API', function () {
|
||||
.send({ username: user.username, password: user.password, totpToken: '12345' })
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(401);
|
||||
expect(response.status).to.equal(401);
|
||||
});
|
||||
|
||||
it('succeeds', async function () {
|
||||
@@ -284,7 +284,7 @@ describe('Profile API', function () {
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/auth/login`)
|
||||
.send({ username: user.username, password: user.password, totpToken: totpToken });
|
||||
|
||||
expect(response.statusCode).to.equal(200);
|
||||
expect(response.status).to.equal(200);
|
||||
expect(response.body).to.be.an(Object);
|
||||
expect(response.body.accessToken).to.be.a('string');
|
||||
});
|
||||
@@ -299,7 +299,7 @@ describe('Profile API', function () {
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/auth/login`)
|
||||
.send({ username: user.username, password: user.password });
|
||||
|
||||
expect(response.statusCode).to.equal(200);
|
||||
expect(response.status).to.equal(200);
|
||||
expect(response.body).to.be.an(Object);
|
||||
expect(response.body.accessToken).to.be.a('string');
|
||||
});
|
||||
@@ -324,7 +324,7 @@ describe('Profile API', function () {
|
||||
|
||||
customAvatarSize = require('fs').readFileSync('./logo.png').length;
|
||||
|
||||
expect(response.statusCode).to.be(202);
|
||||
expect(response.status).to.be(202);
|
||||
});
|
||||
|
||||
it('did set custom avatar', async function () {
|
||||
@@ -336,7 +336,7 @@ describe('Profile API', function () {
|
||||
.ok(() => true);
|
||||
|
||||
expect(parseInt(response2.headers['content-length'])).to.equal(customAvatarSize);
|
||||
expect(response2.statusCode).to.equal(200);
|
||||
expect(response2.status).to.equal(200);
|
||||
});
|
||||
|
||||
it('can set gravatar', async function () {
|
||||
@@ -344,7 +344,7 @@ describe('Profile API', function () {
|
||||
.query({ access_token: user.token })
|
||||
.send({ avatar: 'gravatar' });
|
||||
|
||||
expect(response.statusCode).to.be(202);
|
||||
expect(response.status).to.be(202);
|
||||
});
|
||||
|
||||
it('did set gravatar', async function () {
|
||||
@@ -359,7 +359,7 @@ describe('Profile API', function () {
|
||||
.query({ access_token: user.token })
|
||||
.send({ avatar: '' });
|
||||
|
||||
expect(response.statusCode).to.be(202);
|
||||
expect(response.status).to.be(202);
|
||||
});
|
||||
|
||||
it('did unset avatar', async function () {
|
||||
@@ -378,7 +378,7 @@ describe('Profile API', function () {
|
||||
.query({ access_token: user.token })
|
||||
.send({ language: 'ta' })
|
||||
.ok(() => true);
|
||||
expect(response.statusCode).to.be(400);
|
||||
expect(response.status).to.be(400);
|
||||
});
|
||||
|
||||
it('fails to set bad language', async function () {
|
||||
@@ -386,7 +386,7 @@ describe('Profile API', function () {
|
||||
.query({ access_token: user.token })
|
||||
.send({ language: 123 })
|
||||
.ok(() => true);
|
||||
expect(response.statusCode).to.be(400);
|
||||
expect(response.status).to.be(400);
|
||||
});
|
||||
|
||||
it('fails to set unknown language', async function () {
|
||||
@@ -394,14 +394,14 @@ describe('Profile API', function () {
|
||||
.query({ access_token: user.token })
|
||||
.send({ language: 'ta' })
|
||||
.ok(() => true);
|
||||
expect(response.statusCode).to.be(400);
|
||||
expect(response.status).to.be(400);
|
||||
});
|
||||
|
||||
it('set valid language', async function () {
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/profile/language`)
|
||||
.query({ access_token: user.token })
|
||||
.send({ language: 'en' });
|
||||
expect(response.statusCode).to.be(204);
|
||||
expect(response.status).to.be(204);
|
||||
});
|
||||
|
||||
it('did set language', async function () {
|
||||
@@ -413,7 +413,7 @@ describe('Profile API', function () {
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/profile/language`)
|
||||
.query({ access_token: user.token })
|
||||
.send({ language: '' });
|
||||
expect(response.statusCode).to.be(204);
|
||||
expect(response.status).to.be(204);
|
||||
});
|
||||
|
||||
it('did reset language', async function () {
|
||||
|
||||
Reference in New Issue
Block a user