Skip to content

Commit

Permalink
feat: juz api wrapped and tested
Browse files Browse the repository at this point in the history
  • Loading branch information
PrantaDas committed Jul 28, 2024
1 parent a6737cb commit db224c1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/quran/juz.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import juz from "./juz";

describe("Fetch all the juzs", () => {
beforeEach(() => jest.clearAllMocks());

it("Should fetch all the juzs", async () => {
const res = await juz.getAllJuzs();
expect(res).toHaveProperty('juzs');
});
});
18 changes: 18 additions & 0 deletions src/quran/juz.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { AxiosError } from "axios";
import Api from "../api";
import { JuzApi, JuzResponse } from "../types";
import { handleError, handleResponse } from "../utils";

const api = Api();

const juz: JuzApi = {
getAllJuzs(): Promise<JuzResponse | Error | AxiosError> {
return new Promise((resolve, reject) => {
api.get('/juzs')
.then(handleResponse(resolve))
.catch(handleError(reject));
});
},
};

export default juz;
10 changes: 10 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,14 @@ export interface ChapterApi {
listChapters: (language?: string) => Promise<ListChapters | Error | AxiosError>;
getChapter: (id: number, language?: string) => Promise<Chapter | Error | AxiosError>;
getChapterInfo: (chapter_id: number, language?: string) => Promise<ChapterInfo | Error | AxiosError>;
};


export interface JuzResponse {
juzs: any[];
};


export interface JuzApi {
getAllJuzs: () => Promise<JuzResponse | Error | AxiosError>;
};

0 comments on commit db224c1

Please sign in to comment.