Skip to content

Commit

Permalink
Merge pull request #134 from spira/feature/edit-profile
Browse files Browse the repository at this point in the history
Feature/edit profile
  • Loading branch information
zakhenry committed Aug 10, 2015
2 parents baa2654 + 3b646c3 commit 56485df
Show file tree
Hide file tree
Showing 17 changed files with 532 additions and 100 deletions.
6 changes: 5 additions & 1 deletion api/app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,11 @@ public function patchOne($id, Request $request)
$model->setProfile($profile);
}

return $this->getResponse()->noContent();
$jwtAuth = App::make('Tymon\JWTAuth\JWTAuth');

$token = $jwtAuth->fromUser($model);

return $this->getResponse()->header('Authorization-Update', $token)->noContent();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions api/app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class User extends BaseModel implements AuthenticatableContract, Caller, UserOwn
];

/**
* The attributes that should be mutated to dates.
* The attributes that should be mutated to datetimes.
*
* @var array
*/
Expand All @@ -66,7 +66,7 @@ class User extends BaseModel implements AuthenticatableContract, Caller, UserOwn
* @var array
*/
protected $casts = [
'email_confirmed' => 'datetime'
'email_confirmed' => 'datetime',
];

/**
Expand Down
22 changes: 20 additions & 2 deletions api/app/Models/UserProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

class UserProfile extends BaseModel
{
/**
* The character length of the 'about' field
*/
const ABOUT_LENGTH = 120;

