Skip to content
This repository has been archived by the owner on Nov 30, 2019. It is now read-only.

Commit

Permalink
Fixes issue #10
Browse files Browse the repository at this point in the history
Corrected `founded` type and added test for 100% coverage.
  • Loading branch information
amnuts committed Oct 11, 2019
1 parent ef41fd8 commit 2e4a0d8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
28 changes: 24 additions & 4 deletions tests/build-query.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { buildQuery } = require('../src/build-query');
describe('Build Query', () => {
describe('when a valid config is passed into buildQuery', () => {
const expectedQuery =
'?page=98&itemsPerPage=99&search=soup&language=Gaelic&sort=Ascending&filter[]=regulation(182%2C26)&facet[]=facets&facet[]=exist&filter[]=filters&filter[]=exist';
'?page=98&itemsPerPage=99&search=soup&language=Gaelic&sort=Ascending&filter[]=regulation(182%2C26)&facet[]=facets&facet[]=exist&filter[]=filters&filter[]=exist&filter[]=founded.year%3A2010';

let result;

Expand All @@ -32,7 +32,7 @@ describe('Build Query', () => {

describe('when a config is passed with invalid regulation fields', () => {
const expectedQueryNoRegulationValues =
'?page=98&itemsPerPage=99&search=soup&language=Gaelic&sort=Ascending&facet[]=facets&facet[]=exist&filter[]=filters&filter[]=exist';
'?page=98&itemsPerPage=99&search=soup&language=Gaelic&sort=Ascending&facet[]=facets&facet[]=exist&filter[]=filters&filter[]=exist&filter[]=founded.year%3A2010';

let result;

Expand All @@ -54,7 +54,7 @@ describe('Build Query', () => {

describe('when a config is passed with a non-numeric regulation size', () => {
const expectedQueryRegulationSizeNull =
'?page=98&itemsPerPage=99&search=soup&language=Gaelic&sort=Ascending&filter[]=regulation(null%2C26)&facet[]=facets&facet[]=exist&filter[]=filters&filter[]=exist';
'?page=98&itemsPerPage=99&search=soup&language=Gaelic&sort=Ascending&filter[]=regulation(null%2C26)&facet[]=facets&facet[]=exist&filter[]=filters&filter[]=exist&filter[]=founded.year%3A2010';

let result;

Expand All @@ -77,7 +77,7 @@ describe('Build Query', () => {

describe('when a config is passed with a non-numeric regulation age', () => {
const expectedQueryRegulationAgeNull =
'?page=98&itemsPerPage=99&search=soup&language=Gaelic&sort=Ascending&filter[]=regulation(182%2Cnull)&facet[]=facets&facet[]=exist&filter[]=filters&filter[]=exist';
'?page=98&itemsPerPage=99&search=soup&language=Gaelic&sort=Ascending&filter[]=regulation(182%2Cnull)&facet[]=facets&facet[]=exist&filter[]=filters&filter[]=exist&filter[]=founded.year%3A2010';

let result;

Expand All @@ -97,4 +97,24 @@ describe('Build Query', () => {
expect(result).toEqual(expectedQueryRegulationAgeNull);
});
});

describe('when a config is passed with a non-numeric founded year', () => {
const expectedQueryFoundedYearNull =
'?page=98&itemsPerPage=99&search=soup&language=Gaelic&sort=Ascending&filter[]=regulation(182%2C26)&facet[]=facets&facet[]=exist&filter[]=filters&filter[]=exist';

let result;

const invalidRegulationFields = {
...stubbedConfig,
founded: ['founders', 'exist'],
};

beforeEach(() => {
result = buildQuery(invalidRegulationFields);
});

it('returns founded year as null', () => {
expect(result).toEqual(expectedQueryFoundedYearNull);
});
});
});
2 changes: 1 addition & 1 deletion tests/test-data/stubbed-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ module.exports = {
},
facets: ['facets','exist'],
filters: ['filters', 'exist'],
founded: ['founders', 'exist'],
founded: 2010,
};

0 comments on commit 2e4a0d8

Please sign in to comment.