@openmrs/esm-stock-management-app 3.3.2-pre.231 → 3.3.2-pre.232

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.
@@ -0,0 +1,57 @@
1
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
2
+ import { type FetchResponse, openmrsFetch, restBaseUrl } from '@openmrs/esm-framework';
3
+ import { type StockRule } from '../../../core/api/types/stockItem/StockRule';
4
+ import { createOrUpdateStockRule } from './stock-rules.resource';
5
+
6
+ describe('createOrUpdateStockRule', () => {
7
+ beforeEach(() => {
8
+ vi.mocked(openmrsFetch).mockResolvedValue({} as FetchResponse);
9
+ });
10
+
11
+ it('sends only updatable properties when editing a stock rule', async () => {
12
+ const rule = {
13
+ uuid: 'rule-uuid',
14
+ stockItemUuid: 'item-uuid',
15
+ name: 'Updated rule',
16
+ description: 'Description',
17
+ locationUuid: 'location-uuid',
18
+ locationName: 'Location',
19
+ quantity: 5,
20
+ stockItemPackagingUOMUuid: 'packaging-uom-uuid',
21
+ packagingUomName: 'Box',
22
+ enabled: true,
23
+ evaluationFrequency: 60,
24
+ lastEvaluation: new Date('2025-01-01T00:00:00Z'),
25
+ nextEvaluation: new Date('2025-01-02T00:00:00Z'),
26
+ lastActionDate: new Date('2025-01-01T00:00:00Z'),
27
+ actionFrequency: 120,
28
+ alertRole: 'Pharmacist',
29
+ mailRole: 'Manager',
30
+ permission: { canView: true, canEdit: true },
31
+ enableDescendants: false,
32
+ dateCreated: new Date('2024-01-01T00:00:00Z'),
33
+ nextActionDate: new Date('2025-01-03T00:00:00Z'),
34
+ } as StockRule;
35
+
36
+ await createOrUpdateStockRule(rule);
37
+
38
+ expect(openmrsFetch).toHaveBeenCalledWith(
39
+ `${restBaseUrl}/stockmanagement/stockrule/rule-uuid`,
40
+ expect.objectContaining({
41
+ method: 'POST',
42
+ body: {
43
+ name: 'Updated rule',
44
+ description: 'Description',
45
+ quantity: 5,
46
+ stockItemPackagingUOMUuid: 'packaging-uom-uuid',
47
+ enabled: true,
48
+ evaluationFrequency: 60,
49
+ actionFrequency: 120,
50
+ alertRole: 'Pharmacist',
51
+ mailRole: 'Manager',
52
+ enableDescendants: false,
53
+ },
54
+ }),
55
+ );
56
+ });
57
+ });
@@ -55,9 +55,9 @@ export function deleteStockRule(ids: string[]) {
55
55
 
56
56
  // Create Or Update Stock Rule
57
57
  export function createOrUpdateStockRule(item: StockRule) {
58
- const isNew = item.uuid != null;
58
+ const isUpdate = item.uuid != null;
59
59
 
60
- const apiUrl = `${restBaseUrl}/stockmanagement/stockrule${isNew ? '/' + item.uuid : ''}`;
60
+ const apiUrl = `${restBaseUrl}/stockmanagement/stockrule${isUpdate ? '/' + item.uuid : ''}`;
61
61
  const abortController = new AbortController();
62
62
  return openmrsFetch(apiUrl, {
63
63
  method: 'POST',
@@ -65,7 +65,19 @@ export function createOrUpdateStockRule(item: StockRule) {
65
65
  'Content-Type': 'application/json',
66
66
  },
67
67
  signal: abortController.signal,
68
- // body: { ...item, sourceType: item?.sourceType?.uuid },
69
- body: { ...item },
68
+ body: isUpdate
69
+ ? {
70
+ name: item.name,
71
+ description: item.description,
72
+ quantity: item.quantity,
73
+ stockItemPackagingUOMUuid: item.stockItemPackagingUOMUuid,
74
+ enabled: item.enabled,
75
+ evaluationFrequency: item.evaluationFrequency,
76
+ actionFrequency: item.actionFrequency,
77
+ alertRole: item.alertRole,
78
+ mailRole: item.mailRole,
79
+ enableDescendants: item.enableDescendants,
80
+ }
81
+ : { ...item },
70
82
  });
71
83
  }
@@ -122,6 +122,7 @@
122
122
  "errorDeletingRule": "Error deleting a rule",
123
123
  "errorDeletingSource": "Error deleting a source",
124
124
  "errorDeletingUserScope": "Error deleting a user scope",
125
+ "errorEditingRule": "Error editing a rule",
125
126
  "errorEditingStockItem": "Error editing a stock Item",
126
127
  "errorFetchingStockSourceTypes": "Error fetching stock source types",
127
128
  "errorLoadingStockOperation": "Error loading stock operation",
@@ -374,6 +375,7 @@
374
375
  "stockReportsTableHeader": "List of reports requested by users.",
375
376
  "stockRuleAddedSuccessfully": "Stock rule added successfully",
376
377
  "stockRuleDeletedSuccessfully": "Stock Rule Deleted Successfully",
378
+ "stockRuleEditedSuccessfully": "Stock rule edited successfully",
377
379
  "stockRules": "Stock rules",
378
380
  "stockSource": "Stock source",
379
381
  "stockSourceAddedSuccessfully": "Stock source added successfully",