updated tests
gitea/salix/1762-worker_dms This commit looks good
Details
gitea/salix/1762-worker_dms This commit looks good
Details
This commit is contained in:
parent
a077dd5165
commit
f9dba9489f
|
@ -1869,7 +1869,8 @@ INSERT INTO `vn`.`dms`(`id`, `dmsTypeFk`, `file`, `contentType`, `workerFk`, `wa
|
|||
VALUES
|
||||
(1, 14, '1.txt', 'text/plain', 5, 1, 442, NULL, FALSE, 'Ticket:11', 'Ticket:11 dms for the ticket', CURDATE()),
|
||||
(2, 5, '2.txt', 'text/plain', 5, 1, 442, 1, TRUE, 'Client:104', 'Client:104 dms for the client', CURDATE()),
|
||||
(3, 5, '3.txt', 'text/plain', 5, 1, 442, NULL, TRUE, 'Client: 104', 'Client:104 readme', CURDATE());
|
||||
(3, 5, '3.txt', 'text/plain', 5, 1, 442, NULL, TRUE, 'Client: 104', 'Client:104 readme', CURDATE()),
|
||||
(4, 3, '3.txt', 'text/plain', 5, 1, 442, NULL, TRUE, 'Worker: 106', 'Worker:106 readme', CURDATE());
|
||||
|
||||
INSERT INTO `vn`.`ticketDms`(`ticketFk`, `dmsFk`)
|
||||
VALUES
|
||||
|
@ -1880,10 +1881,9 @@ INSERT INTO `vn`.`clientDms`(`clientFk`, `dmsFk`)
|
|||
(104, 2),
|
||||
(104, 3);
|
||||
|
||||
INSERT INTO `vn`.`workerDocument`(`worker`, `document`)
|
||||
INSERT INTO `vn`.`workerDocument`(`id`, `worker`, `document`)
|
||||
VALUES
|
||||
(104, 2),
|
||||
(104, 3);
|
||||
(1, 106, 4);
|
||||
|
||||
INSERT INTO `vn`.`device` (`sn`, `model`, `userFk`)
|
||||
VALUES
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
|
||||
fdescribe('WorkerDms removeFile()', () => {
|
||||
describe('WorkerDms removeFile()', () => {
|
||||
const workerDmsFk = 1;
|
||||
it(`should return an error for a user without enough privileges`, async() => {
|
||||
let clientId = 101;
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
|
||||
describe('Worker uploadFile()', () => {
|
||||
it(`should return an error for a user without enough privileges`, async() => {
|
||||
let workerId = 106;
|
||||
let currentUserId = 102;
|
||||
let hhrrDataId = 3;
|
||||
let ctx = {req: {accessToken: {userId: currentUserId}}, args: {dmsTypeId: hhrrDataId}};
|
||||
|
||||
let error;
|
||||
await app.models.Worker.uploadFile(ctx, workerId).catch(e => {
|
||||
error = e;
|
||||
}).finally(() => {
|
||||
expect(error.message).toEqual(`You don't have enough privileges`);
|
||||
});
|
||||
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
});
|
|
@ -12,9 +12,12 @@
|
|||
}
|
||||
},
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "Number",
|
||||
"id": true
|
||||
},
|
||||
"dmsFk": {
|
||||
"type": "Number",
|
||||
"id": true,
|
||||
"required": true,
|
||||
"mysql": {
|
||||
"columnName": "document"
|
||||
|
|
|
@ -1,45 +1,46 @@
|
|||
import './index';
|
||||
|
||||
describe('Client', () => {
|
||||
describe('Worker', () => {
|
||||
describe('Component vnClientDmsEdit', () => {
|
||||
let controller;
|
||||
let $scope;
|
||||
let $element;
|
||||
let $httpBackend;
|
||||
let $state;
|
||||
|
||||
beforeEach(ngModule('client'));
|
||||
beforeEach(ngModule('worker'));
|
||||
|
||||
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => {
|
||||
$scope = $rootScope.$new();
|
||||
$httpBackend = _$httpBackend_;
|
||||
$state = {params: {dmsId: 1}};
|
||||
controller = $componentController('vnClientDmsEdit', {$scope, $state});
|
||||
controller._client = {id: 1};
|
||||
$element = angular.element(`<vn-worker-dms-edit></vn-worker-dms-edit`);
|
||||
controller = $componentController('vnWorkerDmsEdit', {$element, $scope});
|
||||
controller._worker = {id: 106};
|
||||
controller.$params = {dmsId: 4};
|
||||
}));
|
||||
|
||||
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 = undefined;
|
||||
controller.client = {
|
||||
id: 15
|
||||
controller._worker = undefined;
|
||||
controller.worker = {
|
||||
id: 106
|
||||
};
|
||||
|
||||
expect(controller.setDefaultParams).toHaveBeenCalledWith();
|
||||
expect(controller.client).toBeDefined();
|
||||
expect(controller.worker).toBeDefined();
|
||||
expect(controller.getAllowedContentTypes).toHaveBeenCalledWith();
|
||||
});
|
||||
});
|
||||
|
||||
describe('setDefaultParams()', () => {
|
||||
it('should perform a GET query and define the dms property on controller', () => {
|
||||
const dmsId = 1;
|
||||
const dmsId = 4;
|
||||
const expectedResponse = {
|
||||
reference: 101,
|
||||
warehouseFk: 1,
|
||||
companyFk: 442,
|
||||
dmsTypeFk: 12,
|
||||
dmsTypeFk: 3,
|
||||
description: 'Test',
|
||||
hasFile: false,
|
||||
hasFileAttached: false
|
||||
|
@ -52,7 +53,7 @@ describe('Client', () => {
|
|||
|
||||
expect(controller.dms).toBeDefined();
|
||||
expect(controller.dms.reference).toEqual(101);
|
||||
expect(controller.dms.dmsTypeId).toEqual(12);
|
||||
expect(controller.dms.dmsTypeId).toEqual(3);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -70,8 +71,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();
|
||||
|
||||
|
|
|
@ -1,34 +1,36 @@
|
|||
import './index';
|
||||
import crudModel from 'core/mocks/crud-model';
|
||||
|
||||
describe('Client', () => {
|
||||
describe('Component vnClientDmsIndex', () => {
|
||||
describe('Worker', () => {
|
||||
describe('Component vnWorkerDmsIndex', () => {
|
||||
let $componentController;
|
||||
let $scope;
|
||||
let $element;
|
||||
let $httpBackend;
|
||||
let controller;
|
||||
|
||||
beforeEach(ngModule('client'));
|
||||
beforeEach(ngModule('worker'));
|
||||
|
||||
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$httpBackend_) => {
|
||||
$componentController = _$componentController_;
|
||||
$httpBackend = _$httpBackend_;
|
||||
$scope = $rootScope.$new();
|
||||
controller = $componentController('vnClientDmsIndex', {$: $scope});
|
||||
$element = angular.element(`<vn-worker-dms-index></vn-worker-dms-index`);
|
||||
controller = $componentController('vnWorkerDmsIndex', {$element, $scope});
|
||||
controller.$.model = crudModel;
|
||||
}));
|
||||
|
||||
describe('deleteDms()', () => {
|
||||
it('should make an HTTP Post query', () => {
|
||||
const dmsId = 1;
|
||||
const dmsId = 4;
|
||||
const dmsIndex = 0;
|
||||
spyOn(controller.vnApp, 'showSuccess');
|
||||
spyOn(controller.$.model, 'remove');
|
||||
controller.clientDms = [{dmsFk: 1}];
|
||||
controller.workerDms = [{dmsFk: 4}];
|
||||
controller.dmsIndex = dmsIndex;
|
||||
|
||||
$httpBackend.when('POST', `clientDms/${dmsId}/removeFile`).respond({});
|
||||
$httpBackend.expect('POST', `clientDms/${dmsId}/removeFile`);
|
||||
$httpBackend.when('POST', `WorkerDms/${dmsId}/removeFile`).respond({});
|
||||
$httpBackend.expect('POST', `WorkerDms/${dmsId}/removeFile`);
|
||||
controller.deleteDms('accept');
|
||||
$httpBackend.flush();
|
||||
|
||||
|
|
Loading…
Reference in New Issue