@wordpress/abilities 0.1.1-next.dc3f6d3c1.0 → 0.2.1-next.8b30e05b0.0
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.
- package/CHANGELOG.md +2 -0
- package/build-types/store/index.d.ts +1 -1
- package/build-types/store/index.d.ts.map +1 -1
- package/package.json +18 -9
- package/build/store/tests/actions.test.js +0 -792
- package/build/store/tests/actions.test.js.map +0 -7
- package/build/store/tests/reducer.test.js +0 -743
- package/build/store/tests/reducer.test.js.map +0 -7
- package/build/store/tests/resolvers.test.js +0 -520
- package/build/store/tests/resolvers.test.js.map +0 -7
- package/build/store/tests/selectors.test.js +0 -349
- package/build/store/tests/selectors.test.js.map +0 -7
- package/build/tests/api.test.js +0 -546
- package/build/tests/api.test.js.map +0 -7
- package/build/tests/validation.test.js +0 -453
- package/build/tests/validation.test.js.map +0 -7
- package/build-module/store/tests/actions.test.js +0 -804
- package/build-module/store/tests/actions.test.js.map +0 -7
- package/build-module/store/tests/reducer.test.js +0 -726
- package/build-module/store/tests/reducer.test.js.map +0 -7
- package/build-module/store/tests/resolvers.test.js +0 -523
- package/build-module/store/tests/resolvers.test.js.map +0 -7
- package/build-module/store/tests/selectors.test.js +0 -352
- package/build-module/store/tests/selectors.test.js.map +0 -7
- package/build-module/tests/api.test.js +0 -530
- package/build-module/tests/api.test.js.map +0 -7
- package/build-module/tests/validation.test.js +0 -451
- package/build-module/tests/validation.test.js.map +0 -7
|
@@ -1,743 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
-
for (let key of __getOwnPropNames(from))
|
|
11
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
-
}
|
|
14
|
-
return to;
|
|
15
|
-
};
|
|
16
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
-
mod
|
|
23
|
-
));
|
|
24
|
-
|
|
25
|
-
// packages/abilities/src/store/tests/reducer.test.ts
|
|
26
|
-
var import_reducer = __toESM(require("../reducer"));
|
|
27
|
-
var import_constants = require("../constants");
|
|
28
|
-
describe("Store Reducer", () => {
|
|
29
|
-
describe("abilitiesByName", () => {
|
|
30
|
-
const defaultState = {};
|
|
31
|
-
describe("RECEIVE_ABILITIES", () => {
|
|
32
|
-
it("should add abilities to the state", () => {
|
|
33
|
-
const abilities = [
|
|
34
|
-
{
|
|
35
|
-
name: "test/ability1",
|
|
36
|
-
label: "Test Ability 1",
|
|
37
|
-
description: "First test ability",
|
|
38
|
-
input_schema: { type: "object" }
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
name: "test/ability2",
|
|
42
|
-
label: "Test Ability 2",
|
|
43
|
-
description: "Second test ability",
|
|
44
|
-
output_schema: { type: "object" }
|
|
45
|
-
}
|
|
46
|
-
];
|
|
47
|
-
const action = {
|
|
48
|
-
type: import_constants.RECEIVE_ABILITIES,
|
|
49
|
-
abilities
|
|
50
|
-
};
|
|
51
|
-
const state = (0, import_reducer.default)(
|
|
52
|
-
{ abilitiesByName: defaultState },
|
|
53
|
-
action
|
|
54
|
-
);
|
|
55
|
-
expect(state.abilitiesByName).toHaveProperty(
|
|
56
|
-
"test/ability1"
|
|
57
|
-
);
|
|
58
|
-
expect(state.abilitiesByName).toHaveProperty(
|
|
59
|
-
"test/ability2"
|
|
60
|
-
);
|
|
61
|
-
expect(state.abilitiesByName["test/ability1"].label).toBe(
|
|
62
|
-
"Test Ability 1"
|
|
63
|
-
);
|
|
64
|
-
expect(state.abilitiesByName["test/ability2"].label).toBe(
|
|
65
|
-
"Test Ability 2"
|
|
66
|
-
);
|
|
67
|
-
});
|
|
68
|
-
it("should filter out _links from server responses", () => {
|
|
69
|
-
const abilities = [
|
|
70
|
-
{
|
|
71
|
-
name: "test/ability",
|
|
72
|
-
label: "Test Ability",
|
|
73
|
-
description: "Test ability with links",
|
|
74
|
-
_links: {
|
|
75
|
-
self: {
|
|
76
|
-
href: "/wp-abilities/v1/abilities/test/ability"
|
|
77
|
-
},
|
|
78
|
-
collection: { href: "/wp-abilities/v1/abilities" }
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
];
|
|
82
|
-
const action = {
|
|
83
|
-
type: import_constants.RECEIVE_ABILITIES,
|
|
84
|
-
abilities
|
|
85
|
-
};
|
|
86
|
-
const state = (0, import_reducer.default)(
|
|
87
|
-
{ abilitiesByName: defaultState },
|
|
88
|
-
action
|
|
89
|
-
);
|
|
90
|
-
expect(
|
|
91
|
-
state.abilitiesByName["test/ability"]
|
|
92
|
-
).not.toHaveProperty("_links");
|
|
93
|
-
expect(state.abilitiesByName["test/ability"].name).toBe(
|
|
94
|
-
"test/ability"
|
|
95
|
-
);
|
|
96
|
-
expect(state.abilitiesByName["test/ability"].label).toBe(
|
|
97
|
-
"Test Ability"
|
|
98
|
-
);
|
|
99
|
-
});
|
|
100
|
-
it("should filter out _embedded from server responses", () => {
|
|
101
|
-
const abilities = [
|
|
102
|
-
{
|
|
103
|
-
name: "test/ability",
|
|
104
|
-
label: "Test Ability",
|
|
105
|
-
description: "Test ability with embedded",
|
|
106
|
-
_embedded: {
|
|
107
|
-
author: { id: 1, name: "Admin" }
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
];
|
|
111
|
-
const action = {
|
|
112
|
-
type: import_constants.RECEIVE_ABILITIES,
|
|
113
|
-
abilities
|
|
114
|
-
};
|
|
115
|
-
const state = (0, import_reducer.default)(
|
|
116
|
-
{ abilitiesByName: defaultState },
|
|
117
|
-
action
|
|
118
|
-
);
|
|
119
|
-
expect(
|
|
120
|
-
state.abilitiesByName["test/ability"]
|
|
121
|
-
).not.toHaveProperty("_embedded");
|
|
122
|
-
});
|
|
123
|
-
it("should preserve all valid ability properties", () => {
|
|
124
|
-
const abilities = [
|
|
125
|
-
{
|
|
126
|
-
name: "test/ability",
|
|
127
|
-
label: "Test Ability",
|
|
128
|
-
description: "Full test ability.",
|
|
129
|
-
input_schema: { type: "object" },
|
|
130
|
-
output_schema: { type: "object" },
|
|
131
|
-
meta: {
|
|
132
|
-
category: "test"
|
|
133
|
-
},
|
|
134
|
-
callback: () => Promise.resolve({}),
|
|
135
|
-
permissionCallback: () => true,
|
|
136
|
-
// Extra properties that should be filtered out
|
|
137
|
-
_links: { self: { href: "/test" } },
|
|
138
|
-
_embedded: { test: "value" },
|
|
139
|
-
extra_field: "should be removed"
|
|
140
|
-
}
|
|
141
|
-
];
|
|
142
|
-
const action = {
|
|
143
|
-
type: import_constants.RECEIVE_ABILITIES,
|
|
144
|
-
abilities
|
|
145
|
-
};
|
|
146
|
-
const state = (0, import_reducer.default)(
|
|
147
|
-
{ abilitiesByName: defaultState },
|
|
148
|
-
action
|
|
149
|
-
);
|
|
150
|
-
const ability = state.abilitiesByName["test/ability"];
|
|
151
|
-
expect(ability.name).toBe("test/ability");
|
|
152
|
-
expect(ability.label).toBe("Test Ability");
|
|
153
|
-
expect(ability.description).toBe("Full test ability.");
|
|
154
|
-
expect(ability.input_schema).toEqual({ type: "object" });
|
|
155
|
-
expect(ability.output_schema).toEqual({ type: "object" });
|
|
156
|
-
expect(ability.meta).toEqual({ category: "test" });
|
|
157
|
-
expect(ability.callback).toBeDefined();
|
|
158
|
-
expect(ability.permissionCallback).toBeDefined();
|
|
159
|
-
expect(ability).not.toHaveProperty("_links");
|
|
160
|
-
expect(ability).not.toHaveProperty("_embedded");
|
|
161
|
-
expect(ability).not.toHaveProperty("extra_field");
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
describe("REGISTER_ABILITY", () => {
|
|
165
|
-
it("should add ability to the state", () => {
|
|
166
|
-
const ability = {
|
|
167
|
-
name: "test/ability",
|
|
168
|
-
label: "Test Ability",
|
|
169
|
-
description: "Test ability",
|
|
170
|
-
callback: () => Promise.resolve({})
|
|
171
|
-
};
|
|
172
|
-
const action = {
|
|
173
|
-
type: import_constants.REGISTER_ABILITY,
|
|
174
|
-
ability
|
|
175
|
-
};
|
|
176
|
-
const state = (0, import_reducer.default)(
|
|
177
|
-
{ abilitiesByName: defaultState },
|
|
178
|
-
action
|
|
179
|
-
);
|
|
180
|
-
expect(state.abilitiesByName).toHaveProperty(
|
|
181
|
-
"test/ability"
|
|
182
|
-
);
|
|
183
|
-
expect(state.abilitiesByName["test/ability"].label).toBe(
|
|
184
|
-
"Test Ability"
|
|
185
|
-
);
|
|
186
|
-
});
|
|
187
|
-
it("should filter out extra properties when registering", () => {
|
|
188
|
-
const ability = {
|
|
189
|
-
name: "test/ability",
|
|
190
|
-
label: "Test Ability",
|
|
191
|
-
description: "Test ability",
|
|
192
|
-
callback: () => Promise.resolve({}),
|
|
193
|
-
// Extra properties that should be filtered out
|
|
194
|
-
_links: { self: { href: "/test" } },
|
|
195
|
-
extra_field: "should be removed"
|
|
196
|
-
};
|
|
197
|
-
const action = {
|
|
198
|
-
type: import_constants.REGISTER_ABILITY,
|
|
199
|
-
ability
|
|
200
|
-
};
|
|
201
|
-
const state = (0, import_reducer.default)(
|
|
202
|
-
{ abilitiesByName: defaultState },
|
|
203
|
-
action
|
|
204
|
-
);
|
|
205
|
-
const registeredAbility = state.abilitiesByName["test/ability"];
|
|
206
|
-
expect(registeredAbility.name).toBe("test/ability");
|
|
207
|
-
expect(registeredAbility.label).toBe("Test Ability");
|
|
208
|
-
expect(registeredAbility.description).toBe("Test ability");
|
|
209
|
-
expect(registeredAbility.callback).toBeDefined();
|
|
210
|
-
expect(registeredAbility).not.toHaveProperty("_links");
|
|
211
|
-
expect(registeredAbility).not.toHaveProperty("extra_field");
|
|
212
|
-
});
|
|
213
|
-
it("should replace existing ability", () => {
|
|
214
|
-
const initialState = {
|
|
215
|
-
"test/ability": {
|
|
216
|
-
name: "test/ability",
|
|
217
|
-
label: "Old Label",
|
|
218
|
-
description: "Old description"
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
|
-
const ability = {
|
|
222
|
-
name: "test/ability",
|
|
223
|
-
label: "New Label",
|
|
224
|
-
description: "New description",
|
|
225
|
-
input_schema: { type: "string" }
|
|
226
|
-
};
|
|
227
|
-
const action = {
|
|
228
|
-
type: import_constants.REGISTER_ABILITY,
|
|
229
|
-
ability
|
|
230
|
-
};
|
|
231
|
-
const state = (0, import_reducer.default)(
|
|
232
|
-
{ abilitiesByName: initialState },
|
|
233
|
-
action
|
|
234
|
-
);
|
|
235
|
-
expect(state.abilitiesByName["test/ability"].label).toBe(
|
|
236
|
-
"New Label"
|
|
237
|
-
);
|
|
238
|
-
expect(
|
|
239
|
-
state.abilitiesByName["test/ability"].description
|
|
240
|
-
).toBe("New description");
|
|
241
|
-
expect(
|
|
242
|
-
state.abilitiesByName["test/ability"].input_schema
|
|
243
|
-
).toEqual({ type: "string" });
|
|
244
|
-
});
|
|
245
|
-
});
|
|
246
|
-
describe("UNREGISTER_ABILITY", () => {
|
|
247
|
-
it("should remove ability from the state", () => {
|
|
248
|
-
const initialState = {
|
|
249
|
-
"test/ability1": {
|
|
250
|
-
name: "test/ability1",
|
|
251
|
-
label: "Test Ability 1",
|
|
252
|
-
description: "First test ability"
|
|
253
|
-
},
|
|
254
|
-
"test/ability2": {
|
|
255
|
-
name: "test/ability2",
|
|
256
|
-
label: "Test Ability 2",
|
|
257
|
-
description: "Second test ability"
|
|
258
|
-
}
|
|
259
|
-
};
|
|
260
|
-
const action = {
|
|
261
|
-
type: import_constants.UNREGISTER_ABILITY,
|
|
262
|
-
name: "test/ability1"
|
|
263
|
-
};
|
|
264
|
-
const state = (0, import_reducer.default)(
|
|
265
|
-
{ abilitiesByName: initialState },
|
|
266
|
-
action
|
|
267
|
-
);
|
|
268
|
-
expect(state.abilitiesByName).not.toHaveProperty(
|
|
269
|
-
"test/ability1"
|
|
270
|
-
);
|
|
271
|
-
expect(state.abilitiesByName).toHaveProperty(
|
|
272
|
-
"test/ability2"
|
|
273
|
-
);
|
|
274
|
-
});
|
|
275
|
-
});
|
|
276
|
-
describe("Edge cases", () => {
|
|
277
|
-
it("should handle unregistering non-existent ability", () => {
|
|
278
|
-
const initialState = {
|
|
279
|
-
"test/ability": {
|
|
280
|
-
name: "test/ability",
|
|
281
|
-
label: "Test Ability",
|
|
282
|
-
description: "Test ability"
|
|
283
|
-
}
|
|
284
|
-
};
|
|
285
|
-
const action = {
|
|
286
|
-
type: import_constants.UNREGISTER_ABILITY,
|
|
287
|
-
name: "test/non-existent"
|
|
288
|
-
};
|
|
289
|
-
const state = (0, import_reducer.default)(
|
|
290
|
-
{ abilitiesByName: initialState },
|
|
291
|
-
action
|
|
292
|
-
);
|
|
293
|
-
expect(state.abilitiesByName).toEqual(initialState);
|
|
294
|
-
});
|
|
295
|
-
it("should handle undefined abilities in RECEIVE_ABILITIES", () => {
|
|
296
|
-
const action = {
|
|
297
|
-
type: import_constants.RECEIVE_ABILITIES,
|
|
298
|
-
abilities: void 0
|
|
299
|
-
};
|
|
300
|
-
const state = (0, import_reducer.default)(
|
|
301
|
-
{ abilitiesByName: defaultState },
|
|
302
|
-
action
|
|
303
|
-
);
|
|
304
|
-
expect(state.abilitiesByName).toEqual(defaultState);
|
|
305
|
-
});
|
|
306
|
-
it("should handle undefined ability in REGISTER_ABILITY", () => {
|
|
307
|
-
const action = {
|
|
308
|
-
type: import_constants.REGISTER_ABILITY,
|
|
309
|
-
ability: void 0
|
|
310
|
-
};
|
|
311
|
-
const state = (0, import_reducer.default)(
|
|
312
|
-
{ abilitiesByName: defaultState },
|
|
313
|
-
action
|
|
314
|
-
);
|
|
315
|
-
expect(state.abilitiesByName).toEqual(defaultState);
|
|
316
|
-
});
|
|
317
|
-
it("should handle undefined properties gracefully", () => {
|
|
318
|
-
const abilities = [
|
|
319
|
-
{
|
|
320
|
-
name: "test/minimal",
|
|
321
|
-
label: "Minimal",
|
|
322
|
-
description: "Minimal ability with undefined properties",
|
|
323
|
-
input_schema: void 0,
|
|
324
|
-
output_schema: void 0,
|
|
325
|
-
meta: void 0,
|
|
326
|
-
callback: void 0,
|
|
327
|
-
permissionCallback: void 0
|
|
328
|
-
}
|
|
329
|
-
];
|
|
330
|
-
const action = {
|
|
331
|
-
type: import_constants.RECEIVE_ABILITIES,
|
|
332
|
-
abilities
|
|
333
|
-
};
|
|
334
|
-
const state = (0, import_reducer.default)(
|
|
335
|
-
{ abilitiesByName: defaultState },
|
|
336
|
-
action
|
|
337
|
-
);
|
|
338
|
-
const ability = state.abilitiesByName["test/minimal"];
|
|
339
|
-
expect(ability.name).toBe("test/minimal");
|
|
340
|
-
expect(ability.label).toBe("Minimal");
|
|
341
|
-
expect(ability.description).toBe(
|
|
342
|
-
"Minimal ability with undefined properties"
|
|
343
|
-
);
|
|
344
|
-
expect(ability).not.toHaveProperty("input_schema");
|
|
345
|
-
expect(ability).not.toHaveProperty("output_schema");
|
|
346
|
-
expect(ability).not.toHaveProperty("meta");
|
|
347
|
-
expect(ability).not.toHaveProperty("callback");
|
|
348
|
-
expect(ability).not.toHaveProperty("permissionCallback");
|
|
349
|
-
});
|
|
350
|
-
});
|
|
351
|
-
});
|
|
352
|
-
describe("categoriesBySlug", () => {
|
|
353
|
-
const defaultState = {};
|
|
354
|
-
describe("RECEIVE_CATEGORIES", () => {
|
|
355
|
-
it("should add categories to the state", () => {
|
|
356
|
-
const categories = [
|
|
357
|
-
{
|
|
358
|
-
slug: "data-retrieval",
|
|
359
|
-
label: "Data Retrieval",
|
|
360
|
-
description: "Abilities that retrieve data"
|
|
361
|
-
},
|
|
362
|
-
{
|
|
363
|
-
slug: "user-management",
|
|
364
|
-
label: "User Management",
|
|
365
|
-
description: "Abilities for managing users"
|
|
366
|
-
}
|
|
367
|
-
];
|
|
368
|
-
const action = {
|
|
369
|
-
type: import_constants.RECEIVE_CATEGORIES,
|
|
370
|
-
categories
|
|
371
|
-
};
|
|
372
|
-
const state = (0, import_reducer.default)(
|
|
373
|
-
{ categoriesBySlug: defaultState, abilitiesByName: {} },
|
|
374
|
-
action
|
|
375
|
-
);
|
|
376
|
-
expect(state.categoriesBySlug).toHaveProperty(
|
|
377
|
-
"data-retrieval"
|
|
378
|
-
);
|
|
379
|
-
expect(state.categoriesBySlug).toHaveProperty(
|
|
380
|
-
"user-management"
|
|
381
|
-
);
|
|
382
|
-
expect(state.categoriesBySlug["data-retrieval"].label).toBe(
|
|
383
|
-
"Data Retrieval"
|
|
384
|
-
);
|
|
385
|
-
expect(
|
|
386
|
-
state.categoriesBySlug["user-management"].label
|
|
387
|
-
).toBe("User Management");
|
|
388
|
-
});
|
|
389
|
-
it("should filter out _links from server responses", () => {
|
|
390
|
-
const categories = [
|
|
391
|
-
{
|
|
392
|
-
slug: "data-retrieval",
|
|
393
|
-
label: "Data Retrieval",
|
|
394
|
-
description: "Test category with links",
|
|
395
|
-
_links: {
|
|
396
|
-
self: {
|
|
397
|
-
href: "/wp-abilities/v1/categories/data-retrieval"
|
|
398
|
-
},
|
|
399
|
-
collection: {
|
|
400
|
-
href: "/wp-abilities/v1/categories"
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
];
|
|
405
|
-
const action = {
|
|
406
|
-
type: import_constants.RECEIVE_CATEGORIES,
|
|
407
|
-
categories
|
|
408
|
-
};
|
|
409
|
-
const state = (0, import_reducer.default)(
|
|
410
|
-
{ categoriesBySlug: defaultState, abilitiesByName: {} },
|
|
411
|
-
action
|
|
412
|
-
);
|
|
413
|
-
expect(
|
|
414
|
-
state.categoriesBySlug["data-retrieval"]
|
|
415
|
-
).not.toHaveProperty("_links");
|
|
416
|
-
expect(state.categoriesBySlug["data-retrieval"].slug).toBe(
|
|
417
|
-
"data-retrieval"
|
|
418
|
-
);
|
|
419
|
-
expect(state.categoriesBySlug["data-retrieval"].label).toBe(
|
|
420
|
-
"Data Retrieval"
|
|
421
|
-
);
|
|
422
|
-
});
|
|
423
|
-
it("should filter out _embedded from server responses", () => {
|
|
424
|
-
const categories = [
|
|
425
|
-
{
|
|
426
|
-
slug: "data-retrieval",
|
|
427
|
-
label: "Data Retrieval",
|
|
428
|
-
description: "Test category with embedded",
|
|
429
|
-
_embedded: {
|
|
430
|
-
author: { id: 1, name: "Admin" }
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
];
|
|
434
|
-
const action = {
|
|
435
|
-
type: import_constants.RECEIVE_CATEGORIES,
|
|
436
|
-
categories
|
|
437
|
-
};
|
|
438
|
-
const state = (0, import_reducer.default)(
|
|
439
|
-
{ categoriesBySlug: defaultState, abilitiesByName: {} },
|
|
440
|
-
action
|
|
441
|
-
);
|
|
442
|
-
expect(
|
|
443
|
-
state.categoriesBySlug["data-retrieval"]
|
|
444
|
-
).not.toHaveProperty("_embedded");
|
|
445
|
-
});
|
|
446
|
-
it("should preserve all valid category properties", () => {
|
|
447
|
-
const categories = [
|
|
448
|
-
{
|
|
449
|
-
slug: "data-retrieval",
|
|
450
|
-
label: "Data Retrieval",
|
|
451
|
-
description: "Full test category.",
|
|
452
|
-
meta: {
|
|
453
|
-
priority: "high",
|
|
454
|
-
color: "blue"
|
|
455
|
-
},
|
|
456
|
-
// Extra properties that should be filtered out
|
|
457
|
-
_links: { self: { href: "/test" } },
|
|
458
|
-
_embedded: { test: "value" },
|
|
459
|
-
extra_field: "should be removed"
|
|
460
|
-
}
|
|
461
|
-
];
|
|
462
|
-
const action = {
|
|
463
|
-
type: import_constants.RECEIVE_CATEGORIES,
|
|
464
|
-
categories
|
|
465
|
-
};
|
|
466
|
-
const state = (0, import_reducer.default)(
|
|
467
|
-
{ categoriesBySlug: defaultState, abilitiesByName: {} },
|
|
468
|
-
action
|
|
469
|
-
);
|
|
470
|
-
const category = state.categoriesBySlug["data-retrieval"];
|
|
471
|
-
expect(category.slug).toBe("data-retrieval");
|
|
472
|
-
expect(category.label).toBe("Data Retrieval");
|
|
473
|
-
expect(category.description).toBe("Full test category.");
|
|
474
|
-
expect(category.meta).toEqual({
|
|
475
|
-
priority: "high",
|
|
476
|
-
color: "blue"
|
|
477
|
-
});
|
|
478
|
-
expect(category).not.toHaveProperty("_links");
|
|
479
|
-
expect(category).not.toHaveProperty("_embedded");
|
|
480
|
-
expect(category).not.toHaveProperty("extra_field");
|
|
481
|
-
});
|
|
482
|
-
it("should overwrite existing categories", () => {
|
|
483
|
-
const initialState = {
|
|
484
|
-
"existing-category": {
|
|
485
|
-
slug: "existing-category",
|
|
486
|
-
label: "Existing Category",
|
|
487
|
-
description: "Already in store"
|
|
488
|
-
}
|
|
489
|
-
};
|
|
490
|
-
const categories = [
|
|
491
|
-
{
|
|
492
|
-
slug: "data-retrieval",
|
|
493
|
-
label: "Data Retrieval",
|
|
494
|
-
description: "New category"
|
|
495
|
-
}
|
|
496
|
-
];
|
|
497
|
-
const action = {
|
|
498
|
-
type: import_constants.RECEIVE_CATEGORIES,
|
|
499
|
-
categories
|
|
500
|
-
};
|
|
501
|
-
const state = (0, import_reducer.default)(
|
|
502
|
-
{ categoriesBySlug: initialState, abilitiesByName: {} },
|
|
503
|
-
action
|
|
504
|
-
);
|
|
505
|
-
expect(state.categoriesBySlug).not.toHaveProperty(
|
|
506
|
-
"existing-category"
|
|
507
|
-
);
|
|
508
|
-
expect(state.categoriesBySlug).toHaveProperty(
|
|
509
|
-
"data-retrieval"
|
|
510
|
-
);
|
|
511
|
-
});
|
|
512
|
-
});
|
|
513
|
-
describe("Edge cases", () => {
|
|
514
|
-
it("should handle undefined categories in RECEIVE_CATEGORIES", () => {
|
|
515
|
-
const action = {
|
|
516
|
-
type: import_constants.RECEIVE_CATEGORIES,
|
|
517
|
-
categories: void 0
|
|
518
|
-
};
|
|
519
|
-
const state = (0, import_reducer.default)(
|
|
520
|
-
{ categoriesBySlug: defaultState, abilitiesByName: {} },
|
|
521
|
-
action
|
|
522
|
-
);
|
|
523
|
-
expect(state.categoriesBySlug).toEqual(defaultState);
|
|
524
|
-
});
|
|
525
|
-
it("should handle empty categories array", () => {
|
|
526
|
-
const action = {
|
|
527
|
-
type: import_constants.RECEIVE_CATEGORIES,
|
|
528
|
-
categories: []
|
|
529
|
-
};
|
|
530
|
-
const state = (0, import_reducer.default)(
|
|
531
|
-
{ categoriesBySlug: defaultState, abilitiesByName: {} },
|
|
532
|
-
action
|
|
533
|
-
);
|
|
534
|
-
expect(state.categoriesBySlug).toEqual(defaultState);
|
|
535
|
-
});
|
|
536
|
-
it("should handle undefined properties gracefully", () => {
|
|
537
|
-
const categories = [
|
|
538
|
-
{
|
|
539
|
-
slug: "minimal",
|
|
540
|
-
label: "Minimal",
|
|
541
|
-
description: "Minimal category with undefined meta",
|
|
542
|
-
meta: void 0
|
|
543
|
-
}
|
|
544
|
-
];
|
|
545
|
-
const action = {
|
|
546
|
-
type: import_constants.RECEIVE_CATEGORIES,
|
|
547
|
-
categories
|
|
548
|
-
};
|
|
549
|
-
const state = (0, import_reducer.default)(
|
|
550
|
-
{ categoriesBySlug: defaultState, abilitiesByName: {} },
|
|
551
|
-
action
|
|
552
|
-
);
|
|
553
|
-
const category = state.categoriesBySlug.minimal;
|
|
554
|
-
expect(category.slug).toBe("minimal");
|
|
555
|
-
expect(category.label).toBe("Minimal");
|
|
556
|
-
expect(category.description).toBe(
|
|
557
|
-
"Minimal category with undefined meta"
|
|
558
|
-
);
|
|
559
|
-
expect(category).not.toHaveProperty("meta");
|
|
560
|
-
});
|
|
561
|
-
});
|
|
562
|
-
describe("REGISTER_ABILITY_CATEGORY", () => {
|
|
563
|
-
it("should add category to the state", () => {
|
|
564
|
-
const category = {
|
|
565
|
-
slug: "test-category",
|
|
566
|
-
label: "Test Category",
|
|
567
|
-
description: "A test category"
|
|
568
|
-
};
|
|
569
|
-
const action = {
|
|
570
|
-
type: import_constants.REGISTER_ABILITY_CATEGORY,
|
|
571
|
-
category
|
|
572
|
-
};
|
|
573
|
-
const state = (0, import_reducer.default)(
|
|
574
|
-
{ categoriesBySlug: defaultState, abilitiesByName: {} },
|
|
575
|
-
action
|
|
576
|
-
);
|
|
577
|
-
expect(state.categoriesBySlug).toHaveProperty(
|
|
578
|
-
"test-category"
|
|
579
|
-
);
|
|
580
|
-
expect(state.categoriesBySlug["test-category"].label).toBe(
|
|
581
|
-
"Test Category"
|
|
582
|
-
);
|
|
583
|
-
});
|
|
584
|
-
it("should add category with meta to the state", () => {
|
|
585
|
-
const category = {
|
|
586
|
-
slug: "test-category",
|
|
587
|
-
label: "Test Category",
|
|
588
|
-
description: "A test category",
|
|
589
|
-
meta: { color: "blue", priority: "high" }
|
|
590
|
-
};
|
|
591
|
-
const action = {
|
|
592
|
-
type: import_constants.REGISTER_ABILITY_CATEGORY,
|
|
593
|
-
category
|
|
594
|
-
};
|
|
595
|
-
const state = (0, import_reducer.default)(
|
|
596
|
-
{ categoriesBySlug: defaultState, abilitiesByName: {} },
|
|
597
|
-
action
|
|
598
|
-
);
|
|
599
|
-
expect(
|
|
600
|
-
state.categoriesBySlug["test-category"].meta
|
|
601
|
-
).toEqual({ color: "blue", priority: "high" });
|
|
602
|
-
});
|
|
603
|
-
it("should filter out extra properties when registering", () => {
|
|
604
|
-
const category = {
|
|
605
|
-
slug: "test-category",
|
|
606
|
-
label: "Test Category",
|
|
607
|
-
description: "A test category",
|
|
608
|
-
// Extra properties that should be filtered out
|
|
609
|
-
_links: { self: { href: "/test" } },
|
|
610
|
-
_embedded: { author: { id: 1 } },
|
|
611
|
-
extra_field: "should be removed"
|
|
612
|
-
};
|
|
613
|
-
const action = {
|
|
614
|
-
type: import_constants.REGISTER_ABILITY_CATEGORY,
|
|
615
|
-
category
|
|
616
|
-
};
|
|
617
|
-
const state = (0, import_reducer.default)(
|
|
618
|
-
{ categoriesBySlug: defaultState, abilitiesByName: {} },
|
|
619
|
-
action
|
|
620
|
-
);
|
|
621
|
-
const registeredCategory = state.categoriesBySlug["test-category"];
|
|
622
|
-
expect(registeredCategory.slug).toBe("test-category");
|
|
623
|
-
expect(registeredCategory.label).toBe("Test Category");
|
|
624
|
-
expect(registeredCategory.description).toBe(
|
|
625
|
-
"A test category"
|
|
626
|
-
);
|
|
627
|
-
expect(registeredCategory).not.toHaveProperty("_links");
|
|
628
|
-
expect(registeredCategory).not.toHaveProperty("_embedded");
|
|
629
|
-
expect(registeredCategory).not.toHaveProperty(
|
|
630
|
-
"extra_field"
|
|
631
|
-
);
|
|
632
|
-
});
|
|
633
|
-
it("should replace existing category", () => {
|
|
634
|
-
const initialState = {
|
|
635
|
-
"test-category": {
|
|
636
|
-
slug: "test-category",
|
|
637
|
-
label: "Old Label",
|
|
638
|
-
description: "Old description"
|
|
639
|
-
}
|
|
640
|
-
};
|
|
641
|
-
const category = {
|
|
642
|
-
slug: "test-category",
|
|
643
|
-
label: "New Label",
|
|
644
|
-
description: "New description",
|
|
645
|
-
meta: { color: "red" }
|
|
646
|
-
};
|
|
647
|
-
const action = {
|
|
648
|
-
type: import_constants.REGISTER_ABILITY_CATEGORY,
|
|
649
|
-
category
|
|
650
|
-
};
|
|
651
|
-
const state = (0, import_reducer.default)(
|
|
652
|
-
{ categoriesBySlug: initialState, abilitiesByName: {} },
|
|
653
|
-
action
|
|
654
|
-
);
|
|
655
|
-
expect(state.categoriesBySlug["test-category"].label).toBe(
|
|
656
|
-
"New Label"
|
|
657
|
-
);
|
|
658
|
-
expect(
|
|
659
|
-
state.categoriesBySlug["test-category"].description
|
|
660
|
-
).toBe("New description");
|
|
661
|
-
expect(
|
|
662
|
-
state.categoriesBySlug["test-category"].meta
|
|
663
|
-
).toEqual({ color: "red" });
|
|
664
|
-
});
|
|
665
|
-
it("should handle undefined category", () => {
|
|
666
|
-
const action = {
|
|
667
|
-
type: import_constants.REGISTER_ABILITY_CATEGORY,
|
|
668
|
-
category: void 0
|
|
669
|
-
};
|
|
670
|
-
const state = (0, import_reducer.default)(
|
|
671
|
-
{ categoriesBySlug: defaultState, abilitiesByName: {} },
|
|
672
|
-
action
|
|
673
|
-
);
|
|
674
|
-
expect(state.categoriesBySlug).toEqual(defaultState);
|
|
675
|
-
});
|
|
676
|
-
});
|
|
677
|
-
describe("UNREGISTER_ABILITY_CATEGORY", () => {
|
|
678
|
-
it("should remove category from the state", () => {
|
|
679
|
-
const initialState = {
|
|
680
|
-
category1: {
|
|
681
|
-
slug: "category1",
|
|
682
|
-
label: "Category 1",
|
|
683
|
-
description: "First category"
|
|
684
|
-
},
|
|
685
|
-
category2: {
|
|
686
|
-
slug: "category2",
|
|
687
|
-
label: "Category 2",
|
|
688
|
-
description: "Second category"
|
|
689
|
-
}
|
|
690
|
-
};
|
|
691
|
-
const action = {
|
|
692
|
-
type: import_constants.UNREGISTER_ABILITY_CATEGORY,
|
|
693
|
-
slug: "category1"
|
|
694
|
-
};
|
|
695
|
-
const state = (0, import_reducer.default)(
|
|
696
|
-
{ categoriesBySlug: initialState, abilitiesByName: {} },
|
|
697
|
-
action
|
|
698
|
-
);
|
|
699
|
-
expect(state.categoriesBySlug).not.toHaveProperty(
|
|
700
|
-
"category1"
|
|
701
|
-
);
|
|
702
|
-
expect(state.categoriesBySlug).toHaveProperty("category2");
|
|
703
|
-
});
|
|
704
|
-
it("should handle unregistering non-existent category", () => {
|
|
705
|
-
const initialState = {
|
|
706
|
-
"test-category": {
|
|
707
|
-
slug: "test-category",
|
|
708
|
-
label: "Test Category",
|
|
709
|
-
description: "A test category"
|
|
710
|
-
}
|
|
711
|
-
};
|
|
712
|
-
const action = {
|
|
713
|
-
type: import_constants.UNREGISTER_ABILITY_CATEGORY,
|
|
714
|
-
slug: "non-existent"
|
|
715
|
-
};
|
|
716
|
-
const state = (0, import_reducer.default)(
|
|
717
|
-
{ categoriesBySlug: initialState, abilitiesByName: {} },
|
|
718
|
-
action
|
|
719
|
-
);
|
|
720
|
-
expect(state.categoriesBySlug).toEqual(initialState);
|
|
721
|
-
});
|
|
722
|
-
it("should handle undefined slug", () => {
|
|
723
|
-
const initialState = {
|
|
724
|
-
"test-category": {
|
|
725
|
-
slug: "test-category",
|
|
726
|
-
label: "Test Category",
|
|
727
|
-
description: "A test category"
|
|
728
|
-
}
|
|
729
|
-
};
|
|
730
|
-
const action = {
|
|
731
|
-
type: import_constants.UNREGISTER_ABILITY_CATEGORY,
|
|
732
|
-
slug: void 0
|
|
733
|
-
};
|
|
734
|
-
const state = (0, import_reducer.default)(
|
|
735
|
-
{ categoriesBySlug: initialState, abilitiesByName: {} },
|
|
736
|
-
action
|
|
737
|
-
);
|
|
738
|
-
expect(state.categoriesBySlug).toEqual(initialState);
|
|
739
|
-
});
|
|
740
|
-
});
|
|
741
|
-
});
|
|
742
|
-
});
|
|
743
|
-
//# sourceMappingURL=reducer.test.js.map
|