diff --git a/scm-ui/src/repos/components/changesets/ChangesetRow.js b/scm-ui/src/repos/components/changesets/ChangesetRow.js
index 645f3b8129..02a97c8da0 100644
--- a/scm-ui/src/repos/components/changesets/ChangesetRow.js
+++ b/scm-ui/src/repos/components/changesets/ChangesetRow.js
@@ -58,7 +58,7 @@ class ChangesetRow extends React.Component {
time={dateFromNow}
/>
{" "}
- {authorLine}
+ {authorLine}
diff --git a/scm-ui/src/repos/containers/Changesets.js b/scm-ui/src/repos/containers/Changesets.js
index 7e22e50055..45f72fb5a7 100644
--- a/scm-ui/src/repos/containers/Changesets.js
+++ b/scm-ui/src/repos/containers/Changesets.js
@@ -15,17 +15,15 @@ import {
fetchChangesetsByLink,
getChangesetsFromState,
fetchChangesetsByPage,
- fetchChangesetsByBranchAndPage
+ fetchChangesetsByBranchAndPage,
+ fetchChangesets
} from "../modules/changesets";
import type { History } from "history";
-import {
- fetchBranchesByNamespaceAndName,
- getBranchNames
-} from "../../repos/modules/branches";
import type { PagedCollection, Repository } from "@scm-manager/ui-types";
import ChangesetList from "../components/changesets/ChangesetList";
import DropDown from "../components/DropDown";
import { withRouter } from "react-router-dom";
+import { fetchBranches, getBranchNames } from "../modules/branches";
type Props = {
repository: Repository,
@@ -53,9 +51,9 @@ class Changesets extends React.PureComponent {
}
onPageChange = (link: string) => {
- const { namespace, name } = this.props.repository;
+ const { repository } = this.props;
const branch = this.props.match.params.branch;
- this.props.fetchChangesetsByLink(namespace, name, link, branch);
+ this.props.fetchChangesetsByLink(repository, link, branch);
};
componentDidMount() {
@@ -63,24 +61,20 @@ class Changesets extends React.PureComponent {
}
updateContent() {
- const { namespace, name } = this.props.repository;
+ const { repository } = this.props;
+
const branchName = this.props.match.params.branch;
const {
- fetchBranchesByNamespaceAndName,
fetchChangesetsByPage,
- fetchChangesetsByBranchAndPage
+ fetchChangesetsByBranchAndPage,
+ fetchBranches
} = this.props;
if (branchName) {
- fetchChangesetsByBranchAndPage(
- namespace,
- name,
- branchName,
- this.props.page
- );
+ fetchChangesetsByBranchAndPage(repository, branchName, this.props.page);
} else {
- fetchChangesetsByPage(namespace, name, this.props.page);
+ fetchChangesetsByPage(repository, this.props.page);
}
- fetchBranchesByNamespaceAndName(namespace, name);
+ fetchBranches(repository);
}
componentDidUpdate(prevProps: Props, prevState: State, snapshot: any) {
@@ -149,7 +143,7 @@ class Changesets extends React.PureComponent {
);
}
- return ;
+ return ;
};
renderPaginator() {
@@ -195,13 +189,14 @@ const getPageFromProps = props => {
};
const mapStateToProps = (state, ownProps: Props) => {
+ const { repository } = ownProps;
const { namespace, name } = ownProps.repository;
const { branch } = ownProps.match.params;
const key = createKey(namespace, name, branch);
- const loading = isFetchChangesetsPending(state, namespace, name, branch);
+ const loading = isFetchChangesetsPending(state, repository, branch);
const changesets = getChangesetsFromState(state, key);
- const branchNames = getBranchNames(namespace, name, state);
- const error = getFetchChangesetsFailure(state, namespace, name, branch);
+ const branchNames = getBranchNames(state, repository);
+ const error = getFetchChangesetsFailure(state, repository, branch);
const list = selectListAsCollection(state, key);
const page = getPageFromProps(ownProps);
@@ -217,27 +212,28 @@ const mapStateToProps = (state, ownProps: Props) => {
const mapDispatchToProps = dispatch => {
return {
- fetchBranchesByNamespaceAndName: (namespace: string, name: string) => {
- dispatch(fetchBranchesByNamespaceAndName(namespace, name));
+ fetchBranches: (repository: Repository) => {
+ dispatch(fetchBranches(repository));
},
- fetchChangesetsByPage: (namespace: string, name: string, page: number) => {
- dispatch(fetchChangesetsByPage(namespace, name, page));
+ fetchChangesets: (repository: Repository) => {
+ dispatch(fetchChangesets(repository));
+ },
+ fetchChangesetsByPage: (repository, page: number) => {
+ dispatch(fetchChangesetsByPage(repository, page));
},
fetchChangesetsByBranchAndPage: (
- namespace: string,
- name: string,
+ repository,
branch: string,
page: number
) => {
- dispatch(fetchChangesetsByBranchAndPage(namespace, name, branch, page));
+ dispatch(fetchChangesetsByBranchAndPage(repository, branch, page));
},
fetchChangesetsByLink: (
- namespace: string,
- name: string,
+ repository: Repository,
link: string,
branch?: string
) => {
- dispatch(fetchChangesetsByLink(namespace, name, link, branch));
+ dispatch(fetchChangesetsByLink(repository, link, branch));
}
};
};
diff --git a/scm-ui/src/repos/modules/branches.js b/scm-ui/src/repos/modules/branches.js
index 1bd8d30df5..9b6a261a85 100644
--- a/scm-ui/src/repos/modules/branches.js
+++ b/scm-ui/src/repos/modules/branches.js
@@ -5,62 +5,71 @@ import {
SUCCESS_SUFFIX
} from "../../modules/types";
import { apiClient } from "@scm-manager/ui-components";
+import type { Repository } from "@scm-manager/ui-types";
export const FETCH_BRANCHES = "scm/repos/FETCH_BRANCHES";
export const FETCH_BRANCHES_PENDING = `${FETCH_BRANCHES}_${PENDING_SUFFIX}`;
export const FETCH_BRANCHES_SUCCESS = `${FETCH_BRANCHES}_${SUCCESS_SUFFIX}`;
export const FETCH_BRANCHES_FAILURE = `${FETCH_BRANCHES}_${FAILURE_SUFFIX}`;
-const REPO_URL = "repositories";
-
// Fetching branches
-export function fetchBranchesByNamespaceAndName(
- namespace: string,
- name: string
-) {
+
+export function fetchBranches(repository: Repository) {
return function(dispatch: any) {
- dispatch(fetchBranchesPending(namespace, name));
+ dispatch(fetchBranchesPending(repository));
return apiClient
- .get(REPO_URL + "/" + namespace + "/" + name + "/branches")
+ .get(repository._links.branches.href)
.then(response => response.json())
.then(data => {
- dispatch(fetchBranchesSuccess(data, namespace, name));
+ dispatch(fetchBranchesSuccess(data, repository));
})
.catch(error => {
- dispatch(fetchBranchesFailure(namespace, name, error));
+ dispatch(fetchBranchesFailure(repository, error));
});
};
}
+// export function fetchBranchesByNamespaceAndName(
+// namespace: string,
+// name: string
+// ) {
+// return function(dispatch: any) {
+// dispatch(fetchBranchesPending(namespace, name));
+// return apiClient
+// .get(REPO_URL + "/" + namespace + "/" + name + "/branches")
+// .then(response => response.json())
+// .then(data => {
+// dispatch(fetchBranchesSuccess(data, namespace, name));
+// })
+// .catch(error => {
+// dispatch(fetchBranchesFailure(namespace, name, error));
+// });
+// };
+// }
// Action creators
-export function fetchBranchesPending(namespace: string, name: string) {
+export function fetchBranchesPending(repository: Repository) {
+ const { namespace, name } = repository;
return {
type: FETCH_BRANCHES_PENDING,
- payload: { namespace, name },
+ payload: { repository },
itemId: namespace + "/" + name
};
}
-export function fetchBranchesSuccess(
- data: string,
- namespace: string,
- name: string
-) {
+export function fetchBranchesSuccess(data: string, repository: Repository) {
+ const { namespace, name } = repository;
return {
type: FETCH_BRANCHES_SUCCESS,
- payload: { data, namespace, name },
+ payload: { data, repository },
itemId: namespace + "/" + name
};
}
-export function fetchBranchesFailure(
- namespace: string,
- name: string,
- error: Error
-) {
+export function fetchBranchesFailure(repository: Repository, error: Error) {
+ const { namespace, name } = repository;
return {
type: FETCH_BRANCHES_FAILURE,
- payload: { error, namespace, name },
+ payload: { error, repository },
itemId: namespace + "/" + name
};
}
@@ -73,7 +82,7 @@ export default function reducer(
): Object {
switch (action.type) {
case FETCH_BRANCHES_SUCCESS:
- const key = action.payload.namespace + "/" + action.payload.name;
+ const key = action.itemId;
let oldBranchesByNames = { [key]: {} };
if (state[key] !== undefined) {
oldBranchesByNames[key] = state[key];
@@ -119,7 +128,8 @@ export function getBranchesForNamespaceAndNameFromState(
return Object.values(state.branches[key].byNames);
}
-export function getBranchNames(namespace: string, name: string, state: Object) {
+export function getBranchNames(state: Object, repository: Repository) {
+ const { namespace, name } = repository;
const key = namespace + "/" + name;
if (!state.branches[key] || !state.branches[key].byNames) {
return null;
diff --git a/scm-ui/src/repos/modules/branches.test.js b/scm-ui/src/repos/modules/branches.test.js
index d97d9aa7bf..361032c78a 100644
--- a/scm-ui/src/repos/modules/branches.test.js
+++ b/scm-ui/src/repos/modules/branches.test.js
@@ -5,148 +5,163 @@ import {
FETCH_BRANCHES_FAILURE,
FETCH_BRANCHES_PENDING,
FETCH_BRANCHES_SUCCESS,
- fetchBranchesByNamespaceAndName, getBranchesForNamespaceAndNameFromState, getBranchNames
+ fetchBranches,
+ getBranchNames
} from "./branches";
import reducer from "./branches";
-
const namespace = "foo";
const name = "bar";
const key = namespace + "/" + name;
+const repository = {
+ namespace: "foo",
+ name: "bar",
+ _links: {
+ branches: {
+ href: "http://scm/api/rest/v2/repositories/foo/bar/branches"
+ }
+ }
+};
-const branch1 = {name: "branch1", revision: "revision1"};
-const branch2 = {name: "branch2", revision: "revision2"};
-const branch3 = {name: "branch3", revision: "revision3"};
+const branch1 = { name: "branch1", revision: "revision1" };
+const branch2 = { name: "branch2", revision: "revision2" };
+const branch3 = { name: "branch3", revision: "revision3" };
+describe("branches", () => {
+ describe("fetch branches", () => {
+ const URL = "http://scm/api/rest/v2/repositories/foo/bar/branches";
+ const mockStore = configureMockStore([thunk]);
-describe("fetch branches", () => {
- const URL = "/api/rest/v2/repositories/foo/bar/branches";
- const mockStore = configureMockStore([thunk]);
+ afterEach(() => {
+ fetchMock.reset();
+ fetchMock.restore();
+ });
+ it("should fetch branches", () => {
+ const collection = {};
- afterEach(() => {
- fetchMock.reset();
- fetchMock.restore();
- });
+ fetchMock.getOnce(URL, "{}");
+ const expectedActions = [
+ {
+ type: FETCH_BRANCHES_PENDING,
+ payload: { repository },
+ itemId: key
+ },
+ {
+ type: FETCH_BRANCHES_SUCCESS,
+ payload: { data: collection, repository },
+ itemId: key
+ }
+ ];
- it("should fetch branches", () => {
- const collection = {};
+ const store = mockStore({});
+ return store.dispatch(fetchBranches(repository)).then(() => {
+ expect(store.getActions()).toEqual(expectedActions);
+ });
+ });
- fetchMock.getOnce(URL, "{}");
+ it("should fail fetching branches on HTTP 500", () => {
+ const collection = {};
- const expectedActions = [
- {
- type: FETCH_BRANCHES_PENDING, payload: {namespace, name},
- itemId: key
- },
- {
- type: FETCH_BRANCHES_SUCCESS,
- payload: {data: collection, namespace, name},
- itemId: key
- }
- ];
+ fetchMock.getOnce(URL, 500);
- const store = mockStore({});
- return store.dispatch(fetchBranchesByNamespaceAndName(namespace, name)).then(() => {
- expect(store.getActions()).toEqual(expectedActions);
+ const expectedActions = [
+ {
+ type: FETCH_BRANCHES_PENDING,
+ payload: { repository },
+ itemId: key
+ },
+ {
+ type: FETCH_BRANCHES_FAILURE,
+ payload: { error: collection, repository },
+ itemId: key
+ }
+ ];
+
+ const store = mockStore({});
+ return store.dispatch(fetchBranches(repository)).then(() => {
+ expect(store.getActions()[0]).toEqual(expectedActions[0]);
+ expect(store.getActions()[1].type).toEqual(FETCH_BRANCHES_FAILURE);
+ });
});
});
- it("should fail fetching branches on HTTP 500", () => {
- const collection = {};
-
- fetchMock.getOnce(URL, 500);
-
- const expectedActions = [
- {
- type: FETCH_BRANCHES_PENDING, payload: {namespace, name},
- itemId: key
- },
- {
- type: FETCH_BRANCHES_FAILURE,
- payload: {error: collection, namespace, name},
- itemId: key
+ describe("branches reducer", () => {
+ const branches = {
+ _embedded: {
+ branches: [branch1, branch2]
}
- ];
+ };
+ const action = {
+ type: FETCH_BRANCHES_SUCCESS,
+ payload: {
+ namespace,
+ name,
+ data: branches
+ }
+ };
- const store = mockStore({});
- return store.dispatch(fetchBranchesByNamespaceAndName(namespace, name)).then(() => {
- expect(store.getActions()[0]).toEqual(expectedActions[0]);
- expect(store.getActions()[1].type).toEqual(FETCH_BRANCHES_FAILURE);
+ it("should update state according to successful fetch", () => {
+ const newState = reducer({}, action);
+ expect(newState).toBeDefined();
+ expect(newState[key]).toBeDefined();
+ expect(newState[key].byNames["branch1"]).toEqual(branch1);
+ expect(newState[key].byNames["branch2"]).toEqual(branch2);
});
- })
-});
-describe("branches reducer", () => {
-
- const branches = {
- _embedded: {
- branches: [branch1, branch2]
- }
- };
- const action = {
- type: FETCH_BRANCHES_SUCCESS,
- payload: {
- namespace,
- name,
- data: branches
- }
- };
-
- it("should update state according to successful fetch", () => {
- const newState = reducer({}, action);
- expect(newState).toBeDefined();
- expect(newState[key]).toBeDefined();
- expect(newState[key].byNames["branch1"]).toEqual(branch1);
- expect(newState[key].byNames["branch2"]).toEqual(branch2);
- });
-
- it("should not delete existing branches from state", () => {
- const oldState = {
- "foo/bar": { byNames: {
- "branch3": branch3
- }}
- };
-
- const newState = reducer(oldState, action);
- console.log(newState);
- expect(newState[key].byNames["branch1"]).toEqual(branch1);
- expect(newState[key].byNames["branch2"]).toEqual(branch2);
- expect(newState[key].byNames["branch3"]).toEqual(branch3);
- });
-});
-
-describe("branch selectors", () => {
- it("should get branches for namespace and name", () => {
- const state = {
- branches: {
- [key]: {
+ it("should not delete existing branches from state", () => {
+ const oldState = {
+ "foo/bar": {
byNames: {
- "branch1": branch1
+ branch3: branch3
}
}
- }
- };
- const branches = getBranchesForNamespaceAndNameFromState(namespace, name, state);
- expect(branches.length).toEqual(1);
- expect(branches[0]).toEqual(branch1);
+ };
+
+ const newState = reducer(oldState, action);
+ console.log(newState);
+ expect(newState[key].byNames["branch1"]).toEqual(branch1);
+ expect(newState[key].byNames["branch2"]).toEqual(branch2);
+ expect(newState[key].byNames["branch3"]).toEqual(branch3);
+ });
});
- it("should return branches names", () => {
- const state = {
- branches: {
- [key]: {
- byNames: {
- "branch1": branch1,
- "branch2": branch2
+ describe("branch selectors", () => {
+ it("should get branches for namespace and name", () => {
+ const state = {
+ branches: {
+ [key]: {
+ byNames: {
+ branch1: branch1
+ }
}
}
- }
- };
- const names = getBranchNames(namespace, name, state);
- expect(names.length).toEqual(2);
- expect(names).toContain("branch1");
- expect(names).toContain("branch2");
+ };
+ const branches = getBranchesForNamespaceAndNameFromState(
+ namespace,
+ name,
+ state
+ );
+ expect(branches.length).toEqual(1);
+ expect(branches[0]).toEqual(branch1);
+ });
+
+ it("should return branches names", () => {
+ const state = {
+ branches: {
+ [key]: {
+ byNames: {
+ branch1: branch1,
+ branch2: branch2
+ }
+ }
+ }
+ };
+ const names = getBranchNames(state, repository);
+ expect(names.length).toEqual(2);
+ expect(names).toContain("branch1");
+ expect(names).toContain("branch2");
+ });
});
});
diff --git a/scm-ui/src/repos/modules/changesets.js b/scm-ui/src/repos/modules/changesets.js
index bcc323a937..dffc87268d 100644
--- a/scm-ui/src/repos/modules/changesets.js
+++ b/scm-ui/src/repos/modules/changesets.js
@@ -9,7 +9,12 @@ import { apiClient } from "@scm-manager/ui-components";
import { isPending } from "../../modules/pending";
import { getFailure } from "../../modules/failure";
import { combineReducers } from "redux";
-import type { Action, Changeset, PagedCollection } from "@scm-manager/ui-types";
+import type {
+ Action,
+ Changeset,
+ PagedCollection,
+ Repository
+} from "@scm-manager/ui-types";
export const FETCH_CHANGESETS = "scm/repos/FETCH_CHANGESETS";
export const FETCH_CHANGESETS_PENDING = `${FETCH_CHANGESETS}_${PENDING_SUFFIX}`;
@@ -21,137 +26,122 @@ const REPO_URL = "repositories";
// actions
export function fetchChangesetsByLink(
- namespace: string,
- name: string,
+ repository: Repository,
link: string,
branch?: string
) {
return function(dispatch: any) {
- dispatch(fetchChangesetsPending(namespace, name, branch));
+ dispatch(fetchChangesetsPending(repository, branch));
return apiClient
.get(link)
.then(response => response.json())
.then(data => {
- dispatch(fetchChangesetsSuccess(data, namespace, name, branch));
+ dispatch(fetchChangesetsSuccess(data, repository, branch));
})
.catch(cause => {
- dispatch(fetchChangesetsFailure(namespace, name, cause, branch));
+ dispatch(fetchChangesetsFailure(repository, cause, branch));
});
};
}
export function fetchChangesetsWithOptions(
- namespace: string,
- name: string,
+ repository: Repository,
branch?: string,
suffix?: string
) {
- let link = REPO_URL + `/${namespace}/${name}`;
+ let link = repository._links.changesets.href;
+
if (branch && branch !== "") {
- link = link + `/branches/${branch}`;
+ const halBranch = repository._links.branches.find(b => b.name === branch);
+ link = halBranch._links.history.href;
}
- link = link + "/changesets";
+
if (suffix) {
link = link + `${suffix}`;
}
-
return function(dispatch: any) {
- dispatch(fetchChangesetsPending(namespace, name, branch));
+ dispatch(fetchChangesetsPending(repository, branch));
return apiClient
.get(link)
.then(response => response.json())
.then(data => {
- dispatch(fetchChangesetsSuccess(data, namespace, name, branch));
+ dispatch(fetchChangesetsSuccess(data, repository, branch));
})
.catch(cause => {
- dispatch(fetchChangesetsFailure(namespace, name, cause, branch));
+ dispatch(fetchChangesetsFailure(repository, cause, branch));
});
};
}
-export function fetchChangesets(namespace: string, name: string) {
- return fetchChangesetsWithOptions(namespace, name);
+export function fetchChangesets(repository: Repository) {
+ return fetchChangesetsWithOptions(repository);
}
-export function fetchChangesetsByPage(
- namespace: string,
- name: string,
- page: number
-) {
- return fetchChangesetsWithOptions(namespace, name, "", `?page=${page - 1}`);
+export function fetchChangesetsByPage(repository: Repository, page: number) {
+ return fetchChangesetsWithOptions(repository, "", `?page=${page - 1}`);
}
+// TODO: Rewrite code to fetch changesets by branches, adjust tests and let BranchChooser fetch branches
export function fetchChangesetsByBranchAndPage(
- namespace: string,
- name: string,
+ repository: Repository,
branch: string,
page: number
) {
- return fetchChangesetsWithOptions(
- namespace,
- name,
- branch,
- `?page=${page - 1}`
- );
+ return fetchChangesetsWithOptions(repository, branch, `?page=${page - 1}`);
}
-export function fetchChangesetsByNamespaceNameAndBranch(
- namespace: string,
- name: string,
+export function fetchChangesetsByBranch(
+ repository: Repository,
branch: string
) {
- return fetchChangesetsWithOptions(namespace, name, branch);
+ return fetchChangesetsWithOptions(repository, branch);
}
export function fetchChangesetsPending(
- namespace: string,
- name: string,
+ repository: Repository,
branch?: string
): Action {
- const itemId = createItemId(namespace, name, branch);
+ const itemId = createItemId(repository, branch);
+ if (!branch) {
+ branch = "";
+ }
return {
type: FETCH_CHANGESETS_PENDING,
- payload: itemId,
+ payload: { repository, branch },
itemId
};
}
export function fetchChangesetsSuccess(
changesets: any,
- namespace: string,
- name: string,
+ repository: Repository,
branch?: string
): Action {
return {
type: FETCH_CHANGESETS_SUCCESS,
payload: changesets,
- itemId: createItemId(namespace, name, branch)
+ itemId: createItemId(repository, branch)
};
}
function fetchChangesetsFailure(
- namespace: string,
- name: string,
+ repository: Repository,
error: Error,
branch?: string
): Action {
return {
type: FETCH_CHANGESETS_FAILURE,
payload: {
- namespace,
- name,
+ repository,
error,
branch
},
- itemId: createItemId(namespace, name, branch)
+ itemId: createItemId(repository, branch)
};
}
-function createItemId(
- namespace: string,
- name: string,
- branch?: string
-): string {
+function createItemId(repository: Repository, branch?: string): string {
+ const { namespace, name } = repository;
let itemId = namespace + "/" + name;
if (branch && branch !== "") {
itemId = itemId + "/" + branch;
@@ -211,13 +201,8 @@ function extractChangesetsByIds(changesets: any, oldChangesetsByIds: any) {
}
//selectors
-export function getChangesets(
- state: Object,
- namespace: string,
- name: string,
- branch?: string
-) {
- const key = createItemId(namespace, name, branch);
+export function getChangesets(state: Object, repository, branch?: string) {
+ const key = createItemId(repository, branch);
if (!state.changesets.byKey[key]) {
return null;
}
@@ -226,28 +211,18 @@ export function getChangesets(
export function isFetchChangesetsPending(
state: Object,
- namespace: string,
- name: string,
+ repository: Repository,
branch?: string
) {
- return isPending(
- state,
- FETCH_CHANGESETS,
- createItemId(namespace, name, branch)
- );
+ return isPending(state, FETCH_CHANGESETS, createItemId(repository, branch));
}
export function getFetchChangesetsFailure(
state: Object,
- namespace: string,
- name: string,
+ repository: Repository,
branch?: string
) {
- return getFailure(
- state,
- FETCH_CHANGESETS,
- createItemId(namespace, name, branch)
- );
+ return getFailure(state, FETCH_CHANGESETS, createItemId(repository, branch));
}
const selectList = (state: Object, key: string) => {
diff --git a/scm-ui/src/repos/modules/changesets.test.js b/scm-ui/src/repos/modules/changesets.test.js
index 40f18c2423..0b73db5e9d 100644
--- a/scm-ui/src/repos/modules/changesets.test.js
+++ b/scm-ui/src/repos/modules/changesets.test.js
@@ -10,7 +10,7 @@ import {
FETCH_CHANGESETS_SUCCESS,
fetchChangesets,
fetchChangesetsByBranchAndPage,
- fetchChangesetsByNamespaceNameAndBranch,
+ fetchChangesetsByBranch,
fetchChangesetsByPage,
fetchChangesetsSuccess,
getChangesets,
@@ -19,13 +19,38 @@ import {
} from "./changesets";
import reducer from "./changesets";
+const repository = {
+ namespace: "foo",
+ name: "bar",
+ _links: {
+ self: {
+ href: "http://scm/api/rest/v2/repositories/foo/bar"
+ },
+ changesets: {
+ href: "http://scm/api/rest/v2/repositories/foo/bar/changesets"
+ },
+ branches: [
+ {
+ name: "specific",
+ _links: {
+ history: {
+ href:
+ "http://scm/api/rest/v2/repositories/foo/bar/branches/specific/changesets"
+ }
+ }
+ }
+ ]
+ }
+};
+
const changesets = {};
describe("changesets", () => {
describe("fetching of changesets", () => {
- const DEFAULT_BRANCH_URL = "/api/rest/v2/repositories/foo/bar/changesets";
+ const DEFAULT_BRANCH_URL =
+ "http://scm/api/rest/v2/repositories/foo/bar/changesets";
const SPECIFIC_BRANCH_URL =
- "/api/rest/v2/repositories/foo/bar/branches/specific/changesets";
+ "http://scm/api/rest/v2/repositories/foo/bar/branches/specific/changesets";
const mockStore = configureMockStore([thunk]);
afterEach(() => {
@@ -39,7 +64,7 @@ describe("changesets", () => {
const expectedActions = [
{
type: FETCH_CHANGESETS_PENDING,
- payload: "foo/bar",
+ payload: { repository, branch: "" },
itemId: "foo/bar"
},
{
@@ -50,7 +75,7 @@ describe("changesets", () => {
];
const store = mockStore({});
- return store.dispatch(fetchChangesets("foo", "bar")).then(() => {
+ return store.dispatch(fetchChangesets(repository)).then(() => {
expect(store.getActions()).toEqual(expectedActions);
});
});
@@ -62,7 +87,7 @@ describe("changesets", () => {
const expectedActions = [
{
type: FETCH_CHANGESETS_PENDING,
- payload: itemId,
+ payload: { repository, branch: "specific" },
itemId
},
{
@@ -74,9 +99,7 @@ describe("changesets", () => {
const store = mockStore({});
return store
- .dispatch(
- fetchChangesetsByNamespaceNameAndBranch("foo", "bar", "specific")
- )
+ .dispatch(fetchChangesetsByBranch(repository, "specific"))
.then(() => {
expect(store.getActions()).toEqual(expectedActions);
});
@@ -89,13 +112,13 @@ describe("changesets", () => {
const expectedActions = [
{
type: FETCH_CHANGESETS_PENDING,
- payload: itemId,
+ payload: { repository, branch: "" },
itemId
}
];
const store = mockStore({});
- return store.dispatch(fetchChangesets("foo", "bar")).then(() => {
+ return store.dispatch(fetchChangesets(repository)).then(() => {
expect(store.getActions()[0]).toEqual(expectedActions[0]);
expect(store.getActions()[1].type).toEqual(FETCH_CHANGESETS_FAILURE);
expect(store.getActions()[1].payload).toBeDefined();
@@ -109,16 +132,14 @@ describe("changesets", () => {
const expectedActions = [
{
type: FETCH_CHANGESETS_PENDING,
- payload: itemId,
+ payload: { repository, branch: "specific" },
itemId
}
];
const store = mockStore({});
return store
- .dispatch(
- fetchChangesetsByNamespaceNameAndBranch("foo", "bar", "specific")
- )
+ .dispatch(fetchChangesetsByBranch(repository, "specific"))
.then(() => {
expect(store.getActions()[0]).toEqual(expectedActions[0]);
expect(store.getActions()[1].type).toEqual(FETCH_CHANGESETS_FAILURE);
@@ -132,7 +153,7 @@ describe("changesets", () => {
const expectedActions = [
{
type: FETCH_CHANGESETS_PENDING,
- payload: "foo/bar",
+ payload: { repository, branch: "" },
itemId: "foo/bar"
},
{
@@ -143,7 +164,7 @@ describe("changesets", () => {
];
const store = mockStore({});
- return store.dispatch(fetchChangesetsByPage("foo", "bar", 5)).then(() => {
+ return store.dispatch(fetchChangesetsByPage(repository, 5)).then(() => {
expect(store.getActions()).toEqual(expectedActions);
});
});
@@ -154,7 +175,7 @@ describe("changesets", () => {
const expectedActions = [
{
type: FETCH_CHANGESETS_PENDING,
- payload: "foo/bar/specific",
+ payload: { repository, branch: "specific" },
itemId: "foo/bar/specific"
},
{
@@ -166,7 +187,7 @@ describe("changesets", () => {
const store = mockStore({});
return store
- .dispatch(fetchChangesetsByBranchAndPage("foo", "bar", "specific", 5))
+ .dispatch(fetchChangesetsByBranchAndPage(repository, "specific", 5))
.then(() => {
expect(store.getActions()).toEqual(expectedActions);
});
@@ -195,7 +216,7 @@ describe("changesets", () => {
it("should set state to received changesets", () => {
const newState = reducer(
{},
- fetchChangesetsSuccess(responseBody, "foo", "bar")
+ fetchChangesetsSuccess(responseBody, repository)
);
expect(newState).toBeDefined();
expect(newState.byKey["foo/bar"].byId["changeset1"].author.mail).toEqual(
@@ -243,7 +264,7 @@ describe("changesets", () => {
}
}
},
- fetchChangesetsSuccess(responseBody, "foo", "bar")
+ fetchChangesetsSuccess(responseBody, repository)
);
expect(newState.byKey["foo/bar"].byId["changeset2"]).toBeDefined();
expect(newState.byKey["foo/bar"].byId["changeset1"]).toBeDefined();
@@ -253,7 +274,7 @@ describe("changesets", () => {
describe("changeset selectors", () => {
const error = new Error("Something went wrong");
- it("should get all changesets for a given namespace and name", () => {
+ it("should get all changesets for a given repository", () => {
const state = {
changesets: {
byKey: {
@@ -266,7 +287,7 @@ describe("changesets", () => {
}
}
};
- const result = getChangesets(state, "foo", "bar");
+ const result = getChangesets(state, repository);
expect(result).toContainEqual({ id: "id1" });
});
@@ -277,11 +298,11 @@ describe("changesets", () => {
}
};
- expect(isFetchChangesetsPending(state, "foo", "bar")).toBeTruthy();
+ expect(isFetchChangesetsPending(state, repository)).toBeTruthy();
});
it("should return false, when fetching changesets is not pending", () => {
- expect(isFetchChangesetsPending({}, "foo", "bar")).toEqual(false);
+ expect(isFetchChangesetsPending({}, repository)).toEqual(false);
});
it("should return error if fetching changesets failed", () => {
@@ -291,11 +312,11 @@ describe("changesets", () => {
}
};
- expect(getFetchChangesetsFailure(state, "foo", "bar")).toEqual(error);
+ expect(getFetchChangesetsFailure(state, repository)).toEqual(error);
});
it("should return false if fetching changesets did not fail", () => {
- expect(getFetchChangesetsFailure({}, "foo", "bar")).toBeUndefined();
+ expect(getFetchChangesetsFailure({}, repository)).toBeUndefined();
});
});
});