-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathupdateAssetURLForGQL.test.ts
More file actions
47 lines (36 loc) · 1.86 KB
/
updateAssetURLForGQL.test.ts
File metadata and controls
47 lines (36 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { updateAssetURLForGQL } from '../src/updateAssetURLForGQL';
import { gqlResponseForAssetUpdate, gqlResponseForAssetUpdateWithoutSystemUid, gqlResponseForAssetUpdateMultipleEntries } from './mock/gql-asset-url-update-mock';
describe('updateAssetURLForGQL test', () => {
it('should update the asset URL in the GQL response when proper response is passed', done => {
const testResponse = { ...gqlResponseForAssetUpdate };
updateAssetURLForGQL(testResponse);
const rteField = testResponse.data.page_json_rte.rte_2;
const assetLink = rteField.json.children[0].attrs['asset-link'];
const expectedUrl = rteField.embedded_itemsConnection.edges[0].node.url;
expect(assetLink).toBe(expectedUrl);
done();
});
it('should update the asset URL in the GQL response with multiple entries when proper response is passed', done => {
const testResponse = { ...gqlResponseForAssetUpdateMultipleEntries };
updateAssetURLForGQL(testResponse);
const rteField = testResponse.data.page_json_rte.items[0].body_new[0].body.body_12;
const assetLink = rteField.json.children[0].attrs['asset-link'];
const expectedUrl = rteField.embedded_itemsConnection.edges[0].node.url;
expect(assetLink).toBe(expectedUrl);
done();
});
it('should throw error when system.uid is not present', done => {
jest.spyOn(console, 'error').mockImplementation(() => {});
const testResponse = { ...gqlResponseForAssetUpdateWithoutSystemUid };
updateAssetURLForGQL(testResponse);
expect(console.error).toHaveBeenCalledWith(
'Error in updating asset URL for GQL response',
expect.any(Error) // Expecting any Error object
);
expect(console.error).toHaveBeenCalledWith(
'Error in updating asset URL for GQL response',
new Error('Asset UID not found in the response') // Expecting any Error object
);
done();
});
});