forked from dzcode-io/leblad
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added getPhoneCodeForWilaya method that returns the first phone code from a list of phone codes for a given wilaya re dzcode-io#19
- Loading branch information
1 parent
ddd3b78
commit 75b9b3c
Showing
5 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const getPhoneCodesForWilaya = require('./getPhoneCodesForWilaya'); | ||
|
||
const getPhoneCodeForWilaya = data => | ||
/** | ||
* Takes a wilaya code (mattricule) and returns the first phone code in wilaya's phone code list. | ||
* | ||
* @example Get phone codes for Alger (code: 16) | ||
* | ||
* //returns 21 | ||
* getPhoneCodeForWilaya(16) | ||
* | ||
* @param { Number } wilayaCode wilaya code (mattricule) | ||
* @returns { Number | Undefined } Returns the first phone code for wilaya, or undefined | ||
*/ | ||
|
||
(wilayaCode) => { | ||
const phoneCodes = getPhoneCodesForWilaya(data)(wilayaCode) || []; | ||
return phoneCodes[0]; | ||
}; | ||
|
||
module.exports = getPhoneCodeForWilaya; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
describe('get phone codes for a wilaya', ()=> { | ||
const mockData = [{ | ||
mattricule: 16, | ||
name: "Alger", | ||
phoneCodes: [21, 23] | ||
}, | ||
{ | ||
mattricule: 31, | ||
name: "Oran", | ||
phoneCodes: [41] | ||
}, | ||
{ | ||
mattricule: 48, | ||
name: "Relizane", | ||
phoneCodes: [46], | ||
}]; | ||
|
||
let getPhoneCodeForWilaya; | ||
|
||
beforeEach(()=> { | ||
getPhoneCodeForWilaya = require('../../src/api/getPhoneCodeForWilaya'); | ||
}); | ||
|
||
it('should export a function', () => { | ||
expect(typeof getPhoneCodeForWilaya).toBe('function'); | ||
}); | ||
|
||
it('should return a curried function that returns the data', () => { | ||
const fn = getPhoneCodeForWilaya(mockData); | ||
|
||
expect(typeof fn).toBe('function'); | ||
}); | ||
|
||
it('should return undefined if the phone codes for the given wilaya code could not be found', () => { | ||
const result = getPhoneCodeForWilaya(mockData)(9); | ||
|
||
expect(result).toBeUndefined(); | ||
}); | ||
|
||
it('should return the correct phone code for a given wilaya', () => { | ||
const result = getPhoneCodeForWilaya(mockData)(31); | ||
|
||
expect(result).toEqual(41); | ||
}); | ||
|
||
it('should return the first phone code in an array of multiple phone codes for a given wilaya', () => { | ||
const result = getPhoneCodeForWilaya(mockData)(16); | ||
|
||
expect(result).toEqual(21); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters