Skip to content

Commit e471f7f

Browse files
committed
test : Media skeleton from Place
1 parent c16fb9b commit e471f7f

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

test/media-model.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
const CONFIG = require('config')
2+
const __ = CONFIG.universalPath
3+
const _ = __.require('lib', 'utils')
4+
require('should')
5+
6+
const Media = __.require('controllers', 'things/models/types/media')
7+
8+
describe('media model', function () {
9+
describe('validateData', function () {
10+
it('should be a function', function (done) {
11+
Media.validateData.should.be.a.Function()
12+
done()
13+
})
14+
15+
const correctData = {
16+
type: 'Feature',
17+
geometry: {
18+
type: 'Point',
19+
coordinates: [
20+
15.144269,
21+
47.050959
22+
]
23+
},
24+
properties: {
25+
name: 'Django'
26+
}
27+
}
28+
29+
it('should return an object if the data is valid', function (done) {
30+
const data = _.cloneDeep(correctData)
31+
const validateData = function () { return Media.validateData(data) }
32+
validateData.should.not.throw()
33+
done()
34+
})
35+
it('should throw if the geojson is not correct', function (done) {
36+
var data = _.cloneDeep(correctData)
37+
data.geometry.coordinates = null
38+
const validateData = function () { Media.validateData(data) }
39+
validateData.should.throw()
40+
try {
41+
validateData()
42+
} catch (err) {
43+
console.log(err)
44+
err.message.should.equal('invalid GeoJSON type supplied')
45+
}
46+
done()
47+
})
48+
it('should throw if latitude is out of bounds', function (done) {
49+
var data = _.cloneDeep(correctData)
50+
data.geometry.coordinates[0] = -200
51+
const validateData = function () { Media.validateData(data) }
52+
validateData.should.throw()
53+
try {
54+
validateData()
55+
} catch (err) {
56+
console.log(err)
57+
err.message.should.equal('coordinate lat out of range')
58+
}
59+
done()
60+
})
61+
it('should throw if longitude is out of bounds', function (done) {
62+
var data = _.cloneDeep(correctData)
63+
data.geometry.coordinates[1] = 2000
64+
const validateData = function () { Media.validateData(data) }
65+
validateData.should.throw()
66+
try {
67+
validateData()
68+
} catch (err) {
69+
console.log(err)
70+
err.message.should.equal('coordinate lon out of range')
71+
}
72+
done()
73+
})
74+
it('should throw if the data has no name', function (done) {
75+
var data = _.cloneDeep(correctData)
76+
data.properties = {}
77+
const validateData = function () { Media.validateData(data) }
78+
validateData.should.throw()
79+
done()
80+
})
81+
it('should throw if the name is empty', function (done) {
82+
var data = _.cloneDeep(correctData)
83+
data.properties.name = ''
84+
const validateData = function () { Media.validateData(data) }
85+
validateData.should.throw()
86+
try {
87+
validateData()
88+
} catch (err) {
89+
console.log(err)
90+
err.message.should.equal('missing name')
91+
}
92+
done()
93+
})
94+
})
95+
})

0 commit comments

Comments
 (0)