-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
170 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -585,205 +585,195 @@ describe("RepoService", () => { | |
directoryName: "pages", | ||
}) | ||
}) | ||
}) | ||
|
||
describe("renameSinglePath", () => { | ||
it("should rename using the local Git file system if the repo is ggs enabled", async () => { | ||
const expected: GitCommitResult = { newSha: "fake-commit-sha" } | ||
MockGitFileCommitService.renameSinglePath.mockResolvedValueOnce( | ||
expected | ||
) | ||
gbSpy.mockReturnValueOnce(true) | ||
|
||
const actual = await RepoService.renameSinglePath( | ||
mockUserWithSiteSessionDataAndGrowthBook, | ||
mockGithubSessionData, | ||
"fake-old-path", | ||
"fake-new-path", | ||
"fake-commit-message" | ||
) | ||
|
||
expect(actual).toEqual(expected) | ||
}) | ||
describe("renameSinglePath", () => { | ||
it("should rename using the local Git file system if the repo is ggs enabled", async () => { | ||
const expected: GitCommitResult = { newSha: "fake-commit-sha" } | ||
MockGitFileCommitService.renameSinglePath.mockResolvedValueOnce(expected) | ||
gbSpy.mockReturnValueOnce(true) | ||
|
||
it("should rename file using GitHub directly if the repo is not ggs enabled", async () => { | ||
const expectedSha = "fake-commit-sha" | ||
const fakeCommitMessage = "fake-commit-message" | ||
const sessionData: UserWithSiteSessionData = new UserWithSiteSessionData( | ||
{ | ||
githubId: mockGithubId, | ||
accessToken: mockAccessToken, | ||
isomerUserId: mockIsomerUserId, | ||
email: mockEmail, | ||
siteName: "not-whitelisted", | ||
} | ||
) | ||
|
||
const gitHubServiceRenameSinglePath = jest.spyOn( | ||
GitHubService.prototype, | ||
"renameSinglePath" | ||
) | ||
gitHubServiceRenameSinglePath.mockResolvedValueOnce({ | ||
newSha: expectedSha, | ||
}) | ||
|
||
const actual = await RepoService.renameSinglePath( | ||
sessionData, | ||
mockGithubSessionData, | ||
"fake-path/old-fake-file.md", | ||
"fake-path/new-fake-file.md", | ||
fakeCommitMessage | ||
) | ||
|
||
expect(actual).toEqual({ newSha: expectedSha }) | ||
}) | ||
const actual = await RepoService.renameSinglePath( | ||
mockUserWithSiteSessionDataAndGrowthBook, | ||
mockGithubSessionData, | ||
"fake-old-path", | ||
"fake-new-path", | ||
"fake-commit-message" | ||
) | ||
|
||
expect(actual).toEqual(expected) | ||
}) | ||
|
||
describe("moveFiles", () => { | ||
it("should move files using the Git local file system if the repo is ggs enabled", async () => { | ||
const expected = { newSha: "fake-commit-sha" } | ||
MockGitFileCommitService.moveFiles.mockResolvedValueOnce(expected) | ||
gbSpy.mockReturnValueOnce(true) | ||
// MockCommitServiceGitFile.push.mockReturnValueOnce(undefined) | ||
|
||
const actual = await RepoService.moveFiles( | ||
mockUserWithSiteSessionDataAndGrowthBook, | ||
mockGithubSessionData, | ||
"fake-old-path", | ||
"fake-new-path", | ||
["fake-file1", "fake-file2"], | ||
"fake-commit-message" | ||
) | ||
|
||
expect(actual).toEqual(expected) | ||
it("should rename file using GitHub directly if the repo is not ggs enabled", async () => { | ||
const expectedSha = "fake-commit-sha" | ||
const fakeCommitMessage = "fake-commit-message" | ||
const sessionData: UserWithSiteSessionData = new UserWithSiteSessionData({ | ||
githubId: mockGithubId, | ||
accessToken: mockAccessToken, | ||
isomerUserId: mockIsomerUserId, | ||
email: mockEmail, | ||
siteName: "not-whitelisted", | ||
}) | ||
|
||
it("should move files using GitHub directly if the repo is not ggs enabled", async () => { | ||
const expected = { newSha: "fake-commit-sha" } | ||
const fakeCommitMessage = "fake-commit-message" | ||
const sessionData: UserWithSiteSessionData = new UserWithSiteSessionData( | ||
{ | ||
githubId: mockGithubId, | ||
accessToken: mockAccessToken, | ||
isomerUserId: mockIsomerUserId, | ||
email: mockEmail, | ||
siteName: "not-whitelisted", | ||
} | ||
) | ||
|
||
const gitHubServiceMoveFiles = jest.spyOn( | ||
GitHubService.prototype, | ||
"moveFiles" | ||
) | ||
gitHubServiceMoveFiles.mockResolvedValueOnce(expected) | ||
|
||
const actual = await RepoService.moveFiles( | ||
sessionData, | ||
mockGithubSessionData, | ||
"fake-path", | ||
"fake-new-path", | ||
["old-fake-file.md", "old-fake-file-two.md"], | ||
fakeCommitMessage | ||
) | ||
|
||
expect(actual).toEqual(expected) | ||
const gitHubServiceRenameSinglePath = jest.spyOn( | ||
GitHubService.prototype, | ||
"renameSinglePath" | ||
) | ||
gitHubServiceRenameSinglePath.mockResolvedValueOnce({ | ||
newSha: expectedSha, | ||
}) | ||
|
||
const actual = await RepoService.renameSinglePath( | ||
sessionData, | ||
mockGithubSessionData, | ||
"fake-path/old-fake-file.md", | ||
"fake-path/new-fake-file.md", | ||
fakeCommitMessage | ||
) | ||
|
||
expect(actual).toEqual({ newSha: expectedSha }) | ||
}) | ||
}) | ||
|
||
describe("getLatestCommitOfBranch", () => { | ||
it("should read the latest commit data from the local Git file system if the repo is ggs enabled", async () => { | ||
const expected: GitHubCommitData = { | ||
author: { | ||
name: "test author", | ||
email: "[email protected]", | ||
date: "2023-07-20T11:25:05+08:00", | ||
}, | ||
sha: "test-sha", | ||
message: "test message", | ||
} | ||
gbSpy.mockReturnValueOnce(true) | ||
MockGitFileSystemService.getLatestCommitOfBranch.mockResolvedValueOnce( | ||
okAsync(expected) | ||
) | ||
|
||
const actual = await RepoService.getLatestCommitOfBranch( | ||
mockUserWithSiteSessionDataAndGrowthBook, | ||
"master" | ||
) | ||
expect(actual).toEqual(expected) | ||
}) | ||
describe("moveFiles", () => { | ||
it("should move files using the Git local file system if the repo is ggs enabled", async () => { | ||
const expected = { newSha: "fake-commit-sha" } | ||
MockGitFileCommitService.moveFiles.mockResolvedValueOnce(expected) | ||
gbSpy.mockReturnValueOnce(true) | ||
// MockCommitServiceGitFile.push.mockReturnValueOnce(undefined) | ||
|
||
it("should read latest commit data from GitHub if the repo is not ggs enabled", async () => { | ||
const sessionData: UserWithSiteSessionData = new UserWithSiteSessionData( | ||
{ | ||
githubId: mockGithubId, | ||
accessToken: mockAccessToken, | ||
isomerUserId: mockIsomerUserId, | ||
email: mockEmail, | ||
siteName: "not-whitelisted", | ||
} | ||
) | ||
const expected: GitHubCommitData = { | ||
author: { | ||
name: "test author", | ||
email: "[email protected]", | ||
date: "2023-07-20T11:25:05+08:00", | ||
}, | ||
message: "test message", | ||
} | ||
const gitHubServiceReadDirectory = jest.spyOn( | ||
GitHubService.prototype, | ||
"getLatestCommitOfBranch" | ||
) | ||
gitHubServiceReadDirectory.mockResolvedValueOnce(expected) | ||
const actual = await RepoService.getLatestCommitOfBranch( | ||
sessionData, | ||
"master" | ||
) | ||
expect(actual).toEqual(expected) | ||
const actual = await RepoService.moveFiles( | ||
mockUserWithSiteSessionDataAndGrowthBook, | ||
mockGithubSessionData, | ||
"fake-old-path", | ||
"fake-new-path", | ||
["fake-file1", "fake-file2"], | ||
"fake-commit-message" | ||
) | ||
|
||
expect(actual).toEqual(expected) | ||
}) | ||
|
||
it("should move files using GitHub directly if the repo is not ggs enabled", async () => { | ||
const expected = { newSha: "fake-commit-sha" } | ||
const fakeCommitMessage = "fake-commit-message" | ||
const sessionData: UserWithSiteSessionData = new UserWithSiteSessionData({ | ||
githubId: mockGithubId, | ||
accessToken: mockAccessToken, | ||
isomerUserId: mockIsomerUserId, | ||
email: mockEmail, | ||
siteName: "not-whitelisted", | ||
}) | ||
|
||
const gitHubServiceMoveFiles = jest.spyOn( | ||
GitHubService.prototype, | ||
"moveFiles" | ||
) | ||
gitHubServiceMoveFiles.mockResolvedValueOnce(expected) | ||
|
||
const actual = await RepoService.moveFiles( | ||
sessionData, | ||
mockGithubSessionData, | ||
"fake-path", | ||
"fake-new-path", | ||
["old-fake-file.md", "old-fake-file-two.md"], | ||
fakeCommitMessage | ||
) | ||
|
||
expect(actual).toEqual(expected) | ||
}) | ||
}) | ||
|
||
describe("getLatestCommitOfBranch", () => { | ||
it("should read the latest commit data from the local Git file system if the repo is ggs enabled", async () => { | ||
const expected: GitHubCommitData = { | ||
author: { | ||
name: "test author", | ||
email: "[email protected]", | ||
date: "2023-07-20T11:25:05+08:00", | ||
}, | ||
sha: "test-sha", | ||
message: "test message", | ||
} | ||
gbSpy.mockReturnValueOnce(true) | ||
MockGitFileSystemService.getLatestCommitOfBranch.mockResolvedValueOnce( | ||
okAsync(expected) | ||
) | ||
|
||
const actual = await RepoService.getLatestCommitOfBranch( | ||
mockUserWithSiteSessionDataAndGrowthBook, | ||
"master" | ||
) | ||
expect(actual).toEqual(expected) | ||
}) | ||
|
||
describe("updateRepoState", () => { | ||
it("should update the repo state on the local Git file system if the repo is ggs enabled", async () => { | ||
MockGitFileSystemService.updateRepoState.mockResolvedValueOnce( | ||
okAsync(undefined) | ||
) | ||
gbSpy.mockReturnValueOnce(true) | ||
|
||
await RepoService.updateRepoState( | ||
mockUserWithSiteSessionDataAndGrowthBook, | ||
{ | ||
commitSha: "fake-sha", | ||
branchName: "master", | ||
} | ||
) | ||
|
||
expect(MockGitFileSystemService.updateRepoState).toBeCalledTimes(1) | ||
it("should read latest commit data from GitHub if the repo is not ggs enabled", async () => { | ||
const sessionData: UserWithSiteSessionData = new UserWithSiteSessionData({ | ||
githubId: mockGithubId, | ||
accessToken: mockAccessToken, | ||
isomerUserId: mockIsomerUserId, | ||
email: mockEmail, | ||
siteName: "not-whitelisted", | ||
}) | ||
const expected: GitHubCommitData = { | ||
author: { | ||
name: "test author", | ||
email: "[email protected]", | ||
date: "2023-07-20T11:25:05+08:00", | ||
}, | ||
message: "test message", | ||
} | ||
const gitHubServiceReadDirectory = jest.spyOn( | ||
GitHubService.prototype, | ||
"getLatestCommitOfBranch" | ||
) | ||
gitHubServiceReadDirectory.mockResolvedValueOnce(expected) | ||
const actual = await RepoService.getLatestCommitOfBranch( | ||
sessionData, | ||
"master" | ||
) | ||
expect(actual).toEqual(expected) | ||
}) | ||
}) | ||
|
||
describe("updateRepoState", () => { | ||
it("should update the repo state on the local Git file system if the repo is ggs enabled", async () => { | ||
MockGitFileSystemService.updateRepoState.mockResolvedValueOnce( | ||
okAsync(undefined) | ||
) | ||
gbSpy.mockReturnValueOnce(true) | ||
|
||
it("should update the repo state on GitHub if the repo is not ggs enabled", async () => { | ||
const sessionData: UserWithSiteSessionData = new UserWithSiteSessionData( | ||
{ | ||
githubId: mockGithubId, | ||
accessToken: mockAccessToken, | ||
isomerUserId: mockIsomerUserId, | ||
email: mockEmail, | ||
siteName: "not-whitelisted", | ||
} | ||
) | ||
const gitHubServiceUpdateRepoState = jest.spyOn( | ||
GitHubService.prototype, | ||
"updateRepoState" | ||
) | ||
gitHubServiceUpdateRepoState.mockResolvedValueOnce(undefined) | ||
|
||
await RepoService.updateRepoState(sessionData, { | ||
await RepoService.updateRepoState( | ||
mockUserWithSiteSessionDataAndGrowthBook, | ||
{ | ||
commitSha: "fake-sha", | ||
branchName: "master", | ||
}) | ||
} | ||
) | ||
|
||
expect(MockGitFileSystemService.updateRepoState).toBeCalledTimes(1) | ||
}) | ||
|
||
it("should update the repo state on GitHub if the repo is not ggs enabled", async () => { | ||
const sessionData: UserWithSiteSessionData = new UserWithSiteSessionData({ | ||
githubId: mockGithubId, | ||
accessToken: mockAccessToken, | ||
isomerUserId: mockIsomerUserId, | ||
email: mockEmail, | ||
siteName: "not-whitelisted", | ||
}) | ||
const gitHubServiceUpdateRepoState = jest.spyOn( | ||
GitHubService.prototype, | ||
"updateRepoState" | ||
) | ||
gitHubServiceUpdateRepoState.mockResolvedValueOnce(undefined) | ||
|
||
expect(gitHubServiceUpdateRepoState).toBeCalledTimes(1) | ||
await RepoService.updateRepoState(sessionData, { | ||
commitSha: "fake-sha", | ||
branchName: "master", | ||
}) | ||
|
||
expect(gitHubServiceUpdateRepoState).toBeCalledTimes(1) | ||
}) | ||
}) | ||
}) |