diff --git a/enviroment.js b/enviroment.js index b340ec6026b371201b25a78c70e8f5ac706217f2..e8faa909d2bd1715542a0370e9e796ce3ae052cc 100644 --- a/enviroment.js +++ b/enviroment.js @@ -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, }; diff --git a/test/geolocation.js b/test/geolocation.js new file mode 100644 index 0000000000000000000000000000000000000000..93b70df52c2006621be8a333fa98b4e811b19a2d --- /dev/null +++ b/test/geolocation.js @@ -0,0 +1,36 @@ +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 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), + '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); + }); + }); + }); +});