-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create user service #217
Merged
Merged
Create user service #217
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e09a4ea
feature (viewer): create user service
39b32c6
tests (playground): adapt spy
4197a22
Merge branch 'main' into wip/dsp-775-user-info
9da60ff
fix (viewer): do not get info about system user
c32402c
tests (viewer): add assertions to user service spec
d0f40d3
fix (viewer): adapt import paths
6292ee1
tests (viewer): add assertions to display edit comp. for standoff links
089c5af
fix (viewer): adapt tooltip message when user info is missing
98d2c34
refactor (viewer): show creator info
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
53 changes: 53 additions & 0 deletions
53
projects/dsp-ui/src/lib/viewer/services/user.service.spec.ts
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,53 @@ | ||
import { async, TestBed } from '@angular/core/testing'; | ||
import { MockUsers, UserResponse } from '@dasch-swiss/dsp-js'; | ||
import { AsyncSubject } from 'rxjs'; | ||
import { DspApiConnectionToken } from '../../core/core.module'; | ||
import { UserService } from './user.service'; | ||
|
||
describe('UserService', () => { | ||
let service: UserService; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [ | ||
{ | ||
provide: DspApiConnectionToken, | ||
useValue: {} | ||
} | ||
] | ||
}); | ||
|
||
service = TestBed.inject(UserService); | ||
})); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
expect(service['_userCache']).toBeDefined(); | ||
}); | ||
|
||
it('should get a user', done => { | ||
|
||
const userCacheSpy = spyOn(service['_userCache'], 'getUser').and.callFake( | ||
() => { | ||
const user = MockUsers.mockUser(); | ||
|
||
const subj: AsyncSubject<UserResponse> = new AsyncSubject(); | ||
subj.next(user.body); | ||
subj.complete(); | ||
|
||
return subj; | ||
} | ||
); | ||
|
||
service.getUser('http://rdfh.ch/users/root').subscribe( | ||
user => { | ||
expect(user.user.id).toEqual('http://rdfh.ch/users/root'); | ||
expect(userCacheSpy).toHaveBeenCalledTimes(1); | ||
expect(userCacheSpy).toHaveBeenCalledWith('http://rdfh.ch/users/root'); | ||
done(); | ||
} | ||
); | ||
|
||
}); | ||
|
||
}); |
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,28 @@ | ||
import { Inject, Injectable } from '@angular/core'; | ||
import { KnoraApiConnection, UserCache, UserResponse } from '@dasch-swiss/dsp-js'; | ||
import { AsyncSubject } from 'rxjs'; | ||
import { DspApiConnectionToken } from '../../core/core.module'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class UserService { | ||
|
||
// instance of user cache | ||
private _userCache: UserCache; | ||
|
||
constructor(@Inject(DspApiConnectionToken) private _dspApiConnection: KnoraApiConnection) { | ||
// instantiate user cache | ||
this._userCache = new UserCache(this._dspApiConnection); | ||
} | ||
|
||
/** | ||
* Retrieves information about the specified user. | ||
* | ||
* @param userIri the Iri identifying the user. | ||
*/ | ||
getUser(userIri: string): AsyncSubject<UserResponse> { | ||
return this._userCache.getUser(userIri); | ||
} | ||
|
||
} |
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mdelez This prevents requesting user info for the system user. Is this fine (the
user
prop) remainsundefined
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The info box does not work properly for the system user:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in 089c5af