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