Skip to content

Commit 1344c1f

Browse files
committed
minor fixes, make tests pass
1 parent 6ddf862 commit 1344c1f

12 files changed

Lines changed: 59 additions & 47 deletions

File tree

handlers/auth/controller/disconnect.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ var config = require('config');
77
exports.post = function* (next) {
88

99
var user = this.user;
10-
// var user = this.req.user;
11-
12-
yield function(callback) {};
1310

1411
for (var i = 0; i < user.providers.length; i++) {
1512
var provider = user.providers[i];

handlers/auth/out.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// deprecated, not used
12
exports.get = function*(next) {
23
this.logout();
34
this.redirect('/');

handlers/auth/test/fixtures/db.js

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

handlers/auth/test/server/local.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ const assert = require('better-assert');
1111
describe('Authorization', function() {
1212

1313
var server;
14-
before(function * () {
14+
before(function* () {
15+
1516
yield* db.loadModels(fixtures);
1617

17-
// app.listen() uses a random port,
18+
// APP.LISTEN() USES A RANDOM PORT,
1819
// which superagent gets as server.address().port
1920
// so that every run will get it's own port
2021
server = app.listen();
@@ -27,7 +28,7 @@ describe('Authorization', function() {
2728
request(server)
2829
.post('/auth/login/local')
2930
.send({
30-
login: fixtures.User[2].email,
31+
email: fixtures.User[2].email,
3132
password: fixtures.User[2].password
3233
})
3334
.expect(401, done);
@@ -45,7 +46,7 @@ describe('Authorization', function() {
4546
agent
4647
.post('/auth/login/local')
4748
.send({
48-
login: fixtures.User[0].email,
49+
email: fixtures.User[0].email,
4950
password: fixtures.User[0].password
5051
})
5152
.expect(200, done);
@@ -74,9 +75,9 @@ describe('Authorization', function() {
7475
});
7576

7677
var userData = {
77-
email: Math.random() + "@gmail.com",
78+
email: Math.random() + "@gmail.com",
7879
displayName: "Random guy",
79-
password: "somepass"
80+
password: "somepass"
8081
};
8182

8283
it('should create a new user', function(done) {
@@ -99,13 +100,13 @@ describe('Authorization', function() {
99100
res.body.displayName.should.be.eql(userData.displayName);
100101
done(err);
101102
});
102-
it('should be log in the new user', function(done) {
103-
request(server)
104-
.post('/auth/login/local')
105-
.send({email: userData.email, password: userData.password})
106-
.expect(200, done);
107-
});
108-
*/
103+
it('should be log in the new user', function(done) {
104+
request(server)
105+
.post('/auth/login/local')
106+
.send({email: userData.email, password: userData.password})
107+
.expect(200, done);
108+
});
109+
*/
109110

110111
it('should fail to create a new user with same email', function(done) {
111112
request(server)

handlers/profileGuest/controller/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ exports.get = function* (next) {
4040
};
4141
});
4242

43-
if (quizResults) {
43+
if (quizResults.length) {
4444
this.locals.tabs.quiz = {
4545
url: `/profile/${user.profileName}/quiz`,
4646
title: 'Тесты'

handlers/users/models/user.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,25 +77,26 @@ var UserSchema = new mongoose.Schema({
7777
},
7878
profileName: {
7979
type: String,
80-
required: true,
8180
validate: [
8281
{
8382
validator: function(value) {
84-
return this.deleted || /^[a-z0-9-]*$/.test(value);
83+
// also checks required
84+
return this.deleted || value && value.length >= 2;
8585
},
86-
msg: "В имени профиля допустимы только буквы a-z, цифры и дефис."
86+
msg: "Минимальная длина имени профиля: 2 символа."
8787
},
8888
{
8989
validator: function(value) {
90-
return this.deleted || value.length <= 64;
90+
return this.deleted || /^[a-z0-9-]*$/.test(value);
9191
},
92-
msg: "Максимальная длина имени профиля: 64 символа."
92+
msg: "В имени профиля допустимы только буквы a-z, цифры и дефис."
9393
},
9494
{
9595
validator: function(value) {
96-
return this.deleted || value.length >= 2;
96+
// if no value, this validator passes (another one triggers the error)
97+
return this.deleted || !value || value.length <= 64;
9798
},
98-
msg: "Минимальная длина имени профиля: 2 символа."
99+
msg: "Максимальная длина имени профиля: 64 символа."
99100
}
100101
],
101102

handlers/users/test/fixtures/db.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ exports.User = [
22
{ "_id": "000000000000000000000001",
33
"created": new Date(2014,0,1),
44
"displayName": "ilya kantor",
5+
"profileName": "iliakan",
56
"email": "iliakan@gmail.com",
67
"password": "1234",
78
"verifiedEmail": true
@@ -10,12 +11,14 @@ exports.User = [
1011
"created": new Date(2014,0,1),
1112
"displayName": "tester",
1213
"email": "tester@mail.com",
14+
"profileName": "tester",
1315
"password": "1234",
1416
"verifiedEmail": true
1517
},
1618
{ "_id": "000000000000000000000003",
1719
"created": new Date(2014,0,1),
1820
"displayName": "vasya",
21+
"profileName": "vasya",
1922
"email": "vasya@mail.com",
2023
"password": "1234",
2124
"verifiedEmail": false

handlers/users/test/unit/model/user.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ describe('User', function() {
1515
var user = new User({
1616
email: "BAD",
1717
displayName: "John",
18+
profileName: "bad",
1819
password: "1234"
1920
});
2021

@@ -27,13 +28,16 @@ describe('User', function() {
2728

2829
// TEST FAILS, @see https://github.com/LearnBoost/mongoose/issues/2446
2930
// does not require password, because social login does not use it
30-
it('requires email & displayName', function() {
31+
it('requires email & displayName & profileName', function() {
3132
[
3233
{
3334
email: "my@gmail.com"
3435
},
3536
{
3637
displayName: "John"
38+
},
39+
{
40+
profileName: "profile"
3741
}
3842
].map(function(data) {
3943
var user = new User(data);

modules/lib/dataUtil.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,16 @@ function *createEmptyDb() {
2121

2222
function *clearDatabase() {
2323

24-
var collections = yield thunk(db.collectionNames)();
24+
var collections = yield new Promise(function(resolve, reject) {
25+
db.listCollections().toArray(function(err, items) {
26+
if (err) return reject(err);
27+
resolve(items);
28+
});
29+
});
2530

2631
var collectionNames = collections
2732
.map(function(collection) {
28-
console.log(collection.name);
33+
//console.log(collection.name);
2934
//var collectionName = collection.name.slice(db.databaseName.length + 1);
3035
if (collection.name.indexOf('system.') === 0) {
3136
return null;

package.json

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@
1919
"angular-ui-router": "*",
2020
"assert-plus": "*",
2121
"async": "*",
22-
"autoprefixer-loader": "^1.2.0",
22+
"autoprefixer-loader": "*",
2323
"babel-core": "*",
2424
"babel-loader": "*",
2525
"bem-jade": "*",
2626
"bluebird": "*",
2727
"browser-pack": "*",
2828
"bunyan": "*",
2929
"co": "*",
30-
"css-loader": "^0.9.1",
30+
"css-loader": "*",
3131
"del": "*",
32-
"docxtemplater": "^1.0.5",
32+
"docxtemplater": "*",
3333
"elasticsearch": "*",
3434
"escape-html": "*",
3535
"event-stream": "*",
36-
"extract-text-webpack-plugin": "^0.5.0",
37-
"file-loader": "^0.8.1",
36+
"extract-text-webpack-plugin": "*",
37+
"file-loader": "*",
3838
"fs-extra": "*",
3939
"glob": "*",
4040
"glob-stream": "*",
@@ -62,7 +62,7 @@
6262
"koa-request": "*",
6363
"koa-router": "*",
6464
"koa-send": "*",
65-
"koa-session-mongoose": "*",
65+
"koa-session-mongoose": "git://github.com/iliakan/koa-session-mongoose#mongoose-4.0",
6666
"koa-views": "*",
6767
"lodash": "*",
6868
"lru-cache": "*",
@@ -73,8 +73,8 @@
7373
"minimatch": "*",
7474
"moment": "*",
7575
"money": "*",
76-
"mongoose": "~3.8.0",
77-
"mongoose-auto-increment": "3.2.2",
76+
"mongoose": "~4.0.0",
77+
"mongoose-auto-increment": "*",
7878
"mongoose-troop": "git://github.com/iliakan/mongoose-troop",
7979
"mongoose-unique-validator": "git://github.com/iliakan/mongoose-unique-validator",
8080
"multiparty": "*",
@@ -100,18 +100,17 @@
100100
"sanitize-html": "*",
101101
"send": "*",
102102
"sha256": "*",
103-
"style-loader": "^0.9.0",
103+
"style-loader": "*",
104104
"styliner": "*",
105105
"stylus": "*",
106-
"stylus-loader": "^1.0.0",
106+
"stylus-loader": "*",
107107
"svgutils": "*",
108-
"thenify": "^3.1.0",
108+
"thenify": "*",
109109
"through": "*",
110110
"through2": "*",
111111
"thunkify": "*",
112-
"uglify-js": "^2.4.17",
113-
"uglifyify": "*",
114-
"url-loader": "^0.5.5",
112+
"uglify-js": "*",
113+
"url-loader": "*",
115114
"vinyl": "*",
116115
"vinyl-fs": "*",
117116
"vinyl-source-stream": "*",
@@ -154,7 +153,7 @@
154153
"js-beautify": "*",
155154
"lazypipe": "*",
156155
"mocha": "*",
157-
"mysql": "^2.5.5",
156+
"mysql": "*",
158157
"ng-annotate-webpack-plugin": "*",
159158
"node-notifier": "*",
160159
"nodemailer-stub-transport": "*",
@@ -168,9 +167,7 @@
168167
"sinon": "*",
169168
"superagent": "*",
170169
"supertest": "*",
171-
"time-require": "*",
172-
"trace": "*",
173-
"webpack-dev-server": "^1.8.0"
170+
"time-require": "*"
174171
},
175172
"engines": {
176173
"node": ">=0.12"

0 commit comments

Comments
 (0)