зеркало из https://github.com/mozilla/fxa.git
mysql works
This commit is contained in:
Родитель
4f035f8c9e
Коммит
a962bcbb04
|
@ -30,6 +30,7 @@ function proxy(method) {
|
|||
return function proxied() {
|
||||
var args = arguments;
|
||||
return withDriver().then(function(driver) {
|
||||
logger.verbose('proxied', method, [].slice.call(args));
|
||||
return driver[method].apply(driver, args);
|
||||
}).catch(function(err) {
|
||||
logger.error(err);
|
||||
|
@ -37,7 +38,7 @@ function proxy(method) {
|
|||
});
|
||||
};
|
||||
}
|
||||
Object.keys(memory.prototype).forEach(function(key) {
|
||||
Object.keys(mysql.prototype).forEach(function(key) {
|
||||
exports[key] = proxy(key);
|
||||
});
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ MysqlStore.prototype = {
|
|||
createProfile: function createProfile(profile) {
|
||||
var defer = Promise.defer();
|
||||
this._connection.query(PROFILE_CREATE_QUERY,
|
||||
[profile.uid, profile.avatar], defer.callback);
|
||||
[profile.uid, profile.avatar], defer.callback);
|
||||
return defer.promise;
|
||||
},
|
||||
getProfile: function getProfile(id) {
|
||||
|
@ -104,12 +104,13 @@ MysqlStore.prototype = {
|
|||
return defer.promise;
|
||||
},
|
||||
setAvatar: function setAvatar(uid, url) {
|
||||
var conn = this._connection;
|
||||
return this.profileExists(uid).then(function(exists) {
|
||||
if (!exists) {
|
||||
throw new Error('User (' + uid + ') does not exist');
|
||||
}
|
||||
var defer = Promise.defer();
|
||||
this._connection.query(AVATAR_SET_QUERY, [url, uid], defer.callback);
|
||||
conn.query(AVATAR_SET_QUERY, [url, uid], defer.callback);
|
||||
return defer.promise;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const crypto = require('crypto');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
|
@ -14,6 +15,10 @@ const db = require('../lib/db');
|
|||
|
||||
var avatarUrl = 'http://example.domain/path/img.png';
|
||||
|
||||
function userid() {
|
||||
return crypto.randomBytes(8).toString('hex');
|
||||
}
|
||||
|
||||
describe('/avatar', function() {
|
||||
|
||||
it('should require authentication', function(done) {
|
||||
|
@ -27,17 +32,18 @@ describe('/avatar', function() {
|
|||
});
|
||||
|
||||
it('should be able to post a url', function(done) {
|
||||
var uid = userid();
|
||||
var imageData = { url: avatarUrl };
|
||||
Server.api.post({
|
||||
url: '/avatar',
|
||||
payload: JSON.stringify(imageData),
|
||||
headers: {
|
||||
authorization: 'userid 1'
|
||||
authorization: 'userid ' + uid
|
||||
}
|
||||
}).then(function(res) {
|
||||
assert.equal(res.statusCode, 200);
|
||||
|
||||
return db.getProfile('1');
|
||||
return db.getProfile(uid);
|
||||
}).then(function(profile) {
|
||||
assert.equal(profile.avatar, avatarUrl);
|
||||
}).done(done);
|
||||
|
@ -70,10 +76,10 @@ describe.skip('/avatar/upload', function() {
|
|||
|
||||
describe('/users/{userId}', function() {
|
||||
|
||||
var userid = require('crypto').randomBytes(8).toString('hex');
|
||||
var uid = userid();
|
||||
before(function(done) {
|
||||
db.createProfile({
|
||||
uid: userid,
|
||||
uid: uid,
|
||||
avatar: avatarUrl
|
||||
}).done(function() {
|
||||
done();
|
||||
|
@ -81,7 +87,7 @@ describe('/users/{userId}', function() {
|
|||
});
|
||||
|
||||
it('should return a profile', function(done) {
|
||||
Server.api.get('/users/' + userid).then(function(res) {
|
||||
Server.api.get('/users/' + uid).then(function(res) {
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert.equal(JSON.parse(res.payload).avatar.url, avatarUrl);
|
||||
}).done(done);
|
||||
|
|
Загрузка…
Ссылка в новой задаче