Skip to content

Commit 9b026b5

Browse files
committed
add tests
1 parent d9e9120 commit 9b026b5

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

src/test/integration/node.test.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ const BASIC_FILE_CONTENTS = {
4949
// const TEST_TARGET_TREE_WITH_BASIC_CHANGES =
5050
// "a3431c9b42b71115c52bc6fbf9da3682cf0ed5e8";
5151

52+
const getTempBranchName = (branch: string) => `changesets-ghcommit-temp/${branch}`;
53+
5254
describe("node", () => {
5355
const branches: string[] = [];
5456

@@ -115,6 +117,17 @@ describe("node", () => {
115117
expect(ref.parents.nodes?.[0]?.oid).toEqual(oid);
116118
};
117119

120+
const expectBranchDoesNotExist = async (branch: string) => {
121+
await expect(
122+
octokit.rest.git.getRef({
123+
...REPO,
124+
ref: `heads/${branch}`,
125+
}),
126+
).rejects.toMatchObject({
127+
status: 404,
128+
});
129+
};
130+
118131
let testTargetCommit: string;
119132
/**
120133
* For tests, important that this commit is not an ancestor of TEST_TARGET_COMMIT,
@@ -323,6 +336,53 @@ describe("node", () => {
323336
});
324337

325338
await expectParentHasOid({ branch, oid: testTargetCommit });
339+
await expectBranchDoesNotExist(getTempBranchName(branch));
340+
});
341+
342+
it("cleans up a pre-existing temporary branch when force is true", async () => {
343+
const branch = `${TEST_BRANCH_PREFIX}-existing-branch-force-existing-temp`;
344+
const tempBranch = getTempBranchName(branch);
345+
branches.push(branch, tempBranch);
346+
347+
await createRefMutation(octokit, {
348+
input: {
349+
repositoryId,
350+
name: `refs/heads/${branch}`,
351+
oid: testTargetCommit2,
352+
},
353+
});
354+
355+
await createRefMutation(octokit, {
356+
input: {
357+
repositoryId,
358+
name: `refs/heads/${tempBranch}`,
359+
oid: testTargetCommit2,
360+
},
361+
});
362+
363+
await commitFilesFromBuffers({
364+
octokit,
365+
...REPO,
366+
branch,
367+
base: {
368+
commit: testTargetCommit,
369+
},
370+
...BASIC_FILE_CONTENTS,
371+
force: true,
372+
});
373+
374+
await waitForGitHubToBeReady();
375+
376+
await expectBranchHasTree({
377+
branch,
378+
file: {
379+
path: BASIC_FILE_CHANGES_PATH,
380+
oid: BASIC_FILE_CHANGES_OID,
381+
},
382+
});
383+
384+
await expectParentHasOid({ branch, oid: testTargetCommit });
385+
await expectBranchDoesNotExist(tempBranch);
326386
});
327387

328388
it("cannot commit to existing branch when force is false", async () => {

0 commit comments

Comments
 (0)