Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add migration endpoint including tests
- Loading branch information
Sharon Funke
committed
Mar 24, 2017
1 parent
fa2fce0
commit 202c3cf
Showing
7 changed files
with
157 additions
and
9 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,19 @@ | ||
// contains all scripts which shall be executed to migrate to tool version 2.0.0 | ||
// each module has to return a result object holding the modified item and a | ||
// flag property indicating if item was changed or not | ||
module.exports.migrate = function(item) { | ||
let result = { | ||
isChanged: false | ||
} | ||
if (item.parties) { | ||
let truthyparties = item.parties.filter(party => { | ||
return party.name !== undefined && party.name !== ''; | ||
}); | ||
if (truthyparties.length < item.parties.length) { | ||
item.parties = truthyparties; | ||
result.isChanged = true; | ||
} | ||
} | ||
result.item = item; | ||
return result; | ||
} |
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,39 @@ | ||
const Joi = require('joi'); | ||
const Boom = require('boom'); | ||
|
||
// register migration scripts here in order of version, | ||
// i.e. list the smalles version first | ||
const migrationScripts = [ | ||
require('../migration-scripts/to-v2.0.0.js') | ||
] | ||
|
||
module.exports = { | ||
method: 'POST', | ||
path:'/migration', | ||
config: { | ||
validate: { | ||
payload: { | ||
item: Joi.object().required() | ||
} | ||
} | ||
}, | ||
handler: (request, reply) => { | ||
let item = request.payload.item; | ||
const results = migrationScripts.map(script => { | ||
const result = script.migrate(item); | ||
if (result.isChanged) { | ||
item = result.item; | ||
} | ||
return result; | ||
}) | ||
const isChanged = results.findIndex(result => { | ||
return result.isChanged; | ||
}); | ||
if (isChanged >= 0) { | ||
return reply({ | ||
item: item | ||
}) | ||
} | ||
return reply().code(304); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
const htmlStatic = require('./rendering-info/html-static.js'); | ||
const stylesheet = require('./stylesheet.js'); | ||
const schema = require('./schema.js'); | ||
const migration = require('./migration.js'); | ||
|
||
module.exports = [ | ||
htmlStatic, | ||
stylesheet, | ||
schema | ||
schema, | ||
migration | ||
] |
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
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
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,53 @@ | ||
module.exports = { | ||
title: "Sitzverteilung Parlament Frankreich", | ||
sources: [ | ||
{ | ||
"text": "asdjfh", | ||
"link": { | ||
"url": "www.nzz.ch", | ||
"isValid": true | ||
} | ||
} | ||
], | ||
subtitle: "Möglichkeit zusätzliche Informationen als Untertitel zu erfassen", | ||
notes: "Jemand musste Josef K. verleumdet haben, denn ohne dass er etwas Böses getan hätte, wurde er eines Morgens verhaftet.", | ||
totalSeats: 200, | ||
parties: [ | ||
{ | ||
color: | ||
{ | ||
colorCode: "#0084c7" | ||
}, | ||
seats: 70, | ||
previous: 71 | ||
}, | ||
{ | ||
name: "Sozialdemokratische Partei Deutschlands", | ||
color: | ||
{ | ||
colorCode: "#c31906", | ||
classAttribute: "s-viz-color-party-sp-5" | ||
}, | ||
seats: 80, | ||
previous: 75 | ||
}, | ||
{ | ||
name: "Bündnis 90/Die Grünen", | ||
color: | ||
{ | ||
colorCode: "#66a622" | ||
}, | ||
seats: 30, | ||
previous: 24 | ||
}, | ||
{ | ||
name: "Die Linke", | ||
color: | ||
{ | ||
colorCode: "#a35fd1" | ||
}, | ||
seats: 20, | ||
previous: 15 | ||
} | ||
] | ||
} |
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
202c3cf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
implements #28