Skip to content
This repository has been archived by the owner on Aug 3, 2022. It is now read-only.

Commit

Permalink
[#786] Add tests for place/dataset instance methods
Browse files Browse the repository at this point in the history
Test for scores with a year and cascade options specified.
  • Loading branch information
brew committed Oct 11, 2016
1 parent c162ce9 commit 8e0aed4
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 31 deletions.
28 changes: 21 additions & 7 deletions fixtures/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,26 @@ var users = require('./user');

function answers() {
return {
digital: _.sample([false, true]),
exists: _.sample([false, true]),
machinereadable: _.sample([false, true]),
openlicense: _.sample([false, true]),
online: _.sample([false, true]),
public: _.sample([false, true]),
digital: true,
exists: 'Yes',
machinereadable: true,
openlicense: false,
online: false,
public: false,
publisher: 'Acme',
format: ['CSV', 'PSF'],
license: 'http://example.com'
};
}

function currentAnswers() {
return {
digital: false,
exists: false,
machinereadable: false,
openlicense: true,
online: true,
public: true,
publisher: 'Acme',
format: ['CSV', 'PSF'],
license: 'http://example.com'
Expand Down Expand Up @@ -54,7 +68,7 @@ var objects = [
year: 2015,
place: 'place11',
dataset: 'dataset11',
answers: answers(),
answers: currentAnswers(),
submissionNotes: '',
reviewed: true,
reviewResult: true,
Expand Down
38 changes: 31 additions & 7 deletions fixtures/question.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,14 @@ var objects = [
'description': 'the description',
'placeholder': 'the placeholder',
'type': '',
'score': 15,
'icon': 'dollar'
'score': 5,
'icon': 'dollar',
'config': {
'score': {
'weight': 5,
'passValue': ['Yes', true]
}
}
}
},
{
Expand All @@ -86,7 +92,13 @@ var objects = [
'type': '',
'score': 5,
'icon': 'download',
'dependants': ['url']
'dependants': ['url'],
'config': {
'score': {
'weight': 5,
'passValue': ['Yes', true]
}
}
}
},
{
Expand All @@ -100,9 +112,15 @@ var objects = [
'description': 'the description',
'placeholder': 'the placeholder',
'type': '',
'score': 15,
'score': 5,
'icon': 'keyboard',
'dependants': ['format']
'dependants': ['format'],
'config': {
'score': {
'weight': 5,
'passValue': ['Yes', true]
}
}
}
},
{
Expand Down Expand Up @@ -131,9 +149,15 @@ var objects = [
'description': 'the description',
'placeholder': 'the placeholder',
'type': '',
'score': 30,
'score': 5,
'icon': 'unlock-alt',
'dependants': ['licenseurl']
'dependants': ['licenseurl'],
'config': {
'score': {
'weight': 5,
'passValue': ['Yes', true]
}
}
}
},
{
Expand Down
95 changes: 78 additions & 17 deletions tests/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ var rewire = require('rewire');
var _ = require('lodash');
var models = require('../census/models');
var modelUtils = rewire('../census/models/utils');
var chai = require('chai');
var expect = chai.expect;
var assert = require('chai').assert;
var expect = require('chai').expect;
var utils = require('./utils');

describe('Question instance methods', function() {
Expand Down Expand Up @@ -114,8 +114,8 @@ describe('Dataset instance methods', function() {
beforeEach(utils.setupFixtures);
afterEach(utils.dropFixtures);

it('.getQuestions', function() {
var dataOptions = {
before(function() {
this.dataOptions = {
models: models,
domain: 'site1',
dataset: 'dataset11',
Expand All @@ -126,7 +126,10 @@ describe('Dataset instance methods', function() {
locale: null,
with: {Entry: true, Dataset: true, Place: true, Question: true}
};
return modelUtils.getData(dataOptions)
});

it('.getQuestions', function() {
return modelUtils.getData(this.dataOptions)
.then(data => {
expect(data).to.have.property('dataset');
return data.dataset.getQuestions();
Expand All @@ -137,29 +140,87 @@ describe('Dataset instance methods', function() {
});

it('.getQuestionSetSchema', function() {
var dataOptions = {
return modelUtils.getData(this.dataOptions)
.then(data => {
expect(data).to.have.property('dataset');
return data.dataset.getQuestionSetSchema();
})
.then(qsSchema => {
expect(qsSchema).to.have.length(12);
let firstQuestionSchema = qsSchema[0];
expect(firstQuestionSchema).to.have.property('id');
expect(firstQuestionSchema).to.have.property('ifProvider');
expect(firstQuestionSchema).to.have.property('position');
expect(firstQuestionSchema).to.have.property('defaultProperties');
});
});

it('.score with cascading', function() {
let dataOptions = _.assign(this.dataOptions, {year: 2015, cascade: true});
return modelUtils.getData(dataOptions)
.then(data => {
expect(data).to.have.property('dataset');
return data.dataset.score(data.entries, data.questions);
})
.then(score => {
assert.equal(score, 25);
});
});

it('.score without cascading', function() {
let dataOptions = _.assign(this.dataOptions, {year: 2015, cascade: false});
return modelUtils.getData(dataOptions)
.then(data => {
expect(data).to.have.property('dataset');
return data.dataset.score(data.entries, data.questions);
})
.then(score => {
assert.equal(score, 15);
});
});
});

describe('Place instance methods', function() {
this.timeout(20000);

beforeEach(utils.setupFixtures);
afterEach(utils.dropFixtures);

before(function() {
this.dataOptions = {
models: models,
domain: 'site1',
dataset: 'dataset11',
place: null,
dataset: null,
place: 'place11',
year: null,
cascade: true,
scoredQuestionsOnly: true,
locale: null,
with: {Entry: true, Dataset: true, Place: true, Question: true}
};
});

it('.score with cascading', function() {
let dataOptions = _.assign(this.dataOptions, {year: 2015, cascade: true});
return modelUtils.getData(dataOptions)
.then(data => {
expect(data).to.have.property('dataset');
return data.dataset.getQuestionSetSchema();
expect(data).to.have.property('place');
return data.place.score(data.entries, data.questions);
})
.then(qsSchema => {
expect(qsSchema).to.have.length(12);
var firstQuestionSchema = qsSchema[0];
expect(firstQuestionSchema).to.have.property('id');
expect(firstQuestionSchema).to.have.property('ifProvider');
expect(firstQuestionSchema).to.have.property('position');
expect(firstQuestionSchema).to.have.property('defaultProperties');
.then(score => {
assert.equal(score, 25);
});
});

it('.score without cascading', function() {
let dataOptions = _.assign(this.dataOptions, {year: 2015, cascade: false});
return modelUtils.getData(dataOptions)
.then(data => {
expect(data).to.have.property('place');
return data.place.score(data.entries, data.questions);
})
.then(score => {
assert.equal(score, 25);
});
});
});
Expand Down

0 comments on commit 8e0aed4

Please sign in to comment.