1762-worker_dms #31

Manually merged
bernat merged 4 commits from 1762-worker_dms into dev 2019-11-25 08:33:06 +00:00
3 changed files with 24 additions and 17 deletions
Showing only changes of commit a077dd5165 - Show all commits

View File

@ -1880,6 +1880,11 @@ INSERT INTO `vn`.`clientDms`(`clientFk`, `dmsFk`)
(104, 2),
(104, 3);
INSERT INTO `vn`.`workerDocument`(`worker`, `document`)
VALUES
(104, 2),
(104, 3);
INSERT INTO `vn`.`device` (`sn`, `model`, `userFk`)
VALUES
('aaa', 'android', '9');

View File

@ -1,13 +1,13 @@
const app = require('vn-loopback/server/server');
describe('ClientDms removeFile()', () => {
const clientDmsFk = 3;
fdescribe('WorkerDms removeFile()', () => {
const workerDmsFk = 1;
it(`should return an error for a user without enough privileges`, async() => {
let clientId = 101;
let ctx = {req: {accessToken: {userId: clientId}}};
let error;
await app.models.ClientDms.removeFile(ctx, clientDmsFk).catch(e => {
await app.models.WorkerDms.removeFile(ctx, workerDmsFk).catch(e => {
error = e;
}).finally(() => {
expect(error.message).toEqual(`You don't have enough privileges`);

View File

@ -1,32 +1,34 @@
import './index';
describe('Client', () => {
describe('Component vnClientDmsCreate', () => {
describe('Component vnWorkerDmsCreate', () => {
let $element;
let controller;
let $scope;
let $httpBackend;
let $httpParamSerializer;
beforeEach(ngModule('client'));
beforeEach(ngModule('worker'));
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => {
beforeEach(angular.mock.inject(($compile, $rootScope, _$httpBackend_, _$httpParamSerializer_) => {
$scope = $rootScope.$new();
$httpBackend = _$httpBackend_;
$httpParamSerializer = _$httpParamSerializer_;
controller = $componentController('vnClientDmsCreate', {$scope});
controller._client = {id: 101, name: 'Bruce wayne'};
$element = $compile(`<vn-worker-dms-create></vn-worker-dms-create>`)($rootScope);
controller = $element.controller('vnWorkerDmsCreate');
controller._worker = {id: 101, name: 'Bruce wayne'};
}));
describe('client() setter', () => {
it('should set the client data and then call setDefaultParams() and getAllowedContentTypes()', () => {
describe('worker() setter', () => {
it('should set the worker data and then call setDefaultParams() and getAllowedContentTypes()', () => {
spyOn(controller, 'setDefaultParams');
spyOn(controller, 'getAllowedContentTypes');
controller.client = {
controller.worker = {
id: 15,
name: 'Bruce wayne'
};
expect(controller.client).toBeDefined();
expect(controller.worker).toBeDefined();
expect(controller.setDefaultParams).toHaveBeenCalledWith();
expect(controller.getAllowedContentTypes).toHaveBeenCalledWith();
});
@ -34,12 +36,12 @@ describe('Client', () => {
describe('setDefaultParams()', () => {
it('should perform a GET query and define the dms property on controller', () => {
$httpBackend.whenRoute('GET', `DmsTypes`).respond({id: 12, code: 'hhrrData'});
const params = {filter: {
where: {code: 'paymentsLaw'}
where: {code: 'hhrrData'}
}};
let serializedParams = $httpParamSerializer(params);
$httpBackend.when('GET', `DmsTypes/findOne?${serializedParams}`).respond({id: 12, code: 'paymentsLaw'});
$httpBackend.expect('GET', `DmsTypes/findOne?${serializedParams}`);
$httpBackend.when('GET', `DmsTypes/findOne?${serializedParams}`).respond({id: 12, code: 'hhrrData'});
controller.setDefaultParams();
$httpBackend.flush();
@ -62,8 +64,8 @@ describe('Client', () => {
describe('getAllowedContentTypes()', () => {
it('should make an HTTP GET request to get the allowed content types', () => {
const expectedResponse = ['image/png', 'image/jpg'];
$httpBackend.when('GET', `clientDms/allowedContentTypes`).respond(expectedResponse);
$httpBackend.expect('GET', `clientDms/allowedContentTypes`);
$httpBackend.when('GET', `workerDms/allowedContentTypes`).respond(expectedResponse);
$httpBackend.expect('GET', `workerDms/allowedContentTypes`);
controller.getAllowedContentTypes();
$httpBackend.flush();