mirror of https://github.com/pelias/api.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
126 lines
2.7 KiB
126 lines
2.7 KiB
8 years ago
|
module.exports.tests = {};
|
||
|
|
||
8 years ago
|
const PlaceHolder = require('../../../../service/configurations/PlaceHolder');
|
||
8 years ago
|
|
||
|
module.exports.tests.all = (test, common) => {
|
||
|
test('getName should return \'placeholder\'', (t) => {
|
||
8 years ago
|
const configBlob = {
|
||
|
url: 'base url',
|
||
|
timeout: 17,
|
||
|
retries: 19
|
||
|
};
|
||
8 years ago
|
|
||
8 years ago
|
const placeholder = new PlaceHolder(configBlob);
|
||
8 years ago
|
|
||
8 years ago
|
t.equals(placeholder.getName(), 'placeholder');
|
||
8 years ago
|
t.equals(placeholder.getBaseUrl(), 'base url');
|
||
8 years ago
|
t.equals(placeholder.getTimeout(), 17);
|
||
|
t.equals(placeholder.getRetries(), 19);
|
||
8 years ago
|
t.end();
|
||
|
|
||
|
});
|
||
|
|
||
|
test('getUrl should return value passed to constructor', (t) => {
|
||
8 years ago
|
const configBlob = {
|
||
|
url: 'base url',
|
||
|
timeout: 17,
|
||
|
retries: 19
|
||
|
};
|
||
|
|
||
|
const placeholder = new PlaceHolder(configBlob);
|
||
8 years ago
|
|
||
8 years ago
|
t.equals(placeholder.getUrl(), 'base url/search');
|
||
8 years ago
|
t.end();
|
||
|
|
||
|
});
|
||
|
|
||
|
test('getParameters should return object with text and lang from req', (t) => {
|
||
8 years ago
|
const configBlob = {
|
||
|
url: 'base url',
|
||
|
timeout: 17,
|
||
|
retries: 19
|
||
|
};
|
||
|
|
||
|
const placeholder = new PlaceHolder(configBlob);
|
||
8 years ago
|
|
||
|
const req = {
|
||
|
clean: {
|
||
|
text: 'text value',
|
||
|
lang: {
|
||
|
iso6393: 'lang value'
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
t.deepEquals(placeholder.getParameters(req), { text: 'text value', lang: 'lang value' });
|
||
|
t.end();
|
||
|
|
||
|
});
|
||
|
|
||
|
test('getHeaders should return empty object', (t) => {
|
||
8 years ago
|
const configBlob = {
|
||
|
url: 'base url',
|
||
|
timeout: 17,
|
||
|
retries: 19
|
||
|
};
|
||
|
|
||
|
const placeholder = new PlaceHolder(configBlob);
|
||
8 years ago
|
|
||
8 years ago
|
t.deepEquals(placeholder.getHeaders(), {});
|
||
8 years ago
|
t.end();
|
||
|
|
||
|
});
|
||
|
|
||
|
test('getParameters should not include lang if req.clean.lang is unavailable', (t) => {
|
||
8 years ago
|
const configBlob = {
|
||
|
url: 'base url',
|
||
|
timeout: 17,
|
||
|
retries: 19
|
||
|
};
|
||
|
|
||
|
const placeholder = new PlaceHolder(configBlob);
|
||
8 years ago
|
|
||
|
const req = {
|
||
|
clean: {
|
||
|
text: 'text value'
|
||
|
}
|
||
|
};
|
||
|
|
||
|
t.deepEquals(placeholder.getParameters(req), { text: 'text value' });
|
||
|
t.end();
|
||
|
|
||
|
});
|
||
|
|
||
|
test('getParameters should not include lang if req.clean.lang.iso6393 is unavailable', (t) => {
|
||
8 years ago
|
const configBlob = {
|
||
|
url: 'base url',
|
||
|
timeout: 17,
|
||
|
retries: 19
|
||
|
};
|
||
|
|
||
|
const placeholder = new PlaceHolder(configBlob);
|
||
8 years ago
|
|
||
|
const req = {
|
||
|
clean: {
|
||
|
text: 'text value',
|
||
|
lang: {}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
t.deepEquals(placeholder.getParameters(req), { text: 'text value' });
|
||
|
t.end();
|
||
|
|
||
|
});
|
||
|
|
||
|
};
|
||
|
|
||
|
module.exports.all = (tape, common) => {
|
||
|
function test(name, testFunction) {
|
||
8 years ago
|
return tape(`SERVICE CONFIGURATION /PlaceHolder ${name}`, testFunction);
|
||
8 years ago
|
}
|
||
|
|
||
|
for( var testCase in module.exports.tests ){
|
||
|
module.exports.tests[testCase](test, common);
|
||
|
}
|
||
|
};
|