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

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.
@@ -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.8",
4
4
  "description": "Shared code for Orckestra applications",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
@@ -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
  });