This repository has been archived by the owner on Mar 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(account): fix the ability to delete the current account (#1020)
PR Close #1020
- Loading branch information
1 parent
94d1a6d
commit 3bdfa3d
Showing
2 changed files
with
50 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters