npm package diff
Package: @forge/react
Versions: 10.10.2-next.0-experimental-d6acbbd - 10.10.3-next.0
File: package/out/hooks/__test__/confluenceEntity.test.js
Index: package/out/hooks/__test__/confluenceEntity.test.js
===================================================================
--- package/out/hooks/__test__/confluenceEntity.test.js
+++ package/out/hooks/__test__/confluenceEntity.test.js
@@ -125,8 +125,38 @@
mockRequestConf.mockReset();
mockRequestConf.mockResolvedValueOnce(mockPropertyHook_1.mockConfGetExistingRes).mockResolvedValueOnce(mockPropertyHook_1.mockFailedRes);
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).`);
});
+ describe('if the property does not exist, it should create it', () => {
+ beforeEach(() => {
+ mockRequestConf.mockReset();
+ mockRequestConf
+ .mockResolvedValueOnce(mockPropertyHook_1.mockConfGetNonExistentRes)
+ .mockResolvedValueOnce(mockPropertyHook_1.mockConfCreateRes)
+ .mockResolvedValueOnce(mockPropertyHook_1.mockConfUpdateValueRes);
+ });
+ it('should make a POST request to the API with the right URL and body', async () => {
+ const contentGetUrl = contentEndpoints.fetch('forge-MOCK_LOCAL_ID-MOCK_PROP_KEY');
+ const contentGetBody = expect.objectContaining({ method: 'GET' });
+ const contentPutUrl = contentEndpoints.update('MOCK_PROP_ID');
+ const contentPostUrl = contentEndpoints.create();
+ const contentPostBody = expect.objectContaining({
+ method: 'POST',
+ body: JSON.stringify({ key: 'forge-MOCK_LOCAL_ID-MOCK_PROP_KEY', value: mockPropertyHook_1.DEFAULT_PROP_VALUE })
+ });
+ // both value & version props need to be present in body string
+ const valueUpdateStr = `"value":${mockPropertyHook_1.UPDATED_PROP_VALUE}`;
+ const contentPutBody = (updateStr) => expect.objectContaining({
+ body: expect.stringContaining(updateStr)
+ });
+ const valUpdate = await contentEntity.update(mockPropertyHook_1.UPDATED_PROP_VALUE);
+ expect(valUpdate).toEqual(mockPropertyHook_1.UPDATED_PROP_VALUE);
+ expect(mockRequestConf).toHaveBeenCalledTimes(3);
+ expect(mockRequestConf).toHaveBeenNthCalledWith(1, contentGetUrl, contentGetBody);
+ expect(mockRequestConf).toHaveBeenNthCalledWith(2, contentPostUrl, contentPostBody);
+ expect(mockRequestConf).toHaveBeenNthCalledWith(3, contentPutUrl, contentPutBody(valueUpdateStr));
+ });
+ });
});
describe('when running its delete() output function', () => {
beforeEach(() => {
mockRequestConf.mockResolvedValueOnce(mockPropertyHook_1.mockConfGetExistingRes).mockResolvedValueOnce(mockPropertyHook_1.mockConfDeleteRes);