From db224c1f9723bdf3f0b0ffdeb5839e015262e8f0 Mon Sep 17 00:00:00 2001 From: Prantadas Date: Sun, 28 Jul 2024 10:21:36 +0600 Subject: [PATCH] feat: juz api wrapped and tested --- src/quran/juz.test.ts | 10 ++++++++++ src/quran/juz.ts | 18 ++++++++++++++++++ src/types.ts | 10 ++++++++++ 3 files changed, 38 insertions(+) create mode 100644 src/quran/juz.test.ts create mode 100644 src/quran/juz.ts diff --git a/src/quran/juz.test.ts b/src/quran/juz.test.ts new file mode 100644 index 0000000..d8dd0e5 --- /dev/null +++ b/src/quran/juz.test.ts @@ -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'); + }); +}); \ No newline at end of file diff --git a/src/quran/juz.ts b/src/quran/juz.ts new file mode 100644 index 0000000..35241ed --- /dev/null +++ b/src/quran/juz.ts @@ -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 { + return new Promise((resolve, reject) => { + api.get('/juzs') + .then(handleResponse(resolve)) + .catch(handleError(reject)); + }); + }, +}; + +export default juz; \ No newline at end of file diff --git a/src/types.ts b/src/types.ts index dca9138..7283584 100644 --- a/src/types.ts +++ b/src/types.ts @@ -167,4 +167,14 @@ export interface ChapterApi { listChapters: (language?: string) => Promise; getChapter: (id: number, language?: string) => Promise; getChapterInfo: (chapter_id: number, language?: string) => Promise; +}; + + +export interface JuzResponse { + juzs: any[]; +}; + + +export interface JuzApi { + getAllJuzs: () => Promise; }; \ No newline at end of file