1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00

fixing backend unit tests, refactoring test assets location

This commit is contained in:
Patrik J. Braun 2020-01-07 22:28:59 +01:00
parent 5b4f06e789
commit bf95454db5
12 changed files with 24 additions and 19 deletions

View File

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 38 KiB

View File

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -50,7 +50,10 @@ describe('Authentication middleware', () => {
expect(err.code).to.be.eql(ErrorCodes.NOT_AUTHENTICATED);
done();
};
AuthenticationMWs.authenticate(req, null, next);
AuthenticationMWs.authenticate(req, <any>{
status: () => {
}
}, next);
});
});
@ -59,7 +62,9 @@ describe('Authentication middleware', () => {
describe('authorisePath', () => {
const req = {
user: {permissions: <string[]>null},
session: {
user: {permissions: <string[]>null}
},
sessionOptions: {},
query: {},
params: {
@ -80,14 +85,14 @@ describe('Authentication middleware', () => {
};
it('should catch unauthorized path usage', async () => {
req.user.permissions = [path.normalize('/sub/subsub')];
req.session.user.permissions = [path.normalize('/sub/subsub')];
expect(await test('/sub/subsub')).to.be.eql('ok');
expect(await test('/test')).to.be.eql(403);
expect(await test('/')).to.be.eql(403);
expect(await test('/sub/test')).to.be.eql(403);
expect(await test('/sub/subsub/test')).to.be.eql(403);
expect(await test('/sub/subsub/test/test2')).to.be.eql(403);
req.user.permissions = [path.normalize('/sub/subsub'), path.normalize('/sub/subsub2')];
req.session.user.permissions = [path.normalize('/sub/subsub'), path.normalize('/sub/subsub2')];
expect(await test('/sub/subsub2')).to.be.eql('ok');
expect(await test('/sub/subsub')).to.be.eql('ok');
expect(await test('/test')).to.be.eql(403);
@ -95,7 +100,7 @@ describe('Authentication middleware', () => {
expect(await test('/sub/test')).to.be.eql(403);
expect(await test('/sub/subsub/test')).to.be.eql(403);
expect(await test('/sub/subsub2/test')).to.be.eql(403);
req.user.permissions = [path.normalize('/sub/subsub*')];
req.session.user.permissions = [path.normalize('/sub/subsub*')];
expect(await test('/b')).to.be.eql(403);
expect(await test('/sub')).to.be.eql(403);
expect(await test('/sub/subsub2')).to.be.eql(403);
@ -272,7 +277,7 @@ describe('Authentication middleware', () => {
};
const next = (err: ErrorDTO) => {
expect(err).to.be.undefined;
expect(req.user).to.be.eql('test user');
expect(req.session.user).to.be.eql('test user');
done();
};
ObjectManagers.getInstance().UserManager = <IUserManager>{

View File

@ -12,7 +12,7 @@ describe('PhotoProcessing', () => {
Config.load();
Config.Client.Media.Thumbnail.thumbnailSizes = [];
ProjectPath.ImageFolder = path.join(__dirname, './../../assets');
ProjectPath.ImageFolder = path.join(__dirname, './../../../assets');
const photoPath = path.join(ProjectPath.ImageFolder, 'test_png.png');
expect(await PhotoProcessing
@ -39,7 +39,7 @@ describe('PhotoProcessing', () => {
Config.load();
Config.Server.Media.Photo.Converting.resolution = <any>null;
Config.Client.Media.Thumbnail.thumbnailSizes = [10, 20];
ProjectPath.ImageFolder = path.join(__dirname, './../../assets');
ProjectPath.ImageFolder = path.join(__dirname, './../../../assets');
const photoPath = path.join(ProjectPath.ImageFolder, 'test_png.png');
for (let i = 0; i < Config.Client.Media.Thumbnail.thumbnailSizes.length; ++i) {

View File

@ -10,7 +10,7 @@ describe('VideoProcessing', () => {
// tslint:disable:no-unused-expression
it('should generate converted file path', async () => {
ProjectPath.ImageFolder = path.join(__dirname, './../../assets');
ProjectPath.ImageFolder = path.join(__dirname, './../../../assets');
const videoPath = path.join(ProjectPath.ImageFolder, 'video.mp4');
expect(await VideoProcessing
.isValidConvertedPath(VideoProcessing.generateConvertedFilePath(videoPath)))

View File

@ -8,11 +8,11 @@ import {Utils} from '../../../../../src/common/Utils';
describe('DiskMangerWorker', () => {
it('should parse metadata', async () => {
Config.Server.Media.folder = path.join(__dirname, '/../../assets');
ProjectPath.ImageFolder = path.join(__dirname, '/../../assets');
Config.Server.Media.folder = path.join(__dirname, '/../../../assets');
ProjectPath.ImageFolder = path.join(__dirname, '/../../../assets');
const dir = await DiskMangerWorker.scanDirectory('/');
expect(dir.media.length).to.be.equals(4);
const expected = require(path.join(__dirname, '/../../assets/test image öüóőúéáű-.,.json'));
const expected = require(path.join(__dirname, '/../../../assets/test image öüóőúéáű-.,.json'));
expect(Utils.clone(dir.media[1].name)).to.be.deep.equal('test image öüóőúéáű-.,.jpg');
expect(Utils.clone(dir.media[1].metadata)).to.be.deep.equal(expected);
});

View File

@ -6,7 +6,7 @@ import * as path from 'path';
describe('MetadataLoader', () => {
it('should load png', async () => {
const data = await MetadataLoader.loadPhotoMetadata(path.join(__dirname, '/../../assets/test_png.png'));
const data = await MetadataLoader.loadPhotoMetadata(path.join(__dirname, '/../../../assets/test_png.png'));
delete data.creationDate; // creation time for png not supported
expect(Utils.clone(data)).to.be.deep.equal(Utils.clone({
fileSize: 2155,
@ -19,22 +19,22 @@ describe('MetadataLoader', () => {
});
it('should load jpg', async () => {
const data = await MetadataLoader.loadPhotoMetadata(path.join(__dirname, '/../../assets/test image öüóőúéáű-.,.jpg'));
const expected = require(path.join(__dirname, '/../../assets/test image öüóőúéáű-.,.json'));
const data = await MetadataLoader.loadPhotoMetadata(path.join(__dirname, '/../../../assets/test image öüóőúéáű-.,.jpg'));
const expected = require(path.join(__dirname, '/../../../assets/test image öüóőúéáű-.,.json'));
expect(Utils.clone(data)).to.be.deep.equal(expected);
});
it('should load jpg 2', async () => {
const data = await MetadataLoader.loadPhotoMetadata(path.join(__dirname, '/../../assets/old_photo.jpg'));
const expected = require(path.join(__dirname, '/../../assets/old_photo.json'));
const data = await MetadataLoader.loadPhotoMetadata(path.join(__dirname, '/../../../assets/old_photo.jpg'));
const expected = require(path.join(__dirname, '/../../../assets/old_photo.json'));
expect(Utils.clone(data)).to.be.deep.equal(expected);
});
it('should load mp4', async () => {
const data = await MetadataLoader.loadVideoMetadata(path.join(__dirname, '/../../assets/video.mp4'));
const expected = require(path.join(__dirname, '/../../assets/video.json'));
const data = await MetadataLoader.loadVideoMetadata(path.join(__dirname, '/../../../assets/video.mp4'));
const expected = require(path.join(__dirname, '/../../../assets/video.json'));
expect(Utils.clone(data)).to.be.deep.equal(expected);
});