|
| 1 | +/* |
| 2 | + * Copyright OpenSearch Contributors |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +import { httpServiceMock } from '../../../../core/public/mocks'; |
| 7 | +import { duplicateSavedObjects } from './duplicate_saved_objects'; |
| 8 | + |
| 9 | +describe('copy saved objects', () => { |
| 10 | + const httpClient = httpServiceMock.createStartContract(); |
| 11 | + const objects = [ |
| 12 | + { type: 'dashboard', id: '1' }, |
| 13 | + { type: 'visualization', id: '2' }, |
| 14 | + ]; |
| 15 | + const targetWorkspace = '1'; |
| 16 | + |
| 17 | + it('make http call with all parameter provided', async () => { |
| 18 | + const includeReferencesDeep = true; |
| 19 | + await duplicateSavedObjects(httpClient, objects, targetWorkspace, includeReferencesDeep); |
| 20 | + expect(httpClient.post).toMatchInlineSnapshot(` |
| 21 | + [MockFunction] { |
| 22 | + "calls": Array [ |
| 23 | + Array [ |
| 24 | + "/api/workspaces/_duplicate_saved_objects", |
| 25 | + Object { |
| 26 | + "body": "{\\"objects\\":[{\\"type\\":\\"dashboard\\",\\"id\\":\\"1\\"},{\\"type\\":\\"visualization\\",\\"id\\":\\"2\\"}],\\"includeReferencesDeep\\":true,\\"targetWorkspace\\":\\"1\\"}", |
| 27 | + }, |
| 28 | + ], |
| 29 | + ], |
| 30 | + "results": Array [ |
| 31 | + Object { |
| 32 | + "type": "return", |
| 33 | + "value": undefined, |
| 34 | + }, |
| 35 | + ], |
| 36 | + } |
| 37 | + `); |
| 38 | + }); |
| 39 | + |
| 40 | + it('make http call without includeReferencesDeep parameter provided', async () => { |
| 41 | + await duplicateSavedObjects(httpClient, objects, targetWorkspace); |
| 42 | + expect(httpClient.post).toMatchInlineSnapshot(` |
| 43 | + [MockFunction] { |
| 44 | + "calls": Array [ |
| 45 | + Array [ |
| 46 | + "/api/workspaces/_duplicate_saved_objects", |
| 47 | + Object { |
| 48 | + "body": "{\\"objects\\":[{\\"type\\":\\"dashboard\\",\\"id\\":\\"1\\"},{\\"type\\":\\"visualization\\",\\"id\\":\\"2\\"}],\\"includeReferencesDeep\\":true,\\"targetWorkspace\\":\\"1\\"}", |
| 49 | + }, |
| 50 | + ], |
| 51 | + Array [ |
| 52 | + "/api/workspaces/_duplicate_saved_objects", |
| 53 | + Object { |
| 54 | + "body": "{\\"objects\\":[{\\"type\\":\\"dashboard\\",\\"id\\":\\"1\\"},{\\"type\\":\\"visualization\\",\\"id\\":\\"2\\"}],\\"includeReferencesDeep\\":true,\\"targetWorkspace\\":\\"1\\"}", |
| 55 | + }, |
| 56 | + ], |
| 57 | + ], |
| 58 | + "results": Array [ |
| 59 | + Object { |
| 60 | + "type": "return", |
| 61 | + "value": undefined, |
| 62 | + }, |
| 63 | + Object { |
| 64 | + "type": "return", |
| 65 | + "value": undefined, |
| 66 | + }, |
| 67 | + ], |
| 68 | + } |
| 69 | + `); |
| 70 | + }); |
| 71 | +}); |
0 commit comments