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

Commit

Permalink
Removed old tests ready for new test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Caudle committed May 15, 2015
1 parent 7c8588c commit 5109f6d
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 265 deletions.
7 changes: 5 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ module.exports = function (grunt) {
pkg: grunt.file.readJSON('package.json'),
jshint: {
all: ['Gruntfile.js', 'lib/**/*.js', 'test/**/*.js']
},
nodeunit: {
all: ['tests/*.js']
}
});

grunt.loadNpmTasks('grunt-contrib-jshint');
/*grunt.loadNpmTasks('grunt-contrib-nodeunit');*/
grunt.registerTask('default', ['jshint' /*, 'nodeunit' */]);
grunt.loadNpmTasks('grunt-contrib-nodeunit');
grunt.registerTask('default', ['jshint', 'nodeunit']);
};
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ The client library uses Grunt to run it's tests and will also lint the files. To

## Changelog

- 1.1.2: Removed old tests ready for new test suite
- 1.1.1: PYLON GA release
- 1.1.0: Added PYLON endpoints & examples
- 1.0.0: Promoted out of BETA
Expand Down
2 changes: 1 addition & 1 deletion lib/library-version.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = { version: "1.1.1"};
module.exports = { version: "1.1.2"};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "datasift-node",
"version": "1.1.1",
"version": "1.1.2",
"description": "DataSift REST API Client",
"main": "./lib/datasift.js",
"repository": {
Expand Down
267 changes: 6 additions & 261 deletions tests/datasift.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,166 +2,13 @@
undef:true, unused:true, curly:true, browser:true, jquery:true, node:true, indent:4, maxerr:50, globalstrict:true */

var DataSift = require('../lib/datasift'),
manifest = require('../lib/version/1.json'),
request = require('request'),
async = require('async'),
apikey = '12345',
username = 'test',
testServer = '127.0.0.1:7000',
queue = [];
async = require('async');
//config = require('./config.json');

var apikey = '12345',
username = 'test';

var loopManifest = function (callback) {
Object.keys(manifest).forEach(function (key) {
_loopManifest(manifest, key, [key], callback);
});
};

var _loopManifest = function (definition, key, chain, callback) {
if (definition[key].uri !== undefined) {
callback(definition[key], key, chain);
} else {
Object.keys(definition[key]).forEach(function (subkey) {
var nChain = chain.slice(0);
nChain.push(subkey);
_loopManifest(definition[key], subkey, nChain, callback);
}.bind(this));
}
};

var stringGenerator = function () {
var text = '',
possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
for (var i=0; i < 5; i++ ) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
};


loopManifest(function (endpoint, key, chain) {

// create a new test for the endpoint
exports['test' + key.toUpperCase()] = function (test) {

var queue = [];

// setup the mock server
var mockServer = function (next) {

var body = {
'endpoint': '/v1' + endpoint.uri,
'verbs': [endpoint.method.toUpperCase()],
'code': '200',
'body': '',
'headers': {'content-type': 'application/json'}
};

request({
method: 'POST',
uri: 'http://' + testServer + '/register-endpoint',
body: body,
json: true
}, function () {
console.log('Created server for "' + key + '"');
next();
});
};

var testEndpoint = function (next) {
var ds = new DataSift(username, apikey, testServer, false),
params = {};

// let everyone know what we are testing
console.log('Testing endpoint "' + key + '"');

// generate dummy params information
endpoint.params.forEach(function (param) {
params[param.name] = param.type === 'string' ? stringGenerator() : Math.floor(Math.random() * 100);
});

// crawl down the DS prototype
var method = ds;
chain.forEach(function (key) {
method = method[key];
});

// send the request
method(params, function (err, response, code) {
//console.log(response, code);
test.equal(code, 200);
next();
});
};

queue.push(mockServer);
queue.push(testEndpoint);
async.series(queue, function () {
test.done();
});
};
});




/*
Object.keys(manifest).forEach(function (endpoint) {
if (manifest[endpoint].uri !== undefined) {
// recurse
}
});
// now send off all the request
Object.keys(manifest).forEach(function (endpoint) {
// create a new test for the endpoint
exports['test' + endpoint.toUpperCase()] = function (test) {
var ds = new DataSift(username, apikey, testServer),
params = {};
// let everyone know what we are testing
console.log('Testing endpoint ' + endpoint);
var stringGenerator = function () {
var text = '',
possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
for (var i=0; i < 5; i++ ) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
};
// generate dummy params information
manifest[endpoint].params.forEach(function (param) {
params[param.name] = param.type === 'string' ? stringGenerator() : Math.floor(Math.random() * 100);
});
// send the request
ds[endpoint](params, function (err, response) {
test.equal(response.statusCode, 200);
test.done();
});
};
});
console.log(exports);
// send every endpoint
/*exports.constructor = function (test) {
exports.constructor = function (test) {

// test empty params
test.throws(function () { new DataSift(); });
Expand All @@ -174,106 +21,4 @@ console.log(exports);
test.equals(apikey, ds.apikey);

test.done();
};
exports.topLevelFunctions = function (test) {
var ds = new DataSift(username, apikey);
// make sure we throw an error if we are missing a param
test.throws(function () { ds.validate(); });
// or if a param is the wrong type (int when should be string)
test.throws(function () { ds.validate({ 'csdl': 1 }); });
// test the int now
test.throws(function () { ds.stream({ 'hash': '1234', 'count': '1'}); });
test.done();
};
exports.secondLevelEndpoints = function (test) {
var ds = new DataSift(username, apikey);
// check mandatory args are sill enforced
test.throws(function () { ds.push.pause(); });
// check validation of argument types still occurs
test.throws(function () { ds.push.pause({ 'id': true }); });
test.done();
};
exports.thirdLevelEndpoints = function (test) {
var ds = new DataSift(username, apikey);
// check mandatory args are sill enforced
test.throws(function () { ds.list.replace.start(); });
// check validation of argument types still occurs
test.throws(function () { ds.list.replace.start({ 'list_id': 1 }); });
test.done();
};*/

/*
exports.endToEnd = function (test) {
// create the client
var queue = [],
hash = false,
ds = new DataSift(config.username, config.apikey);
// test the require param fails
test.throws(function () {
ds.compile('test');
});
// testing complilation of CSDL
var compile = function (next) {
console.log('Compiling .....');
ds.compile({
'csdl': 'interaction.content contains "test"'
}, function (err, resp) {
console.log('Compiling completed');
test.ok(resp, 'reponse is null');
test.equal(typeof resp, 'object', 'response is not valid JSON');
hash = resp.hash;
next();
});
};
// testing the streaming componants
var stream = function (next) {
console.log('Streaming ' + hash);
ds.connect();
ds.on('connect', function () {
console.log('Connected to datasift');
ds.subscribe(hash);
});
ds.on('error', function (error) {
console.log('Connection errored with: ' + error);
});
ds.on('interaction', function (data) {
console.log('Recieved data');
test.ok(data, 'We recived no data');
ds.disconnect();
next();
});
};
queue.push(compile);
queue.push(stream);
async.series(queue, function () {
test.done();
});
};*/
};

0 comments on commit 5109f6d

Please sign in to comment.