2020-01-07 23:48:54 +02:00
|
|
|
import {Config} from '../../../../src/common/config/private/Config';
|
|
|
|
import {Server} from '../../../../src/backend/server';
|
|
|
|
import * as path from 'path';
|
2021-01-04 11:32:19 +02:00
|
|
|
import * as fs from 'fs';
|
2020-01-07 23:48:54 +02:00
|
|
|
import {expect} from 'chai';
|
|
|
|
import {SuperAgentStatic} from 'superagent';
|
|
|
|
import {ProjectPath} from '../../../../src/backend/ProjectPath';
|
2021-04-01 21:48:38 +02:00
|
|
|
import {DBTestHelper} from '../../DBTestHelper';
|
2021-04-18 15:48:35 +02:00
|
|
|
import {ReIndexingSensitivity} from '../../../../src/common/config/private/PrivateConfig';
|
2020-01-07 23:48:54 +02:00
|
|
|
|
|
|
|
|
|
|
|
process.env.NODE_ENV = 'test';
|
|
|
|
const chai: any = require('chai');
|
|
|
|
const chaiHttp = require('chai-http');
|
|
|
|
const should = chai.should();
|
|
|
|
chai.use(chaiHttp);
|
|
|
|
|
2021-04-01 21:48:38 +02:00
|
|
|
// to help WebStorm to handle the test cases
|
|
|
|
declare let describe: any;
|
|
|
|
declare const after: any;
|
|
|
|
declare const it: any;
|
|
|
|
const tmpDescribe = describe;
|
|
|
|
describe = DBTestHelper.describe({memory: true});
|
|
|
|
|
|
|
|
describe('GalleryRouter', (sqlHelper: DBTestHelper) => {
|
|
|
|
describe = tmpDescribe;
|
2020-01-07 23:48:54 +02:00
|
|
|
|
|
|
|
const tempDir = path.join(__dirname, '../../tmp');
|
|
|
|
let server: Server;
|
|
|
|
const setUp = async () => {
|
2021-04-01 21:48:38 +02:00
|
|
|
await sqlHelper.initDB();
|
2022-01-15 12:32:46 +02:00
|
|
|
await fs.promises.rm(tempDir, {recursive: true, force: true});
|
2020-01-07 23:48:54 +02:00
|
|
|
Config.Client.authenticationRequired = false;
|
|
|
|
Config.Server.Threading.enabled = false;
|
|
|
|
Config.Client.Media.Video.enabled = true;
|
2021-04-01 21:48:38 +02:00
|
|
|
Config.Server.Media.folder = path.join(__dirname, '../../assets');
|
|
|
|
Config.Server.Media.tempFolder = path.join(__dirname, '../../tmp');
|
2020-12-30 23:22:40 +02:00
|
|
|
ProjectPath.reset();
|
2021-04-01 21:48:38 +02:00
|
|
|
// ProjectPath.ImageFolder = path.join(__dirname, '../../assets');
|
|
|
|
// ProjectPath.TempFolder = tempDir;
|
2020-01-07 23:48:54 +02:00
|
|
|
|
|
|
|
server = new Server();
|
|
|
|
await server.onStarted.wait();
|
|
|
|
|
|
|
|
};
|
|
|
|
const tearDown = async () => {
|
2021-04-01 21:48:38 +02:00
|
|
|
await sqlHelper.clearDB();
|
2020-01-07 23:48:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-04-01 21:48:38 +02:00
|
|
|
describe('/GET /api/gallery/content/', async () => {
|
|
|
|
|
|
|
|
beforeEach(setUp);
|
|
|
|
afterEach(tearDown);
|
|
|
|
|
|
|
|
it('should load gallery', async () => {
|
|
|
|
const result = await (chai.request(server.App) as SuperAgentStatic)
|
2022-12-10 01:04:08 +02:00
|
|
|
.get(Config.Client.apiPath + '/gallery/content/');
|
2021-04-01 21:48:38 +02:00
|
|
|
|
|
|
|
(result.should as any).have.status(200);
|
|
|
|
expect(result.body.error).to.be.equal(null);
|
|
|
|
expect(result.body.result).to.not.be.equal(null);
|
|
|
|
expect(result.body.result.directory).to.not.be.equal(null);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should load gallery twice (to force loading form db)', async () => {
|
|
|
|
Config.Server.Indexing.reIndexingSensitivity = ReIndexingSensitivity.low;
|
|
|
|
const _ = await (chai.request(server.App) as SuperAgentStatic)
|
2022-12-10 01:04:08 +02:00
|
|
|
.get(Config.Client.apiPath + '/gallery/content/orientation');
|
2021-04-01 21:48:38 +02:00
|
|
|
|
|
|
|
const result = await (chai.request(server.App) as SuperAgentStatic)
|
2022-12-10 01:04:08 +02:00
|
|
|
.get(Config.Client.apiPath + '/gallery/content/orientation');
|
2021-04-01 21:48:38 +02:00
|
|
|
|
|
|
|
(result.should as any).have.status(200);
|
|
|
|
expect(result.body.error).to.be.equal(null);
|
|
|
|
expect(result.body.result).to.not.be.equal(null);
|
|
|
|
expect(result.body.result.directory).to.not.be.equal(null);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('/GET /api/gallery/content/video.mp4/bestFit', async () => {
|
2020-01-07 23:48:54 +02:00
|
|
|
|
|
|
|
beforeEach(setUp);
|
|
|
|
afterEach(tearDown);
|
|
|
|
|
|
|
|
it('should get video without transcoding', async () => {
|
|
|
|
const result = await (chai.request(server.App) as SuperAgentStatic)
|
2022-12-10 01:04:08 +02:00
|
|
|
.get(Config.Client.apiPath + '/gallery/content/video.mp4/bestFit');
|
2020-01-07 23:48:54 +02:00
|
|
|
|
|
|
|
(result.should as any).have.status(200);
|
|
|
|
expect(result.body).to.be.instanceof(Buffer);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
});
|