Skip to content
This repository has been archived by the owner on Mar 25, 2023. It is now read-only.

Commit

Permalink
fix(account): fix the ability to delete the current account (#1020)
Browse files Browse the repository at this point in the history
PR Close #1020
  • Loading branch information
tamazlykar authored Apr 11, 2018
1 parent 94d1a6d commit 3bdfa3d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
48 changes: 48 additions & 0 deletions src/app/account/account/account-item.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { TestBed } from '@angular/core/testing';
import { AccountItemComponent } from './account-item.component';
import { AuthService } from '../../shared/services/auth.service';
import { User } from '../../shared/models/user.model';
import { Account } from '../../shared/models';
import { AccountUser } from '../../shared/models/account-user.model';

class MockAuthService {
_user: User;

get user() {
return this._user;
}
}

describe('AccountItemComponent class only', () => {
let comp: AccountItemComponent;
let authService: AuthService;
let authServiceStub: Partial<AuthService>;

beforeEach(() => {
authServiceStub = new MockAuthService();

TestBed.configureTestingModule({
providers: [{provide: AuthService, useValue: authServiceStub}]
});

authService = TestBed.get(AuthService);
comp = new AccountItemComponent(authService);
});

it('should determine whether the current user belongs to the account', () => {
const account1 = 'Jonn Doe';
const account2 = 'admin';
const spy = spyOnProperty(authService, 'user', 'get');
comp.item = {user: [{account: account1} as AccountUser]} as Account;

spy.and.returnValue({
account: account1
});
expect(comp.isSelf).toBe(true);

spy.and.returnValue({
account: account2
});
expect(comp.isSelf).toBe(false);
});
});
4 changes: 2 additions & 2 deletions src/app/account/account/account-item.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export class AccountItemComponent {
readonly stateTranslations = stateTranslations;

public get isSelf() {
return this.authService.user.username === this.item.name
&& this.authService.user.domainid === this.item.domainid;
const account = this.item.user[0].account;
return this.authService.user.account === account;
}

constructor(protected authService: AuthService) {
Expand Down

0 comments on commit 3bdfa3d

Please sign in to comment.