Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • hvehrenfried/Loopback-API-Example
  • SMPPIR/Loopback-API-Example
2 results
Select Git revision
Show changes
Commits on Source (3)
......@@ -32,10 +32,23 @@ const randomWord = function(num, allUpper = false, firstUpper = false) {
return word;
};
const randomId = function(num) {
let word = '';
for (let i = 0; i < num; i++) {
if (randomNumber(0, 1) == 0) {
word = word + randomNumber(0, 9);
} else {
word = word + randomLowerCase();
}
}
return word;
};
module.exports = {
URL,
randomLowerCase,
randomUpperCase,
randomNumber,
randomWord,
randomId,
};
var chakram = require('chakram'), expect = chakram.expect;
var env = require('../enviroment');
const URL = env.URL;
describe('Geolocation', function() {
it('should create a geolocation as an android user', function() {
let credential = {
'email': 'user@user.com',
'password': 'user',
};
return chakram.post(`${URL}end_users/login`, credential).then(function(loginResponse) {
let testObject = {
'category_id': 1,
'geolocation_name': env.randomWord(10),
'latitude': 10.2123,
'longitude': 112.2124214,
'when_sent': new Date(Date.now()),
'android_id': env.randomId(20),
'user_id': loginResponse.body.result.userId,
'description_location': env.randomWord(6, false, true) + ' ' + env.randomWord(6),
};
return chakram.post(`${URL}geolocations`, testObject).then(function(myResponse) {
expect(myResponse).to.have.status(200);
expect(myResponse.body.result).to.be.a('object');
});
});
});
it('should create a geolocation as a logged user', function() {
let testObject = {
'category_id': 1,
'geolocation_name': env.randomWord(10),
'latitude': 116.2123,
'longitude': 50.2124214,
'when_sent': new Date(Date.now()),
'description_location': env.randomWord(6, false, true) + ' ' + env.randomWord(6),
};
return chakram.post(`${URL}geolocations`, testObject).then(function(myResponse) {
expect(myResponse).to.have.status(200);
expect(myResponse.body.result).to.be.a('object');
});
});
it('should return all geolocations', function() {
return chakram.get(`${URL}geolocations`).then(function(myResponse) {
expect(myResponse).to.have.status(200);
expect(myResponse.body.result).to.be.a('array');
});
});
it('should return one geolocation', function() {
return chakram.get(`${URL}geolocations`).then(function(myResponse) {
let geolocation = myResponse.body.result[0];
return chakram.get(`${URL}geolocations/${myResponse.body.result[0].id}`).then(function(myResponse2) {
expect(myResponse2).to.have.status(200);
expect(myResponse2.body.result.geolocation_name).to.contain(geolocation.geolocation_name);
});
});
});
it('should try to remove one geolocation', function() {
return chakram.get(`${URL}geolocations`).then(function(myResponse) {
let id = myResponse.body.result[0].id;
return chakram.delete(`${URL}geolocations/${id}`).then(function(myResponse2) {
expect(myResponse2).to.have.status(401);
expect(myResponse2.body.error.code).to.contain('AUTHORIZATION_REQUIRED');
});
});
});
});