1
0
Fork 0
mirror of https://github.com/mmumshad/ansible-playable.git synced 2025-03-09 23:38:54 +00:00

Update server side test cases and disable client side tests for now. Integrate later.

This commit is contained in:
Mumshad Mannambeth 2017-07-07 12:23:45 -04:00
parent ab295a073a
commit 9c880c0bba
13 changed files with 588 additions and 318 deletions

View file

@ -4,187 +4,168 @@
var app = require('../..');
import request from 'supertest';
import User from '../user/user.model';
var newCustomModule;
describe('CustomModule API:', function() {
describe('GET /api/custom_modules', function() {
var token;
var user;
// Clear users before testing
before(function() {
return User.remove().then(function() {
user = new User({
name: 'Fake User',
email: 'test@example.com',
password: 'password'
});
return user.save();
});
});
// Clear users after testing
after(function() {
return User.remove();
});
describe('GET /api/users/me', function() {
before(function(done) {
request(app)
.post('/auth/local')
.send({
email: 'test@example.com',
password: 'password'
})
.expect(200)
.expect('Content-Type', /json/)
.end((err, res) => {
token = res.body.token;
done();
});
});
it('should respond with a user profile when authenticated', function(done) {
request(app)
.get('/api/users/me')
.set('authorization', `Bearer ${token}`)
.expect(200)
.expect('Content-Type', /json/)
.end((err, res) => {
expect(res.body._id.toString()).to.equal(user._id.toString());
done();
});
});
it('should respond with a 401 when not authenticated', function(done) {
request(app)
.get('/api/users/me')
.expect(401)
.end(done);
});
});
describe('POST /api/custom_modules/template.py/get', function() {
var customModules;
beforeEach(function(done) {
request(app)
.get('/api/custom_modules')
.post('/api/custom_modules/template.py/get')
.set('authorization', `Bearer ${token}`)
.expect(200)
.expect('Content-Type', /json/)
.end((err, res) => {
if(err) {
return done(err);
}
customModules = res.body;
done();
});
});
it('should respond with JSON array', function() {
expect(customModules).to.be.instanceOf(Array);
});
});
describe('POST /api/custom_modules', function() {
beforeEach(function(done) {
request(app)
.post('/api/custom_modules')
.send({
name: 'New CustomModule',
info: 'This is the brand new customModule!!!'
ansibleEngine: {
host : '',
customModules: '/'
}
})
.expect(201)
.expect('Content-Type', /json/)
//.expect('Content-Type', /json/)
.end((err, res) => {
if(err) {
return done(err);
}
newCustomModule = res.body;
customModules = res.text;
done();
});
});
it('should respond with the newly created customModule', function() {
expect(newCustomModule.name).to.equal('New CustomModule');
expect(newCustomModule.info).to.equal('This is the brand new customModule!!!');
it('should respond with module_template', function() {
expect(customModules).to.contain('import AnsibleModule');
});
});
describe('GET /api/custom_modules/:id', function() {
var customModule;
describe('POST /api/custom_modules/test_module.py', function() {
var customModules;
beforeEach(function(done) {
request(app)
.get(`/api/custom_modules/${newCustomModule._id}`)
.post('/api/custom_modules/test_module.py')
.set('authorization', `Bearer ${token}`)
.expect(200)
.expect('Content-Type', /json/)
.end((err, res) => {
if(err) {
return done(err);
}
customModule = res.body;
done();
});
});
afterEach(function() {
customModule = {};
});
it('should respond with the requested customModule', function() {
expect(customModule.name).to.equal('New CustomModule');
expect(customModule.info).to.equal('This is the brand new customModule!!!');
});
});
describe('PUT /api/custom_modules/:id', function() {
var updatedCustomModule;
beforeEach(function(done) {
request(app)
.put(`/api/custom_modules/${newCustomModule._id}`)
.send({
name: 'Updated CustomModule',
info: 'This is the updated customModule!!!'
ansibleEngine: {
host : '',
customModules: '/tmp'
},
custom_module_code: '#!/usr/bin/python\n' +
'\n' +
'import datetime\n' +
'import json\n' +
'\n' +
'date = str(datetime.datetime.now())\n' +
'print(json.dumps({\n' +
'"time" : date\n' +
'}))'
})
.expect(200)
.expect('Content-Type', /json/)
.end(function(err, res) {
if(err) {
return done(err);
}
updatedCustomModule = res.body;
done();
});
});
afterEach(function() {
updatedCustomModule = {};
});
it('should respond with the updated customModule', function() {
expect(updatedCustomModule.name).to.equal('Updated CustomModule');
expect(updatedCustomModule.info).to.equal('This is the updated customModule!!!');
});
it('should respond with the updated customModule on a subsequent GET', function(done) {
request(app)
.get(`/api/custom_modules/${newCustomModule._id}`)
.expect(200)
.expect('Content-Type', /json/)
//.expect('Content-Type', /json/)
.end((err, res) => {
if(err) {
return done(err);
}
let customModule = res.body;
expect(customModule.name).to.equal('Updated CustomModule');
expect(customModule.info).to.equal('This is the updated customModule!!!');
customModules = res.text;
done();
});
});
it('should respond with "Saved"', function() {
expect(customModules).to.contain('Saved');
});
});
describe('PATCH /api/custom_modules/:id', function() {
var patchedCustomModule;
describe('POST /api/custom_modules/test_module.py/test', function() {
var result;
beforeEach(function(done) {
request(app)
.patch(`/api/custom_modules/${newCustomModule._id}`)
.send([
{ op: 'replace', path: '/name', value: 'Patched CustomModule' },
{ op: 'replace', path: '/info', value: 'This is the patched customModule!!!' }
])
.post('/api/custom_modules/test_module.py/test')
.set('authorization', `Bearer ${token}`)
.expect(200)
.expect('Content-Type', /json/)
.end(function(err, res) {
.send({
ansibleEngine: {
host : '',
customModules: '/tmp'
},
moduleArgs: {}
})
//.expect('Content-Type', /json/)
.end((err, res) => {
if(err) {
return done(err);
}
patchedCustomModule = res.body;
result = res;
done();
});
});
afterEach(function() {
patchedCustomModule = {};
});
it('should respond with the patched customModule', function() {
expect(patchedCustomModule.name).to.equal('Patched CustomModule');
expect(patchedCustomModule.info).to.equal('This is the patched customModule!!!');
it('should respond with 200', function() {
expect(result.status).to.equal(200);
});
});
describe('DELETE /api/custom_modules/:id', function() {
it('should respond with 204 on successful removal', function(done) {
request(app)
.delete(`/api/custom_modules/${newCustomModule._id}`)
.expect(204)
.end(err => {
if(err) {
return done(err);
}
done();
});
});
//TODO: Add more test cases
it('should respond with 404 when customModule does not exist', function(done) {
request(app)
.delete(`/api/custom_modules/${newCustomModule._id}`)
.expect(404)
.end(err => {
if(err) {
return done(err);
}
done();
});
});
});
});