orc-shared 1.6.0-dev.7 → 1.6.0-dev.9

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.
@@ -46,7 +46,8 @@ var requestReducer = function requestReducer(state, action) {
46
46
  }
47
47
  if (action.type.endsWith("_FAILURE")) {
48
48
  var _requestName2 = action.type.replace(/_FAILURE$/, "");
49
- if ((0, _utils.safeGet)(action, "payload", "status") === 403) {
49
+ var status = (0, _utils.safeGet)(action, "payload", "status");
50
+ if (status === 403 || status === 401) {
50
51
  return state.deleteIn(["actives", _requestName2]).set("logout", true);
51
52
  } else {
52
53
  return state.deleteIn(["actives", _requestName2]).set("error", _immutable.default.fromJS(action));
@@ -31,6 +31,9 @@ var scopeReducer = function scopeReducer(state, action) {
31
31
  {
32
32
  var loadedScopes = state.toJS();
33
33
  var normalizedScopes = (0, _normalizr.normalize)(action.payload, _scopes.default);
34
+ if (action.meta && action.meta.reset) {
35
+ return _immutable.default.fromJS(normalizedScopes.entities.scopes);
36
+ }
34
37
  if (Object.keys(loadedScopes).length > 0) {
35
38
  var addedScope = {};
36
39
  Object.values(normalizedScopes.entities.scopes).forEach(function (scope) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orc-shared",
3
- "version": "1.6.0-dev.7",
3
+ "version": "1.6.0-dev.9",
4
4
  "description": "Shared code for Orckestra applications",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
@@ -24,7 +24,8 @@ const requestReducer = (state = initialState, action) => {
24
24
  }
25
25
  if (action.type.endsWith("_FAILURE")) {
26
26
  const requestName = action.type.replace(/_FAILURE$/, "");
27
- if (safeGet(action, "payload", "status") === 403) {
27
+ const status = safeGet(action, "payload", "status");
28
+ if (status === 403 || status === 401) {
28
29
  return state.deleteIn(["actives", requestName]).set("logout", true);
29
30
  } else {
30
31
  return state.deleteIn(["actives", requestName]).set("error", Immutable.fromJS(action));
@@ -125,4 +125,27 @@ describe("Request reducer", () => {
125
125
  }),
126
126
  );
127
127
  });
128
+
129
+ it("clears activity flag and sets login flag when a request fails with status 401", () => {
130
+ const oldState = Immutable.fromJS({
131
+ actives: {
132
+ SOME_FLAG: true,
133
+ TEST_THIS: true,
134
+ },
135
+ });
136
+ const action = {
137
+ type: "TEST_THIS_FAILURE",
138
+ payload: { status: 401, message: "UnauthorizedAccessException" },
139
+ };
140
+ const newState = reducer(oldState, action);
141
+ expect(newState, "not to be", oldState).and(
142
+ "to equal",
143
+ Immutable.fromJS({
144
+ actives: {
145
+ SOME_FLAG: true,
146
+ },
147
+ [LOGOUT]: true,
148
+ }),
149
+ );
150
+ });
128
151
  });
@@ -10,6 +10,9 @@ const scopeReducer = (state = initialState, action) => {
10
10
  case GET_SCOPES_SUCCESS: {
11
11
  const loadedScopes = state.toJS();
12
12
  const normalizedScopes = normalize(action.payload, scopeSchema);
13
+ if (action.meta && action.meta.reset) {
14
+ return Immutable.fromJS(normalizedScopes.entities.scopes);
15
+ }
13
16
 
14
17
  if (Object.keys(loadedScopes).length > 0) {
15
18
  const addedScope = {};
@@ -91,4 +91,51 @@ describe("scopes", () => {
91
91
  }),
92
92
  );
93
93
  });
94
+
95
+ it("reset option should override previous state", () => {
96
+ const oldState = Immutable.Map({
97
+ Global: {
98
+ id: "Global",
99
+ isAuthorizedScope: true,
100
+ children: ["Child1", "Child2", "Child3"],
101
+ scopePath: ["Global"],
102
+ },
103
+ Child1: { id: "Child1", isAuthorizedScope: true, scopePath: ["Global", "Child1"], children: [] },
104
+ Child2: { id: "Child2", isAuthorizedScope: false, scopePath: ["Global", "Child2"], children: [] },
105
+ ChildOld: { id: "ChildOld", isAuthorizedScope: false, scopePath: ["Global", "ChildOld"], children: [] },
106
+ });
107
+
108
+ const action = {
109
+ type: GET_SCOPES_SUCCESS,
110
+ payload: {
111
+ id: "Global",
112
+ isAuthorizedScope: true,
113
+ children: [
114
+ { id: "Child1", isAuthorizedScope: false, children: [], parentScopeId: "Global" },
115
+ { id: "Child2", isAuthorizedScope: true, children: [], parentScopeId: "Global" },
116
+ { id: "Child3", isAuthorizedScope: false, children: [], parentScopeId: "Global" },
117
+ { id: "Child4", isAuthorizedScope: true, children: [], parentScopeId: "Global" },
118
+ ],
119
+ },
120
+ meta: {
121
+ reset: true,
122
+ },
123
+ };
124
+ const newState = reducer(oldState, action);
125
+ return expect(newState, "not to be", oldState).and(
126
+ "to satisfy",
127
+ Immutable.fromJS({
128
+ Global: {
129
+ id: "Global",
130
+ isAuthorizedScope: true,
131
+ children: ["Child1", "Child2", "Child3", "Child4"],
132
+ scopePath: ["Global"],
133
+ },
134
+ Child1: { id: "Child1", isAuthorizedScope: false, scopePath: ["Global", "Child1"], children: [] },
135
+ Child2: { id: "Child2", isAuthorizedScope: true, scopePath: ["Global", "Child2"], children: [] },
136
+ Child3: { id: "Child3", isAuthorizedScope: false, scopePath: ["Global", "Child3"], children: [] },
137
+ Child4: { id: "Child4", isAuthorizedScope: true, scopePath: ["Global", "Child4"], children: [] },
138
+ }),
139
+ );
140
+ });
94
141
  });