feat(vnApp): getUrl and create salix.url. test(boxing): getVideoList
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Alex Moreno 2022-09-26 14:49:11 +02:00
parent f698a22fcf
commit 2c691eb796
8 changed files with 133 additions and 25 deletions

View File

@ -101,6 +101,9 @@
"Town": { "Town": {
"dataSource": "vn" "dataSource": "vn"
}, },
"Url": {
"dataSource": "vn"
},
"UserConfig": { "UserConfig": {
"dataSource": "vn" "dataSource": "vn"
}, },

25
back/models/url.json Normal file
View File

@ -0,0 +1,25 @@
{
"name": "Url",
"base": "VnModel",
"options": {
"mysql": {
"table": "salix.url"
}
},
"properties": {
"appName": {
"type": "string",
"required": true,
"id": 1
},
"environment": {
"type": "string",
"required": true,
"id": 2
},
"url": {
"type": "string",
"required": true
}
}
}

View File

@ -11,7 +11,7 @@ INSERT INTO `vn`.`packingSiteConfig` SET
shinobiUrl = 'https://shinobi.verdnatura.es', shinobiUrl = 'https://shinobi.verdnatura.es',
shinobiToken = 'BW4o7FZyJ85she1hlRDe6QnwW3jwEP', shinobiToken = 'BW4o7FZyJ85she1hlRDe6QnwW3jwEP',
shinobiGroupKey = 'xVqft9LFXg', shinobiGroupKey = 'xVqft9LFXg',
avgBoxingTime = 30; avgBoxingTime = 6000;
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
VALUES VALUES

View File

@ -0,0 +1,33 @@
CREATE TABLE `salix`.`url` (
`appName` varchar(100) NOT NULL,
`environment` varchar(100) NOT NULL,
`url` varchar(255) NOT NULL,
PRIMARY KEY (`appName`,`environment`)
);
INSERT INTO `salix`.`url` (`appName`, `environment`, `url`)
VALUES
('salix', 'production', 'https://salix.verdnatura.es/#!/');
INSERT INTO `salix`.`url` (`appName`, `environment`, `url`)
VALUES
('salix', 'test', 'https://test-salix.verdnatura.es/#!/');
INSERT INTO `salix`.`url` (`appName`, `environment`, `url`)
VALUES
('salix', 'dev', 'http://localhost:5000/#!/');
INSERT INTO `salix`.`url` (`appName`, `environment`, `url`)
VALUES
('lilium', 'production', 'https://lilium.verdnatura.es/#/');
INSERT INTO `salix`.`url` (`appName`, `environment`, `url`)
VALUES
('lilium', 'test', 'https://test-lilium.verdnatura.es/#/');
INSERT INTO `salix`.`url` (`appName`, `environment`, `url`)
VALUES
('lilium', 'dev', 'http://localhost:8080/#/');
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
VALUES
('Url', '*', 'READ', 'ALLOW', 'ROLE', 'employee');
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
VALUES
('Url', '*', 'WRITE', 'ALLOW', 'ROLE', 'it');

View File

@ -54,6 +54,23 @@ export default class App {
localStorage.setItem('salix-version', newVersion); localStorage.setItem('salix-version', newVersion);
} }
} }
getUrl(route, appName) {
if (!appName) appName = 'lilium';
const env = process.env.NODE_ENV;
const filter = {
where: {and: [
{appName: appName},
{environment: env}
]}
};
return this.logger.$http.get('Urls/findOne', {filter})
.then(res => {
return res.data.url + route;
});
}
} }
ngModule.service('vnApp', App); ngModule.service('vnApp', App);

View File

@ -0,0 +1,40 @@
const models = require('vn-loopback/server/server').models;
const https = require('https');
xdescribe('boxing getVideo()', () => {
it('should return data', async() => {
const tx = await models.PackingSiteConfig.beginTransaction({});
try {
const options = {transaction: tx};
const id = 1;
const video = 'video.mp4';
const response = {
pipe: () => {},
on: () => {},
end: () => {},
};
const req = {
headers: 'apiHeader',
data: {
pipe: () => {},
on: () => {},
}
};
spyOn(https, 'request').and.returnValue(response);
const result = await models.Boxing.getVideo(id, video, req, null, options);
expect(result[0]).toEqual(response.data.videos[0].filename);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});

View File

@ -2,29 +2,30 @@ const models = require('vn-loopback/server/server').models;
const axios = require('axios'); const axios = require('axios');
describe('boxing getVideoList()', () => { describe('boxing getVideoList()', () => {
it('should return data', async() => { it('should return video list', async() => {
const tx = await models.PackingSiteConfig.beginTransaction({}); const tx = await models.PackingSiteConfig.beginTransaction({});
try { try {
const options = {transaction: tx}; const options = {transaction: tx};
const params = { const id = 1;
id: 1, const from = 1;
from: 1, const to = 2;
to: 2
};
const response = { const response = {
data: { data: {
pipe: () => {}, videos: [{
on: () => {}, id: 1,
filename: 'video1.mp4'
}]
} }
}; };
spyOn(axios, 'get').and.returnValue(new Promise(resolve => resolve(response))); spyOn(axios, 'get').and.returnValue(new Promise(resolve => resolve(response)));
const result = await models.Sale.canEdit(params, options); const result = await models.Boxing.getVideoList(id, from, to, options);
expect(result).toEqual([]); expect(result[0]).toEqual(response.data.videos[0].filename);
await tx.rollback(); await tx.rollback();
} catch (e) { } catch (e) {

View File

@ -6,20 +6,9 @@ class Controller extends Section {
super($element, $); super($element, $);
} }
$onInit() { async $onInit() {
window.location.href = this.lilium(`ticket/${this.ticket.id}/boxing`); const url = await this.vnApp.getUrl(`ticket/${this.$params.id}/boxing`);
} window.open(url).focus();
lilium(route) {
const env = process.env.NODE_ENV;
let newRoute = 'http://localhost:8080/#/' + route;
if (env == 'test')
newRoute = 'https://test-lilium.verdnatura.es/#/' + route;
if (env == 'producction')
newRoute = 'https://lilium.verdnatura.es/#/' + route;
return newRoute;
} }
} }