Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions e2e/applications-gallery-page.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';

var helpers = require('./po/helpers.po');
var galleryPage = require('./po/application-card-gallery.po');
var registration = require('./po/service-instance-registration.po');

describe('Application Gallery Page', function () {
beforeAll(function () {
helpers.setBrowserNormal();
helpers.loadApp();
helpers.resetDatabase();
galleryPage.login();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to add a browser.driver.sleep(1000); after line 10 since there's a verify session step that uses a timeout.

registration.connect(0);
browser.driver.sleep(1000);
registration.doneButton().click();
});

describe('content', function () {
describe('applications tab', function() {
it("should show the applications gallery", function() {
galleryPage.showApplicationsGallery();
expect(browser.getCurrentUrl()).toBe('http://' + helpers.getHost() +'/#/cf/applications/list/gallery-view');
});
describe("and you click a card", function() {
it('should go to application detail', function () {
galleryPage.showApplicationDetails();
expect(browser.getCurrentUrl()).toMatch(/summary$/);
});
})
});
});
});
1 change: 1 addition & 0 deletions e2e/login-page.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ describe('Login Page', function () {
beforeAll(function () {
helpers.setBrowserNormal();
helpers.loadApp();
helpers.resetDatabase();
});

describe('content', function () {
Expand Down
36 changes: 36 additions & 0 deletions e2e/po/application-card-gallery.po.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';
var loginPage = require('./login-page.po');

// Navbar helpers
module.exports = {
login : login,
showApplicationsGallery : showApplicationsGallery,
showApplicationDetails : showApplicationDetails
};

function applicationGalleryCard() {
return element.all(by.css('application-gallery-card')).get(0)
.element(by.css('gallery-card'));
}

function applicationsGalleryButton() {
return element(by.css('navigation'))
.element(by.css('[href="#cf/applications/list/gallery-view"]'));
}

function showApplicationsGallery() {
applicationsGalleryButton().click();
}

function showApplicationDetails() {
applicationGalleryCard().click();
}

function login() {
var fields = loginPage.loginFormFields();
var usernameField = fields.get(0);
usernameField.clear();
usernameField.sendKeys('dev');
fields.get(1).sendKeys('dev');
loginPage.loginButton().click();
}
54 changes: 53 additions & 1 deletion e2e/po/helpers.po.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var sh = require('../../tools/node_modules/shelljs');
var request = require('../../tools/node_modules/request');

// Get host IP
var CMD = "/sbin/ip route|awk '/default/ { print $3 }'";
Expand All @@ -23,7 +24,11 @@ module.exports = {

getTableRows: getTableRows,
getTableRowAt: getTableRowAt,
getTableCellAt: getTableCellAt
getTableCellAt: getTableCellAt,

removeInstance: removeInstance,
resetDatabase: resetDatabase,
createSession: createSession

};

Expand Down Expand Up @@ -89,3 +94,50 @@ function getTableRowAt(table, rowIndex) {
function getTableCellAt(table, rowIndex, colIndex) {
return getTableRows(table).get(rowIndex).all(by.css('td')).get(colIndex);
}

/**
* Clean up database
*/

function createSession(req) {
return new Promise(function (resolve, reject) {
var loginUrl = 'http://' + hostIp + ':3000/api/auth/login';

req.post({
headers: {'content-type': 'application/json'},
url: loginUrl,
body: JSON.stringify({username: 'dev', password: 'dev'})
}, function (error, response) {
if (!error && response.statusCode === 200) {
resolve();
} else {
reject(error);
}
});
});
}

function removeInstance(req, jar) {
var removeUrl = 'http://' + hostIp + ':3000/api/service-instances/user/remove';
req.post({
cookie: jar.getCookieString(hostIp),
headers: {'content-type': 'application/json'},
url: removeUrl,
body: JSON.stringify({url: 'api.15.126.233.29.xip.io'})
})
}

function resetDatabase() {
var cookieJar = request.jar();
var req = request.defaults({
jar: cookieJar
});

createSession(req).then(function () {
removeInstance(req, cookieJar);
}, function (err) {
console.log('Unable to reset the DB');
console.log('Error:' + err);
}
);
}
47 changes: 17 additions & 30 deletions src/app/api/serviceInstance/serviceInstance.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
'use strict';

/**
* @namespace app.api
* @memberOf app.api
* @name app.api.serviceInstance
* @namespace app.api.serviceInstance
* @memberof app.api
* @name serviceInstance
* @description Service instance API
*/
angular
Expand All @@ -21,9 +21,9 @@
}

/**
* @namespace app.api
* @namespace app.api.serviceInstance.ServiceInstanceApi
* @memberof app.api.serviceInstance
* @name app.api.serviceInstance.ServiceInstanceApi
* @name ServiceInstanceApi
* @param {object} $http - the Angular $http service
* @property {object} $http - the Angular $http service
* @class
Expand All @@ -34,52 +34,39 @@

angular.extend(ServiceInstanceApi.prototype, {
/**
* @function connect
* @function create
* @memberof app.api.serviceInstance.ServiceInstanceApi
* @description Connect a service instance
* @description Create a service instance
* @param {string} url - the service instance endpoint
* @param {string} name - the service instance friendly name
* @returns {promise} A resolved/rejected promise
* @public
*/
connect: function (url) {
return this.$http.post('/api/service-instances/user/connect', { url: url });
create: function (url, name) {
return this.$http.post('/api/service-instances', { url: url, name: name });
},

/**
* @function disconnect
* @function remove
* @memberof app.api.serviceInstance.ServiceInstanceApi
* @description Disconnect user from service instance
* @param {string} url - the service instance endpoint
* @description Remove service instance
* @param {number} id - the ID of the service instance to remove
* @returns {promise} A resolved/rejected promise
* @public
*/
disconnect: function (url) {
return this.$http.post('/api/service-instances/user/disconnect', { url: url });
remove: function (id) {
return this.$http.delete('/api/service-instances/' + id);
},

/**
* @function list
* @memberof app.api.serviceInstance.ServiceInstanceApi
* @description Returns a list of service instances for the user
* @description Returns a list of service instances (master list)
* @returns {promise} A resolved/rejected promise
* @public
*/
list: function () {
return this.$http.get('/api/service-instances/user');
},

/**
* @function register
* @memberof app.api.serviceInstance.ServiceInstanceApi
* @description Set the service instances as registered
* @param {array} urls - the service instance endpoints
* @returns {promise} A resolved/rejected promise
* @public
*/
register: function (urls) {
return this.$http.post('/api/service-instances/user/register', {
serviceInstances: urls
});
return this.$http.get('/api/service-instances');
}
});

Expand Down
32 changes: 14 additions & 18 deletions src/app/api/serviceInstance/serviceInstance.api.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function () {
'use strict';

describe('service instance API', function () {
describe('user service instance API', function () {
var $httpBackend, serviceInstanceApi;

beforeEach(module('green-box-console'));
Expand All @@ -25,17 +25,22 @@
expect(serviceInstanceApi.$http).toBeDefined();
});

it('should send POST request for connect', function () {
$httpBackend.expectPOST('/api/service-instances/user/connect', { url: 'url' }).respond(200, '');
serviceInstanceApi.connect('url');
it('should send POST request for create()', function () {
var mockRespondData = { id: 1, url: 'url', name: 'name' };
$httpBackend.expectPOST('/api/service-instances', { url: 'url', name: 'name' })
.respond(200, mockRespondData);
serviceInstanceApi.create('url', 'name')
.then(function (response) {
expect(response.data).toEqual({ id: 1, url: 'url', name: 'name' });
});
$httpBackend.flush();
});

it('should return service instances for specified user', function () {
it('should return all service instances (master list)', function () {
var data = {
items: ['x','y','z']
};
$httpBackend.when('GET', '/api/service-instances/user').respond(200, data);
$httpBackend.when('GET', '/api/service-instances').respond(200, data);

serviceInstanceApi.list().then(function (response) {
expect(response.data).toEqual({items: ['x','y','z']});
Expand All @@ -44,18 +49,9 @@
$httpBackend.flush();
});

it('should send POST request for register', function () {
var data = {
serviceInstances: ['url1', 'url2']
};
$httpBackend.expectPOST('/api/service-instances/user/register', data).respond(200, '');
serviceInstanceApi.register(['url1', 'url2']);
$httpBackend.flush();
});

it('should send POST request for disconnect', function () {
$httpBackend.expectPOST('/api/service-instances/user/disconnect', { url: 'url' }).respond(200, '');
serviceInstanceApi.disconnect('url');
it('should send DELETE request remove()', function () {
$httpBackend.expectDELETE('/api/service-instances/1').respond(200, '');
serviceInstanceApi.remove(1);
$httpBackend.flush();
});
});
Expand Down
86 changes: 86 additions & 0 deletions src/app/api/serviceInstance/user/userServiceInstance.api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
(function () {
'use strict';

/**
* @namespace app.api.serviceInstance.user
* @memberof app.api.serviceInstance
* @name user
* @description User service instance API
*/
angular
.module('app.api')
.run(registerUserServiceInstanceApi);

registerUserServiceInstanceApi.$inject = [
'$http',
'app.api.apiManager'
];

function registerUserServiceInstanceApi($http, apiManager) {
apiManager.register('app.api.serviceInstance.user', new UserServiceInstanceApi($http));
}

/**
* @namespace app.api.serviceInstance.user.UserServiceInstanceApi
* @memberof app.api.serviceInstance.user
* @name UserServiceInstanceApi
* @param {object} $http - the Angular $http service
* @property {object} $http - the Angular $http service
* @class
*/
function UserServiceInstanceApi($http) {
this.$http = $http;
}

angular.extend(UserServiceInstanceApi.prototype, {
/**
* @function connect
* @memberof app.api.serviceInstance.user.UserServiceInstanceApi
* @description Connect a service instance
* @param {string} url - the service instance endpoint
* @returns {promise} A resolved/rejected promise
* @public
*/
connect: function (url) {
return this.$http.post('/api/service-instances/user/connect', { url: url });
},

/**
* @function disconnect
* @memberof app.api.serviceInstance.user.UserServiceInstanceApi
* @description Disconnect user from service instance
* @param {string} url - the service instance endpoint
* @returns {promise} A resolved/rejected promise
* @public
*/
disconnect: function (url) {
return this.$http.post('/api/service-instances/user/disconnect', { url: url });
},

/**
* @function list
* @memberof app.api.serviceInstance.user.UserServiceInstanceApi
* @description Returns a list of service instances for the user
* @returns {promise} A resolved/rejected promise
* @public
*/
list: function () {
return this.$http.get('/api/service-instances/user');
},

/**
* @function register
* @memberof app.api.serviceInstance.user.UserServiceInstanceApi
* @description Set the service instances as registered
* @param {array} urls - the service instance endpoints
* @returns {promise} A resolved/rejected promise
* @public
*/
register: function (urls) {
return this.$http.post('/api/service-instances/user/register', {
serviceInstances: urls
});
}
});

})();
Loading