|
| 1 | +import { baseApi } from '../../../baseApi' |
| 2 | +import ServerActionsService from './ServerActionsService' |
| 3 | + |
| 4 | +test('list calls the correct endpoint', async () => { |
| 5 | + const mockFn = jest.spyOn(baseApi, 'get').mockResolvedValue({ |
| 6 | + data: { hello: 'world' } |
| 7 | + }) |
| 8 | + await ServerActionsService.list() |
| 9 | + expect(mockFn).toHaveBeenCalledWith('/v3/cmp/serverActions/') |
| 10 | +}) |
| 11 | + |
| 12 | +test('get calls the correct endpoint', async () => { |
| 13 | + const mockFn = jest.spyOn(baseApi, 'get').mockResolvedValue({ |
| 14 | + data: { hello: 'world' } |
| 15 | + }) |
| 16 | + await ServerActionsService.get('serverAction-id') |
| 17 | + expect(mockFn).toHaveBeenCalledWith('/v3/cmp/serverActions/serverAction-id/') |
| 18 | +}) |
| 19 | + |
| 20 | +test('create calls the correct endpoint', async () => { |
| 21 | + const mockFn = jest.spyOn(baseApi, 'post').mockResolvedValue({ |
| 22 | + data: { hello: 'world' } |
| 23 | + }) |
| 24 | + const mockServerAction = { |
| 25 | + zipFile: 'world.zip' |
| 26 | + } |
| 27 | + await ServerActionsService.create(mockServerAction) |
| 28 | + expect(mockFn).toHaveBeenCalledWith( |
| 29 | + '/v3/cmp/serverActions/', |
| 30 | + mockServerAction |
| 31 | + ) |
| 32 | +}) |
| 33 | + |
| 34 | +test('export calls the correct endpoint', async () => { |
| 35 | + const mockFn = jest.spyOn(baseApi, 'post').mockResolvedValue({ |
| 36 | + data: { hello: 'world' }, |
| 37 | + headers: { |
| 38 | + 'content-disposition': 'attachment; filename=action.zip' |
| 39 | + } |
| 40 | + }) |
| 41 | + |
| 42 | + await ServerActionsService.export('serverAction-id') |
| 43 | + expect(mockFn).toHaveBeenCalledWith( |
| 44 | + '/v3/cmp/serverActions/serverAction-id/export/', |
| 45 | + {}, |
| 46 | + { responseType: 'blob' } |
| 47 | + ) |
| 48 | +}) |
| 49 | + |
| 50 | +test('export with options calls the correct endpoint', async () => { |
| 51 | + const mockFn = jest.spyOn(baseApi, 'post').mockResolvedValue({ |
| 52 | + data: { hello: 'world' }, |
| 53 | + headers: { |
| 54 | + 'content-disposition': 'attachment; filename=action.zip' |
| 55 | + } |
| 56 | + }) |
| 57 | + const mockServerActionsOptions = { |
| 58 | + password: 'worldServerActions', |
| 59 | + instanceSpecificInfo: true |
| 60 | + } |
| 61 | + await ServerActionsService.export('serverAction-id', mockServerActionsOptions) |
| 62 | + expect(mockFn).toHaveBeenCalledWith( |
| 63 | + '/v3/cmp/serverActions/serverAction-id/export/', |
| 64 | + mockServerActionsOptions, |
| 65 | + { responseType: 'blob' } |
| 66 | + ) |
| 67 | +}) |
| 68 | + |
| 69 | +test('run calls the correct endpoint', async () => { |
| 70 | + const mockFn = jest.spyOn(baseApi, 'post').mockResolvedValue({ |
| 71 | + data: { hello: 'world' } |
| 72 | + }) |
| 73 | + const mockServerAction = { |
| 74 | + servers: ['server-href'], |
| 75 | + parameters: { |
| 76 | + param1: 'value1' |
| 77 | + } |
| 78 | + } |
| 79 | + await ServerActionsService.run('serverAction-id', mockServerAction) |
| 80 | + expect(mockFn).toHaveBeenCalledWith( |
| 81 | + '/v3/cmp/serverActions/serverAction-id/runAction/', |
| 82 | + mockServerAction |
| 83 | + ) |
| 84 | +}) |
0 commit comments