@forge/react 10.10.2 → 10.10.3-next.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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @forge/react
2
2
 
3
+ ## 10.10.3-next.0
4
+
5
+ ### Patch Changes
6
+
7
+ - ea9fa2a: Fix update method in useSpaceProperty to ensure it works as expect when value does not exist
8
+
3
9
  ## 10.10.2
4
10
 
5
11
  ### Patch Changes
@@ -126,6 +126,36 @@ describe('confluenceEntity', () => {
126
126
  mockRequestConf.mockResolvedValueOnce(mockPropertyHook_1.mockConfGetExistingRes).mockResolvedValueOnce(mockPropertyHook_1.mockFailedRes);
127
127
  await expect(() => contentEntity.update(mockPropertyHook_1.UPDATED_PROP_VALUE)).rejects.toThrow(`The request to update the content property (forge-MOCK_LOCAL_ID-MOCK_PROP_KEY) failed with status (400).`);
128
128
  });
129
+ describe('if the property does not exist, it should create it', () => {
130
+ beforeEach(() => {
131
+ mockRequestConf.mockReset();
132
+ mockRequestConf
133
+ .mockResolvedValueOnce(mockPropertyHook_1.mockConfGetNonExistentRes)
134
+ .mockResolvedValueOnce(mockPropertyHook_1.mockConfCreateRes)
135
+ .mockResolvedValueOnce(mockPropertyHook_1.mockConfUpdateValueRes);
136
+ });
137
+ it('should make a POST request to the API with the right URL and body', async () => {
138
+ const contentGetUrl = contentEndpoints.fetch('forge-MOCK_LOCAL_ID-MOCK_PROP_KEY');
139
+ const contentGetBody = expect.objectContaining({ method: 'GET' });
140
+ const contentPutUrl = contentEndpoints.update('MOCK_PROP_ID');
141
+ const contentPostUrl = contentEndpoints.create();
142
+ const contentPostBody = expect.objectContaining({
143
+ method: 'POST',
144
+ body: JSON.stringify({ key: 'forge-MOCK_LOCAL_ID-MOCK_PROP_KEY', value: mockPropertyHook_1.DEFAULT_PROP_VALUE })
145
+ });
146
+ // both value & version props need to be present in body string
147
+ const valueUpdateStr = `"value":${mockPropertyHook_1.UPDATED_PROP_VALUE}`;
148
+ const contentPutBody = (updateStr) => expect.objectContaining({
149
+ body: expect.stringContaining(updateStr)
150
+ });
151
+ const valUpdate = await contentEntity.update(mockPropertyHook_1.UPDATED_PROP_VALUE);
152
+ expect(valUpdate).toEqual(mockPropertyHook_1.UPDATED_PROP_VALUE);
153
+ expect(mockRequestConf).toHaveBeenCalledTimes(3);
154
+ expect(mockRequestConf).toHaveBeenNthCalledWith(1, contentGetUrl, contentGetBody);
155
+ expect(mockRequestConf).toHaveBeenNthCalledWith(2, contentPostUrl, contentPostBody);
156
+ expect(mockRequestConf).toHaveBeenNthCalledWith(3, contentPutUrl, contentPutBody(valueUpdateStr));
157
+ });
158
+ });
129
159
  });
130
160
  describe('when running its delete() output function', () => {
131
161
  beforeEach(() => {
@@ -1 +1 @@
1
- {"version":3,"file":"confluenceEntity.d.ts","sourceRoot":"","sources":["../../src/hooks/confluenceEntity.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,uBAAuB,EAEvB,eAAe,EACf,oBAAoB,EACpB,aAAa,EAEd,MAAM,SAAS,CAAC;AAEjB;;;GAGG;AACH,eAAO,MAAM,gBAAgB,4BAA6B,uBAAuB;;yBAqBxD,MAAM;yBACN,MAAM;yBACN,MAAM;CAE9B,CAAC;AAEF,eAAO,MAAM,gBAAgB;gBAIiB,oBAAoB;8BAqGjE,CAAC"}
1
+ {"version":3,"file":"confluenceEntity.d.ts","sourceRoot":"","sources":["../../src/hooks/confluenceEntity.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,uBAAuB,EAEvB,eAAe,EACf,oBAAoB,EACpB,aAAa,EAEd,MAAM,SAAS,CAAC;AAEjB;;;GAGG;AACH,eAAO,MAAM,gBAAgB,4BAA6B,uBAAuB;;yBAqBxD,MAAM;yBACN,MAAM;yBACN,MAAM;CAE9B,CAAC;AAEF,eAAO,MAAM,gBAAgB;gBAIiB,oBAAoB;8BAkGjE,CAAC"}
@@ -69,10 +69,10 @@ const confluenceEntity = ({ entityType, origPropertyKey, initValue }) => {
69
69
  const response = await (0, apiRequestUtils_1.makeRequest)({ url, apiMethod, method: 'DELETE' });
70
70
  (0, apiRequestUtils_1.assertSuccessfulResponse)({ entityType, propertyKey, operation: 'delete', response });
71
71
  };
72
- const get = async ({ endpointFactory, propertyKey }) => {
72
+ const getProp = async ({ endpointFactory, propertyKey }) => {
73
73
  const existingProp = await fetchOriginal({ endpointFactory, propertyKey });
74
74
  if (existingProp) {
75
- return existingProp.value;
75
+ return existingProp;
76
76
  }
77
77
  // if property doesn't exist, create it
78
78
  const resolvedInitVal = await (0, valueUtils_1.resolveValue)(initValue);
@@ -80,19 +80,15 @@ const confluenceEntity = ({ entityType, origPropertyKey, initValue }) => {
80
80
  const body = JSON.stringify({ key: propertyKey, value: resolvedInitVal });
81
81
  const response = await (0, apiRequestUtils_1.makeRequest)({ url, apiMethod, method: 'POST', body });
82
82
  (0, apiRequestUtils_1.assertSuccessfulResponse)({ entityType, propertyKey, operation: 'create', response });
83
- return (await (0, apiRequestUtils_1.getJSONData)(response)).value;
83
+ return await (0, apiRequestUtils_1.getJSONData)(response);
84
+ };
85
+ const get = async ({ endpointFactory, propertyKey }) => {
86
+ const propData = await getProp({ endpointFactory, propertyKey });
87
+ return propData.value;
84
88
  };
85
89
  const update = async ({ endpointFactory, propertyKey }, valueUpdate) => {
86
90
  // fetch original prop first to update based on its value + version + id
87
- const originalProp = await fetchOriginal({ endpointFactory, propertyKey });
88
- if (!originalProp) {
89
- throw new types_1.EntityPropertyRequestFailedError({
90
- entityType,
91
- propertyKey,
92
- operation: 'update',
93
- status: 404
94
- });
95
- }
91
+ const originalProp = await getProp({ endpointFactory, propertyKey });
96
92
  const newValue = valueUpdate instanceof Function ? valueUpdate(originalProp.value) : valueUpdate;
97
93
  const propertyId = originalProp.id;
98
94
  const origVersion = originalProp?.version?.number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forge/react",
3
- "version": "10.10.2",
3
+ "version": "10.10.3-next.0",
4
4
  "description": "Forge React reconciler",
5
5
  "author": "Atlassian",
6
6
  "license": "UNLICENSED",