Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions tests/integration/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
expectBranchHasFile,
expectBranchHasTree,
expectBranchNotHaveFile,
expectParentHasOid,
getOid,
expectParentHasSha,
getSha,
getTempBranch,
octokit,
owner,
Expand All @@ -26,7 +26,7 @@ import {

const BASIC_FILE_CHANGES_PATH = "foo.txt";
const BASIC_FILE_BUFFER = Buffer.alloc(1024, "Hello, world!");
const BASIC_FILE_CHANGES_OID = getOid(BASIC_FILE_BUFFER);
const BASIC_FILE_CHANGES_SHA = getSha(BASIC_FILE_BUFFER);
const BASIC_FILE_CONTENTS = BASIC_FILE_BUFFER.toString("base64");
const BASIC_FILE_CHANGES = {
additions: [
Expand Down Expand Up @@ -95,13 +95,13 @@ describe("commitFilesFromBase64", () => {
.trim()
.split("\n")
.map((line) => {
const [oid, tree] = line.split(" ");
return { oid, tree };
const [commitSha, treeSha] = line.split(" ");
return { commitSha, treeSha };
});

testTargetCommit = logs[1]?.oid ?? "N/A";
testTargetCommit2 = logs[0]?.oid ?? "N/A";
testTargetTree2 = logs[0]?.tree ?? "N/A";
testTargetCommit = logs[1]?.commitSha ?? "N/A";
testTargetCommit2 = logs[0]?.commitSha ?? "N/A";
testTargetTree2 = logs[0]?.treeSha ?? "N/A";
});

it("can commit files", async () => {
Expand Down Expand Up @@ -140,17 +140,17 @@ describe("commitFilesFromBase64", () => {
await expectBranchHasFile({
branch,
filePath: "new-file.txt",
fileOid: getOid(buffers.newFile),
fileSha: getSha(buffers.newFile),
});
await expectBranchHasFile({
branch,
filePath: "README.md",
fileOid: getOid(buffers.updated),
fileSha: getSha(buffers.updated),
});
await expectBranchHasFile({
branch,
filePath: "tests/file.txt",
fileOid: getOid(buffers.nested),
fileSha: getSha(buffers.nested),
});
await expectBranchNotHaveFile({ branch, filePath: "CHANGELOG.md" });
});
Expand Down Expand Up @@ -181,7 +181,7 @@ describe("commitFilesFromBase64", () => {
await expectBranchHasFile({
branch,
filePath: `${sizeName}.txt`,
fileOid: getOid(buffer),
fileSha: getSha(buffer),
});
}
});
Expand All @@ -204,7 +204,7 @@ describe("commitFilesFromBase64", () => {
await expectBranchHasFile({
branch,
filePath: BASIC_FILE_CHANGES_PATH,
fileOid: BASIC_FILE_CHANGES_OID,
fileSha: BASIC_FILE_CHANGES_SHA,
});
});

Expand All @@ -229,7 +229,7 @@ describe("commitFilesFromBase64", () => {
await expectBranchHasFile({
branch,
filePath: BASIC_FILE_CHANGES_PATH,
fileOid: BASIC_FILE_CHANGES_OID,
fileSha: BASIC_FILE_CHANGES_SHA,
});
});

Expand All @@ -250,7 +250,7 @@ describe("commitFilesFromBase64", () => {
await expectBranchHasFile({
branch,
filePath: BASIC_FILE_CHANGES_PATH,
fileOid: BASIC_FILE_CHANGES_OID,
fileSha: BASIC_FILE_CHANGES_SHA,
});
});

Expand Down Expand Up @@ -281,10 +281,10 @@ describe("commitFilesFromBase64", () => {
await expectBranchHasFile({
branch,
filePath: BASIC_FILE_CHANGES_PATH,
fileOid: BASIC_FILE_CHANGES_OID,
fileSha: BASIC_FILE_CHANGES_SHA,
});

await expectParentHasOid({ branch, oid: testTargetCommit });
await expectParentHasSha({ branch, sha: testTargetCommit });
await expectBranchDoesNotExist(internalTempBranch);
});

Expand Down Expand Up @@ -321,10 +321,10 @@ describe("commitFilesFromBase64", () => {
await expectBranchHasFile({
branch,
filePath: BASIC_FILE_CHANGES_PATH,
fileOid: BASIC_FILE_CHANGES_OID,
fileSha: BASIC_FILE_CHANGES_SHA,
});

await expectParentHasOid({ branch, oid: testTargetCommit });
await expectParentHasSha({ branch, sha: testTargetCommit });
await expectBranchDoesNotExist(internalTempBranch);
});

Expand Down Expand Up @@ -354,7 +354,7 @@ describe("commitFilesFromBase64", () => {

await expectBranchHasTree({
branch,
treeOid: testTargetTree2,
treeSha: testTargetTree2,
});
});

Expand Down Expand Up @@ -383,7 +383,7 @@ describe("commitFilesFromBase64", () => {
await expectBranchHasFile({
branch,
filePath: BASIC_FILE_CHANGES_PATH,
fileOid: BASIC_FILE_CHANGES_OID,
fileSha: BASIC_FILE_CHANGES_SHA,
});
});

Expand Down Expand Up @@ -412,7 +412,7 @@ describe("commitFilesFromBase64", () => {
await expectBranchHasFile({
branch,
filePath: BASIC_FILE_CHANGES_PATH,
fileOid: BASIC_FILE_CHANGES_OID,
fileSha: BASIC_FILE_CHANGES_SHA,
});
});
});
Expand Down
22 changes: 11 additions & 11 deletions tests/integration/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function getTempBranch(name: string) {
/**
* Calculate the SHA using git blob hash format
*/
export function getOid(contents: Buffer): string {
export function getSha(contents: Buffer): string {
const header = Buffer.from(`blob ${contents.length}\0`);
return crypto
.createHash("sha1")
Expand All @@ -48,10 +48,10 @@ export function getOid(contents: Buffer): string {

export async function expectBranchHasTree({
branch,
treeOid,
treeSha,
}: {
branch: string;
treeOid: string;
treeSha: string;
}) {
const ref = (
await getRefTreeQuery(octokit, {
Expand All @@ -66,17 +66,17 @@ export async function expectBranchHasTree({
throw new Error("Unexpected missing ref");
}

expect(ref.tree.oid).toEqual(treeOid);
expect(ref.tree.oid).toEqual(treeSha);
}

export async function expectBranchHasFile({
branch,
filePath,
fileOid,
fileSha,
}: {
branch: string;
filePath: string;
fileOid: string;
fileSha: string;
}) {
const ref = (
await getRefTreeQuery(octokit, {
Expand All @@ -91,7 +91,7 @@ export async function expectBranchHasFile({
throw new Error("Unexpected missing ref");
}

expect(ref.file?.oid).toEqual(fileOid);
expect(ref.file?.oid).toEqual(fileSha);
}

export async function expectBranchNotHaveFile({
Expand All @@ -111,12 +111,12 @@ export async function expectBranchNotHaveFile({
).rejects.toThrow("Could not resolve file for path");
}

export async function expectParentHasOid({
export async function expectParentHasSha({
branch,
oid,
sha,
}: {
branch: string;
oid: string;
sha: string;
}) {
const ref = (
await getRefTreeQuery(octokit, {
Expand All @@ -131,7 +131,7 @@ export async function expectParentHasOid({
throw new Error("Unexpected result");
}

expect(ref.parents.nodes?.[0]?.oid).toEqual(oid);
expect(ref.parents.nodes?.[0]?.oid).toEqual(sha);
}

export async function expectBranchDoesNotExist(branch: string) {
Expand Down