Skip to content

Commit

Permalink
mocha test request
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaslabbe committed Sep 22, 2016
1 parent 1b8aad0 commit df84324
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 2 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ src/server/public/css/styles.css
cli/config/*-local.js

# debug
abe-logs/*
test/*
abe-logs/*
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"url": "git://github.com/AdFabConnect/abejs.git"
},
"scripts": {
"test": "mocha --compilers js:babel-core/register",
"start": "node --debug --harmony ./dist/server/index.js",
"startpm2": "pm2 startOrRestart ./processes.json",
"babel": "babelify src/server/public/scripts/template-engine.js -o src/server/public/scripts/template-engine-compiled.js",
Expand Down Expand Up @@ -82,7 +83,9 @@
"babel-preset-stage-0": "^6.3.13",
"babelify": "^7.2.0",
"browserify": "^13.0.0",
"chai": "^3.5.0",
"mkdirp": "^0.5.1",
"mocha": "^3.0.2",
"node-sass": "^3.6.0",
"nodemon": "^1.8.1",
"parallelshell": "^2.0.0",
Expand Down
5 changes: 5 additions & 0 deletions src/cli/models/Manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ class Manager {
return this._list
}

setList(list) {

this._list = list
}

_init() {
const pathTemplate = path.join(config.root, config.templates.url);
getSelectTemplateKeys(pathTemplate)
Expand Down
175 changes: 175 additions & 0 deletions test/request.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
var chai = require('chai');

describe('Request', function() {

/**
* Sql.getAllAttributes
*
*/
it('Util.getAllAttributes()', function() {
var Util = require('../src/cli').Util
var attributes = Util.getAllAttributes("{{abe type='data' key='top_things_slider_highlight' desc='Automatic slider' source=\"select * from ../\" editable=\"false\"}}", {})
chai.assert.equal(attributes.sourceString, 'select * from ../', 'sourceString is ok');
});

/**
* Sql.executeQuery
*
*/
it('Sql.executeQuery()', function() {
var Sql = require('../src/cli').Sql

var match = 'select * from ../'
var jsonPage = {}
var res = Sql.handleSqlRequest(match, {})

chai.assert.equal(res.string, 'select ["*"] from ["___abe_dot______abe_dot______abe___"] ', 'select not well formatted')
});

/**
* Sql.executeFromClause
*
*/
it('Sql.executeFromClause()', function() {
var Sql = require('../src/cli').Sql;
var Manager = require('../src/cli').Manager;

var list = Manager.instance.setList([
{"path": "/Users/nicolas/Documents/programmation/websites/sofitel/data/test.json", "published": true},
{"path": "/Users/nicolas/Documents/programmation/websites/sofitel/data/truc/test.json", "published": true}
])

var from = ["/truc"]
var res = Sql.executeFromClause(from, from)

chai.expect(res).to.have.length(1);
});

/**
* Sql.executeWhereClause
*
*/
it('Sql.executeWhereClause()', function() {
var Sql = require('../src/cli').Sql;

var files = [
{"abe_meta": {"template": "test"}, "published": true},
{"abe_meta": {"template": "truc"}, "published": true}
];
var where = [{ left: 'template', right: 'test', compare: '=', operator: '' }]

var res = Sql.executeWhereClause(files, where, -1, ['*'], {})

chai.expect(res).to.have.length(1);
});

/**
* Sql.whereEquals
*
*/
it('Sql.whereEquals()', function() {
var Sql = require('../src/cli').Sql;

var json = {"template": "test", "title": "test"}

chai.expect(json)
.to.deep.equal(
Sql.whereEquals(
[{ left: 'template' }],
json.template,
"test",
json
)
);

chai.expect(json)
.to.deep.equal(
Sql.whereEquals(
[{ left: 'title' }],
json.title,
"test",
json
)
);

chai.expect(json)
.to.not.deep.equal(
Sql.whereEquals(
[{ left: 'title' }],
json.title,
"ttt",
json
)
);
});

/**
* Sql.whereNotEquals
*
*/
it('Sql.whereNotEquals()', function() {
var Sql = require('../src/cli').Sql;

var json = {"template": "truc", "title": "truc"}

chai.expect(json)
.to.deep.equal(
Sql.whereNotEquals(
[{ left: 'template' }],
json.template,
"test",
json
)
);

chai.expect(json)
.to.deep.equal(
Sql.whereNotEquals(
[{ left: 'title' }],
json.title,
"test",
json
)
);

chai.expect(json)
.to.not.deep.equal(
Sql.whereNotEquals(
[{ left: 'template' }],
json.title,
"truc",
json
)
);
});

/**
* Sql.whereLike
*
*/
it('Sql.whereLike()', function() {
var Sql = require('../src/cli').Sql;

var json = {"template": "test", "title": "test"}

chai.expect(json)
.to.deep.equal(
Sql.whereLike(
[{ left: 'template' }],
json.template,
"te",
json
)
);

chai.expect(json)
.to.not.deep.equal(
Sql.whereLike(
[{ left: 'title' }],
json.title,
"tu",
json
)
);
});
});

0 comments on commit df84324

Please sign in to comment.