Guest User

Untitled

a guest
Jun 4th, 2018
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. @Effect()
  2. authSignup$ = this.actions$
  3. .ofType(AuthActions.TRY_SIGNUP)
  4. .switchMap((signUpData: {
  5. first_name: string,
  6. last_name: string,
  7. username: string,
  8. password: string,
  9. type: string,
  10. agreement: boolean
  11. }) =>
  12. this.httpClient.post(
  13. '/custom-endpoint',
  14. {
  15. first_name: signUpData.first_name,
  16. last_name: signUpData.last_name,
  17. username: signUpData.username,
  18. password: signUpData.password,
  19. type: signUpData.type,
  20. agreement: signUpData.agreement
  21. },
  22. {
  23. headers: new HttpHeaders({
  24. 'Content-Type': 'application/json'
  25. })
  26. })
  27. .map((res) => {
  28. return new AuthActions.SuccessfulSignup();
  29. })
  30. .catch((error: {reason: string}) => {
  31. return Observable.of(new AuthActions.UnsuccessfulSignup({reason: error.reason}))
  32. })
  33. );
  34.  
  35. export class TestActions extends Actions {
  36. constructor() {
  37. super(empty());
  38. }
  39.  
  40. set stream(source: Observable<any>) {
  41. this.source = source;
  42. }
  43. }
  44.  
  45. export function getTestActions() {
  46. return new TestActions();
  47. }
  48.  
  49. fdescribe('AuthEffects', () => {
  50.  
  51. let actions$: TestActions;
  52. let effects: fromEffects.AuthEffects;
  53.  
  54. beforeEach(() => {
  55. TestBed.configureTestingModule({
  56. imports: [
  57. CookieModule.forRoot(),
  58. StoreModule.forRoot({...fromGlobal.reducers}),
  59. RouterTestingModule,
  60. HttpClientTestingModule
  61. ],
  62. providers: [
  63. fromEffects.AuthEffects,
  64. CookieAesService,
  65. { provide: Actions, useFactory: getTestActions },
  66. ],
  67. });
  68. actions$ = TestBed.get(Actions);
  69. effects = TestBed.get(fromEffects.AuthEffects);
  70. });
  71.  
  72. it('should attempt to Sign Up the user', () => {
  73. const trySignup = new fromActions.TrySignup({
  74. first_name: 'test',
  75. last_name: 'test',
  76. password: 'test',
  77. username: 'test@test.com',
  78. type: 'test',
  79. agreement: false
  80. });
  81. const unsuccessfulSignup = new fromActions.UnsuccessfulSignup({ reason: 'test' });
  82.  
  83. actions$.stream = hot('a', { a: trySignup });
  84. const expected = cold('b', { b: unsuccessfulSignup });
  85. expect(effects.authSignup$).toBeObservable(expected);
  86. });
  87. });
  88.  
  89. Expected $.length = 0 to equal 1.
  90. Expected $[0] = undefined to equal Object({ frame: 0, notification: Notification({ kind: 'N', value: UnsuccessfulSignup({ payload: Object({ reason: 'test' }), type: 'UNSUCCESSFUL_SIGNUP' }), error: undefined, hasValue: true }) }).
Add Comment
Please, Sign In to add comment