-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #131 from Suraj-Bhandarkar-S/v.0.13.0
test cases for Phone number
- Loading branch information
Showing
1 changed file
with
114 additions
and
0 deletions.
There are no files selected for viewing
114 changes: 114 additions & 0 deletions
114
modules/phone-numbers/test/api/phone-number-routes.test.ts
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,114 @@ | ||
import countryNumberData from '../../consts/countryNumberData' | ||
|
||
const request = require('supertest'); | ||
const baseURL = 'http://localhost:3000'; | ||
|
||
|
||
// Test case: for One phone number is returned check | ||
describe('phonenumber api endpoints', () => { | ||
describe('GET /phonenumbers/', () => { | ||
it('should return a one random country phonenumbers', async () => { | ||
const qty = 1; | ||
|
||
const response = await request(baseURL).get('/phonenumbers/'); | ||
expect([response.body].length).toStrictEqual(qty) | ||
}); | ||
}); | ||
}); | ||
|
||
// Test case: for One phone number imei is returned check | ||
describe('phonenumber imei endpoints', () => { | ||
describe('GET /phonenumbers/imei', () => { | ||
it('should return a one random imei', async () => { | ||
const qty = 1; | ||
const response = await request(baseURL).get('/phonenumbers/imei'); | ||
expect([response.body].length).toStrictEqual(qty) | ||
}); | ||
}); | ||
}); | ||
|
||
// Test case: for One phone number with format: space is returned check | ||
|
||
describe('phonenumber with country code & format endpoints', () => { | ||
describe('GET /phonenumbers/country/:cc/:format?', () => { | ||
it('should return a one random imei', async () => { | ||
const countrycode = 'US'; | ||
const format ='space'; | ||
const qty = 1; | ||
const response = await request(baseURL).get(`/phonenumbers/country/${countrycode}/${format}`); | ||
expect([response.body].length).toStrictEqual(qty) | ||
}); | ||
}); | ||
}); | ||
|
||
|
||
// Test case: for One phone number with format: nospace is returned check | ||
describe('phonenumber with country code & format endpoints', () => { | ||
describe('GET /phonenumbers/country/:cc/:format?', () => { | ||
it('should return a one random imei', async () => { | ||
const countrycode = 'GB'; | ||
const format ='nospace'; | ||
const qty = 1; | ||
const response = await request(baseURL).get(`/phonenumbers/country/${countrycode}/${format}`); | ||
expect([response.body].length).toStrictEqual(qty) | ||
}); | ||
}); | ||
}); | ||
|
||
// Test case: for One phone number with format: dash is returned check | ||
describe('phonenumber with country code & format endpoints', () => { | ||
describe('GET /phonenumbers/country/:cc/:format?', () => { | ||
it('should return a one random imei', async () => { | ||
const countrycode = 'US'; | ||
const format ='dash'; | ||
const qty = 1; | ||
const response = await request(baseURL).get(`/phonenumbers/country/${countrycode}/${format}`); | ||
expect([response.body].length).toStrictEqual(qty) | ||
}); | ||
}); | ||
}); | ||
|
||
//Test case: US and format space regex | ||
describe('phonenumber with country code as US & format space', () => { | ||
describe('GET /phonenumbers/country/:cc/:format?', () => { | ||
it('should return a one random imei', async () => { | ||
const countrycode = 'US'; | ||
const format ='space'; | ||
const qty = 1; | ||
const response = await request(baseURL).get(`/phonenumbers/country/${countrycode}/${format}`); | ||
expect(/^[+](1\s?)?(\d{3}|\(\d{3}\))[\s]?\d{3}[\s]?\d{4}$/.test(response.body)) | ||
}); | ||
}); | ||
}); | ||
|
||
|
||
//Test case: US and format dash regex | ||
describe('phonenumber with country code as US & format space', () => { | ||
describe('GET /phonenumbers/country/:cc/:format?', () => { | ||
it('should return a one random imei', async () => { | ||
const countrycode = 'US'; | ||
const format ='dash'; | ||
const qty = 1; | ||
const response = await request(baseURL).get(`/phonenumbers/country/${countrycode}/${format}`); | ||
expect(/^[+](1\-?)?(\d{3}|\(\d{3}\))[\-]?\d{3}[\-]?\d{4}$/.test(response.body)) | ||
}); | ||
}); | ||
}); | ||
|
||
|
||
//Test case: US and format no space regex | ||
describe('phonenumber with country code as US & format space', () => { | ||
describe('GET /phonenumbers/country/:cc/:format?', () => { | ||
it('should return a one random imei', async () => { | ||
const countrycode = 'US'; | ||
const format ='dash'; | ||
const qty = 1; | ||
const response = await request(baseURL).get(`/phonenumbers/country/${countrycode}/${format}`); | ||
expect(/^[+](1?)?(\d{3}|\(\d{3}\))?\d{3}?\d{4}$/.test(response.body)) | ||
}); | ||
}); | ||
}); | ||
|
||
|
||
|
||
|