-
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.
- Loading branch information
Showing
2 changed files
with
131 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* eslint-env mocha */ | ||
const request = require('supertest'); | ||
const server = require('../server/server'); | ||
|
||
describe('[ MOVIES API ]', () => { | ||
let app = null; | ||
let testContacts = [{ | ||
id: 'jdfjdjfdkjkdjdikd', | ||
first_name: 'Joe', | ||
last_name: 'Degs', | ||
email: '[email protected]', | ||
gender: 'Male', | ||
phone_number: '99298383839' | ||
}, { | ||
id: 'oiroeirodkdkfdfijier', | ||
first_name: 'Benard', | ||
last_name: 'Kofi_son', | ||
email: '[email protected]', | ||
gender: 'Male', | ||
phone_number: '9393394884' | ||
}, { | ||
id: 'hdfdhfuihuerhuhdfjdhf', | ||
first_name: 'Lupez', | ||
last_name: 'Marcieli', | ||
email: '[email protected]', | ||
gender: 'Female', | ||
phone_number: '92039384' | ||
}]; | ||
|
||
const pick = (contact) => { | ||
return { | ||
first_name: contact.first_name, | ||
last_name: contact.last_name, | ||
email: contact.email, | ||
gender: contact.gender, | ||
phone_number: contact.phone_number, | ||
uri: `/api/v1/contacterd/get/${contact._id}` | ||
} | ||
} | ||
|
||
let testRepo = { | ||
getAllContacts () { | ||
const res = { | ||
count: testContacts.length, | ||
contacts: contacts.map(pick) | ||
} | ||
return Promise.resolve(res); | ||
}, | ||
getContact (ID) { | ||
const contact = testContacts.find(({ id }) => ID === id); | ||
return Promise.resolve(...[contact].map(pick)); | ||
}, | ||
addContact (body) { | ||
body.id = 'jfdkfjirierdjfkdjfkei'; | ||
const res = testContacts.push(body); | ||
return Promise.resolve(...[body].map(pick)) | ||
}, | ||
updateContact (Id, body) { | ||
const arrItemIdx = testContacts.findIndex(({ id }) => id === Id); | ||
Object.keys(body).forEach(prop => testContacts[arrItemIdx][prop] = body[prop]); | ||
return Promise.resolve(...[testContacts[arrItemIdx]].map(pick)); | ||
}, | ||
deleteContact (Id) { | ||
const arrItemIdx = testContacts.findIndex(({ id }) => id === Id); | ||
const removed = testContacts.splice(arrItemIdx, 1); | ||
return Promise.resolve(...[removed].map(pick)); | ||
} | ||
} | ||
|
||
beforeEach(() => { | ||
return server.start({ | ||
port: 3000, | ||
repo: testRepo | ||
}).then(serv => { | ||
app = serv | ||
}) | ||
}); | ||
|
||
afterEach(() => { | ||
app.close(); | ||
app = null; | ||
}); | ||
|
||
it('returns all contacts', (done) => { | ||
request(app) | ||
.get('/api/v1/contacterd/get') | ||
.expect(res => { | ||
res.body.contacts.should.containEql({ | ||
'first_name': 'Lupez', | ||
'last_name': 'Marcieli', | ||
'email': '[email protected]', | ||
'gender': 'Female', | ||
'phone_number': '92039384' | ||
'url': '/api/v1/contacterd/get/hdfdhfuihuerhuhdfjdhf' | ||
}) | ||
.expect(200, done) | ||
}) | ||
}); | ||
|
||
it('should return one contact', (done) => { | ||
request(app) | ||
.post('/api/v1/contacterd/post') | ||
.send({ | ||
first_name: 'Joe', | ||
last_name: 'Screen', | ||
email: '[email protected]', | ||
gender: 'Male', | ||
phone_number: '343434334' | ||
}) | ||
.expect(res => { | ||
res.body | ||
}) | ||
}); | ||
}); |
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