Skip to content
This repository has been archived by the owner on Mar 8, 2020. It is now read-only.

Commit

Permalink
Added Mongo DB features to the framework
Browse files Browse the repository at this point in the history
  • Loading branch information
rajeshi committed Aug 2, 2017
1 parent 9b87618 commit acd1c2a
Show file tree
Hide file tree
Showing 12 changed files with 169 additions and 14 deletions.
9 changes: 9 additions & 0 deletions .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"ExpandedNodes": [
"",
"\\features",
"\\features\\event"
],
"SelectedNode": "\\rest_factory.js",
"PreviewInSolutionExplorer": false
}
Binary file added .vs/features/v15/.suo
Binary file not shown.
Binary file added .vs/slnx.sqlite
Binary file not shown.
34 changes: 34 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Grunt task",
"program": "${workspaceRoot}/node_modules/grunt-cli/bin/grunt"
},
{
"type": "node",
"request": "attach",
"name": "Attach by Process ID",
"processId": "${command:PickProcess}"
},
{
"type": "node",
"request": "attach",
"name": "Attach",
"port": 5858
},
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "node_modules\\grunt-cli\\bin\\grunt",
"stopOnEntry": true,
"cwd": "${workspaceRoot}"
}
]
}
98 changes: 98 additions & 0 deletions data_factory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
var Db = require('mongodb').Db;
var Connection = require('mongodb').Connection;
var Server = require('mongodb').Server;
var BSON = require('mongodb').BSON;
var ObjectID = require('mongodb').ObjectID;

dataFactory = function(db, host, port) {
this.db= new Db(db, new Server(host, port, {safe: false}, {auto_reconnect: true}, {}));
this.db.open(function(){});
};


dataFactory.prototype.getCollection= function(collection, callback) {
this.db.collection(collection, function(error, data_collection) {
if( error ) callback(error);
else callback(null, data_collection);
});
};

//find all datas
dataFactory.prototype.findAll = function(callback) {
this.getCollection(function(error, data_collection) {
if( error ) callback(error)
else {
data_collection.find().toArray(function(error, results) {
if( error ) callback(error)
else callback(null, results)
});
}
});
};

//find an data by ID
dataFactory.prototype.findById = function(id, callback) {
this.getCollection(function(error, data_collection) {
if( error ) callback(error)
else {
data_collection.findOne({_id: data_collection.db.bson_serializer.ObjectID.createFromHexString(id)}, function(error, result) {
if( error ) callback(error)
else callback(null, result)
});
}
});
};


//save new data
dataFactory.prototype.save = function(collection, callback) {
this.getCollection(function(error, data_collection) {
if( error ) callback(error)
else {
if( typeof(collection.length)=="undefined")
collection = [collection];

for( var i =0;i< datas.length;i++ ) {
data = collection[i];
data.created_at = new Date();
}

data_collection.insert(datas, function() {
callback(null, collection);
});
}
});
};

// update an data
dataFactory.prototype.update = function(dataId, collection, callback) {
this.getCollection(function(error, data_collection) {
if( error ) callback(error);
else {
data_collection.update(
{_id: data_collection.db.bson_serializer.ObjectID.createFromHexString(dataId)},
datas,
function(error, collection) {
if(error) callback(error);
else callback(null, collection)
});
}
});
};

//delete data
dataFactory.prototype.delete = function(dataId, callback) {
this.getCollection(function(error, data_collection) {
if(error) callback(error);
else {
data_collection.remove(
{_id: data_collection.db.bson_serializer.ObjectID.createFromHexString(dataId)},
function(error, data){
if(error) callback(error);
else callback(null, data)
});
}
});
};

exports.dataFactory = dataFactory;
4 changes: 2 additions & 2 deletions features/dialog/step_definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ var restFactory = require("../../rest_factory");

module.exports = function() {

this.Given(/^there are Identity records as follows:$/, function (table) {
/*this.Given(/^there are Identity records as follows:$/, function (table) {
checkWhetherRecordsPresent();
});
});*/

this.Given(/^there are Dialog records as follows:$/, function (table) {
checkWhetherRecordsPresent();
Expand Down
2 changes: 1 addition & 1 deletion features/event/post_event.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Feature: new event
| BRONZE_RECORD |
| GOLD_RECORD |

@acceptance @valid_event_received
@acceptance @valid_event_received @for_testing
Scenario: Valid event received
When a valid new Event is received
Then save the Event
Expand Down
11 changes: 6 additions & 5 deletions features/event/step_definition.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';

var expect = require('chai').expect;
var identifier = null;
var restFactory = require("../../rest_factory");

var expect = require('chai').expect;
var identifier = null;
var helloWorld = require("../../hello_world");
var restFactory = require('../../rest_factory');
// Public Api:
// https://api.utu.ai/v1/track
// header:
Expand All @@ -29,10 +29,11 @@ module.exports = function() {
// Call the mongoDB and check whether the table contents are present in the database MongoDB utility
// If not, insert the contents into the database
// then validate true to complete this step.
this.restFactory.message('Rajesh');
};

this.When(/^a valid new Event is received$/, function (callback) {

this.helloWorld.message('Rajesh');
var apiKey = "0475dbadc4cb410bbf562d605ea2cd47";
var context = {
platform: "sms",
Expand Down
4 changes: 1 addition & 3 deletions features/identity/alias_identity.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,16 @@ Feature: alias identity
Rules:
- ...

@for_testing
Background:
Given there are Identity records as follows:
| identityKey |
| TIN_RECORD |
| BRONZE_RECORD |
| GOLD_RECORD |

@acceptance @for_testing
@acceptance
Scenario: Alias called for a known identity
When an aliased foreignId is received
Then review medal match when upserting an Identity tin record
And push update to all medal Identity views
And push impacted Identity rollup to related services

4 changes: 2 additions & 2 deletions features/identity/step_definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ var restFactory = require("../../rest_factory");

module.exports = function() {

this.Given(/^there are Identity records as follows:$/, function (table) {
/*this.Given(/^there are Identity records as follows:$/, function (table) {
checkWhetherRecordsPresent();
});
});*/

var checkWhetherRecordsPresent = function(){
// Call the mongoDB and check whether the table contents are present in the database MongoDB utility
Expand Down
11 changes: 11 additions & 0 deletions hello_world.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';
var helloWorld = function helloWorld(callback){

self = this;

this.message = function(name){
console('Hello '+name);
}

module.exports.helloWorld = helloWorld;
}
6 changes: 5 additions & 1 deletion rest_factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ var restFactory = function restFactory(callback) {

this.lastResponse = null;

this.message = function(name){
console.info('Hello '+ name);
}

this.get = function(path, callback) {
var uri = this.uri(path)
request.get({url: uri, headers: {'User-Agent': 'request'}},
Expand Down Expand Up @@ -92,4 +96,4 @@ var restFactory = function restFactory(callback) {
callback();
}

exports.restFactory = restFactory;
module.exports.restFactory = restFactory;

0 comments on commit acd1c2a

Please sign in to comment.