70 lines
2.1 KiB
TypeScript
70 lines
2.1 KiB
TypeScript
import { Test, TestingModule } from '@nestjs/testing';
|
|
import { getRepositoryToken } from '@nestjs/typeorm';
|
|
import { Project } from '../projects/project.entity';
|
|
import { ReposService } from './repos.service';
|
|
import { ConfigService, ConfigModule } from '@nestjs/config';
|
|
import { rm } from 'fs/promises';
|
|
import { join } from 'path';
|
|
import configuration from '../commons/config/configuration';
|
|
|
|
describe('ReposService', () => {
|
|
let service: ReposService;
|
|
const repositoryMockFactory = jest.fn(() => ({
|
|
findOneOrFail: jest.fn(
|
|
(entity): Project => ({
|
|
id: '1',
|
|
// sshUrl: 'ssh://gitea@git.ivanli.cc:7018/ivan/test1.git',
|
|
sshUrl: 'ssh://gitea@git.ivanli.cc:7018/Fennec/fennec-fe.git',
|
|
name: 'test1',
|
|
...entity,
|
|
}),
|
|
),
|
|
}));
|
|
let workspacesRoot: string;
|
|
afterEach(async () => {
|
|
await rm(join(workspacesRoot, 'test1'), {
|
|
recursive: true,
|
|
}).catch(() => undefined);
|
|
});
|
|
beforeEach(async () => {
|
|
const module: TestingModule = await Test.createTestingModule({
|
|
imports: [
|
|
ConfigModule.forRoot({
|
|
load: [configuration],
|
|
}),
|
|
],
|
|
providers: [
|
|
ReposService,
|
|
{
|
|
provide: getRepositoryToken(Project),
|
|
useFactory: repositoryMockFactory,
|
|
},
|
|
],
|
|
}).compile();
|
|
|
|
service = module.get<ReposService>(ReposService);
|
|
const configServer = module.get<ConfigService>(ConfigService);
|
|
workspacesRoot = configServer.get<string>('workspaces.root');
|
|
|
|
await rm(join(workspacesRoot, 'test1'), {
|
|
recursive: true,
|
|
}).catch(() => undefined);
|
|
});
|
|
|
|
it('should be defined', () => {
|
|
expect(service).toBeDefined();
|
|
});
|
|
describe('listLogs', () => {
|
|
it('should be return logs', async () => {
|
|
const result = await service.listLogs({ projectId: '1' });
|
|
expect(result).toBeDefined();
|
|
}, 20_000);
|
|
});
|
|
describe('listBranch', () => {
|
|
it('should be return branches', async () => {
|
|
const result = await service.listBranches({ projectId: '1' });
|
|
expect(result).toBeDefined();
|
|
}, 10_000);
|
|
});
|
|
});
|