Skip to content

Commit

Permalink
🔥 Only need overwrite for authors file
Browse files Browse the repository at this point in the history
  • Loading branch information
rkotze committed Dec 28, 2023
1 parent 0e1697b commit b264a38
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ test('Save coauthor file in home directory', async () => {
mockGitAuthors.mockReturnValue(mockGitAuthorsObject);

await expect(createCoAuthorsFile()).resolves.toEqual(true);
expect(mockGitAuthorsObject.write).toHaveBeenCalled();
expect(mockGitAuthorsObject.overwrite).toHaveBeenCalled();
});

test('Save coauthor file with defined coauthor list', async () => {
Expand All @@ -49,7 +49,7 @@ test('Save coauthor file with defined coauthor list', async () => {
createCoAuthorsFile([new Author('rk', 'rich kid', 'richkid@gmail.com')])
).resolves.toEqual(true);

expect(mockGitAuthorsObject.write).toHaveBeenCalledWith({
expect(mockGitAuthorsObject.overwrite).toHaveBeenCalledWith({
coauthors: expectAuthor,
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ export async function createCoAuthorsFile(authorList: Author[]): Promise<boolean
string,
Record<string, { name: string; email: string }>
>;
await authorOps.write(schema);
await authorOps.overwrite(schema);
} else {
await authorOps.write(coAuthorSchema);
await authorOps.overwrite(coAuthorSchema);
}

return true;
Expand Down
20 changes: 0 additions & 20 deletions packages/git-mob-core/src/git-mob-api/git-authors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,6 @@ export function gitAuthors(readFilePromise, writeFilePromise, overwriteFilePromi
}
}

async function writeToFile(path, content) {
const writeToPromise = writeFilePromise || promisify(fs.appendFile);
try {
return await writeToPromise(path, content, 'utf8');
} catch (error) {
throw new Error(error.message);
}
}

async function overwriteFile(path, content) {
const overwritePromise = overwriteFilePromise || promisify(fs.writeFile);
try {
Expand All @@ -43,17 +34,6 @@ export function gitAuthors(readFilePromise, writeFilePromise, overwriteFilePromi
}
},

write: async authorJson => {
try {
return writeToFile(
await pathToCoAuthors(),
JSON.stringify(authorJson, null, 2)
);
} catch (error) {
throw new Error('Invalid JSON ' + error.message);
}
},

overwrite: async authorJson => {
try {
return overwriteFile(
Expand Down
1 change: 0 additions & 1 deletion packages/git-mob-core/src/test-helpers/author-mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export function mockGitAuthors(keys: string[]) {
const coAuthors = buildCoAuthorObject(keys);
return {
read: jest.fn(async () => coAuthors),
write: jest.fn(async () => ''),
overwrite: jest.fn(async () => ''),
coAuthors: jest.fn(() => []),
author: jest.fn(() => ({})),
Expand Down

0 comments on commit b264a38

Please sign in to comment.