Browse Source

Remove fetching of country_code from database:

The database does not have this, nor can this be imported easily.
We'll need to solve the country-code later.
tags/0.3.0^2
Bèr Kessels 2 years ago
parent
commit
50f8ccec16

+ 0
- 1
models/place.js View File

@@ -14,7 +14,6 @@ module.exports = (sequelize, DataTypes) => {
addr_housenumber: DataTypes.STRING,
addr_postcode: DataTypes.STRING,
addr_city: DataTypes.STRING,
addr_country_code: DataTypes.STRING,
opening_hours: DataTypes.STRING,

geometry: DataTypes.GEOMETRY('POINT')

+ 7
- 15
serializers/place.js View File

@@ -22,19 +22,6 @@ Serializer.register('places', {
]
})

const nominatim = function (place) {
var countryCode = place.addr_country_code || config.default_country_code
return {
address: {
street: place.addr_street,
housenumber: place.addr_housenumber,
postcode: place.addr_postcode,
city: place.addr_city,
country_code: countryCode
}
}
}

const intervals = function (oh, _moment) {
var moment = _moment || require('moment')

@@ -64,12 +51,17 @@ const intervals = function (oh, _moment) {
*/
const decorator = function (thisUrl, _openingHours, _moment) {
var OpeningHours = _openingHours || require('opening_hours')
var oh = new OpeningHours(this.opening_hours, nominatim(this))
var oh = new OpeningHours(this.opening_hours, { address: { country_code: config.default_country_code } })

var place = {
id: this.id,
raw_opening_hours: this.opening_hours,
address: nominatim(this).address,
address: {
street: this.addr_street,
housenumber: this.addr_housenumber,
postcode: this.addr_postcode,
city: this.addr_city
},
name: this.name,
open_this_week: intervals(oh, _moment),
status: oh.getState(),

+ 0
- 1
test/fixtures/json/hm.json View File

@@ -54,7 +54,6 @@
"lon": 5.8653234,
"address" : {
"postcode" : "6511RA",
"country_code" : "nl",
"city" : "Nijmegen",
"housenumber" : "1",
"street" : "Burchtstraat"

+ 1
- 3
test/integration/get_place.test.js View File

@@ -33,7 +33,7 @@ describe('express rest API server', () => {
})
})

describe('place without address and PHs', () => {
describe('place with PH in opening_hours', () => {
var id

before((done) => {
@@ -47,8 +47,6 @@ describe('express rest API server', () => {
request().get('/places/' + id)
.end(function (e, res) {
expect(e).to.be.null
// Fallback to default configurated country_code
expect(res.body.data.attributes.address.country_code).to.equal('nl')
expect(res).to.have.status(200)
expect(res.body.data.attributes.status).to.be.true
done()

+ 1
- 41
test/serializers/place.test.js View File

@@ -67,38 +67,7 @@ describe('decorator', () => {
done()
})

describe('with country_code', () => {
beforeEach(() => {
place.addr_country_code = 'uk'
})

it('instantiates opening_hours with the country_code', (done) => {
var spy = sandbox.spy(openingHours)
place.decorate(url, spy)
sinon.assert.calledWithNew(spy)
sinon.assert.calledWith(spy, '24/7', {
address: {
street: undefined,
housenumber: undefined,
postcode: undefined,
city: undefined,
country_code: 'uk'
}
})
done()
})

it('set address.country_code to country_code', (done) => {
expect(place.decorate(url).address.country_code).to.equal('uk')
done()
})
})

describe('without country_code', () => {
beforeEach(() => {
place.addr_country_code = null
})

describe('country_code', () => {
it('instantiates opening_hours with default country code nl', (done) => {
var spy = sandbox.spy(openingHours)
place.decorate(url, spy)
@@ -108,19 +77,10 @@ describe('decorator', () => {
sinon.assert.calledWithNew(spy)
sinon.assert.calledWith(spy, '24/7', {
address: {
street: undefined,
housenumber: undefined,
postcode: undefined,
city: undefined,
country_code: 'nl'
}
})
done()
})

it('set address.country_code to country_code', (done) => {
expect(place.decorate(url).address.country_code).to.equal('nl')
done()
})
})
})

Loading…
Cancel
Save