2023-12-27 02:50:43 -08:00
|
|
|
import { Container } from 'typedi';
|
2023-07-26 00:25:01 -07:00
|
|
|
import type { SuperAgentTest } from 'supertest';
|
2023-12-27 02:50:43 -08:00
|
|
|
|
2023-07-26 00:25:01 -07:00
|
|
|
import type { User } from '@db/entities/User';
|
2023-09-14 02:34:51 -07:00
|
|
|
import config from '@/config';
|
2023-07-26 00:25:01 -07:00
|
|
|
import { SourceControlPreferencesService } from '@/environments/sourceControl/sourceControlPreferences.service.ee';
|
|
|
|
import { SourceControlService } from '@/environments/sourceControl/sourceControl.service.ee';
|
|
|
|
import type { SourceControlledFile } from '@/environments/sourceControl/types/sourceControlledFile';
|
2023-12-27 02:50:43 -08:00
|
|
|
|
|
|
|
import * as utils from '../shared/utils/';
|
2023-11-08 07:29:39 -08:00
|
|
|
import { createUser } from '../shared/db/users';
|
2024-05-17 01:53:15 -07:00
|
|
|
import { mockInstance } from '../../shared/mocking';
|
|
|
|
import { WaitTracker } from '@/WaitTracker';
|
2023-07-26 00:25:01 -07:00
|
|
|
|
|
|
|
let authOwnerAgent: SuperAgentTest;
|
|
|
|
let owner: User;
|
|
|
|
|
2024-05-17 01:53:15 -07:00
|
|
|
// This is necessary for the tests to shutdown cleanly.
|
|
|
|
mockInstance(WaitTracker);
|
|
|
|
|
2023-07-26 00:25:01 -07:00
|
|
|
const testServer = utils.setupTestServer({
|
|
|
|
endpointGroups: ['sourceControl', 'license', 'auth'],
|
|
|
|
enabledFeatures: ['feat:sourceControl', 'feat:sharing'],
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
2024-01-24 04:38:57 -08:00
|
|
|
owner = await createUser({ role: 'global:owner' });
|
2023-07-26 00:25:01 -07:00
|
|
|
authOwnerAgent = testServer.authAgentFor(owner);
|
|
|
|
|
|
|
|
Container.get(SourceControlPreferencesService).isSourceControlConnected = () => true;
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('GET /sourceControl/preferences', () => {
|
|
|
|
test('should return Source Control preferences', async () => {
|
|
|
|
await authOwnerAgent
|
2023-12-27 02:50:43 -08:00
|
|
|
.get('/source-control/preferences')
|
2023-07-26 00:25:01 -07:00
|
|
|
.expect(200)
|
|
|
|
.expect((res) => {
|
|
|
|
return 'repositoryUrl' in res.body && 'branchName' in res.body;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should return repo sync status', async () => {
|
|
|
|
Container.get(SourceControlService).getStatus = async () => {
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
id: 'haQetoXq9GxHSkft',
|
|
|
|
name: 'My workflow 6 edit',
|
|
|
|
type: 'workflow',
|
|
|
|
status: 'modified',
|
|
|
|
location: 'local',
|
|
|
|
conflict: true,
|
|
|
|
file: '/Users/michael/.n8n/git/workflows/haQetoXq9GxHSkft.json',
|
|
|
|
updatedAt: '2023-07-14T11:24:41.000Z',
|
|
|
|
},
|
|
|
|
] as SourceControlledFile[];
|
|
|
|
};
|
|
|
|
await authOwnerAgent
|
2023-12-27 02:50:43 -08:00
|
|
|
.get('/source-control/get-status')
|
2023-07-26 00:25:01 -07:00
|
|
|
.query({ direction: 'push', preferLocalVersion: 'true', verbose: 'false' })
|
|
|
|
.expect(200)
|
|
|
|
.expect((res) => {
|
|
|
|
const data: SourceControlledFile[] = res.body.data;
|
|
|
|
expect(data.length).toBe(1);
|
|
|
|
expect(data[0].id).toBe('haQetoXq9GxHSkft');
|
|
|
|
});
|
|
|
|
});
|
2023-09-14 02:34:51 -07:00
|
|
|
|
|
|
|
test('refreshing key pairsshould return new rsa key', async () => {
|
|
|
|
config.set('sourceControl.defaultKeyPairType', 'rsa');
|
|
|
|
await authOwnerAgent
|
2023-12-27 02:50:43 -08:00
|
|
|
.post('/source-control/generate-key-pair')
|
2023-09-14 02:34:51 -07:00
|
|
|
.send()
|
|
|
|
.expect(200)
|
|
|
|
.expect((res) => {
|
|
|
|
expect(
|
|
|
|
Container.get(SourceControlPreferencesService).getPreferences().keyGeneratorType,
|
|
|
|
).toBe('rsa');
|
|
|
|
expect(res.body.data).toHaveProperty('publicKey');
|
|
|
|
expect(res.body.data).toHaveProperty('keyGeneratorType');
|
|
|
|
expect(res.body.data.keyGeneratorType).toBe('rsa');
|
|
|
|
expect(res.body.data.publicKey).toContain('ssh-rsa');
|
|
|
|
});
|
|
|
|
});
|
2023-07-26 00:25:01 -07:00
|
|
|
});
|