Fix missing encoding of useBranch hook (#1798)

This commit is contained in:
Sebastian Sdorra
2021-09-08 07:45:41 +02:00
committed by GitHub
parent 059f1aeab0
commit 92fa67e937
4 changed files with 23 additions and 6 deletions

View File

@@ -51,6 +51,16 @@ describe("Test branches hooks", () => {
},
};
const feature: Branch = {
name: "feature/something-special",
revision: "42",
_links: {
delete: {
href: "/hog/branches/feature%2Fsomething-special",
},
},
};
const branches: BranchCollection = {
_embedded: {
branches: [develop],
@@ -101,10 +111,10 @@ describe("Test branches hooks", () => {
});
describe("useBranch tests", () => {
const fetchBranch = async () => {
fetchMock.getOnce("/api/v2/hog/branches/develop", develop);
const fetchBranch = async (name: string, branch: Branch) => {
fetchMock.getOnce("/api/v2/hog/branches/" + encodeURIComponent(name), branch);
const { result, waitFor } = renderHook(() => useBranch(repository, "develop"), {
const { result, waitFor } = renderHook(() => useBranch(repository, name), {
wrapper: createWrapper(undefined, queryClient),
});
@@ -118,9 +128,14 @@ describe("Test branches hooks", () => {
};
it("should return branch", async () => {
const branch = await fetchBranch();
const branch = await fetchBranch("develop", develop);
expect(branch).toEqual(develop);
});
it("should escape branch name", async () => {
const branch = await fetchBranch("feature/something-special", feature);
expect(branch).toEqual(feature);
});
});
describe("useCreateBranch tests", () => {