mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Update API test
This commit is contained in:
parent
0f4902d98d
commit
9785df221f
4 changed files with 82 additions and 7 deletions
|
@ -1,6 +1,6 @@
|
|||
define(function (require) {
|
||||
var Promise = require('bluebird');
|
||||
var expect = require('intern/dojo/node!expect.js');
|
||||
var testData = require('intern/dojo/node!../../../unit/api/i18n/data');
|
||||
|
||||
return function (bdd, scenarioManager, request) {
|
||||
bdd.describe('GET translations', function postIngest() {
|
||||
|
@ -9,13 +9,22 @@ define(function (require) {
|
|||
return scenarioManager.reload('emptyKibana');
|
||||
});
|
||||
|
||||
bdd.it('should return 200 for an valid payload', function validPayload() {
|
||||
return Promise.all([
|
||||
request.get('/i18n/translations').expect(200),
|
||||
]);
|
||||
bdd.before(function () {
|
||||
return testData.createTestTranslations();
|
||||
});
|
||||
//TODO (hickeyma): Extend test cases once I have refactored the module and hapi APIs after feedback on removeing plugin namd and language from API
|
||||
|
||||
bdd.it('should return 200 and a valid response payload', function validPayload() {
|
||||
return request.get('/i18n/translations')
|
||||
.expect(200)
|
||||
.then(function (res) {
|
||||
var translationsReturned = JSON.parse(res.text);
|
||||
expect(testData.checkReturnedTranslations(translationsReturned)).to.be(true);
|
||||
});
|
||||
});
|
||||
|
||||
bdd.after(function () {
|
||||
return testData.deleteTestTranslations();
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
});
|
||||
|
|
52
test/unit/api/i18n/data.js
Normal file
52
test/unit/api/i18n/data.js
Normal file
|
@ -0,0 +1,52 @@
|
|||
var fs = require('fs');
|
||||
var mkdirp = require('mkdirp');
|
||||
var process = require('child_process');
|
||||
|
||||
var TRANSLATION_STORE_PATH = __dirname + '/../../../../data/translations';
|
||||
|
||||
var checkReturnedTranslations = function (actualTranslationJson) {
|
||||
var language = 'en';
|
||||
var expectedTranslationJsonFile = __dirname + '/data/reference/' + language + '.json';
|
||||
var expectedTranslationJson = require(expectedTranslationJsonFile);
|
||||
|
||||
return compareTranslations(actualTranslationJson, expectedTranslationJson);
|
||||
};
|
||||
|
||||
var createTestTranslations = function () {
|
||||
var translationStorePath = TRANSLATION_STORE_PATH;
|
||||
var language = 'en';
|
||||
var srcFile = __dirname + '/data/reference/' + language + '.json';
|
||||
var destFile = translationStorePath + '/' + language + '.json';
|
||||
|
||||
if (!fs.existsSync(translationStorePath)) {
|
||||
mkdirp.sync(translationStorePath);
|
||||
}
|
||||
console.log('Write file: ' + srcFile + ' to file: ' + destFile);
|
||||
fs.writeFileSync(destFile, fs.readFileSync(srcFile));
|
||||
};
|
||||
|
||||
var deleteTestTranslations = function () {
|
||||
var translationStorePath = TRANSLATION_STORE_PATH;
|
||||
process.execSync('rm -rf ' + translationStorePath);
|
||||
};
|
||||
|
||||
function compareTranslations(actual, expected) {
|
||||
var equal = true;
|
||||
|
||||
for (var key in expected) {
|
||||
if (!actual.hasOwnProperty(key)) {
|
||||
equal = false;
|
||||
break;
|
||||
}
|
||||
if (actual[key] !== expected[key]) {
|
||||
equal = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return equal;
|
||||
}
|
||||
|
||||
module.exports.checkReturnedTranslations = checkReturnedTranslations;
|
||||
module.exports.createTestTranslations = createTestTranslations;
|
||||
module.exports.deleteTestTranslations = deleteTestTranslations;
|
4
test/unit/api/i18n/data/reference/de.json
Normal file
4
test/unit/api/i18n/data/reference/de.json
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"test_plugin_1-NO_SSL": "Dont run the DE dev server using HTTPS",
|
||||
"test_plugin_1-DEV": "Run the DE server with development mode defaults"
|
||||
}
|
10
test/unit/api/i18n/data/reference/en.json
Normal file
10
test/unit/api/i18n/data/reference/en.json
Normal file
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"test_plugin_1-NO_SSL": "Dont run the dev server using HTTPS",
|
||||
"test_plugin_1-DEV": "Run the server with development mode defaults",
|
||||
"test_plugin_1-NO_RUN_SERVER": "Dont run the dev server",
|
||||
"test_plugin_1-HOME": "Run along home now!",
|
||||
"test_plugin_2-XXXXXX": "This is XXXXXX string",
|
||||
"test_plugin_2-YYYY_PPPP": "This is YYYY_PPPP string",
|
||||
"test_plugin_2-FFFFFFFFFFFF": "This is FFFFFFFFFFFF string",
|
||||
"test_plugin_2-ZZZ": "This is ZZZ string"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue