Skip to content

Commit

Permalink
dev-kbin push
Browse files Browse the repository at this point in the history
  • Loading branch information
PrantaDas committed Aug 6, 2024
1 parent a8593af commit abf0ab3
Show file tree
Hide file tree
Showing 6 changed files with 383 additions and 245 deletions.
3 changes: 1 addition & 2 deletions src/quran/audio.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { AxiosError } from "axios";
import url from "url";
import Api from "../api";
import { AudioApi, AudioQueryParams, IAudio, IListOfAllAudioOfAReciter, IRecitation, ISingleRecitation, IReciters, IAyahRecitationSpecificSurah, IAyahRecitationSpecificJuz, IAyahRecitationSpecificMadaniMushafPage, IAyahRecitationSpecificRubelHizb, IAyahRecitationSpecificHizb, IAyahRecitationSpecificAyah } from "../types";
import { AudioApi, AudioQueryParams, IAudio, IListOfAllAudioOfAReciter, IRecitation, ISingleRecitation, IReciters, IAyahRecitationSpecificSurah, IAyahRecitationSpecificJuz, IAyahRecitationSpecificMadaniMushafPage, IAyahRecitationSpecificRubelHizb, IAyahRecitationSpecificHizb, IAyahRecitationSpecificAyah, ALLOWED_LANGUAGES } from "../types";
import { handleError, handleResponse } from "../utils";

const api = Api();

const ALLOWED_LANGUAGES = new Set(['en', 'ur', 'bn', 'tr', 'es', 'fr', 'bs', 'ru', 'ml', 'id', 'uz', 'nl', 'de', 'tg', 'ta', 'ja', 'it', 'vi', 'zh', 'sq', 'fa', 'bg', 'bm', 'ha', 'pt', 'ro', 'hi', 'sw', 'kk', 'th', 'tl', 'km', 'as', 'ko', 'so', 'az', 'ku', 'dv', 'ms', 'prs', 'zgh', 'am', 'ce', 'cs', 'fi', 'gu', 'he', 'ka', 'kn', 'ks', 'lg', 'mk', 'mr', 'mrn', 'ne', 'no', 'om', 'pl', 'ps', 'rw', 'sd', 'se', 'si', 'sr', 'sv', 'te', 'tt', 'ug', 'uk', 'sq', 'yo']);

const audio: AudioApi = {

Expand Down
4 changes: 1 addition & 3 deletions src/quran/chapter.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { AxiosError } from "axios";
import Api from "../api";
import { ChapterApi, ListChapters, Chapter, ChapterInfo } from "../types";
import { ChapterApi, ListChapters, Chapter, ChapterInfo, ALLOWED_LANGUAGES } from "../types";
import { handleError, handleResponse } from "../utils";

const api = Api();

const ALLOWED_LANGUAGES = new Set(['en', 'ur', 'bn', 'tr', 'es', 'fr', 'bs', 'ru', 'ml', 'id', 'uz', 'nl', 'de', 'tg', 'ta', 'ja', 'it', 'vi', 'zh', 'sq', 'fa', 'bg', 'bm', 'ha', 'pt', 'ro', 'hi', 'sw', 'kk', 'th', 'tl', 'km', 'as', 'ko', 'so', 'az', 'ku', 'dv', 'ms', 'prs', 'zgh', 'am', 'ce', 'cs', 'fi', 'gu', 'he', 'ka', 'kn', 'ks', 'lg', 'mk', 'mr', 'mrn', 'ne', 'no', 'om', 'pl', 'ps', 'rw', 'sd', 'se', 'si', 'sr', 'sv', 'te', 'tt', 'ug', 'uk', 'sq', 'yo']);


const chapter: ChapterApi = {
listChapters(language = 'en'): Promise<ListChapters | Error | AxiosError> {
Expand Down
200 changes: 100 additions & 100 deletions src/quran/resource.test.ts
Original file line number Diff line number Diff line change
@@ -1,131 +1,131 @@
import resources from "./resource";

describe("Fetching the recitation by id", () => {
beforeEach(() => jest.clearAllMocks());

it("Should fetch the recitation info of a specific recitaion", async () => {
const res: any = await resources.getRecitationInfo('1');
expect(res).toHaveProperty('info');
expect(res.info).toHaveProperty('id');
expect(res.info).toHaveProperty('info');
});

it("Should return a response with 404 status code", async () => {
const res: any = await resources.getRecitationInfo('101839');
expect(res).toHaveProperty('status');
expect(res.status).toEqual(404);
});
beforeEach(() => jest.clearAllMocks());

it("Should fetch the recitation info of a specific recitaion", async () => {
const res: any = await resources.getRecitationInfo('1');
expect(res).toHaveProperty('info');
expect(res.info).toHaveProperty('id');
expect(res.info).toHaveProperty('info');
});

it("Should return a response with 404 status code", async () => {
const res: any = await resources.getRecitationInfo('101839');
expect(res).toHaveProperty('status');
expect(res.status).toEqual(404);
});
});

describe("Fetching the translation info by translation_id", () => {
beforeEach(() => jest.clearAllMocks());

it("Should fetch the translation info of a specific recitaion by translation_id", async () => {
const res: any = await resources.getTranslationInfo('23');
expect(res).toHaveProperty('info');
expect(res.info).toHaveProperty('id');
expect(res.info).toHaveProperty('info');
expect(res.info.info).toBeNull();
});

it("Should return a response with 404 status code", async () => {
const res: any = await resources.getTranslationInfo('101839');
expect(res).toHaveProperty('status');
expect(res.status).toEqual(404);
});
beforeEach(() => jest.clearAllMocks());

it("Should fetch the translation info of a specific recitaion by translation_id", async () => {
const res: any = await resources.getTranslationInfo('23');
expect(res).toHaveProperty('info');
expect(res.info).toHaveProperty('id');
expect(res.info).toHaveProperty('info');
expect(res.info.info).toBeNull();
});

it("Should return a response with 404 status code", async () => {
const res: any = await resources.getTranslationInfo('101839');
expect(res).toHaveProperty('status');
expect(res.status).toEqual(404);
});
});

describe("Fetching all translations info by language", () => {
beforeEach(() => jest.clearAllMocks());

it("Should fetch all translations info by language", async () => {
const res: any = await resources.getTranslations('ha');
expect(res).toHaveProperty('translations');
});

it("Should reject with a error if an invalid language iso code is provided", async () => {
try {
const res: any = await resources.getTranslations('abcd');
} catch (err: any) {
expect(err.message).toEqual('Provided language is not supported');
}
});
beforeEach(() => jest.clearAllMocks());

it("Should fetch all translations info by language", async () => {
const res: any = await resources.getTranslations('ha');
expect(res).toHaveProperty('translations');
});

it("Should reject with a error if an invalid language iso code is provided", async () => {
try {
const res: any = await resources.getTranslations('abcd');
} catch (err: any) {
expect(err.message).toEqual('Provided language is not supported');
}
});
});

describe("Fetching all tafsirs info by language", () => {
beforeEach(() => jest.clearAllMocks());

it("Should fetch all tafsirs info by language", async () => {
const res: any = await resources.getTafsirs('ha');
expect(res).toHaveProperty('tafsirs');
});

it("Should reject with a error if an invalid language iso code is provided", async () => {
try {
const res: any = await resources.getTafsirs('abcd');
} catch (err: any) {
expect(err.message).toEqual('Provided language is not supported');
}
});
beforeEach(() => jest.clearAllMocks());

it("Should fetch all tafsirs info by language", async () => {
const res: any = await resources.getTafsirs('ha');
expect(res).toHaveProperty('tafsirs');
});

it("Should reject with a error if an invalid language iso code is provided", async () => {
try {
const res: any = await resources.getTafsirs('abcd');
} catch (err: any) {
expect(err.message).toEqual('Provided language is not supported');
}
});
});

describe("Fetching tafsir info by tafsir_id", () => {
beforeEach(() => jest.clearAllMocks());

it("Should fetch tafsir info by tafsir_id", async () => {
const res: any = await resources.getTafsirInfo('381');
expect(res).toHaveProperty('info');
expect(res.info).toHaveProperty('id');
expect(res.info.id).toBe(381);
expect(res.info.info).toBe("");
});

it("Should reject with a error if an invalid tafsir_id is provided", async () => {
const res: any = await resources.getTafsirInfo('1');
expect(res).toHaveProperty('status');
expect(res.status).toEqual(404);
expect(res.error).toBe('Tafsir not found');
});
beforeEach(() => jest.clearAllMocks());

it("Should fetch tafsir info by tafsir_id", async () => {
const res: any = await resources.getTafsirInfo('381');
expect(res).toHaveProperty('info');
expect(res.info).toHaveProperty('id');
expect(res.info.id).toBe(381);
expect(res.info.info).toBe("");
});

it("Should reject with a error if an invalid tafsir_id is provided", async () => {
const res: any = await resources.getTafsirInfo('1');
expect(res).toHaveProperty('status');
expect(res.status).toEqual(404);
expect(res.error).toBe('Tafsir not found');
});
});

describe("Fetching all recitation styles", () => {
beforeEach(() => jest.clearAllMocks());

it("Should fetch all recitation styles", async () => {
const res: any = await resources.getRecitationStyles();
expect(res).toHaveProperty('recitation_styles');
expect(res.recitation_styles).toHaveProperty('mujawwad');
expect(res.recitation_styles).toHaveProperty('murattal');
expect(res.recitation_styles).toHaveProperty('muallim');
});
beforeEach(() => jest.clearAllMocks());

it("Should fetch all recitation styles", async () => {
const res: any = await resources.getRecitationStyles();
expect(res).toHaveProperty('recitation_styles');
expect(res.recitation_styles).toHaveProperty('mujawwad');
expect(res.recitation_styles).toHaveProperty('murattal');
expect(res.recitation_styles).toHaveProperty('muallim');
});
});

describe("Fetching all languages", () => {
beforeEach(() => jest.clearAllMocks());
beforeEach(() => jest.clearAllMocks());

it("Should fetch all languages", async () => {
const res: any = await resources.getLanguages();
expect(res).toHaveProperty('languages');;
expect(res.languages).toBeInstanceOf(Array);
});
it("Should fetch all languages", async () => {
const res: any = await resources.getLanguages();
expect(res).toHaveProperty('languages');;
expect(res.languages).toBeInstanceOf(Array);
});
});

describe("Fetching all Chapter infos", () => {
beforeEach(() => jest.clearAllMocks());
beforeEach(() => jest.clearAllMocks());

it("Should fetch all Chapter infos", async () => {
const res: any = await resources.getChapterInfos();
expect(res).toHaveProperty('chapter_infos');;
expect(res.chapter_infos).toBeInstanceOf(Array);
});
it("Should fetch all Chapter infos", async () => {
const res: any = await resources.getChapterInfos();
expect(res).toHaveProperty('chapter_infos');;
expect(res.chapter_infos).toBeInstanceOf(Array);
});
});

describe("Fetching all Media verses", () => {
beforeEach(() => jest.clearAllMocks());
beforeEach(() => jest.clearAllMocks());

it("Should fetch all Media verses", async () => {
const res: any = await resources.getVerseMedias();
expect(res).toHaveProperty('verse_media');;
expect(res.verse_media).toBeInstanceOf(Array);
});
it("Should fetch all Media verses", async () => {
const res: any = await resources.getVerseMedias();
expect(res).toHaveProperty('verse_media');;
expect(res.verse_media).toBeInstanceOf(Array);
});
});
3 changes: 1 addition & 2 deletions src/quran/resource.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { AxiosError } from "axios";
import Api from "../api";
import { ResourceApi, RecitaionInfo, TranslationInfo, TranslationResponse, TafsirsResponse, TafsirInfoResponse, RecitationStyleResponse, LanguageResponse, ChapterInfos, VerseMediaResponse } from "../types";
import { ResourceApi, RecitaionInfo, TranslationInfo, TranslationResponse, TafsirsResponse, TafsirInfoResponse, RecitationStyleResponse, LanguageResponse, ChapterInfos, VerseMediaResponse, ALLOWED_LANGUAGES } from "../types";
import { handleError, handleResponse } from "../utils";

const api = Api();

const ALLOWED_LANGUAGES = new Set(['en', 'ur', 'bn', 'tr', 'es', 'fr', 'bs', 'ru', 'ml', 'id', 'uz', 'nl', 'de', 'tg', 'ta', 'ja', 'it', 'vi', 'zh', 'sq', 'fa', 'bg', 'bm', 'ha', 'pt', 'ro', 'hi', 'sw', 'kk', 'th', 'tl', 'km', 'as', 'ko', 'so', 'az', 'ku', 'dv', 'ms', 'prs', 'zgh', 'am', 'ce', 'cs', 'fi', 'gu', 'he', 'ka', 'kn', 'ks', 'lg', 'mk', 'mr', 'mrn', 'ne', 'no', 'om', 'pl', 'ps', 'rw', 'sd', 'se', 'si', 'sr', 'sv', 'te', 'tt', 'ug', 'uk', 'sq', 'yo']);

const resources: ResourceApi = {
getRecitationInfo(recitation_id: string): Promise<RecitaionInfo | Error | AxiosError> {
Expand Down
54 changes: 54 additions & 0 deletions src/quran/verse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { AxiosError } from "axios";
import Api from "../api";
import { ALLOWED_LANGUAGES, VerseApi, VerseQuery, VerseResponse } from "../types";
import { handleError, handleResponse } from "../utils";

const api = Api();

const verse: VerseApi = {
getVerseByChapter(chapter_number: string, query?: VerseQuery): Promise<VerseResponse | AxiosError | Error> {
if (query?.language && !ALLOWED_LANGUAGES.has(query.language)) throw new Error('Provided query language is not allowed');
const uri = query ? `/verses/by_chapter/${chapter_number}?${new URLSearchParams(query as URLSearchParams)}` : `/verses/by_chapter/${chapter_number}`;
return new Promise((resolve, reject) => {
api.get(uri)
.then(handleResponse(resolve))
.catch(handleError(reject));
});
},
getVerseByPage(page_number: string, query?: VerseQuery): Promise<VerseResponse | AxiosError | Error> {
if (query?.language && !ALLOWED_LANGUAGES.has(query.language)) throw new Error('Provided query language is not allowed');
const uri = query ? `/verses/by_page/${page_number}?${new URLSearchParams(query as URLSearchParams)}` : `/verses/by_page/${page_number}`;
return new Promise((resolve, reject) => {
api.get(uri)
.then(handleResponse(resolve))
.catch(handleError(reject));
});
},
getVerseByJuz(juz_number: string, query?: VerseQuery): Promise<VerseResponse | AxiosError | Error> {
if (query?.language && !ALLOWED_LANGUAGES.has(query.language)) throw new Error('Provided query language is not allowed');
const uri = query ? `/verses/by_juz/${juz_number}?${new URLSearchParams(query as URLSearchParams)}` : `/verses/by_juz/${juz_number}`;
return new Promise((resolve, reject) => {
api.get(uri)
.then(handleResponse(resolve))
.catch(handleError(reject));
});
},
getVerseByHizbNumber(hizb_number: string, query?: VerseQuery): Promise<VerseResponse | AxiosError | Error> {
if (query?.language && !ALLOWED_LANGUAGES.has(query.language)) throw new Error('Provided query language is not allowed');
const uri = query ? `/verses/by_hizb/${hizb_number}?${new URLSearchParams(query as URLSearchParams)}` : `/verses/by_hizb/${hizb_number}`;
return new Promise((resolve, reject) => {
api.get(uri)
.then(handleResponse(resolve))
.catch(handleError(reject));
});
},
getVerseByRubElHizbNumber(rub_el_hizb_number: string, query?: VerseQuery): Promise<VerseResponse | AxiosError | Error> {
if (query?.language && !ALLOWED_LANGUAGES.has(query.language)) throw new Error('Provided query language is not allowed');
const uri = query ? `/verses/by_rub/${rub_el_hizb_number}?${new URLSearchParams(query as URLSearchParams)}` : `/verses/by_rub/${rub_el_hizb_number}`;
return new Promise((resolve, reject) => {
api.get(uri)
.then(handleResponse(resolve))
.catch(handleError(reject));
});
},
};
Loading

0 comments on commit abf0ab3

Please sign in to comment.