Skip to content

Commit

Permalink
Seems to be working
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolaidavies committed Jun 26, 2018
1 parent 4df3eea commit 116cd72
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 58 deletions.
1 change: 1 addition & 0 deletions src/v7/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const case_location = require('./routes/foci/case_locations')
const maas = require('./maas')
const config = require('./routes/config')
const geodata = require('./routes/geodata')
const seasons = require('./routes/seasons')

const {url_base} = require('./lib/url_helper')

Expand Down
23 changes: 23 additions & 0 deletions src/v7/routes/seasons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = {
async put(req, res) {
// /seasons
const config_id = req.body.config_id
const config_version = req.body.config_version
const season_start_dates = req.body.season_start_dates

if (!config_id || !config_version || !season_start_dates) {
return res.status(400).send()
}

const config_collection = req.db.collection('config');
const document_id = `${config_id}@${config_version}`

try {
const result = await config_collection.updateOne({ _id: document_id}, {$set: {'applets.irs_monitor.season_start_dates': season_start_dates}})
res.send(result)
} catch (e) {
console.log('e', e);
res.status(500).send({error: e.message})
}
}
}
2 changes: 1 addition & 1 deletion test/bwa-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const bwa_config = {
"config_version": "1.0.0",
"applets": {
"irs_monitor": {
"season_start_dates": ["2017-10-01", "2018-01-01", "2018-02-01", "2018-03-01"],
"season_start_dates": ["2017-10-01"],
"map": {
"chart_type": "map",
"bin_by": "location.selection.id",
Expand Down
46 changes: 46 additions & 0 deletions test/v7/integration/seasons.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import {app} from "../../../src/api";
const request = require('supertest');
const test = require('ava').test
const {tear_down} = require('../helper')
const { findByUsernamePassword } = require('../../../src/v7/lib/auth')


test.afterEach(async () => {
tear_down()
})

// TODO: split this out into more and smaller tests
test.serial('Send only season start dates to add a season', async t => {
await request(app).get('/v7/').send()

const user = findByUsernamePassword('configAdmin', 'passwd')

const bwa_config = require('../../bwa-config')

// upload config so it exists
await request(app).post('/v7/config?country=all')
.set('Api-Key', user.key)
.send(bwa_config)

// update season_start_dates
const season_start_dates = bwa_config.config_data.applets.irs_monitor.season_start_dates;
season_start_dates.push('2018-04-05')

const data = {
config_id: bwa_config.config_data.instance.slug,
config_version: bwa_config.config_data.config_version,
season_start_dates: season_start_dates
}

const seasons_result = await request(app).put('/v7/seasons?country=all')
.set('Api-Key', user.key)
.send(data)

t.deepEqual(seasons_result.status, 200);

const config_after_update = await request(app).get('/v7/config/bwa?country=all')

const updated_season_start_dates = config_after_update.body.applets.irs_monitor.season_start_dates
t.deepEqual(updated_season_start_dates, season_start_dates)
})

57 changes: 0 additions & 57 deletions test/v7/intrgration/seasons.test.js

This file was deleted.

1 change: 1 addition & 0 deletions users.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ _id,name,password,username,read,write,instance_slug
u1,Test User 1,password,user1,"irs_plan, irs_tasker","irs_tasker",swz
u2,Test User 2,password,user2,,,swz
sm,sm,m,sm,"irs_plan, irs_tasker","irs_plan,irs_tasker",swz
"configAdmin","configAdmin","passwd","configAdmin","config","config","all"

0 comments on commit 116cd72

Please sign in to comment.