-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
app: simple API client based on rxjs added
- Loading branch information
Showing
10 changed files
with
65 additions
and
29 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
20 changes: 20 additions & 0 deletions
20
src/app/modules/github-profile/api/github-profile-api.client.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,20 @@ | ||
import { fromFetch } from 'rxjs/fetch' | ||
import { GithubUserDto } from './github-profile-api.typings' | ||
import { switchMap } from 'rxjs/operators' | ||
import { throwError, Observable } from 'rxjs' | ||
|
||
export const ghProfileApiClient = { | ||
getProfile, | ||
} | ||
|
||
function getProfile(username: string): Observable<GithubUserDto> { | ||
return fromFetch(`https://api.github.com/users/${username}`).pipe( | ||
switchMap(resp => { | ||
if (resp.ok) { | ||
return resp.json() | ||
} else { | ||
return throwError(resp) | ||
} | ||
}) | ||
) | ||
} |
File renamed without changes.
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
6 changes: 4 additions & 2 deletions
6
src/app/modules/github-profile/state/github-profile.actions.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
16 changes: 9 additions & 7 deletions
16
src/app/modules/github-profile/state/github-profile.epics.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 |
---|---|---|
@@ -1,19 +1,21 @@ | ||
import { Epic, ofType } from 'redux-observable' | ||
import { switchMap, map, startWith } from 'rxjs/operators' | ||
import { of } from 'rxjs' | ||
import { GithubUserDto } from '../api/github-profile.api.typings' | ||
import { ghProfileApiClient } from '../api/github-profile-api.client' | ||
import { GhProfileAnyAction, ghProfileActions } from './github-profile.actions' | ||
|
||
const DEFAULT_USERNAME = 'rodmax' | ||
|
||
export const ghProfileFetchDataEpic: Epic<GhProfileAnyAction> = action$ => { | ||
return action$.pipe( | ||
ofType(ghProfileActions.fetchRequested.type), | ||
startWith(true), // For debug we load data when app inited | ||
switchMap(() => { | ||
return of({ login: 'rod-max' } as GithubUserDto).pipe( | ||
map(useDto => { | ||
return ghProfileActions.fetchComplete.create(useDto) | ||
return ghProfileApiClient.getProfile(DEFAULT_USERNAME).pipe( | ||
map(userDto => { | ||
return ghProfileActions.fetchComplete.create(userDto) | ||
}) | ||
) | ||
}) | ||
}), | ||
// Kick start initial loading | ||
startWith(ghProfileActions.fetchRequested.create({ username: DEFAULT_USERNAME })) | ||
) | ||
} |
11 changes: 7 additions & 4 deletions
11
src/app/modules/github-profile/state/github-profile.reducer.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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Selector } from 'testcafe' | ||
import { e2eConfig } from '../e2e-config' | ||
|
||
fixture(`Getting Started`).page(`http://localhost:${e2eConfig.port}`) | ||
|
||
test('WHEN open app THEN main header text visible [<App/> works]', async t => { | ||
await t.expect(Selector('h1').innerText).eql('App component') | ||
}) | ||
|
||
test('WHEN open app THEN rodmax-s github profile info visible [Redux works/github API works]', async t => { | ||
await t.expect(Selector('pre').innerText).contains('"name": "Maxim Rodionov"') | ||
}) |
This file was deleted.
Oops, something went wrong.