Commit 846a80eb authored by Clement Ho's avatar Clement Ho

Merge branch '46032/deploy-keys-axios' into 'master'

refactor "deploy_keys" to use axios

See merge request gitlab-org/gitlab-ce!18792
parents f0a0da69 0cc349f0
import Vue from 'vue'; import axios from '~/lib/utils/axios_utils';
import VueResource from 'vue-resource';
Vue.use(VueResource);
export default class DeployKeysService { export default class DeployKeysService {
constructor(endpoint) { constructor(endpoint) {
this.endpoint = endpoint; this.axios = axios.create({
baseURL: endpoint,
this.resource = Vue.resource( });
`${this.endpoint}{/id}`,
{},
{
enable: {
method: 'PUT',
url: `${this.endpoint}{/id}/enable`,
},
disable: {
method: 'PUT',
url: `${this.endpoint}{/id}/disable`,
},
},
);
} }
getKeys() { getKeys() {
return this.resource.get().then(response => response.json()); return this.axios.get()
.then(response => response.data);
} }
enableKey(id) { enableKey(id) {
return this.resource.enable({ id }, {}); return this.axios.put(`${id}/enable`)
.then(response => response.data);
} }
disableKey(id) { disableKey(id) {
return this.resource.disable({ id }, {}); return this.axios.put(`${id}/disable`)
.then(response => response.data);
} }
} }
import _ from 'underscore';
import Vue from 'vue'; import Vue from 'vue';
import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
import eventHub from '~/deploy_keys/eventhub'; import eventHub from '~/deploy_keys/eventhub';
import deployKeysApp from '~/deploy_keys/components/app.vue'; import deployKeysApp from '~/deploy_keys/components/app.vue';
import { TEST_HOST } from 'spec/test_constants';
describe('Deploy keys app component', () => { describe('Deploy keys app component', () => {
const data = getJSONFixture('deploy_keys/keys.json'); const data = getJSONFixture('deploy_keys/keys.json');
let vm; let vm;
let mock;
const deployKeysResponse = (request, next) => { beforeEach((done) => {
next( // setup axios mock before component
request.respondWith(JSON.stringify(data), { mock = new MockAdapter(axios);
status: 200, mock.onGet(`${TEST_HOST}/dummy/`).replyOnce(200, data);
}),
);
};
beforeEach(done => {
const Component = Vue.extend(deployKeysApp); const Component = Vue.extend(deployKeysApp);
Vue.http.interceptors.push(deployKeysResponse);
vm = new Component({ vm = new Component({
propsData: { propsData: {
endpoint: '/test', endpoint: `${TEST_HOST}/dummy`,
projectId: '8', projectId: '8',
}, },
}).$mount(); }).$mount();
...@@ -31,7 +28,7 @@ describe('Deploy keys app component', () => { ...@@ -31,7 +28,7 @@ describe('Deploy keys app component', () => {
}); });
afterEach(() => { afterEach(() => {
Vue.http.interceptors = _.without(Vue.http.interceptors, deployKeysResponse); mock.restore();
}); });
it('renders loading icon', done => { it('renders loading icon', done => {
......
...@@ -444,9 +444,9 @@ aws4@^1.2.1, aws4@^1.6.0: ...@@ -444,9 +444,9 @@ aws4@^1.2.1, aws4@^1.6.0:
version "1.6.0" version "1.6.0"
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.6.0.tgz#83ef5ca860b2b32e4a0deedee8c771b9db57471e" resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.6.0.tgz#83ef5ca860b2b32e4a0deedee8c771b9db57471e"
axios-mock-adapter@^1.10.0: axios-mock-adapter@^1.15.0:
version "1.10.0" version "1.15.0"
resolved "https://registry.yarnpkg.com/axios-mock-adapter/-/axios-mock-adapter-1.10.0.tgz#3ccee65466439a2c7567e932798fc0377d39209d" resolved "https://registry.yarnpkg.com/axios-mock-adapter/-/axios-mock-adapter-1.15.0.tgz#fbc06825d8302c95c3334d21023bba996255d45d"
dependencies: dependencies:
deep-equal "^1.0.1" deep-equal "^1.0.1"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment