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

module.exports.tests = {};
const PlaceHolder = require('../../../../service/configurations/PlaceHolder');
module.exports.tests.all = (test, common) => {
test('getName should return \'placeholder\'', (t) => {
const configBlob = {
url: 'base url',
timeout: 17,
retries: 19
};
const placeholder = new PlaceHolder(configBlob);
t.equals(placeholder.getName(), 'placeholder');
t.equals(placeholder.getBaseUrl(), 'base url');
t.equals(placeholder.getTimeout(), 17);
t.equals(placeholder.getRetries(), 19);
t.end();
});
test('getUrl should return value passed to constructor', (t) => {
const configBlob = {
url: 'base url',
timeout: 17,
retries: 19
};
const placeholder = new PlaceHolder(configBlob);
t.equals(placeholder.getUrl(), 'base url/search');
t.end();
});
test('getParameters should return object with text and lang from req', (t) => {
const configBlob = {
url: 'base url',
timeout: 17,
retries: 19
};
const placeholder = new PlaceHolder(configBlob);
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) => {
const configBlob = {
url: 'base url',
timeout: 17,
retries: 19
};
const placeholder = new PlaceHolder(configBlob);
t.deepEquals(placeholder.getHeaders(), {});
t.end();
});
test('getParameters should not include lang if req.clean.lang is unavailable', (t) => {
const configBlob = {
url: 'base url',
timeout: 17,
retries: 19
};
const placeholder = new PlaceHolder(configBlob);
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) => {
const configBlob = {
url: 'base url',
timeout: 17,
retries: 19
};
const placeholder = new PlaceHolder(configBlob);
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) {
return tape(`SERVICE CONFIGURATION /PlaceHolder ${name}`, testFunction);
}
for( var testCase in module.exports.tests ){
module.exports.tests[testCase](test, common);
}
};