mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
fix mongoose promise, some user validation, tests urls
This commit is contained in:
@@ -6,7 +6,7 @@ import {
|
|||||||
import { v4 as generateRandomUserName } from 'uuid';
|
import { v4 as generateRandomUserName } from 'uuid';
|
||||||
import { each } from 'lodash';
|
import { each } from 'lodash';
|
||||||
|
|
||||||
describe('POST /user/register/local', () => {
|
describe('POST /user/auth/local/register', () => {
|
||||||
context('username and email are free', () => {
|
context('username and email are free', () => {
|
||||||
it('registers a new user', () => {
|
it('registers a new user', () => {
|
||||||
let api = requester();
|
let api = requester();
|
||||||
@@ -14,7 +14,7 @@ describe('POST /user/register/local', () => {
|
|||||||
let email = `${username}@example.com`;
|
let email = `${username}@example.com`;
|
||||||
let password = 'password';
|
let password = 'password';
|
||||||
|
|
||||||
return api.post('/user/register/local', {
|
return api.post('/user/auth/local/register', {
|
||||||
username: username,
|
username: username,
|
||||||
email: email,
|
email: email,
|
||||||
password: password,
|
password: password,
|
||||||
@@ -33,7 +33,7 @@ describe('POST /user/register/local', () => {
|
|||||||
let password = 'password';
|
let password = 'password';
|
||||||
let confirmPassword = 'not password';
|
let confirmPassword = 'not password';
|
||||||
|
|
||||||
return expect(api.post('/user/register/local', {
|
return expect(api.post('/user/auth/local/register', {
|
||||||
username: username,
|
username: username,
|
||||||
email: email,
|
email: email,
|
||||||
password: password,
|
password: password,
|
||||||
@@ -51,7 +51,7 @@ describe('POST /user/register/local', () => {
|
|||||||
let password = 'password';
|
let password = 'password';
|
||||||
let confirmPassword = 'password';
|
let confirmPassword = 'password';
|
||||||
|
|
||||||
return expect(api.post('/user/register/local', {
|
return expect(api.post('/user/auth/local/register', {
|
||||||
email: email,
|
email: email,
|
||||||
password: password,
|
password: password,
|
||||||
confirmPassword: confirmPassword,
|
confirmPassword: confirmPassword,
|
||||||
@@ -68,7 +68,7 @@ describe('POST /user/register/local', () => {
|
|||||||
let password = 'password';
|
let password = 'password';
|
||||||
let confirmPassword = 'password';
|
let confirmPassword = 'password';
|
||||||
|
|
||||||
return expect(api.post('/user/register/local', {
|
return expect(api.post('/user/auth/local/register', {
|
||||||
username: username,
|
username: username,
|
||||||
password: password,
|
password: password,
|
||||||
confirmPassword: confirmPassword,
|
confirmPassword: confirmPassword,
|
||||||
@@ -85,7 +85,7 @@ describe('POST /user/register/local', () => {
|
|||||||
let email = `${username}@example.com`;
|
let email = `${username}@example.com`;
|
||||||
let confirmPassword = 'password';
|
let confirmPassword = 'password';
|
||||||
|
|
||||||
return expect(api.post('/user/register/local', {
|
return expect(api.post('/user/auth/local/register', {
|
||||||
username: username,
|
username: username,
|
||||||
email: email,
|
email: email,
|
||||||
confirmPassword: confirmPassword,
|
confirmPassword: confirmPassword,
|
||||||
@@ -115,7 +115,7 @@ describe('POST /user/register/local', () => {
|
|||||||
let uniqueEmail = `${generateRandomUserName()}@exampe.com`;
|
let uniqueEmail = `${generateRandomUserName()}@exampe.com`;
|
||||||
let password = 'password';
|
let password = 'password';
|
||||||
|
|
||||||
return expect(api.post('/user/register/local', {
|
return expect(api.post('/user/auth/local/register', {
|
||||||
username: username,
|
username: username,
|
||||||
email: uniqueEmail,
|
email: uniqueEmail,
|
||||||
password: password,
|
password: password,
|
||||||
@@ -132,7 +132,7 @@ describe('POST /user/register/local', () => {
|
|||||||
let uniqueUsername = generateRandomUserName();
|
let uniqueUsername = generateRandomUserName();
|
||||||
let password = 'password';
|
let password = 'password';
|
||||||
|
|
||||||
return expect(api.post('/user/register/local', {
|
return expect(api.post('/user/auth/local/register', {
|
||||||
username: uniqueUsername,
|
username: uniqueUsername,
|
||||||
email: email,
|
email: email,
|
||||||
password: password,
|
password: password,
|
||||||
@@ -156,7 +156,7 @@ describe('POST /user/register/local', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('sets all site tour values to -2 (already seen)', () => {
|
it('sets all site tour values to -2 (already seen)', () => {
|
||||||
return api.post('/user/register/local', {
|
return api.post('/user/auth/local/register', {
|
||||||
username: username,
|
username: username,
|
||||||
email: email,
|
email: email,
|
||||||
password: password,
|
password: password,
|
||||||
@@ -171,7 +171,7 @@ describe('POST /user/register/local', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('populates user with default todos, not no other task types', () => {
|
it('populates user with default todos, not no other task types', () => {
|
||||||
return api.post('/user/register/local', {
|
return api.post('/user/auth/local/register', {
|
||||||
username: username,
|
username: username,
|
||||||
email: email,
|
email: email,
|
||||||
password: password,
|
password: password,
|
||||||
@@ -185,7 +185,7 @@ describe('POST /user/register/local', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('populates user with default tags', () => {
|
it('populates user with default tags', () => {
|
||||||
return api.post('/user/register/local', {
|
return api.post('/user/auth/local/register', {
|
||||||
username: username,
|
username: username,
|
||||||
email: email,
|
email: email,
|
||||||
password: password,
|
password: password,
|
||||||
@@ -207,7 +207,7 @@ describe('POST /user/register/local', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('sets all common tutorial flags to true', () => {
|
it('sets all common tutorial flags to true', () => {
|
||||||
return api.post('/user/register/local', {
|
return api.post('/user/auth/local/register', {
|
||||||
username: username,
|
username: username,
|
||||||
email: email,
|
email: email,
|
||||||
password: password,
|
password: password,
|
||||||
@@ -222,7 +222,7 @@ describe('POST /user/register/local', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('populates user with default todos, habits, and rewards', () => {
|
it('populates user with default todos, habits, and rewards', () => {
|
||||||
return api.post('/user/register/local', {
|
return api.post('/user/auth/local/register', {
|
||||||
username: username,
|
username: username,
|
||||||
email: email,
|
email: email,
|
||||||
password: password,
|
password: password,
|
||||||
@@ -236,7 +236,7 @@ describe('POST /user/register/local', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('populates user with default tags', () => {
|
it('populates user with default tags', () => {
|
||||||
return api.post('/user/register/local', {
|
return api.post('/user/auth/local/register', {
|
||||||
username: username,
|
username: username,
|
||||||
email: email,
|
email: email,
|
||||||
password: password,
|
password: password,
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export let schema = new Schema({
|
|||||||
|
|
||||||
auth: {
|
auth: {
|
||||||
blocked: Boolean,
|
blocked: Boolean,
|
||||||
facebook: Schema.Types.Mixed, // TODO validate
|
facebook: {type: Schema.Types.Mixed, default: {}}, // TODO validate, IMPORTANT make sure the {} default isn't shared across all user objects
|
||||||
local: {
|
local: {
|
||||||
email: {
|
email: {
|
||||||
type: String,
|
type: String,
|
||||||
@@ -610,8 +610,7 @@ function _setProfileName (user) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
schema.pre('validate', function beforeValidateUser (next) {
|
schema.pre('validate', function beforeValidateUser (next) {
|
||||||
// Validate the auth path (doesn't work with schema.path('auth').validate)
|
if (!this.auth.facebook.id || this.auth.local.email || this.auth.local.username) {
|
||||||
if (!this.auth.facebook.id) {
|
|
||||||
if (!this.auth.local.email) {
|
if (!this.auth.local.email) {
|
||||||
this.invalidate('auth.local.email', shared.i18n.t('missingEmail'));
|
this.invalidate('auth.local.email', shared.i18n.t('missingEmail'));
|
||||||
return next();
|
return next();
|
||||||
@@ -624,7 +623,7 @@ schema.pre('validate', function beforeValidateUser (next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Validate password and password confirmation and create hashed version
|
// Validate password and password confirmation and create hashed version
|
||||||
if (this.isModified('auth.local.password') || this.isNew() && !this.auth.facebook.id) {
|
if (this.isModified('auth.local.password') || this.isNew() && !this.auth.facebook.id) { // TODO this does not catch when you already have social auth and password isn't passedß
|
||||||
if (!this.auth.local.password) {
|
if (!this.auth.local.password) {
|
||||||
this.invalidate('auth.local.password', shared.i18n.t('missingPassword'));
|
this.invalidate('auth.local.password', shared.i18n.t('missingPassword'));
|
||||||
return next();
|
return next();
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ let app = express();
|
|||||||
// Mongoose configuration
|
// Mongoose configuration
|
||||||
|
|
||||||
// Use Q promises instead of mpromise in mongoose
|
// Use Q promises instead of mpromise in mongoose
|
||||||
mongoose.Promise = Q;
|
mongoose.Promise = Q.Promise;
|
||||||
let mongooseOptions = !IS_PROD ? {} : {
|
let mongooseOptions = !IS_PROD ? {} : {
|
||||||
replset: { socketOptions: { keepAlive: 1, connectTimeoutMS: 30000 } },
|
replset: { socketOptions: { keepAlive: 1, connectTimeoutMS: 30000 } },
|
||||||
server: { socketOptions: { keepAlive: 1, connectTimeoutMS: 30000 } },
|
server: { socketOptions: { keepAlive: 1, connectTimeoutMS: 30000 } },
|
||||||
|
|||||||
Reference in New Issue
Block a user