Commit 8f10fcc0 authored by Martin Wortschack's avatar Martin Wortschack

Merge branch 'Update-board_service.js-to-use-boardsStore' into 'master'

Delete board_service.js file

See merge request gitlab-org/gitlab!20141
parents 1d6332a8 8ca18878
/**
* This file is intended to be deleted.
* The existing functions will removed one by one in favor of using the board store directly.
* see https://gitlab.com/gitlab-org/gitlab-foss/issues/61621
*/
import BoardService from '~/boards/services/board_service';
import boardsStore from '~/boards/stores/boards_store';
export default class BoardServiceEE extends BoardService {
static updateWeight(endpoint, weight = null) {
return boardsStore.updateWeight(endpoint, weight);
}
}
---
title: Updated board_service.js to use boardStore directly
merge_request: 20141
author: nuwe1
type: other
import BoardServiceEE from 'ee/boards/services/board_service';
import { TEST_HOST } from 'helpers/test_constants';
import AxiosMockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
import boardsStore from '~/boards/stores/boards_store';
describe('BoardService', () => {
const dummyResponse = 'just another response in the network';
const boardId = 'dummy-board-id';
const endpoints = {
boardsEndpoint: `${TEST_HOST}/boards`,
listsEndpoint: `${TEST_HOST}/lists`,
bulkUpdatePath: `${TEST_HOST}/bulk/update`,
recentBoardsEndpoint: `${TEST_HOST}/recent/boards`,
};
let axiosMock;
beforeEach(() => {
axiosMock = new AxiosMockAdapter(axios);
boardsStore.setEndpoints({
...endpoints,
boardId,
});
});
describe('updateWeight', () => {
const dummyEndpoint = `${TEST_HOST}/update/weight`;
const weight = 'elephant';
const expectedRequest = expect.objectContaining({ data: JSON.stringify({ weight }) });
let requestSpy;
beforeEach(() => {
requestSpy = jest.fn();
axiosMock.onPut(dummyEndpoint).replyOnce(config => requestSpy(config));
});
it('makes a request to update the weight', () => {
requestSpy.mockReturnValue([200, dummyResponse]);
const expectedResponse = expect.objectContaining({ data: dummyResponse });
return expect(BoardServiceEE.updateWeight(dummyEndpoint, weight))
.resolves.toEqual(expectedResponse)
.then(() => {
expect(requestSpy).toHaveBeenCalledWith(expectedRequest);
});
});
it('fails for error response', () => {
requestSpy.mockReturnValue([500]);
return expect(BoardServiceEE.updateWeight(dummyEndpoint, weight))
.rejects.toThrow()
.then(() => {
expect(requestSpy).toHaveBeenCalledWith(expectedRequest);
});
});
});
});
...@@ -88,4 +88,39 @@ describe('BoardsStoreEE', () => { ...@@ -88,4 +88,39 @@ describe('BoardsStoreEE', () => {
expect(state.milestones).toEqual([]); expect(state.milestones).toEqual([]);
}); });
}); });
describe('updateWeight', () => {
const dummyEndpoint = `${TEST_HOST}/update/weight`;
const dummyResponse = 'just another response in the network';
const weight = 'elephant';
const expectedRequest = expect.objectContaining({ data: JSON.stringify({ weight }) });
let requestSpy;
beforeEach(() => {
requestSpy = jest.fn();
axiosMock.onPut(dummyEndpoint).replyOnce(config => requestSpy(config));
});
it('makes a request to update the weight', () => {
requestSpy.mockReturnValue([200, dummyResponse]);
const expectedResponse = expect.objectContaining({ data: dummyResponse });
return expect(BoardsStoreEE.store.updateWeight(dummyEndpoint, weight))
.resolves.toEqual(expectedResponse)
.then(() => {
expect(requestSpy).toHaveBeenCalledWith(expectedRequest);
});
});
it('fails for error response', () => {
requestSpy.mockReturnValue([500]);
return expect(BoardsStoreEE.store.updateWeight(dummyEndpoint, weight))
.rejects.toThrow()
.then(() => {
expect(requestSpy).toHaveBeenCalledWith(expectedRequest);
});
});
});
}); });
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