Skip to content

Instantly share code, notes, and snippets.

@AbdulKabia
Last active February 2, 2018 04:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AbdulKabia/10a514aca1846f01b1de80aa9ce0418b to your computer and use it in GitHub Desktop.
Save AbdulKabia/10a514aca1846f01b1de80aa9ce0418b to your computer and use it in GitHub Desktop.
describe('API endpoint /', () => {
// GET - Root
it('Should return status 200', () => {
return chai.request(app)
.get('/')
.then((response) => {
expect(response).to.have.status(200);
expect(response.body).to.be.a('object');
});
});
});
describe('API GET request /api/phonenumbers/parse/text/nothing', () => {
// GET - No numbers
it(`Should return {"validNumbers":[],"invalidNumbers":[]}`, () => {
return chai.request(app)
.get('/api/phonenumbers/parse/text/nothing')
.then((response) => {
expect(response).to.have.status(200);
expect(response.body).to.containSubset({
"validNumbers": [],
"invalidNumbers": []
});
});
});
});
describe('API GET request /api/phonenumbers/parse/text/Seneca%20Phone%20Number%3A%20416-154-9036', () => {
// GET - Multiple Numbers
it(`Should return status 200. With {
"validNumbers":[
"(416) 154-9036",
"(905) 365-1864"
],
"invalidNumbers":[]
}`, () => {
return chai.request(app)
.get('/api/phonenumbers/parse/text/Seneca%20Phone%20Number%3A%20416-154-9036,9053651864')
.then((response) => {
expect(response).to.have.status(200);
expect(response.body).to.be.a('object');
expect(response.body).to.containSubset({
"validNumbers": [
"(416) 154-9036",
"(905) 365-1864"
],
"invalidNumbers": []
});
});
});
});
describe('API POST request /api/phonenumbers/parse/file', () => {
// POST - Multiple Numbers
it(`It should resturn status 200. With {
"validNumbers":[
"(416) 987-3546",
"(647) 315-9753",
"(905) 354-1587",
"(416) 987-3546"
],
"invalidNumbers":[]
}`, () => {
return chai.request(app)
.post('/api/phonenumbers/parse/file')
.set('Content-Type', 'text/plain;charset=base64')
.attach('myFile', fs.readFileSync('./phoneNums.txt'), ' ')
.then(function (response) {
expect(response).to.have.status(200);
expect(response.body).to.containSubset({
"validNumbers": [
"(416) 987-3546",
"(647) 315-9753",
"(905) 354-1587",
"(416) 987-3546"],
"invalidNumbers": []
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment