Skip to content

Commit

Permalink
Untitled commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kishore03109 committed Dec 3, 2023
1 parent 2f033d4 commit 636e1af
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 26 deletions.
6 changes: 4 additions & 2 deletions src/services/db/GitHubService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -755,11 +755,13 @@ export default class GitHubService {

async updateRepoState(
sessionData: UserWithSiteSessionData,
{ commitSha }: { commitSha: any }
{ commitSha, branchName }: { commitSha: any; branchName?: string }
) {
const { accessToken } = sessionData
const { siteName } = sessionData
const refEndpoint = `${siteName}/git/refs/heads/${STAGING_BRANCH}`
const refEndpoint = `${siteName}/git/refs/heads/${
branchName || STAGING_BRANCH
}`
const headers = {
Authorization: `token ${accessToken}`,
}
Expand Down
21 changes: 4 additions & 17 deletions src/services/db/__tests__/GitHubService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ describe("Github Service", () => {
fileName,
directoryName,
isMedia: false,
branchName: BRANCH_REF,
})
).resolves.toMatchObject({
sha,
Expand All @@ -200,7 +199,6 @@ describe("Github Service", () => {
fileName: topLevelDirectoryFileName,
directoryName,
isMedia: false,
branchName: BRANCH_REF,
})
).resolves.toMatchObject({
sha,
Expand Down Expand Up @@ -228,7 +226,6 @@ describe("Github Service", () => {
fileName: resourceCategoryFileName,
directoryName,
isMedia: false,
branchName: BRANCH_REF,
})
).resolves.toMatchObject({
sha,
Expand Down Expand Up @@ -257,7 +254,6 @@ describe("Github Service", () => {
fileName,
directoryName,
isMedia: true,
branchName: BRANCH_REF,
})
).resolves.toMatchObject({
sha,
Expand Down Expand Up @@ -289,7 +285,6 @@ describe("Github Service", () => {
fileName,
directoryName,
isMedia: false,
branchName: BRANCH_REF,
})
).rejects.toThrowError(ConflictError)
expect(mockAxiosInstance.put).toHaveBeenCalledWith(
Expand All @@ -309,7 +304,6 @@ describe("Github Service", () => {
fileName,
directoryName,
isMedia: false,
branchName: BRANCH_REF,
})
).rejects.toThrowError(NotFoundError)
expect(mockAxiosInstance.get).toHaveBeenCalledWith(folderParentEndpoint, {
Expand All @@ -332,7 +326,6 @@ describe("Github Service", () => {
fileName: subDirectoryFileName,
directoryName: subDirectoryName,
isMedia: false,
branchName: BRANCH_REF,
})
).rejects.toThrowError()
expect(mockAxiosInstance.get).toHaveBeenCalledWith(fileParentEndpoint, {
Expand All @@ -354,7 +347,6 @@ describe("Github Service", () => {
fileName,
directoryName: `${resourceCategoryName}/_posts`,
isMedia: false,
branchName: BRANCH_REF,
})
).rejects.toThrowError(NotFoundError)
expect(mockAxiosInstance.get).toHaveBeenCalledWith(resourceRoomEndpoint, {
Expand Down Expand Up @@ -892,15 +884,10 @@ describe("Github Service", () => {
.mockResolvedValueOnce(firstResp)
.mockResolvedValueOnce(secondResp)
await expect(
service.updateTree(
sessionData,
mockGithubSessionData,
{
gitTree,
message,
},
true
)
service.updateTree(sessionData, mockGithubSessionData, {
gitTree,
message,
})
).resolves.toEqual(secondSha)
expect(mockAxiosInstance.post).toHaveBeenCalledWith(
url,
Expand Down
26 changes: 19 additions & 7 deletions src/services/db/__tests__/RepoService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ describe("RepoService", () => {
)
})

it("should create files on GitHub directly if the repo is not ggs enabled", async () => {
it("should create files on GitHub directly if the repo is not whitelisted", async () => {
const mockContent = "content"
const mockFileName = "test.md"
const mockDirectoryName = ""
Expand All @@ -176,16 +176,18 @@ describe("RepoService", () => {
const expected = {
sha: "test-sha",
}
const gitHubServiceCreate = jest.spyOn(GitHubService.prototype, "create")
gitHubServiceCreate.mockResolvedValueOnce(expected)

const actual = await RepoService.create(sessionData, {
content: mockContent,
fileName: mockFileName,
directoryName: mockDirectoryName,
content: "content",
fileName: "test.md",
directoryName: "",
isMedia,
})

expect(actual).toEqual(expected)
expect(MockGitHubService.create).toHaveBeenCalledWith(sessionData, {
expect(gitHubServiceCreate).toHaveBeenCalledWith(sessionData, {
content: mockContent,
fileName: mockFileName,
directoryName: mockDirectoryName,
Expand Down Expand Up @@ -564,6 +566,8 @@ describe("RepoService", () => {
email: mockEmail,
siteName: "not-whitelisted",
})
const gitHubServiceUpdate = jest.spyOn(GitHubService.prototype, "update")
gitHubServiceUpdate.mockResolvedValueOnce({ newSha: expectedSha })

const actual = await RepoService.update(sessionData, {
fileContent: "test content",
Expand Down Expand Up @@ -658,7 +662,11 @@ describe("RepoService", () => {
}
)

MockGitHubService.renameSinglePath.mockResolvedValueOnce({
const gitHubServiceRenameSinglePath = jest.spyOn(
GitHubService.prototype,
"renameSinglePath"
)
gitHubServiceRenameSinglePath.mockResolvedValueOnce({
newSha: expectedSha,
})

Expand Down Expand Up @@ -706,7 +714,11 @@ describe("RepoService", () => {
}
)

MockGitHubService.moveFiles.mockResolvedValueOnce(expected)
const gitHubServiceMoveFiles = jest.spyOn(
GitHubService.prototype,
"moveFiles"
)
gitHubServiceMoveFiles.mockResolvedValueOnce(expected)

const actual = await RepoService.moveFiles(
sessionData,
Expand Down

0 comments on commit 636e1af

Please sign in to comment.