Mapper testing

This commit is contained in:
Rashid Khan 2014-02-14 07:38:23 -07:00
parent d59079db86
commit 99c5f5d887
4 changed files with 33 additions and 19 deletions

View file

@ -10,19 +10,14 @@ define(function (require) {
/**
* Gets an object containing all fields with their mappings
* @param {dataSource} dataSource
* @param {Number} type
* @param {dataSource} [dataSource]
* @param {Function} [callback] A function to be executed with the results.
* @param {String} [type]
* @return {Object} A hash containing fields and their related mapping
*/
this.getFields = function (dataSource, type) {
return {
foo: {
type: 'string'
},
'foo.bar': {
type: 'long'
}
};
this.getFields = function (dataSource, callback, type) {
console.log(dataSource);
client.indices.getFieldMapping({index: dataSource.index}, callback);
};
this.getFieldType = function (dataSource, field, type) {

View file

@ -18,16 +18,20 @@ define(function (require) {
scope: {
type: '@'
},
controller: function ($rootScope, $scope) {
controller: function (courier, $rootScope, $scope) {
var source = $rootScope.dataSource.extend()
.type($scope.type)
.source({
include: 'country'
})
.on('results', function (resp) {
$scope.json = JSON.stringify(resp.hits, null, ' ');
//$scope.json = JSON.stringify(resp.hits, null, ' ');
});
courier.mapper.getFields($rootScope.dataSource, function (data) {
$scope.json = data;
});
$scope.$watch('type', source.type);
},
template: '<pre>{{json}}</pre>'

View file

@ -37,7 +37,8 @@
})
require([
'/specs/courier.js',
'/specs/data_source.js'
'/specs/data_source.js',
'/specs/mapper.js'
], function () {
window.mochaRunner = mocha.run().on('end', function(){
window.mochaResults = this.stats;

View file

@ -1,8 +1,9 @@
define(function (require) {
var elasticsearch = require('elasticsearch');
var elasticsearch = require('../bower_components/elasticsearch/elasticsearch.js');
var _ = require('lodash');
var Courier = require('courier/courier');
var DataSource = require('courier/data_source');
var Mapper = require('courier/mapper');
var client = new elasticsearch.Client({
host: 'localhost:9200',
});
@ -14,9 +15,22 @@ define(function (require) {
expect(mapper).to.be.a(Mapper);
});
it('has a function call getFields that returns an empty object', function () {
var mapper = new Mapper(new Courier());
expect(mapper.getFields()).to.eql({
it('has a function called getFields that returns an object', function () {
var courier = new Courier({
client: client
});
var dataSource = courier.createSource('search')
.index('_all')
.size(5);
var mapper = new Mapper(client);
var callback = function(data) {
console.log(data);
};
expect(mapper.getFields(dataSource,callback)).to.eql({
foo: {
type: 'string'
},