Skip to content

Commit

Permalink
Add a prayer test that tests all fixed prayer times
Browse files Browse the repository at this point in the history
  • Loading branch information
kosratdev committed Feb 19, 2024
1 parent 93826f3 commit 9c94e5f
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 18 deletions.
8 changes: 4 additions & 4 deletions Example/MuslimData.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = 4HFFW4423Q;
INFOPLIST_FILE = MuslimData/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -635,7 +635,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = 4HFFW4423Q;
INFOPLIST_FILE = MuslimData/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -661,7 +661,7 @@
"$(inherited)",
);
INFOPLIST_FILE = Tests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -684,7 +684,7 @@
"$(inherited)",
);
INFOPLIST_FILE = Tests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
2 changes: 1 addition & 1 deletion Example/Tests/CityMapperTests/IQCityMapperTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class IQCityMapperTests: XCTestCase {
XCTAssertEqual("Wasan".mapper(countryCode: "IQ"), "Qasre")
XCTAssertEqual("Choma".mapper(countryCode: "IQ"), "Qasre")
XCTAssertEqual("Mergay Khwaru".mapper(countryCode: "IQ"), "Qasre")
XCTAssertEqual("Kani Bast".mapper(countryCode: "IQ"), "Qasre")
XCTAssertEqual("Kani bast".mapper(countryCode: "IQ"), "Qasre")
}

