|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +import mockAxios from '../../../mock/mockAxios' |
| 19 | +import AddObjectStorage from '@/views/infra/AddObjectStorage' |
| 20 | + |
| 21 | +jest.mock('axios', () => mockAxios) |
| 22 | +jest.mock('@/vue-app', () => ({ |
| 23 | + vueProps: { |
| 24 | + $localStorage: { |
| 25 | + get: jest.fn(() => null) |
| 26 | + } |
| 27 | + } |
| 28 | +})) |
| 29 | + |
| 30 | +describe('Views > infra > AddObjectStorage.vue', () => { |
| 31 | + beforeEach(() => { |
| 32 | + mockAxios.mockReset() |
| 33 | + }) |
| 34 | + |
| 35 | + it('submits addObjectStoragePool using POST with the request in the body', async () => { |
| 36 | + mockAxios.mockResolvedValue({}) |
| 37 | + |
| 38 | + const params = { |
| 39 | + name: 'test-store', |
| 40 | + provider: 'MinIO', |
| 41 | + url: 'https://object-storage.example.test', |
| 42 | + 'details[0].key': 'accesskey', |
| 43 | + 'details[0].value': 'test-access-key', |
| 44 | + 'details[1].key': 'secretkey', |
| 45 | + 'details[1].value': 'test-secret-key' |
| 46 | + } |
| 47 | + |
| 48 | + await AddObjectStorage.methods.addObjectStore(params) |
| 49 | + |
| 50 | + expect(mockAxios).toHaveBeenCalledTimes(1) |
| 51 | + const request = mockAxios.mock.calls[0][0] |
| 52 | + expect(request).toMatchObject({ |
| 53 | + url: '/', |
| 54 | + method: 'POST' |
| 55 | + }) |
| 56 | + expect(request.params).toBeUndefined() |
| 57 | + expect(request.data).toBeInstanceOf(URLSearchParams) |
| 58 | + expect(request.data.get('command')).toBe('addObjectStoragePool') |
| 59 | + expect(request.data.get('response')).toBe('json') |
| 60 | + expect(request.data.get('url')).toBe(params.url) |
| 61 | + expect(request.data.get('details[0].value')).toBe(params['details[0].value']) |
| 62 | + expect(request.data.get('details[1].value')).toBe(params['details[1].value']) |
| 63 | + }) |
| 64 | + |
| 65 | + it('propagates an addObjectStoragePool API failure', async () => { |
| 66 | + const error = new Error('request failed') |
| 67 | + mockAxios.mockRejectedValue(error) |
| 68 | + |
| 69 | + await expect(AddObjectStorage.methods.addObjectStore({})).rejects.toBe(error) |
| 70 | + }) |
| 71 | +}) |
0 commit comments