Skip to content

Commit

Permalink
chore(githubService): use existing util funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
kishore03109 committed Oct 18, 2023
1 parent 2db8196 commit 97f43d9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/services/db/GitHubService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ConflictError, inputNameConflictErrorMsg } from "@errors/ConflictError"
import { NotFoundError } from "@errors/NotFoundError"
import { UnprocessableError } from "@errors/UnprocessableError"

import { validateStatus } from "@utils/axios-utils"
import { isAxiosError, validateStatus } from "@utils/axios-utils"

import GithubSessionData from "@root/classes/GithubSessionData"
import UserWithSiteSessionData from "@root/classes/UserWithSiteSessionData"
Expand Down Expand Up @@ -240,7 +240,7 @@ export default class GitHubService {
}

async readMedia(
sessionData: { accessToken?: any; siteName?: any },
sessionData: UserWithSiteSessionData,
{
fileSha,
branchName = STAGING_BRANCH,
Expand Down Expand Up @@ -451,7 +451,7 @@ export default class GitHubService {
return data
}

async getRepoState(sessionData: { accessToken?: any; siteName?: any }) {
async getRepoState(sessionData: UserWithSiteSessionData) {
const { accessToken } = sessionData
const { siteName } = sessionData
const endpoint = `${siteName}/commits`
Expand Down Expand Up @@ -495,7 +495,7 @@ export default class GitHubService {
return latestCommitMeta
} catch (err) {
if (err instanceof NotFoundError) throw err
if (axios.isAxiosError(err) && err.response) {
if (isAxiosError(err) && err.response) {
const { status } = err.response
if (status === 422)
throw new UnprocessableError(`Branch ${branch} does not exist`)
Expand Down Expand Up @@ -643,7 +643,7 @@ export default class GitHubService {
)
return okAsync(null)
} catch (error) {
if (error instanceof AxiosError && error.response) {
if (isAxiosError(error) && error.response) {
const { status } = error.response
// If user is unauthorized or site does not exist, show the same NotFoundError
if (status === 404 || status === 403) {
Expand Down
12 changes: 6 additions & 6 deletions src/services/db/__tests__/RepoService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,17 +200,17 @@ describe("RepoService", () => {
MockCommitServiceGitHub.create.mockResolvedValueOnce(expected)

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

expect(actual).toEqual(expected)
expect(MockCommitServiceGitHub.create).toHaveBeenCalledWith(sessionData, {
content: "content",
fileName: "test.md",
directoryName: "",
content: mockContent,
fileName: mockFileName,
directoryName: mockDirectoryName,
isMedia,
})
})
Expand Down

0 comments on commit 97f43d9

Please sign in to comment.