/**
* The primary key for the model.
*
Expand All @@ -17,8 +22,14 @@ class UserProfile extends BaseModel
protected $fillable = [
'phone',
'mobile',
'avatar_img_url',
'dob'
'dob',
'gender',
'about',
'facebook',
'twitter',
'pinterest',
'instagram',
'website',
];

/**
Expand All @@ -30,6 +41,13 @@ class UserProfile extends BaseModel
'phone' => 'string',
'mobile' => 'string',
'dob' => 'date',
'gender' => 'in:M,F,N/A',
'about' => 'string',
'facebook' => 'string',
'twitter' => 'string',
'pinterest' => 'string',
'instagram' => 'string',
'website' => 'string',
];

/**
Expand Down
15 changes: 11 additions & 4 deletions api/database/factories/ModelFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,28 @@
return [
'user_id' => $faker->uuid,
'email' => $faker->email,
'email_confirmed' => $faker->optional(0.9)->dateTimeThisYear($max = 'now'),
'email_confirmed' => $faker->optional(0.9)->dateTimeThisYear(),
'first_name' => $faker->firstName,
'last_name' => $faker->lastName,
'country' => $faker->randomElement(['AU', 'BE', 'DE', 'NZ', 'US']),
'timezone_identifier' => $faker->timezone,
'user_type' => $faker->randomElement(App\Models\User::$userTypes),
'avatar_img_url' => $faker->optional(0.8)->imageUrl(500, 500, 'people'),
'user_type' => $faker->randomElement(App\Models\User::$userTypes)
];
});

$factory->define(App\Models\UserProfile::class, function ($faker) {
return [
'phone' => $faker->optional(0.5)->phoneNumber,
'mobile' => $faker->optional(0.5)->phoneNumber,
'avatar_img_url' => $faker->optional(0.8)->imageUrl(100, 100, 'people'),
'dob' => $faker->dateTimeThisCentury()->format('Y-m-d')
'dob' => $faker->dateTimeThisCentury()->format('Y-m-d'),
'gender' => $faker->optional(0.5)->randomElement(['M', 'F', 'N/A']),
'about' => $faker->optional(0.5)->text(120),
'facebook' => $faker->boolean() ? substr($faker->url(), 0, 100) : null,
'twitter' => $faker->boolean() ? '@' . $faker->userName() : null,
'pinterest' => $faker->boolean() ? substr($faker->url(), 0, 100) : null,
'instagram' => $faker->boolean() ? substr($faker->url(), 0, 100) : null,
'website' => $faker->boolean() ? substr($faker->url(), 0, 100) : null,
];
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ public function up()

Schema::create($modelClass::getTableName(), function (Blueprint $table) use ($modelClass) {
$table->uuid('user_id');
$table->string('email', 255)->unique();
$table->string('email', 100)->unique();
$table->dateTime('email_confirmed')->nullable()->default(null);
$table->string('first_name', 45)->nullable();
$table->string('last_name', 45)->nullable();
$table->string('country', 2)->nullable();
$table->string('timezone_identifier', 40)->nullable();
$table->enum('user_type', $modelClass::$userTypes);
$table->string('avatar_img_url')->nullable();

$table->dateTime('created_at');
$table->dateTime('updated_at')->nullable();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,15 @@ public function up()
$table->uuid('user_id');
$table->string('phone', 45)->nullable();
$table->string('mobile', 45)->nullable();
$table->string('avatar_img_url')->nullable();
$table->date('dob')->nullable();
$table->enum('gender', ['M', 'F', 'N/A'])->nullable();
$table->string('about', $modelClass::ABOUT_LENGTH)->nullable();
$table->string('facebook', 100)->nullable();
$table->string('twitter', 45)->nullable();
$table->string('pinterest', 100)->nullable();
$table->string('instagram', 100)->nullable();
$table->string('website', 100)->nullable();

$table->dateTime('created_at');
$table->dateTime('updated_at')->nullable();

Expand Down
134 changes: 65 additions & 69 deletions app/src/app/guest/login/resetPassword.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,103 +2,99 @@ namespace app.guest.resetPassword {

describe('ResetPassword', () => {

describe('Configuration', () => {

let ResetPasswordController:ResetPasswordController,
$scope:ng.IScope,
$mdDialog:ng.material.IDialogService,
$timeout:ng.ITimeoutService,
$rootScope:ng.IRootScopeService,
$q:ng.IQService,
$mdToast:ng.material.IToastService,
userService = {
resetPassword: (email:string) => {
if (email == 'invalid@email.com') {
return $q.reject({data: {message: 'this failure message'}});
}
else {
return $q.when(true);
}
let ResetPasswordController:ResetPasswordController,
$scope:ng.IScope,
$mdDialog:ng.material.IDialogService,
$timeout:ng.ITimeoutService,
$rootScope:ng.IRootScopeService,
$q:ng.IQService,
$mdToast:ng.material.IToastService,
userService = {
resetPassword: (email:string) => {
if (email == 'invalid@email.com') {
return $q.reject({data: {message: 'this failure message'}});
}
else {
return $q.when(true);
}
}
;
}
;

beforeEach(() => {
module('app');
});
beforeEach(() => {
module('app');
});

beforeEach(()=> {

inject(($controller, _$rootScope_, _$mdDialog_, _$timeout_, _$q_, _$mdToast_) => {
$rootScope = _$rootScope_;
$scope = $rootScope.$new();
$mdDialog = _$mdDialog_;
$timeout = _$timeout_;
$mdToast = _$mdToast_;
$q = _$q_;

ResetPasswordController = $controller(app.guest.resetPassword.namespace + '.controller', {
$mdDialog: $mdDialog,
userService: userService,
$mdToast: $mdToast,
defaultEmail: null,
});
})
});
beforeEach(()=> {

inject(($controller, _$rootScope_, _$mdDialog_, _$timeout_, _$q_, _$mdToast_) => {
$rootScope = _$rootScope_;
$scope = $rootScope.$new();
$mdDialog = _$mdDialog_;
$timeout = _$timeout_;
$mdToast = _$mdToast_;
$q = _$q_;

ResetPasswordController = $controller(app.guest.resetPassword.namespace + '.controller', {
$mdDialog: $mdDialog,
userService: userService,
$mdToast: $mdToast,
defaultEmail: null,
});
})
});

beforeEach(() => {
beforeEach(() => {

sinon.spy($mdDialog, 'hide');
sinon.spy($mdDialog, 'cancel');
sinon.spy($mdDialog, 'show');
sinon.spy($mdToast, 'show');
sinon.spy($mdToast, 'simple');
sinon.spy($mdDialog, 'hide');
sinon.spy($mdDialog, 'cancel');
sinon.spy($mdDialog, 'show');
sinon.spy($mdToast, 'show');

});
});

afterEach(() => {
afterEach(() => {

(<any>$mdDialog).hide.restore();
(<any>$mdDialog).cancel.restore();
(<any>$mdDialog).show.restore();
(<any>$mdDialog).hide.restore();
(<any>$mdDialog).cancel.restore();
(<any>$mdDialog).show.restore();

});
});

describe('dialog interactions - reset password', () => {
describe('dialog interactions - reset password', () => {

it('should cancel dialog when requested', () => {
it('should cancel dialog when requested', () => {

ResetPasswordController.cancelResetPasswordDialog();
ResetPasswordController.cancelResetPasswordDialog();

$timeout.flush(); //flush timeout as the modal is delayed
$timeout.flush(); //flush timeout as the modal is delayed

expect($mdDialog.cancel).to.have.been.called;
expect($mdDialog.cancel).to.have.been.called;

});
});

it('should display an error message when an invalid email is entered', () => {
it('should display an error message when an invalid email is entered', () => {

let email = 'invalid@email.com';
let email = 'invalid@email.com';

ResetPasswordController.resetPassword(email);
ResetPasswordController.resetPassword(email);

$scope.$apply();
$scope.$apply();

expect($mdToast.show).to.have.been.calledWith(sinon.match.has("template", sinon.match(/this failure message/)));
expect($mdToast.show).to.have.been.calledWith(sinon.match.has("template", sinon.match(/this failure message/)));

});
});

it('should display a success message when a valid email is entered', () => {
it('should display a success message when a valid email is entered', () => {

let email = 'valid@email.com';
let email = 'valid@email.com';

ResetPasswordController.resetPassword(email);
ResetPasswordController.resetPassword(email);

$scope.$apply();
$scope.$apply();

expect($mdToast.show).to.have.been.called.and.not.to.be.calledWith(sinon.match.has("template", sinon.match(/this failure message/)));
expect($mdToast.show).to.have.been.called.and.not.to.be.calledWith(sinon.match.has("template", sinon.match(/this failure message/)));

});
});
});

Expand Down
Loading

0 comments on commit 56485df

Please sign in to comment.