Commit 47fe2a52 authored by Phil Hughes's avatar Phil Hughes

more specs!

parent d4fce4dc
...@@ -10,8 +10,7 @@ export const getMergeRequestData = ( ...@@ -10,8 +10,7 @@ export const getMergeRequestData = (
if (!state.projects[projectId].mergeRequests[mergeRequestId] || force) { if (!state.projects[projectId].mergeRequests[mergeRequestId] || force) {
service service
.getProjectMergeRequestData(projectId, mergeRequestId) .getProjectMergeRequestData(projectId, mergeRequestId)
.then(res => res.data) .then(({ data }) => {
.then(data => {
commit(types.SET_MERGE_REQUEST, { commit(types.SET_MERGE_REQUEST, {
projectPath: projectId, projectPath: projectId,
mergeRequestId, mergeRequestId,
...@@ -45,8 +44,7 @@ export const getMergeRequestChanges = ( ...@@ -45,8 +44,7 @@ export const getMergeRequestChanges = (
if (!state.projects[projectId].mergeRequests[mergeRequestId].changes.length || force) { if (!state.projects[projectId].mergeRequests[mergeRequestId].changes.length || force) {
service service
.getProjectMergeRequestChanges(projectId, mergeRequestId) .getProjectMergeRequestChanges(projectId, mergeRequestId)
.then(res => res.data) .then(({ data }) => {
.then(data => {
commit(types.SET_MERGE_REQUEST_CHANGES, { commit(types.SET_MERGE_REQUEST_CHANGES, {
projectPath: projectId, projectPath: projectId,
mergeRequestId, mergeRequestId,
......
import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
import store from '~/ide/stores'; import store from '~/ide/stores';
import {
getMergeRequestData,
getMergeRequestChanges,
getMergeRequestVersions,
} from '~/ide/stores/actions/merge_request';
import service from '~/ide/services'; import service from '~/ide/services';
import { resetStore } from '../../helpers'; import { resetStore } from '../../helpers';
describe('IDE store merge request actions', () => { describe('IDE store merge request actions', () => {
let mock;
beforeEach(() => { beforeEach(() => {
mock = new MockAdapter(axios);
store.state.projects.abcproject = { store.state.projects.abcproject = {
mergeRequests: {}, mergeRequests: {},
}; };
}); });
afterEach(() => { afterEach(() => {
mock.restore();
resetStore(store); resetStore(store);
}); });
describe('getMergeRequestData', () => { describe('getMergeRequestData', () => {
beforeEach(() => { describe('success', () => {
spyOn(service, 'getProjectMergeRequestData').and.returnValue( beforeEach(() => {
Promise.resolve({ data: { title: 'mergerequest' } }), spyOn(service, 'getProjectMergeRequestData').and.callThrough();
);
mock
.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests\/1/)
.reply(200, { title: 'mergerequest' });
});
it('calls getProjectMergeRequestData service method', done => {
store
.dispatch('getMergeRequestData', { projectId: 'abcproject', mergeRequestId: 1 })
.then(() => {
expect(service.getProjectMergeRequestData).toHaveBeenCalledWith('abcproject', 1);
done();
})
.catch(done.fail);
});
it('sets the Merge Request Object', done => {
store
.dispatch('getMergeRequestData', { projectId: 'abcproject', mergeRequestId: 1 })
.then(() => {
expect(store.state.projects.abcproject.mergeRequests['1'].title).toBe('mergerequest');
expect(store.state.currentMergeRequestId).toBe(1);
done();
})
.catch(done.fail);
});
}); });
it('calls getProjectMergeRequestData service method', done => { describe('error', () => {
store beforeEach(() => {
.dispatch('getMergeRequestData', { projectId: 'abcproject', mergeRequestId: 1 }) mock.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests\/1/).networkError();
.then(() => { });
expect(service.getProjectMergeRequestData).toHaveBeenCalledWith('abcproject', 1);
it('dispatches error action', done => {
done(); const dispatch = jasmine.createSpy('dispatch');
})
.catch(done.fail); getMergeRequestData(
}); {
commit() {},
it('sets the Merge Request Object', done => { dispatch,
store state: store.state,
.dispatch('getMergeRequestData', { projectId: 'abcproject', mergeRequestId: 1 }) },
.then(() => { { projectId: 'abcproject', mergeRequestId: 1 },
expect(store.state.projects.abcproject.mergeRequests['1'].title).toBe('mergerequest'); )
expect(store.state.currentMergeRequestId).toBe(1); .then(done.fail)
.catch(() => {
done(); expect(dispatch).toHaveBeenCalledWith('setErrorMessage', {
}) text: 'An error occured whilst loading the merge request.',
.catch(done.fail); action: jasmine.any(Function),
actionText: 'Please try again',
actionPayload: {
projectId: 'abcproject',
mergeRequestId: 1,
force: false,
},
});
done();
});
});
}); });
}); });
describe('getMergeRequestChanges', () => { describe('getMergeRequestChanges', () => {
beforeEach(() => { beforeEach(() => {
spyOn(service, 'getProjectMergeRequestChanges').and.returnValue(
Promise.resolve({ data: { title: 'mergerequest' } }),
);
store.state.projects.abcproject.mergeRequests['1'] = { changes: [] }; store.state.projects.abcproject.mergeRequests['1'] = { changes: [] };
}); });
it('calls getProjectMergeRequestChanges service method', done => { describe('success', () => {
store beforeEach(() => {
.dispatch('getMergeRequestChanges', { projectId: 'abcproject', mergeRequestId: 1 }) spyOn(service, 'getProjectMergeRequestChanges').and.callThrough();
.then(() => {
expect(service.getProjectMergeRequestChanges).toHaveBeenCalledWith('abcproject', 1); mock
.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests\/1\/changes/)
done(); .reply(200, { title: 'mergerequest' });
}) });
.catch(done.fail);
it('calls getProjectMergeRequestChanges service method', done => {
store
.dispatch('getMergeRequestChanges', { projectId: 'abcproject', mergeRequestId: 1 })
.then(() => {
expect(service.getProjectMergeRequestChanges).toHaveBeenCalledWith('abcproject', 1);
done();
})
.catch(done.fail);
});
it('sets the Merge Request Changes Object', done => {
store
.dispatch('getMergeRequestChanges', { projectId: 'abcproject', mergeRequestId: 1 })
.then(() => {
expect(store.state.projects.abcproject.mergeRequests['1'].changes.title).toBe(
'mergerequest',
);
done();
})
.catch(done.fail);
});
}); });
it('sets the Merge Request Changes Object', done => { describe('error', () => {
store beforeEach(() => {
.dispatch('getMergeRequestChanges', { projectId: 'abcproject', mergeRequestId: 1 }) mock.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests\/1\/changes/).networkError();
.then(() => { });
expect(store.state.projects.abcproject.mergeRequests['1'].changes.title).toBe(
'mergerequest', it('dispatches error action', done => {
); const dispatch = jasmine.createSpy('dispatch');
done();
}) getMergeRequestChanges(
.catch(done.fail); {
commit() {},
dispatch,
state: store.state,
},
{ projectId: 'abcproject', mergeRequestId: 1 },
)
.then(done.fail)
.catch(() => {
expect(dispatch).toHaveBeenCalledWith('setErrorMessage', {
text: 'An error occured whilst loading the merge request changes.',
action: jasmine.any(Function),
actionText: 'Please try again',
actionPayload: {
projectId: 'abcproject',
mergeRequestId: 1,
force: false,
},
});
done();
});
});
}); });
}); });
describe('getMergeRequestVersions', () => { describe('getMergeRequestVersions', () => {
beforeEach(() => { beforeEach(() => {
spyOn(service, 'getProjectMergeRequestVersions').and.returnValue(
Promise.resolve({ data: [{ id: 789 }] }),
);
store.state.projects.abcproject.mergeRequests['1'] = { versions: [] }; store.state.projects.abcproject.mergeRequests['1'] = { versions: [] };
}); });
it('calls getProjectMergeRequestVersions service method', done => { describe('success', () => {
store beforeEach(() => {
.dispatch('getMergeRequestVersions', { projectId: 'abcproject', mergeRequestId: 1 }) mock
.then(() => { .onGet(/api\/(.*)\/projects\/abcproject\/merge_requests\/1\/versions/)
expect(service.getProjectMergeRequestVersions).toHaveBeenCalledWith('abcproject', 1); .reply(200, [{ id: 789 }]);
spyOn(service, 'getProjectMergeRequestVersions').and.callThrough();
done(); });
})
.catch(done.fail); it('calls getProjectMergeRequestVersions service method', done => {
store
.dispatch('getMergeRequestVersions', { projectId: 'abcproject', mergeRequestId: 1 })
.then(() => {
expect(service.getProjectMergeRequestVersions).toHaveBeenCalledWith('abcproject', 1);
done();
})
.catch(done.fail);
});
it('sets the Merge Request Versions Object', done => {
store
.dispatch('getMergeRequestVersions', { projectId: 'abcproject', mergeRequestId: 1 })
.then(() => {
expect(store.state.projects.abcproject.mergeRequests['1'].versions.length).toBe(1);
done();
})
.catch(done.fail);
});
}); });
it('sets the Merge Request Versions Object', done => { describe('error', () => {
store beforeEach(() => {
.dispatch('getMergeRequestVersions', { projectId: 'abcproject', mergeRequestId: 1 }) mock.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests\/1\/versions/).networkError();
.then(() => { });
expect(store.state.projects.abcproject.mergeRequests['1'].versions.length).toBe(1);
done(); it('dispatches error action', done => {
}) const dispatch = jasmine.createSpy('dispatch');
.catch(done.fail);
getMergeRequestVersions(
{
commit() {},
dispatch,
state: store.state,
},
{ projectId: 'abcproject', mergeRequestId: 1 },
)
.then(done.fail)
.catch(() => {
expect(dispatch).toHaveBeenCalledWith('setErrorMessage', {
text: 'An error occured whilst loading the merge request version data.',
action: jasmine.any(Function),
actionText: 'Please try again',
actionPayload: {
projectId: 'abcproject',
mergeRequestId: 1,
force: false,
},
});
done();
});
});
}); });
}); });
}); });
...@@ -116,6 +116,40 @@ describe('Multi-file store tree actions', () => { ...@@ -116,6 +116,40 @@ describe('Multi-file store tree actions', () => {
done(); done();
}); });
}); });
it('dispatches error action', done => {
const dispatch = jasmine.createSpy('dispatchSpy');
store.state.projects = {
'abc/def': {
web_url: `${gl.TEST_HOST}/files`,
},
};
mock.onGet(/(.*)/).replyOnce(500);
getFiles(
{
commit() {},
dispatch,
state: store.state,
},
{
projectId: 'abc/def',
branchId: 'master-testing',
},
)
.then(done.fail)
.catch(() => {
expect(dispatch).toHaveBeenCalledWith('setErrorMessage', {
text: 'An error occured whilst loading all the files.',
action: jasmine.any(Function),
actionText: 'Please try again',
actionPayload: { projectId: 'abc/def', branchId: 'master-testing' },
});
done();
});
});
}); });
}); });
......
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