#981 Back & front tests passed, keybinds on it's own module routes.json
This commit is contained in:
parent
e080802445
commit
30749f0f4d
|
@ -1,35 +1,22 @@
|
||||||
const app = require(`${serviceRoot}/server/server`);
|
const app = require(`${serviceRoot}/server/server`);
|
||||||
|
|
||||||
describe('account login()', () => {
|
describe('account login()', () => {
|
||||||
it('when the user doesnt exist but the client does and the password is correct', async() => {
|
describe('when credentials are correct', () => {
|
||||||
let response = await app.models.Account.login('PetterParker', 'nightmare');
|
it('should return the token', async() => {
|
||||||
|
|
||||||
expect(response.token).toBeDefined();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('when the user exists and the password is correct', () => {
|
|
||||||
it('should login and return the token', async() => {
|
|
||||||
let response = await app.models.Account.login('employee', 'nightmare');
|
let response = await app.models.Account.login('employee', 'nightmare');
|
||||||
|
|
||||||
expect(response.token).toBeDefined();
|
expect(response.token).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should define the url to continue upon login', async() => {
|
it('should return the token if the user doesnt exist but the client does', async() => {
|
||||||
let location = 'http://localhost/auth/?apiKey=salix&continue=continueURL';
|
let response = await app.models.Account.login('PetterParker', 'nightmare');
|
||||||
let response = await app.models.Account.login('employee', 'nightmare', location);
|
|
||||||
|
|
||||||
expect(response.continue).toBe('continueURL');
|
expect(response.token).toBeDefined();
|
||||||
});
|
|
||||||
|
|
||||||
it('should define the loginUrl upon login', async() => {
|
|
||||||
let location = 'http://localhost/auth/?apiKey=salix';
|
|
||||||
let response = await app.models.Account.login('employee', 'nightmare', location);
|
|
||||||
|
|
||||||
expect(response.loginUrl).toBeDefined();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw a 401 error when credentials are incorrect', async() => {
|
describe('when credentials are incorrect', () => {
|
||||||
|
it('should throw a 401 error', async() => {
|
||||||
let error;
|
let error;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -42,4 +29,5 @@ describe('account login()', () => {
|
||||||
expect(error.statusCode).toBe(401);
|
expect(error.statusCode).toBe(401);
|
||||||
expect(error.code).toBe('LOGIN_FAILED');
|
expect(error.code).toBe('LOGIN_FAILED');
|
||||||
});
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,4 +4,5 @@ export * from './module';
|
||||||
export * from './directives';
|
export * from './directives';
|
||||||
export * from './filters';
|
export * from './filters';
|
||||||
export * from './lib';
|
export * from './lib';
|
||||||
|
export * from './services';
|
||||||
export * from './components';
|
export * from './components';
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
|
||||||
|
export default function getMainRoute(routes) {
|
||||||
|
for (let route of routes) {
|
||||||
|
if (!route.abstract)
|
||||||
|
return route;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
|
@ -12,3 +12,4 @@ import './modified';
|
||||||
import './key-codes';
|
import './key-codes';
|
||||||
import './http-error';
|
import './http-error';
|
||||||
import './user-error';
|
import './user-error';
|
||||||
|
import './get-main-route';
|
||||||
|
|
|
@ -3,46 +3,54 @@ describe('Service acl', () => {
|
||||||
|
|
||||||
beforeEach(ngModule('vnCore'));
|
beforeEach(ngModule('vnCore'));
|
||||||
|
|
||||||
beforeEach(ngModule($provide => {
|
beforeEach(inject((_aclService_, $httpBackend) => {
|
||||||
$provide.value('aclConstant', {});
|
$httpBackend.when('GET', `/api/Accounts/acl`).respond({
|
||||||
}));
|
roles: [
|
||||||
|
{role: {name: 'foo'}},
|
||||||
beforeEach(inject(_aclService_ => {
|
{role: {name: 'bar'}},
|
||||||
|
{role: {name: 'baz'}}
|
||||||
|
]
|
||||||
|
});
|
||||||
aclService = _aclService_;
|
aclService = _aclService_;
|
||||||
|
aclService.load();
|
||||||
|
$httpBackend.flush();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should return false as the service doesn\'t have roles', () => {
|
describe('load()', () => {
|
||||||
expect(aclService.routeHasPermission('http://www.verdnatura.es')).toBeFalsy();
|
it('should load roles from backend', () => {
|
||||||
|
expect(aclService.roles).toEqual({
|
||||||
|
foo: true,
|
||||||
|
bar: true,
|
||||||
|
baz: true
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return true as the service has roles but the route has no acl', () => {
|
describe('hasAny()', () => {
|
||||||
aclService.roles = {customer: true};
|
it('should return true when user has any of the passed roles', () => {
|
||||||
|
let hasAny = aclService.hasAny(['foo', 'nonExistent']);
|
||||||
|
|
||||||
expect(aclService.routeHasPermission('http://www.verdnatura.es')).toBeTruthy();
|
expect(hasAny).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return false as the service roles have no length', () => {
|
it('should return true when user has all the passed roles', () => {
|
||||||
aclService.roles = {};
|
let hasAny = aclService.hasAny(['bar', 'baz']);
|
||||||
let route = {url: 'http://www.verdnatura.es', acl: []};
|
|
||||||
|
|
||||||
expect(aclService.routeHasPermission(route)).toBeFalsy();
|
expect(hasAny).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call the service hasAny() function and return false as the service has roles and the rote has acl without length', () => {
|
it('should return true when user has not any of the passed roles', () => {
|
||||||
aclService.roles = {customer: true, employee: true};
|
let hasAny = aclService.hasAny(['inventedRole', 'nonExistent']);
|
||||||
let route = {url: 'http://www.verdnatura.es', acl: []};
|
|
||||||
spyOn(aclService, 'hasAny').and.callThrough();
|
|
||||||
|
|
||||||
expect(aclService.routeHasPermission(route)).toBeFalsy();
|
expect(hasAny).toBeFalsy();
|
||||||
expect(aclService.hasAny).toHaveBeenCalledWith(route.acl);
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call the service hasAny() function to return true as the service has roles matching with the ones in acl', () => {
|
describe('reset()', () => {
|
||||||
aclService.roles = {customer: true, employee: true};
|
it('should reset the roles', () => {
|
||||||
let route = {url: 'http://www.verdnatura.es', acl: ['customer']};
|
aclService.reset();
|
||||||
spyOn(aclService, 'hasAny').and.callThrough();
|
|
||||||
|
|
||||||
expect(aclService.routeHasPermission(route)).toBeTruthy();
|
expect(aclService.roles).toBeNull();
|
||||||
expect(aclService.hasAny).toHaveBeenCalledWith(route.acl);
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import ngModule from '../module';
|
import ngModule from '../module';
|
||||||
import {getMainRoute} from '../routes';
|
import getMainRoute from '../lib/get-main-route';
|
||||||
import keybindings from '../keybindings.yml';
|
|
||||||
|
|
||||||
export default class Modules {
|
export default class Modules {
|
||||||
constructor(aclService, $window) {
|
constructor(aclService, $window) {
|
||||||
|
@ -25,8 +24,8 @@ export default class Modules {
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
let keyBind;
|
let keyBind;
|
||||||
if (keybindings) {
|
if (mod.keybindings) {
|
||||||
let res = keybindings.find(i => i.sref == route.state);
|
let res = mod.keybindings.find(i => i.sref == route.state);
|
||||||
if (res) keyBind = res.key.toUpperCase();
|
if (res) keyBind = res.key.toUpperCase();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import './module';
|
import './module';
|
||||||
import './routes';
|
import './routes';
|
||||||
import './components/index';
|
import './components';
|
||||||
import './lib/index';
|
import './styles';
|
||||||
import './styles/index';
|
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
[
|
|
||||||
{key: r, sref: claim.index},
|
|
||||||
{key: c, sref: client.index},
|
|
||||||
{key: a, sref: item.index},
|
|
||||||
{key: t, sref: ticket.index},
|
|
||||||
]
|
|
|
@ -1,6 +1,5 @@
|
||||||
import {ng} from 'core/vendor';
|
import {ng} from 'core/vendor';
|
||||||
import 'core';
|
import 'core';
|
||||||
import keybindings from './keybindings.yml';
|
|
||||||
|
|
||||||
export const appName = 'salix';
|
export const appName = 'salix';
|
||||||
|
|
||||||
|
@ -21,8 +20,13 @@ export function run($window, $rootScope, vnAuth, vnApp, $state, $document) {
|
||||||
window.myAppErrorLog.push(error);
|
window.myAppErrorLog.push(error);
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const binding in keybindings) {
|
if ($window.routes) {
|
||||||
if (!keybindings[binding].key || !keybindings[binding].sref)
|
for (const mod of $window.routes) {
|
||||||
|
if (!mod || !mod.keybindings)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
for (const binding of mod.keybindings) {
|
||||||
|
if (!binding.key || !binding.sref)
|
||||||
throw new Error('Binding not formed correctly');
|
throw new Error('Binding not formed correctly');
|
||||||
|
|
||||||
$document.on('keyup', function(e) {
|
$document.on('keyup', function(e) {
|
||||||
|
@ -31,7 +35,7 @@ export function run($window, $rootScope, vnAuth, vnApp, $state, $document) {
|
||||||
let shortcut = {
|
let shortcut = {
|
||||||
altKey: true,
|
altKey: true,
|
||||||
ctrlKey: true,
|
ctrlKey: true,
|
||||||
key: keybindings[binding].key
|
key: binding.key
|
||||||
};
|
};
|
||||||
|
|
||||||
let correctShortcut = true;
|
let correctShortcut = true;
|
||||||
|
@ -40,11 +44,13 @@ export function run($window, $rootScope, vnAuth, vnApp, $state, $document) {
|
||||||
correctShortcut = correctShortcut && shortcut[key] == e[key];
|
correctShortcut = correctShortcut && shortcut[key] == e[key];
|
||||||
|
|
||||||
if (correctShortcut) {
|
if (correctShortcut) {
|
||||||
$state.go(keybindings[binding].sref);
|
$state.go(binding.sref);
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ngModule.run(run);
|
ngModule.run(run);
|
||||||
|
|
||||||
|
|
|
@ -2,14 +2,7 @@ import ngModule from './module';
|
||||||
import deps from 'modules.yml';
|
import deps from 'modules.yml';
|
||||||
import modules from 'spliting';
|
import modules from 'spliting';
|
||||||
import splitingRegister from 'core/lib/spliting-register';
|
import splitingRegister from 'core/lib/spliting-register';
|
||||||
|
import getMainRoute from 'core/lib/get-main-route';
|
||||||
export function getMainRoute(routes) {
|
|
||||||
for (let route of routes) {
|
|
||||||
if (!route.abstract)
|
|
||||||
return route;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function loader(moduleName, validations) {
|
function loader(moduleName, validations) {
|
||||||
load.$inject = ['vnModuleLoader'];
|
load.$inject = ['vnModuleLoader'];
|
||||||
|
|
|
@ -78,5 +78,8 @@
|
||||||
{"state": "claim.card.detail", "icon": "icon-details"},
|
{"state": "claim.card.detail", "icon": "icon-details"},
|
||||||
{"state": "claim.card.development", "icon": "icon-traceability"},
|
{"state": "claim.card.development", "icon": "icon-traceability"},
|
||||||
{"state": "claim.card.action", "icon": "icon-actions"}
|
{"state": "claim.card.action", "icon": "icon-actions"}
|
||||||
|
],
|
||||||
|
"keybindings": [
|
||||||
|
{"key": "r", "sref": "claim.index"}
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -11,7 +11,7 @@ describe('Client', () => {
|
||||||
beforeEach(angular.mock.inject((_$componentController_, $rootScope) => {
|
beforeEach(angular.mock.inject((_$componentController_, $rootScope) => {
|
||||||
$componentController = _$componentController_;
|
$componentController = _$componentController_;
|
||||||
$scope = $rootScope.$new();
|
$scope = $rootScope.$new();
|
||||||
controller = $componentController('vnClientRiskIndex', {$scope: $scope});
|
controller = $componentController('vnClientRiskIndex', {$scope});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('risks() setter', () => {
|
describe('risks() setter', () => {
|
||||||
|
|
|
@ -347,5 +347,8 @@
|
||||||
{"state": "client.card.webPayment", "icon": "icon-onlinepayment"}
|
{"state": "client.card.webPayment", "icon": "icon-onlinepayment"}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"keybindings": [
|
||||||
|
{"key": "c", "sref": "client.index"}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,5 +125,8 @@
|
||||||
{"state": "item.card.itemBarcode", "icon": "icon-barcode"},
|
{"state": "item.card.itemBarcode", "icon": "icon-barcode"},
|
||||||
{"state": "item.card.diary", "icon": "icon-transaction"},
|
{"state": "item.card.diary", "icon": "icon-transaction"},
|
||||||
{"state": "item.card.last-entries", "icon": "icon-regentry"}
|
{"state": "item.card.last-entries", "icon": "icon-regentry"}
|
||||||
|
],
|
||||||
|
"keybindings": [
|
||||||
|
{"key": "a", "sref": "item.index"}
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -240,5 +240,8 @@
|
||||||
{"state": "ticket.card.picture", "icon": "image"},
|
{"state": "ticket.card.picture", "icon": "image"},
|
||||||
{"state": "ticket.card.log", "icon": "history"},
|
{"state": "ticket.card.log", "icon": "history"},
|
||||||
{"state": "ticket.card.request.index", "icon": "icon-100"}
|
{"state": "ticket.card.request.index", "icon": "icon-100"}
|
||||||
|
],
|
||||||
|
"keybindings": [
|
||||||
|
{"key": "t", "sref": "ticket.index"}
|
||||||
]
|
]
|
||||||
}
|
}
|
Loading…
Reference in New Issue