1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2025-11-27 22:38:10 +02:00
Files
pigallery2/test/backend/integration/routers/GalleryRouter.spec.ts
2025-10-28 19:46:36 +01:00

146 lines
4.8 KiB
TypeScript

import {Config} from '../../../../src/common/config/private/Config';
import {Server} from '../../../../src/backend/server';
import * as path from 'path';
import * as chai from 'chai';
import {expect} from 'chai';
import {SuperAgentStatic} from 'superagent';
import {ProjectPath} from '../../../../src/backend/ProjectPath';
import {DBTestHelper} from '../../DBTestHelper';
import {ReIndexingSensitivity} from '../../../../src/common/config/private/PrivateConfig';
import {TestHelper} from '../../../TestHelper';
import {default as chaiHttp, request} from 'chai-http';
import {ErrorCodes} from '../../../../src/common/entities/Error';
process.env.NODE_ENV = 'test';
chai.should();
chai.use(chaiHttp);
// to help WebStorm to handle the test cases
declare let describe: any;
declare const after: any;
declare const it: any;
declare global {
export interface Object {
should: Chai.Assertion;
}
}
const tmpDescribe = describe;
describe = DBTestHelper.describe({sqlite: true});
describe('GalleryRouter', (sqlHelper: DBTestHelper) => {
describe = tmpDescribe;
let server: Server;
const setUp = async () => {
await sqlHelper.initDB();
Config.Users.authenticationRequired = false;
Config.Media.Video.enabled = true;
Config.Media.folder = path.join(__dirname, '../../assets');
Config.Media.tempFolder = TestHelper.TMP_DIR;
ProjectPath.reset();
server = new Server(false);
await server.onStarted.wait();
};
const tearDown = async () => {
await sqlHelper.clearDB();
};
describe('/GET /api/gallery/content/', async () => {
beforeEach(setUp);
afterEach(tearDown);
it('should load gallery', async () => {
const result = await (request.execute(server.Server) as SuperAgentStatic)
.get(Config.Server.apiPath + '/gallery/content/');
(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.Indexing.reIndexingSensitivity = ReIndexingSensitivity.low;
const _ = await (request.execute(server.Server) as SuperAgentStatic)
.get(Config.Server.apiPath + '/gallery/content/orientation');
const result = await (request.execute(server.Server) as SuperAgentStatic)
.get(Config.Server.apiPath + '/gallery/content/orientation');
(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('express uri parsing', async () => {
beforeEach(setUp);
afterEach(tearDown);
it('express should parse path orientation/JPEG', async () => {
Config.Indexing.reIndexingSensitivity = ReIndexingSensitivity.low;
const result = await (request.execute(server.Server) as SuperAgentStatic)
.get(Config.Server.apiPath + '/gallery/content/orientation/JPEG');
(result.should as any).have.status(200);
expect(result.body.error).to.not.be.equal(null);
expect(result.body.result).to.be.equal(null);
expect(result.body.error.code).to.be.equal(ErrorCodes.PATH_ERROR);
});
it('express should parse path orientation encoded', async () => {
Config.Indexing.reIndexingSensitivity = ReIndexingSensitivity.low;
const result = await (request.execute(server.Server) as SuperAgentStatic)
.get(Config.Server.apiPath + '/gallery/content/' + encodeURIComponent('orientation'));
(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('express should parse path orientation/JPEG encoded', async () => {
Config.Indexing.reIndexingSensitivity = ReIndexingSensitivity.low;
const result = await (request.execute(server.Server) as SuperAgentStatic)
.get(Config.Server.apiPath + '/gallery/content/' + encodeURIComponent('orientation/JPEG'));
(result.should as any).have.status(200);
expect(result.body.error).to.not.be.equal(null);
expect(result.body.result).to.be.equal(null);
expect(result.body.error.code).to.be.equal(ErrorCodes.PATH_ERROR);
});
});
describe('/GET /api/gallery/content/video.mp4/bestFit', async () => {
beforeEach(setUp);
afterEach(tearDown);
it('should get video without transcoding', async () => {
const result = await (request.execute(server.Server) as SuperAgentStatic)
.get(Config.Server.apiPath + '/gallery/content/video.mp4/bestFit');
(result.should as any).have.status(200);
expect(result.body).to.be.instanceof(Buffer);
});
});
});