func testKirkukCityMapper() {
Expand Down
2 changes: 1 addition & 1 deletion Example/Tests/CityMapperTests/KWCityMapperTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class KWCityMapperTests: XCTestCase {
XCTAssertEqual("Bneid Al Qar".mapper(countryCode: "KW"), "Al Asimah")
XCTAssertEqual("Kaifan".mapper(countryCode: "KW"), "Al Asimah")
XCTAssertEqual("Mansouriya".mapper(countryCode: "KW"), "Al Asimah")
XCTAssertEqual("Abdullah Al-Salem".mapper(countryCode: "KW"), "Al Asimah")
XCTAssertEqual("Abdullah al-Salem".mapper(countryCode: "KW"), "Al Asimah")
XCTAssertEqual("Nuzha".mapper(countryCode: "KW"), "Al Asimah")
XCTAssertEqual("Faiha".mapper(countryCode: "KW"), "Al Asimah")
XCTAssertEqual("Shamiya".mapper(countryCode: "KW"), "Al Asimah")
Expand Down
10 changes: 10 additions & 0 deletions Example/Tests/PrayerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ class PrayerTests: XCTestCase {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

func testAllFixedPrayerTimes() {
let locations = LocationHelper.shared.fixedPrayerTimesList()
locations!.forEach({ location in
PrayerTime.getPrayerTimes(location: location, date: self.date, attributes: self.attributes) { prayer, error in
XCTAssertNil(error)
XCTAssertNotNil(prayer)
}
})
}

func testFixedPrayer() {
// Test fixed prayer times for Sulav, Iraq
let sulav = Location(latitude: 0.0, longitude: 0.0, cityName: "Sulav", countryCode: "IQ",
Expand Down
4 changes: 2 additions & 2 deletions MuslimData/Assets/cityMapper.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"Bardarash": ["Mamuzin"],
"Erbil": ["Kalak", "Pirmam", "Shaqlawa", "Harir", "Khalifan", "Rawanduz", "Soran", "Mergasur", "Galala", "Choman", "Hiran", "Qushtapa", "Kasnazan"],
"Qasre": ["Wallze","Soraban","Shnawa","Rashdur","Makosan","Saya","Walash","Eskawa","Xazena","Dilman",
"Sarkan", "Chomsak","Qalat","Koila","Mawnan","Wasan","Choma","Mergay Khwaru","Kani Bast"],
"Sarkan", "Chomsak","Qalat","Koila","Mawnan","Wasan","Choma","Mergay Khwaru","Kani bast"],
"Kirkuk": ["Taza Khurmatu"],
"Sulaymaniyah": ["Mawat", "Arbat"],
"Qaladiza": ["Halsho", "Nawdasht", "Tasluja", "Bazian", "Sangasar", "Zharawa", "Bngrd", "Hero"],
Expand All @@ -21,7 +21,7 @@
"Urmia": ["Orumiyeh"]
},
"KW": {
"Al Asimah": ["Kuwait City", "Dasman Palace", "Sharq", "Mirqab", "Jibla", "Dasma", "Daiya", "Salhia", "Bneid Al Qar", "Kaifan", "Mansouriya", "Abdullah Al-Salem", "Nuzha", "Faiha", "Shamiya", "Rawda", "Adailiya", "Khaldiya", "Qadsiya", "Qortuba", "Surra", "Yarmouk", "Shuwaikh Industrial", "Rai", "Granada", "Sulaibikhat", "Doha", "Nahdha", "Jaber Al Ahmad", "Qairawan", "Ahmadi", "Al Wafrah", "Sabah Al Salem", "Messila", "Al-Masayel", "Adan", "Fnaitees", "Qusor", "Qurain", "Abu Fatira", "Mubarak Al Kabeer", "Jeleeb Al-Shuyoukh", "Eqaila", "Fintas", "Dahar", "Mahboula", "Hadiya", "Al-Riqqa", "Abu Halifa", "Fahad Al Ahmad", "Assabahiyah", "Mangaf", "Fahaheel", "South Sabahiya", "Ali Sabah Al Salem", "Shalayhat Mina Abdullah", "Zour", "Al Khiran"],
"Al Asimah": ["Kuwait City", "Dasman Palace", "Sharq", "Mirqab", "Jibla", "Dasma", "Daiya", "Salhia", "Bneid Al Qar", "Kaifan", "Mansouriya", "Abdullah al-Salem", "Nuzha", "Faiha", "Shamiya", "Rawda", "Adailiya", "Khaldiya", "Qadsiya", "Qortuba", "Surra", "Yarmouk", "Shuwaikh Industrial", "Rai", "Granada", "Sulaibikhat", "Doha", "Nahdha", "Jaber Al Ahmad", "Qairawan", "Ahmadi", "Al Wafrah", "Sabah Al Salem", "Messila", "Al-Masayel", "Adan", "Fnaitees", "Qusor", "Qurain", "Abu Fatira", "Mubarak Al Kabeer", "Jeleeb Al-Shuyoukh", "Eqaila", "Fintas", "Dahar", "Mahboula", "Hadiya", "Al-Riqqa", "Abu Halifa", "Fahad Al Ahmad", "Assabahiyah", "Mangaf", "Fahaheel", "South Sabahiya", "Ali Sabah Al Salem", "Shalayhat Mina Abdullah", "Zour", "Al Khiran"],
"Failaka Island": ["Zoor", "Kubbar Island", "Al-Nuwaiseeb"],
"Abdali": ["Jahra"]
}
Expand Down
14 changes: 7 additions & 7 deletions MuslimData/Classes/DB Helper/DBHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class DBHelper {
try dbPool?.read { dbConnect in
let result = try Row.fetchOne(dbConnect, sql: """
SELECT * FROM prayer_time
WHERE country_code = '\(countryCode)' and city = '\(city.mapper(countryCode: countryCode))'
and date = '\(formatPrayerDate(date))'
WHERE country_code = "\(countryCode)" and city = "\(city.mapper(countryCode: countryCode))"
and date = "\(formatPrayerDate(date))"
""")
guard let row = result else {
callback(nil, "Found nil while unwrapping result.")
Expand All @@ -59,7 +59,7 @@ class DBHelper {
let result = try Name.fetchAll(dbConnect, sql: """
SELECT org.name , tr.name as translated
FROM name as org
INNER JOIN name_translation as tr on tr.name_id = org._id and tr.language = '\(language)'
INNER JOIN name_translation as tr on tr.name_id = org._id and tr.language = "\(language)"
""")
guard result.count > 0 else {
callback(nil, "No row found")
Expand All @@ -84,7 +84,7 @@ class DBHelper {
SELECT org._id, category_name
FROM azkar_category as org
INNER JOIN azkar_category_translation as tr on tr.category_id = org._id
and language = '\(language)'
and language = "\(language)"
""")
guard result.count > 0 else {
callback(nil, "No row found")
Expand Down Expand Up @@ -113,7 +113,7 @@ class DBHelper {
let result = try AzkarChapter.fetchAll(dbConnect, sql: """
SELECT org._id, category_id, chapter_name
FROM azkar_chapter as org
INNER JOIN azkar_chapter_translation as tr on tr.chapter_id = org._id and language = '\(language)'
INNER JOIN azkar_chapter_translation as tr on tr.chapter_id = org._id and language = "\(language)"
\(category)
""")
guard result.count > 0 else {
Expand All @@ -139,11 +139,11 @@ class DBHelper {
let result = try AzkarItem.fetchAll(dbConnect, sql: """
SELECT org._id, org.chapter_id, org.item, tr.item_translation, rtr.reference
FROM azkar_item as org
INNER JOIN azkar_item_translation as tr on tr.item_id = org._id and tr.language = '\(language)'
INNER JOIN azkar_item_translation as tr on tr.item_id = org._id and tr.language = "\(language)"
and org.chapter_id = \(chapterId)
INNER JOIN azkar_reference as ref on ref.item_id = org._id
INNER JOIN azkar_reference_translation as rtr on rtr.reference_id = ref._id
and rtr.language = '\(language)'
and rtr.language = "\(language)"
""")
guard result.count > 0 else {
callback(nil, "No row found")
Expand Down
2 changes: 1 addition & 1 deletion MuslimData/Classes/Extensions/String+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extension String {
/// - Parameter countryCode: Country code
/// - Returns: Parent city if available else the city it self.
func mapper(countryCode: String) -> String {
let city = capitalized
let city = self
var parentCity: String?
if let path = Bundle(for: DBHelper.self).path(forResource: "cityMapper", ofType: "json") {
do {
Expand Down
23 changes: 21 additions & 2 deletions MuslimData/Classes/Location/LocationHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public struct LocationHelper {
latitude, longitude, has_fixed_prayer_time
FROM city
INNER JOIN country on city.country_code = country.country_code
WHERE city.city_name like '\(city)%'
WHERE city.city_name like "\(city)%"
""")
DispatchQueue.main.async {
callback(locations, nil)
Expand Down Expand Up @@ -64,7 +64,7 @@ public struct LocationHelper {
longitude, has_fixed_prayer_time
FROM city
INNER JOIN country on city.country_code = country.country_code
WHERE city.country_code='\(countryCode)' COLLATE NOCASE and city.city_name='\(city)' COLLATE NOCASE
WHERE city.country_code="\(countryCode)" COLLATE NOCASE and city.city_name="\(city)" COLLATE NOCASE
""")

guard var location = result else {
Expand Down Expand Up @@ -108,4 +108,23 @@ public struct LocationHelper {
callback(nil)
}
}

/// Get all the locations that has fixed prayer times.
/// - Returns: Location list
public func fixedPrayerTimesList() -> [Location]?{
do {
return try self.dbHelper.dbPool?.read { dbConnect in
let locations = try Location.fetchAll(dbConnect, sql: """
SELECT city.country_code as country_code, country_name, city_name,
latitude, longitude, has_fixed_prayer_time
FROM city
INNER JOIN country on city.country_code = country.country_code
WHERE has_fixed_prayer_time=1
""")
return locations
}
} catch {
return nil
}
}
}

0 comments on commit 9c94e5f

Please sign in to comment.