test: added test for external image via new change picture API

isekai-main
Julian Lam 3 years ago
parent cdaea61136
commit 8cbad61e8a

@ -10,6 +10,16 @@ const utils = require('../../public/src/utils');
const helpers = module.exports;
helpers.getCsrfToken = async (jar) => {
const { csrf_token: token } = await requestAsync({
url: `${nconf.get('url')}/api/config`,
json: true,
jar,
});
return token;
};
helpers.loginUser = function (username, password, callback) {
const jar = request.jar();

@ -5,6 +5,7 @@ const async = require('async');
const fs = require('fs');
const path = require('path');
const nconf = require('nconf');
const validator = require('validator');
const request = require('request');
const requestAsync = require('request-promise-native');
const jwt = require('jsonwebtoken');
@ -1070,6 +1071,28 @@ describe('User', () => {
});
});
it('should let you set an external image', async () => {
const token = await helpers.getCsrfToken(jar);
const body = await requestAsync(`${nconf.get('url')}/api/v3/users/${uid}/picture`, {
jar,
method: 'put',
json: true,
headers: {
'x-csrf-token': token,
},
body: {
type: 'external',
url: 'https://example.org/picture.jpg',
},
});
assert(body && body.status && body.response);
assert.strictEqual(body.status.code, 'ok');
const picture = await User.getUserField(uid, 'picture');
assert.strictEqual(picture, validator.escape('https://example.org/picture.jpg'));
});
it('should fail to change user picture with invalid data', (done) => {
socketUser.changePicture({ uid: uid }, null, (err) => {
assert.equal(err.message, '[[error:invalid-data]]');

Loading…
Cancel
Save