Skip to content

Commit

Permalink
Merge pull request #131 from Suraj-Bhandarkar-S/v.0.13.0
Browse files Browse the repository at this point in the history
test cases for Phone number
  • Loading branch information
ageddesi committed Oct 3, 2022
2 parents fc10425 + 68b1794 commit 887b93d
Showing 1 changed file with 114 additions and 0 deletions.
114 changes: 114 additions & 0 deletions modules/phone-numbers/test/api/phone-number-routes.test.ts
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))
});
});
});




0 comments on commit 887b93d

Please sign in to comment.