@daffodil/auth 0.0.0-PLACEHOLDER

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (240) hide show
  1. package/.eslintrc.js +51 -0
  2. package/README.md +14 -0
  3. package/driver/in-memory/ng-package.json +8 -0
  4. package/driver/in-memory/package.json +3 -0
  5. package/driver/in-memory/src/backend/auth.service.integration.spec.ts +125 -0
  6. package/driver/in-memory/src/backend/auth.service.ts +131 -0
  7. package/driver/in-memory/src/backend/auth.service.unit.spec.ts +119 -0
  8. package/driver/in-memory/src/drivers/auth/auth.service.spec.ts +57 -0
  9. package/driver/in-memory/src/drivers/auth/auth.service.ts +24 -0
  10. package/driver/in-memory/src/drivers/auth-driver.module.ts +48 -0
  11. package/driver/in-memory/src/drivers/login/login.service.spec.ts +93 -0
  12. package/driver/in-memory/src/drivers/login/login.service.ts +36 -0
  13. package/driver/in-memory/src/drivers/public_api.ts +4 -0
  14. package/driver/in-memory/src/drivers/register/register.service.spec.ts +113 -0
  15. package/driver/in-memory/src/drivers/register/register.service.ts +38 -0
  16. package/driver/in-memory/src/drivers/reset-password/service.spec.ts +149 -0
  17. package/driver/in-memory/src/drivers/reset-password/service.ts +42 -0
  18. package/driver/in-memory/src/index.ts +1 -0
  19. package/driver/in-memory/src/models/db-customer.type.ts +8 -0
  20. package/driver/in-memory/src/public_api.ts +3 -0
  21. package/driver/magento/ng-package.json +8 -0
  22. package/driver/magento/package.json +3 -0
  23. package/driver/magento/src/apollo-bearer-token-link-generator.spec.ts +107 -0
  24. package/driver/magento/src/apollo-bearer-token-link-generator.ts +39 -0
  25. package/driver/magento/src/auth-driver.module.ts +48 -0
  26. package/driver/magento/src/auth.service.spec.ts +154 -0
  27. package/driver/magento/src/auth.service.ts +40 -0
  28. package/driver/magento/src/errors/codes.ts +5 -0
  29. package/driver/magento/src/errors/map.ts +14 -0
  30. package/driver/magento/src/errors/transform.spec.ts +41 -0
  31. package/driver/magento/src/errors/transform.ts +6 -0
  32. package/driver/magento/src/index.ts +1 -0
  33. package/driver/magento/src/login.service.spec.ts +261 -0
  34. package/driver/magento/src/login.service.ts +65 -0
  35. package/driver/magento/src/models/public_api.ts +4 -0
  36. package/driver/magento/src/models/response/auth.ts +3 -0
  37. package/driver/magento/src/models/response/register.type.ts +7 -0
  38. package/driver/magento/src/models/response/reset-password.type.ts +3 -0
  39. package/driver/magento/src/models/response/send-reset-email.type.ts +3 -0
  40. package/driver/magento/src/public_api.ts +12 -0
  41. package/driver/magento/src/queries/check-token.ts +10 -0
  42. package/driver/magento/src/queries/create-customer.ts +24 -0
  43. package/driver/magento/src/queries/generate-token.ts +13 -0
  44. package/driver/magento/src/queries/public_api.ts +8 -0
  45. package/driver/magento/src/queries/reset-password.ts +12 -0
  46. package/driver/magento/src/queries/responses/check-token-response.ts +5 -0
  47. package/driver/magento/src/queries/responses/generate-token-response.ts +5 -0
  48. package/driver/magento/src/queries/responses/public_api.ts +3 -0
  49. package/driver/magento/src/queries/responses/revoke-customer-token-response.ts +5 -0
  50. package/driver/magento/src/queries/revoke-customer-token.ts +10 -0
  51. package/driver/magento/src/queries/send-reset-email.ts +10 -0
  52. package/driver/magento/src/register.service.spec.ts +189 -0
  53. package/driver/magento/src/register.service.ts +65 -0
  54. package/driver/magento/src/reset-password.service.spec.ts +342 -0
  55. package/driver/magento/src/reset-password.service.ts +78 -0
  56. package/driver/magento/src/transforms/auth-transformer.service.spec.ts +42 -0
  57. package/driver/magento/src/transforms/auth-transformer.service.ts +25 -0
  58. package/driver/magento/src/validators/check-token.spec.ts +40 -0
  59. package/driver/magento/src/validators/check-token.ts +13 -0
  60. package/driver/magento/src/validators/generate-token.spec.ts +40 -0
  61. package/driver/magento/src/validators/generate-token.ts +13 -0
  62. package/driver/magento/src/validators/public_api.ts +5 -0
  63. package/driver/magento/src/validators/reset-password.spec.ts +38 -0
  64. package/driver/magento/src/validators/reset-password.ts +13 -0
  65. package/driver/magento/src/validators/revoke-token.spec.ts +40 -0
  66. package/driver/magento/src/validators/revoke-token.ts +13 -0
  67. package/driver/magento/src/validators/send-reset-email.spec.ts +38 -0
  68. package/driver/magento/src/validators/send-reset-email.ts +13 -0
  69. package/driver/ng-package.json +8 -0
  70. package/driver/package.json +3 -0
  71. package/driver/src/errors/authentication-failed.ts +14 -0
  72. package/driver/src/errors/codes.enum.ts +6 -0
  73. package/driver/src/errors/invalid-api-response.ts +14 -0
  74. package/driver/src/errors/map.ts +15 -0
  75. package/driver/src/errors/public_api.ts +6 -0
  76. package/driver/src/errors/registration-failed.ts +17 -0
  77. package/driver/src/errors/unauthorized.ts +14 -0
  78. package/driver/src/index.ts +1 -0
  79. package/driver/src/interfaces/auth-service.interface.ts +11 -0
  80. package/driver/src/interfaces/login-service.interface.ts +26 -0
  81. package/driver/src/interfaces/public_api.ts +4 -0
  82. package/driver/src/interfaces/register-service.interface.ts +26 -0
  83. package/driver/src/interfaces/reset-password-service.interface.ts +26 -0
  84. package/driver/src/public_api.ts +3 -0
  85. package/driver/src/services/auth-check.service.spec.ts +81 -0
  86. package/driver/src/services/auth-check.service.ts +50 -0
  87. package/driver/src/services/public_api.ts +1 -0
  88. package/driver/testing/ng-package.json +8 -0
  89. package/driver/testing/package.json +3 -0
  90. package/driver/testing/src/drivers/auth/auth.service.spec.ts +40 -0
  91. package/driver/testing/src/drivers/auth/auth.service.ts +19 -0
  92. package/driver/testing/src/drivers/auth-driver.module.ts +48 -0
  93. package/driver/testing/src/drivers/login/login.service.spec.ts +59 -0
  94. package/driver/testing/src/drivers/login/login.service.ts +30 -0
  95. package/driver/testing/src/drivers/public_api.ts +4 -0
  96. package/driver/testing/src/drivers/register/register.service.spec.ts +49 -0
  97. package/driver/testing/src/drivers/register/register.service.ts +32 -0
  98. package/driver/testing/src/drivers/reset-password/service.spec.ts +48 -0
  99. package/driver/testing/src/drivers/reset-password/service.ts +33 -0
  100. package/driver/testing/src/index.ts +1 -0
  101. package/driver/testing/src/public_api.ts +1 -0
  102. package/karma.conf.js +10 -0
  103. package/ng-package.json +8 -0
  104. package/ng-package.prod.json +7 -0
  105. package/package.json +39 -0
  106. package/routing/ng-package.json +8 -0
  107. package/routing/package.json +3 -0
  108. package/routing/src/config/default.ts +9 -0
  109. package/routing/src/config/interface.ts +33 -0
  110. package/routing/src/config/public_api.ts +6 -0
  111. package/routing/src/config/token.ts +24 -0
  112. package/routing/src/effects/redirect.effects.spec.ts +236 -0
  113. package/routing/src/effects/redirect.effects.ts +85 -0
  114. package/routing/src/guards/guest-only-guard-redirect.token.ts +3 -0
  115. package/routing/src/guards/guest-only.guard.spec.ts +127 -0
  116. package/routing/src/guards/guest-only.guard.ts +69 -0
  117. package/routing/src/guards/member-only-guard-redirect.token.ts +3 -0
  118. package/routing/src/guards/member-only.guard.spec.ts +127 -0
  119. package/routing/src/guards/member-only.guard.ts +70 -0
  120. package/routing/src/guards/public_api.ts +6 -0
  121. package/routing/src/guards/reset-password.guard.spec.ts +113 -0
  122. package/routing/src/guards/reset-password.guard.ts +44 -0
  123. package/routing/src/index.ts +1 -0
  124. package/routing/src/module.ts +34 -0
  125. package/routing/src/public_api.ts +5 -0
  126. package/routing/src/redirect.module.ts +13 -0
  127. package/src/errors/codes.enum.ts +3 -0
  128. package/src/errors/map.ts +9 -0
  129. package/src/errors/missing-token.ts +18 -0
  130. package/src/errors/public_api.ts +3 -0
  131. package/src/index.ts +1 -0
  132. package/src/injection-tokens/error-matcher.token.ts +12 -0
  133. package/src/injection-tokens/public_api.ts +1 -0
  134. package/src/models/account-registration.ts +18 -0
  135. package/src/models/auth-token.ts +3 -0
  136. package/src/models/login-info.ts +4 -0
  137. package/src/models/public_api.ts +4 -0
  138. package/src/models/reset-password-info.type.ts +14 -0
  139. package/src/public_api.ts +5 -0
  140. package/src/storage/auth-storage.service.spec.ts +43 -0
  141. package/src/storage/auth-storage.service.ts +30 -0
  142. package/state/ng-package.json +8 -0
  143. package/state/package.json +3 -0
  144. package/state/src/actions/auth.actions.ts +75 -0
  145. package/state/src/actions/login.actions.ts +85 -0
  146. package/state/src/actions/public_api.ts +4 -0
  147. package/state/src/actions/register.actions.ts +50 -0
  148. package/state/src/actions/reset-password.actions.ts +92 -0
  149. package/state/src/auth-state.module.ts +45 -0
  150. package/state/src/config/default.ts +7 -0
  151. package/state/src/config/public_api.ts +6 -0
  152. package/state/src/config/token.ts +14 -0
  153. package/state/src/config/type.ts +7 -0
  154. package/state/src/effects/auth.effects.spec.ts +232 -0
  155. package/state/src/effects/auth.effects.ts +125 -0
  156. package/state/src/effects/login.effects.spec.ts +258 -0
  157. package/state/src/effects/login.effects.ts +126 -0
  158. package/state/src/effects/register.effects.spec.ts +206 -0
  159. package/state/src/effects/register.effects.ts +93 -0
  160. package/state/src/effects/reset-password.effects.spec.ts +238 -0
  161. package/state/src/effects/reset-password.effects.ts +110 -0
  162. package/state/src/facades/auth/facade.interface.ts +18 -0
  163. package/state/src/facades/auth/facade.spec.ts +135 -0
  164. package/state/src/facades/auth/facade.ts +42 -0
  165. package/state/src/facades/auth/public_api.ts +2 -0
  166. package/state/src/facades/login/facade.interface.ts +14 -0
  167. package/state/src/facades/login/facade.spec.ts +111 -0
  168. package/state/src/facades/login/facade.ts +38 -0
  169. package/state/src/facades/login/public_api.ts +2 -0
  170. package/state/src/facades/public_api.ts +4 -0
  171. package/state/src/facades/register/facade.interface.ts +14 -0
  172. package/state/src/facades/register/facade.spec.ts +103 -0
  173. package/state/src/facades/register/facade.ts +38 -0
  174. package/state/src/facades/register/public_api.ts +2 -0
  175. package/state/src/facades/reset-password/facade.interface.ts +17 -0
  176. package/state/src/facades/reset-password/facade.spec.ts +112 -0
  177. package/state/src/facades/reset-password/facade.ts +44 -0
  178. package/state/src/facades/reset-password/public_api.ts +2 -0
  179. package/state/src/index.ts +1 -0
  180. package/state/src/public_api.ts +8 -0
  181. package/state/src/reducers/auth/auth-initial-state.ts +7 -0
  182. package/state/src/reducers/auth/auth-reducer-state.interface.ts +7 -0
  183. package/state/src/reducers/auth/auth.reducer.spec.ts +250 -0
  184. package/state/src/reducers/auth/auth.reducer.ts +72 -0
  185. package/state/src/reducers/auth/public_api.ts +3 -0
  186. package/state/src/reducers/auth-feature-state.interface.ts +16 -0
  187. package/state/src/reducers/auth-reducers.ts +14 -0
  188. package/state/src/reducers/auth-store-feature-key.ts +1 -0
  189. package/state/src/reducers/login/login-initial-state.ts +6 -0
  190. package/state/src/reducers/login/login-reducer-state.interface.ts +6 -0
  191. package/state/src/reducers/login/login.reducer.spec.ts +190 -0
  192. package/state/src/reducers/login/login.reducer.ts +47 -0
  193. package/state/src/reducers/login/public_api.ts +3 -0
  194. package/state/src/reducers/public_api.ts +11 -0
  195. package/state/src/reducers/register/public_api.ts +3 -0
  196. package/state/src/reducers/register/register-initial-state.ts +6 -0
  197. package/state/src/reducers/register/register-reducer-state.interface.ts +6 -0
  198. package/state/src/reducers/register/register.reducer.spec.ts +111 -0
  199. package/state/src/reducers/register/register.reducer.ts +40 -0
  200. package/state/src/reducers/reset-password/initial-state.ts +7 -0
  201. package/state/src/reducers/reset-password/public_api.ts +3 -0
  202. package/state/src/reducers/reset-password/reducer.spec.ts +196 -0
  203. package/state/src/reducers/reset-password/reducer.ts +49 -0
  204. package/state/src/reducers/reset-password/state.interface.ts +8 -0
  205. package/state/src/selectors/auth/auth.selector.spec.ts +87 -0
  206. package/state/src/selectors/auth/auth.selector.ts +51 -0
  207. package/state/src/selectors/auth-all.selector.ts +40 -0
  208. package/state/src/selectors/auth-feature.selector.ts +18 -0
  209. package/state/src/selectors/login/login.selector.spec.ts +88 -0
  210. package/state/src/selectors/login/login.selector.ts +44 -0
  211. package/state/src/selectors/public_api.ts +1 -0
  212. package/state/src/selectors/register/register.selector.spec.ts +75 -0
  213. package/state/src/selectors/register/register.selector.ts +45 -0
  214. package/state/src/selectors/reset-password/selector.spec.ts +90 -0
  215. package/state/src/selectors/reset-password/selector.ts +52 -0
  216. package/state/testing/ng-package.json +8 -0
  217. package/state/testing/package.json +3 -0
  218. package/state/testing/src/auth-testing.module.ts +23 -0
  219. package/state/testing/src/index.ts +1 -0
  220. package/state/testing/src/mock-auth-facade.ts +18 -0
  221. package/state/testing/src/mock-login-facade.ts +17 -0
  222. package/state/testing/src/mock-register-facade.ts +17 -0
  223. package/state/testing/src/mock-reset-password-facade.ts +18 -0
  224. package/state/testing/src/public_api.ts +5 -0
  225. package/test.ts +24 -0
  226. package/testing/ng-package.json +8 -0
  227. package/testing/package.json +3 -0
  228. package/testing/src/factories/account-registration.factory.spec.ts +37 -0
  229. package/testing/src/factories/account-registration.factory.ts +22 -0
  230. package/testing/src/factories/auth-token.factory.ts +18 -0
  231. package/testing/src/factories/auth.factory.spec.ts +45 -0
  232. package/testing/src/factories/public_api.ts +3 -0
  233. package/testing/src/factories/reset-password-info.factory.spec.ts +35 -0
  234. package/testing/src/factories/reset-password-info.factory.ts +20 -0
  235. package/testing/src/index.ts +1 -0
  236. package/testing/src/public_api.ts +1 -0
  237. package/tsconfig.json +38 -0
  238. package/tsconfig.lib.json +28 -0
  239. package/tsconfig.lib.prod.json +9 -0
  240. package/tsconfig.spec.json +17 -0
@@ -0,0 +1,72 @@
1
+ import {
2
+ DaffAuthActionTypes,
3
+ DaffAuthActions,
4
+ DaffAuthLoginActionTypes,
5
+ DaffAuthLoginActions,
6
+ DaffAuthRegisterActionTypes,
7
+ DaffAuthRegisterSuccess,
8
+ DaffAuthResetPasswordActionTypes,
9
+ DaffAuthResetPasswordActions,
10
+ } from '../../actions/public_api';
11
+ import { daffAuthInitialState } from './auth-initial-state';
12
+ import { DaffAuthReducerState } from './auth-reducer-state.interface';
13
+
14
+ export function daffAuthReducer(
15
+ state = daffAuthInitialState,
16
+ action: DaffAuthActions | DaffAuthLoginActions | DaffAuthRegisterSuccess | DaffAuthResetPasswordActions,
17
+ ): DaffAuthReducerState {
18
+ switch (action.type) {
19
+ case DaffAuthActionTypes.AuthCheckAction:
20
+ return {
21
+ ...state,
22
+ loading: true,
23
+ };
24
+
25
+ case DaffAuthActionTypes.AuthCheckSuccessAction:
26
+ return {
27
+ ...state,
28
+ loggedIn: true,
29
+ loading: false,
30
+ errors: [],
31
+ };
32
+
33
+ case DaffAuthActionTypes.AuthCheckFailureAction:
34
+ case DaffAuthActionTypes.AuthGuardLogoutAction:
35
+ return {
36
+ ...state,
37
+ loggedIn: false,
38
+ loading: false,
39
+ errors: [action.errorMessage],
40
+ };
41
+
42
+ case DaffAuthActionTypes.AuthServerSideAction:
43
+ case DaffAuthActionTypes.AuthStorageFailureAction:
44
+ return {
45
+ ...state,
46
+ loading: false,
47
+ errors: [action.errorMessage],
48
+ };
49
+
50
+ case DaffAuthLoginActionTypes.LoginSuccessAction:
51
+ return {
52
+ ...state,
53
+ loggedIn: true,
54
+ };
55
+
56
+ case DaffAuthRegisterActionTypes.RegisterSuccessAction:
57
+ case DaffAuthResetPasswordActionTypes.ResetPasswordSuccessAction:
58
+ return action.token ? {
59
+ ...state,
60
+ loggedIn: true,
61
+ } : state;
62
+
63
+ case DaffAuthLoginActionTypes.LogoutSuccessAction:
64
+ return {
65
+ ...state,
66
+ loggedIn: false,
67
+ };
68
+
69
+ default:
70
+ return state;
71
+ }
72
+ }
@@ -0,0 +1,3 @@
1
+ export { DaffAuthReducerState } from './auth-reducer-state.interface';
2
+ export { daffAuthReducer } from './auth.reducer';
3
+ export { daffAuthInitialState } from './auth-initial-state';
@@ -0,0 +1,16 @@
1
+ import { DAFF_AUTH_STORE_FEATURE_KEY } from './auth-store-feature-key';
2
+ import { DaffAuthReducerState } from './auth/public_api';
3
+ import { DaffAuthLoginReducerState } from './login/public_api';
4
+ import { DaffAuthRegisterReducerState } from './register/public_api';
5
+ import { DaffAuthResetPasswordReducerState } from './reset-password/public_api';
6
+
7
+ export interface DaffAuthFeatureState {
8
+ auth: DaffAuthReducerState;
9
+ login: DaffAuthLoginReducerState;
10
+ register: DaffAuthRegisterReducerState;
11
+ resetPassword: DaffAuthResetPasswordReducerState;
12
+ }
13
+
14
+ export interface DaffAuthStateRootSlice {
15
+ [DAFF_AUTH_STORE_FEATURE_KEY]: DaffAuthFeatureState;
16
+ }
@@ -0,0 +1,14 @@
1
+ import { ActionReducerMap } from '@ngrx/store';
2
+
3
+ import { DaffAuthFeatureState } from './auth-feature-state.interface';
4
+ import { daffAuthReducer } from './auth/public_api';
5
+ import { daffAuthLoginReducer } from './login/public_api';
6
+ import { daffAuthRegisterReducer } from './register/public_api';
7
+ import { daffAuthResetPasswordReducer } from './reset-password/public_api';
8
+
9
+ export const daffAuthReducers: ActionReducerMap<DaffAuthFeatureState> = {
10
+ auth: daffAuthReducer,
11
+ login: daffAuthLoginReducer,
12
+ register: daffAuthRegisterReducer,
13
+ resetPassword: daffAuthResetPasswordReducer,
14
+ };
@@ -0,0 +1 @@
1
+ export const DAFF_AUTH_STORE_FEATURE_KEY = 'daffAuth';
@@ -0,0 +1,6 @@
1
+ import { DaffAuthLoginReducerState } from './login-reducer-state.interface';
2
+
3
+ export const daffAuthLoginInitialState: DaffAuthLoginReducerState = {
4
+ loading: false,
5
+ errors: [],
6
+ };
@@ -0,0 +1,6 @@
1
+ import { DaffStateError } from '@daffodil/core/state';
2
+
3
+ export interface DaffAuthLoginReducerState {
4
+ loading: boolean;
5
+ errors: DaffStateError[];
6
+ }
@@ -0,0 +1,190 @@
1
+ import { TestBed } from '@angular/core/testing';
2
+
3
+ import {
4
+ DaffAuthToken,
5
+ DaffLoginInfo,
6
+ DaffAccountRegistration,
7
+ } from '@daffodil/auth';
8
+ import {
9
+ DaffAuthLogin,
10
+ DaffAuthLoginReducerState,
11
+ DaffAuthLoginSuccess,
12
+ DaffAuthLoginFailure,
13
+ DaffAuthLogout,
14
+ DaffAuthLogoutSuccess,
15
+ DaffAuthLogoutFailure,
16
+ daffAuthLoginInitialState as initialState,
17
+ } from '@daffodil/auth/state';
18
+ import {
19
+ DaffAuthTokenFactory,
20
+ DaffAccountRegistrationFactory,
21
+ } from '@daffodil/auth/testing';
22
+ import { DaffStateError } from '@daffodil/core/state';
23
+
24
+ import { daffAuthLoginReducer as reducer } from './login.reducer';
25
+
26
+ describe('@daffodil/auth/state | daffAuthLoginReducer', () => {
27
+ let registrationFactory: DaffAccountRegistrationFactory;
28
+ const authTokenFactory: DaffAuthTokenFactory = new DaffAuthTokenFactory();
29
+
30
+ let mockAuthToken: DaffAuthToken;
31
+ let mockLoginInfo: DaffLoginInfo;
32
+ let mockRegistration: DaffAccountRegistration;
33
+ let email: string;
34
+ let password: string;
35
+
36
+ beforeEach(() => {
37
+ registrationFactory = TestBed.inject(DaffAccountRegistrationFactory);
38
+
39
+ mockRegistration = registrationFactory.create();
40
+ mockAuthToken = authTokenFactory.create();
41
+
42
+ email = mockRegistration.email;
43
+ password = mockRegistration.password;
44
+ mockLoginInfo = { email, password };
45
+ });
46
+
47
+ describe('when an unknown action is triggered', () => {
48
+ it('should return the current state', () => {
49
+ const action = <any>{};
50
+
51
+ const result = reducer(initialState, action);
52
+
53
+ expect(result).toBe(initialState);
54
+ });
55
+ });
56
+
57
+ describe('when AuthLoginAction is triggered', () => {
58
+ let result: DaffAuthLoginReducerState;
59
+
60
+ beforeEach(() => {
61
+ const authLoginAction: DaffAuthLogin<DaffLoginInfo> = new DaffAuthLogin(mockLoginInfo);
62
+
63
+ result = reducer(initialState, authLoginAction);
64
+ });
65
+
66
+ it('sets loading state to true', () => {
67
+ expect(result.loading).toEqual(true);
68
+ });
69
+ });
70
+
71
+ describe('when AuthLoginSuccessAction is triggered', () => {
72
+ let result: DaffAuthLoginReducerState;
73
+ let state: DaffAuthLoginReducerState;
74
+
75
+ beforeEach(() => {
76
+ state = {
77
+ ...initialState,
78
+ loading: true,
79
+ errors: [{ code: 'firstErrorCode', message: 'firstErrorMessage' }],
80
+ };
81
+
82
+ const authLoginSuccess = new DaffAuthLoginSuccess(mockAuthToken);
83
+ result = reducer(state, authLoginSuccess);
84
+ });
85
+
86
+ it('sets loading to false', () => {
87
+ expect(result.loading).toEqual(false);
88
+ });
89
+
90
+ it('resets errors', () => {
91
+ expect(result.errors).toEqual([]);
92
+ });
93
+ });
94
+
95
+ describe('when AuthLoginFailureAction is triggered', () => {
96
+ const error: DaffStateError = {
97
+ code: 'error code',
98
+ message: 'error message',
99
+ };
100
+ let result: DaffAuthLoginReducerState;
101
+ let state: DaffAuthLoginReducerState;
102
+
103
+ beforeEach(() => {
104
+ state = {
105
+ ...initialState,
106
+ loading: true,
107
+ errors: [{ code: 'firstErrorCode', message: 'firstErrorMessage' }],
108
+ };
109
+
110
+ const authLoginFailure = new DaffAuthLoginFailure(error);
111
+
112
+ result = reducer(state, authLoginFailure);
113
+ });
114
+
115
+ it('sets loading to false', () => {
116
+ expect(result.loading).toEqual(false);
117
+ });
118
+
119
+ it('adds an error to state.errors', () => {
120
+ expect(result.errors).toEqual([error]);
121
+ });
122
+ });
123
+
124
+ describe('when AuthLogoutAction is triggered', () => {
125
+ let result: DaffAuthLoginReducerState;
126
+
127
+ beforeEach(() => {
128
+ const authLogoutAction = new DaffAuthLogout();
129
+
130
+ result = reducer(initialState, authLogoutAction);
131
+ });
132
+
133
+ it('sets loading state to true', () => {
134
+ expect(result.loading).toEqual(true);
135
+ });
136
+ });
137
+
138
+ describe('when AuthLogoutSuccessAction is triggered', () => {
139
+ let result: DaffAuthLoginReducerState;
140
+ let state: DaffAuthLoginReducerState;
141
+
142
+ beforeEach(() => {
143
+ state = {
144
+ ...initialState,
145
+ loading: true,
146
+ errors: [{ code: 'firstErrorCode', message: 'firstErrorMessage' }],
147
+ };
148
+
149
+ const authLogoutSuccess = new DaffAuthLogoutSuccess();
150
+ result = reducer(state, authLogoutSuccess);
151
+ });
152
+
153
+ it('sets loading to false', () => {
154
+ expect(result.loading).toEqual(false);
155
+ });
156
+
157
+ it('resets errors', () => {
158
+ expect(result.errors).toEqual([]);
159
+ });
160
+ });
161
+
162
+ describe('when AuthLogoutFailureAction is triggered', () => {
163
+ const error: DaffStateError = {
164
+ code: 'error code',
165
+ message: 'error message',
166
+ };
167
+ let result: DaffAuthLoginReducerState;
168
+ let state: DaffAuthLoginReducerState;
169
+
170
+ beforeEach(() => {
171
+ state = {
172
+ ...initialState,
173
+ loading: true,
174
+ errors: [{ code: 'firstErrorCode', message: 'firstErrorMessage' }],
175
+ };
176
+
177
+ const authLogoutFailure = new DaffAuthLogoutFailure(error);
178
+
179
+ result = reducer(state, authLogoutFailure);
180
+ });
181
+
182
+ it('sets loading to false', () => {
183
+ expect(result.loading).toEqual(false);
184
+ });
185
+
186
+ it('adds an error to state.errors', () => {
187
+ expect(result.errors).toEqual([error]);
188
+ });
189
+ });
190
+ });
@@ -0,0 +1,47 @@
1
+ import {
2
+ DaffLoginInfo,
3
+ DaffAuthToken,
4
+ } from '@daffodil/auth';
5
+
6
+ import {
7
+ DaffAuthLoginActionTypes,
8
+ DaffAuthLoginActions,
9
+ } from '../../actions/public_api';
10
+ import { daffAuthLoginInitialState } from './login-initial-state';
11
+ import { DaffAuthLoginReducerState } from './login-reducer-state.interface';
12
+
13
+ export function daffAuthLoginReducer<
14
+ T extends DaffLoginInfo,
15
+ U extends DaffAuthToken,
16
+ >(
17
+ state = daffAuthLoginInitialState,
18
+ action: DaffAuthLoginActions<T, U>,
19
+ ): DaffAuthLoginReducerState {
20
+ switch (action.type) {
21
+ case DaffAuthLoginActionTypes.LoginAction:
22
+ case DaffAuthLoginActionTypes.LogoutAction:
23
+ return {
24
+ ...state,
25
+ loading: true,
26
+ };
27
+
28
+ case DaffAuthLoginActionTypes.LoginSuccessAction:
29
+ case DaffAuthLoginActionTypes.LogoutSuccessAction:
30
+ return {
31
+ ...state,
32
+ loading: false,
33
+ errors: [],
34
+ };
35
+
36
+ case DaffAuthLoginActionTypes.LoginFailureAction:
37
+ case DaffAuthLoginActionTypes.LogoutFailureAction:
38
+ return {
39
+ ...state,
40
+ loading: false,
41
+ errors: [action.errorMessage],
42
+ };
43
+
44
+ default:
45
+ return state;
46
+ }
47
+ }
@@ -0,0 +1,3 @@
1
+ export { DaffAuthLoginReducerState } from './login-reducer-state.interface';
2
+ export { daffAuthLoginReducer } from './login.reducer';
3
+ export { daffAuthLoginInitialState } from './login-initial-state';
@@ -0,0 +1,11 @@
1
+ export * from './auth/public_api';
2
+ export * from './login/public_api';
3
+ export * from './register/public_api';
4
+ export * from './reset-password/public_api';
5
+
6
+ export { DAFF_AUTH_STORE_FEATURE_KEY } from './auth-store-feature-key';
7
+ export { daffAuthReducers } from './auth-reducers';
8
+ export {
9
+ DaffAuthFeatureState,
10
+ DaffAuthStateRootSlice,
11
+ } from './auth-feature-state.interface';
@@ -0,0 +1,3 @@
1
+ export { DaffAuthRegisterReducerState } from './register-reducer-state.interface';
2
+ export { daffAuthRegisterReducer } from './register.reducer';
3
+ export { daffAuthRegisterInitialState } from './register-initial-state';
@@ -0,0 +1,6 @@
1
+ import { DaffAuthRegisterReducerState } from './register-reducer-state.interface';
2
+
3
+ export const daffAuthRegisterInitialState: DaffAuthRegisterReducerState = {
4
+ loading: false,
5
+ errors: [],
6
+ };
@@ -0,0 +1,6 @@
1
+ import { DaffStateError } from '@daffodil/core/state';
2
+
3
+ export interface DaffAuthRegisterReducerState {
4
+ loading: boolean;
5
+ errors: DaffStateError[];
6
+ }
@@ -0,0 +1,111 @@
1
+ import { TestBed } from '@angular/core/testing';
2
+
3
+ import {
4
+ DaffLoginInfo,
5
+ DaffAccountRegistration,
6
+ } from '@daffodil/auth';
7
+ import {
8
+ DaffAuthRegister,
9
+ DaffAuthRegisterReducerState,
10
+ DaffAuthRegisterSuccess,
11
+ DaffAuthRegisterFailure,
12
+ daffAuthRegisterInitialState as initialState,
13
+ } from '@daffodil/auth/state';
14
+ import { DaffAccountRegistrationFactory } from '@daffodil/auth/testing';
15
+ import { DaffStateError } from '@daffodil/core/state';
16
+
17
+ import { daffAuthRegisterReducer as reducer } from './register.reducer';
18
+
19
+ describe('@daffodil/auth/state | daffAuthRegisterReducer', () => {
20
+ let registrationFactory: DaffAccountRegistrationFactory;
21
+
22
+ let mockRegistration: DaffAccountRegistration;
23
+ let email: string;
24
+ let password: string;
25
+
26
+ beforeEach(() => {
27
+ registrationFactory = TestBed.inject(DaffAccountRegistrationFactory);
28
+
29
+ mockRegistration = registrationFactory.create();
30
+
31
+ email = mockRegistration.email;
32
+ password = mockRegistration.password;
33
+ });
34
+
35
+ describe('when an unknown action is triggered', () => {
36
+ it('should return the current state', () => {
37
+ const action = <any>{};
38
+
39
+ const result = reducer(initialState, action);
40
+
41
+ expect(result).toBe(initialState);
42
+ });
43
+ });
44
+
45
+ describe('when AuthRegisterAction is triggered', () => {
46
+ let result;
47
+
48
+ beforeEach(() => {
49
+ const authRegisterAction: DaffAuthRegister<DaffAccountRegistration> = new DaffAuthRegister(mockRegistration);
50
+
51
+ result = reducer(initialState, authRegisterAction);
52
+ });
53
+
54
+ it('sets loading state to true', () => {
55
+ expect(result.loading).toEqual(true);
56
+ });
57
+ });
58
+
59
+ describe('when AuthRegisterSuccessAction is triggered', () => {
60
+ let result;
61
+ let state: DaffAuthRegisterReducerState;
62
+
63
+ beforeEach(() => {
64
+ state = {
65
+ ...initialState,
66
+ loading: true,
67
+ errors: [{ code: 'firstErrorCode', message: 'firstErrorMessage' }],
68
+ };
69
+
70
+ const authRegisterSuccess = new DaffAuthRegisterSuccess();
71
+ result = reducer(state, authRegisterSuccess);
72
+ });
73
+
74
+ it('sets loading to false', () => {
75
+ expect(result.loading).toEqual(false);
76
+ });
77
+
78
+ it('resets errors', () => {
79
+ expect(result.errors).toEqual([]);
80
+ });
81
+ });
82
+
83
+ describe('when AuthRegisterFailureAction is triggered', () => {
84
+ const error: DaffStateError = {
85
+ code: 'error code',
86
+ message: 'error message',
87
+ };
88
+ let result;
89
+ let state: DaffAuthRegisterReducerState;
90
+
91
+ beforeEach(() => {
92
+ state = {
93
+ ...initialState,
94
+ loading: true,
95
+ errors: [{ code: 'firstErrorCode', message: 'firstErrorMessage' }],
96
+ };
97
+
98
+ const authRegisterFailure = new DaffAuthRegisterFailure(error);
99
+
100
+ result = reducer(state, authRegisterFailure);
101
+ });
102
+
103
+ it('sets loading to false', () => {
104
+ expect(result.loading).toEqual(false);
105
+ });
106
+
107
+ it('adds an error to state.errors', () => {
108
+ expect(result.errors).toEqual([error]);
109
+ });
110
+ });
111
+ });
@@ -0,0 +1,40 @@
1
+ import { DaffAccountRegistration } from '@daffodil/auth';
2
+
3
+ import {
4
+ DaffAuthRegisterActionTypes,
5
+ DaffAuthRegisterActions,
6
+ } from '../../actions/public_api';
7
+ import { daffAuthRegisterInitialState } from './register-initial-state';
8
+ import { DaffAuthRegisterReducerState } from './register-reducer-state.interface';
9
+
10
+ export function daffAuthRegisterReducer<
11
+ T extends DaffAccountRegistration,
12
+ >(
13
+ state = daffAuthRegisterInitialState,
14
+ action: DaffAuthRegisterActions<T>,
15
+ ): DaffAuthRegisterReducerState {
16
+ switch (action.type) {
17
+ case DaffAuthRegisterActionTypes.RegisterAction:
18
+ return {
19
+ ...state,
20
+ loading: true,
21
+ };
22
+
23
+ case DaffAuthRegisterActionTypes.RegisterSuccessAction:
24
+ return {
25
+ ...state,
26
+ loading: false,
27
+ errors: [],
28
+ };
29
+
30
+ case DaffAuthRegisterActionTypes.RegisterFailureAction:
31
+ return {
32
+ ...state,
33
+ loading: false,
34
+ errors: [action.errorMessage],
35
+ };
36
+
37
+ default:
38
+ return state;
39
+ }
40
+ }
@@ -0,0 +1,7 @@
1
+ import { DaffAuthResetPasswordReducerState } from './state.interface';
2
+
3
+ export const daffAuthResetPasswordInitialState: DaffAuthResetPasswordReducerState = {
4
+ loading: false,
5
+ errors: [],
6
+ token: null,
7
+ };
@@ -0,0 +1,3 @@
1
+ export { DaffAuthResetPasswordReducerState } from './state.interface';
2
+ export { daffAuthResetPasswordReducer } from './reducer';
3
+ export { daffAuthResetPasswordInitialState } from './initial-state';