@into-cps-association/libms 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/config/http.json +1 -0
- package/dist/src/app.module.js +5 -6
- package/dist/src/app.module.js.map +1 -1
- package/dist/src/bootstrap.js +11 -21
- package/dist/src/bootstrap.js.map +1 -1
- package/dist/src/config/config.interface.d.ts +14 -0
- package/dist/src/config/config.interface.js +2 -0
- package/dist/src/config/config.interface.js.map +1 -0
- package/dist/src/config/config.model.d.ts +14 -0
- package/dist/src/config/config.model.js +2 -0
- package/dist/src/config/config.model.js.map +1 -0
- package/dist/src/config/config.module.d.ts +2 -0
- package/dist/src/config/config.module.js +33 -0
- package/dist/src/config/config.module.js.map +1 -0
- package/dist/src/config/config.service.d.ts +17 -0
- package/dist/src/config/config.service.js +61 -0
- package/dist/src/config/config.service.js.map +1 -0
- package/dist/src/config/util.d.ts +1 -0
- package/dist/src/config/util.js +5 -0
- package/dist/src/config/util.js.map +1 -0
- package/dist/src/files/files-service.factory.d.ts +2 -2
- package/dist/src/files/files-service.factory.js +4 -1
- package/dist/src/files/files-service.factory.js.map +1 -1
- package/dist/src/files/files.module.js +2 -2
- package/dist/src/files/files.module.js.map +1 -1
- package/dist/src/files/git/git-files.service.d.ts +4 -2
- package/dist/src/files/git/git-files.service.js +31 -20
- package/dist/src/files/git/git-files.service.js.map +1 -1
- package/dist/src/files/interfaces/files.service.interface.d.ts +1 -0
- package/dist/src/files/local/local-files.service.d.ts +3 -2
- package/dist/src/files/local/local-files.service.js +12 -4
- package/dist/src/files/local/local-files.service.js.map +1 -1
- package/dist/src/main.d.ts +4 -1
- package/dist/test/cloudcmd/cloudcmd.spec.js +3 -3
- package/dist/test/cloudcmd/cloudcmd.spec.js.map +1 -1
- package/dist/test/e2e/app.e2e.spec.js +18 -12
- package/dist/test/e2e/app.e2e.spec.js.map +1 -1
- package/dist/test/integration/files.service.integration.spec.js +6 -6
- package/dist/test/integration/files.service.integration.spec.js.map +1 -1
- package/dist/test/testUtil.d.ts +7 -1
- package/dist/test/testUtil.js +20 -17
- package/dist/test/testUtil.js.map +1 -1
- package/dist/test/unit/files-service.factory.unit.spec.js +20 -8
- package/dist/test/unit/files-service.factory.unit.spec.js.map +1 -1
- package/dist/test/unit/files.resolver.unit.spec.js +1 -0
- package/dist/test/unit/files.resolver.unit.spec.js.map +1 -1
- package/dist/test/unit/git-files.service.unit.spec.js +6 -5
- package/dist/test/unit/git-files.service.unit.spec.js.map +1 -1
- package/dist/test/unit/local-files.service.unit.spec.js +36 -21
- package/dist/test/unit/local-files.service.unit.spec.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/eslint.config.js +5 -0
- package/libms.yaml.sample +12 -0
- package/package.json +9 -7
- package/src/app.module.ts +6 -7
- package/src/bootstrap.ts +14 -21
- package/src/config/config.interface.ts +14 -0
- package/src/config/config.model.ts +13 -0
- package/src/config/config.module.ts +23 -0
- package/src/config/config.service.ts +54 -0
- package/src/config/util.ts +5 -0
- package/src/files/files-service.factory.ts +5 -3
- package/src/files/files.module.ts +3 -3
- package/src/files/git/git-files.service.ts +28 -21
- package/src/files/interfaces/files.service.interface.ts +1 -0
- package/src/files/local/local-files.service.ts +13 -4
- package/src/main.ts +1 -1
- package/test/cloudcmd/cloudcmd.spec.ts +4 -4
- package/test/data/user2/tools/large_file.md +1 -0
- package/test/e2e/app.e2e.spec.ts +23 -13
- package/test/integration/files.service.integration.spec.ts +9 -10
- package/test/jest-e2e.json +3 -0
- package/test/libms.test.yaml +6 -0
- package/test/testUtil.ts +23 -19
- package/test/unit/files-service.factory.unit.spec.ts +22 -11
- package/test/unit/files.resolver.unit.spec.ts +1 -0
- package/test/unit/git-files.service.unit.spec.ts +6 -5
- package/test/unit/local-files.service.unit.spec.ts +41 -25
- package/test/update-config.js +25 -0
package/test/e2e/app.e2e.spec.ts
CHANGED
|
@@ -17,14 +17,11 @@ import {
|
|
|
17
17
|
expectedFileContentResponse,
|
|
18
18
|
expectedListDirectoryResponse,
|
|
19
19
|
} from '../testUtil';
|
|
20
|
+
import { CONFIG_SERVICE, IConfig } from 'src/config/config.interface';
|
|
21
|
+
import Config from 'src/config/config.service';
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
uri: `http://localhost:${process.env.PORT}${process.env.APOLLO_PATH}`,
|
|
24
|
-
fetch,
|
|
25
|
-
}),
|
|
26
|
-
cache: new InMemoryCache({ addTypename: false }),
|
|
27
|
-
});
|
|
23
|
+
let client;
|
|
24
|
+
let configService: IConfig;
|
|
28
25
|
|
|
29
26
|
describe('End to End test for the application', () => {
|
|
30
27
|
let app: INestApplication;
|
|
@@ -33,13 +30,24 @@ describe('End to End test for the application', () => {
|
|
|
33
30
|
const moduleFixture: TestingModule = await Test.createTestingModule({
|
|
34
31
|
imports: [AppModule],
|
|
35
32
|
}).compile();
|
|
33
|
+
configService = moduleFixture.get<Config>(CONFIG_SERVICE);
|
|
36
34
|
app = moduleFixture.createNestApplication();
|
|
35
|
+
client = new ApolloClient({
|
|
36
|
+
link: new HttpLink({
|
|
37
|
+
uri: `http://localhost:${configService.getPort()}${configService.getApolloPath()}`,
|
|
38
|
+
fetch,
|
|
39
|
+
}),
|
|
40
|
+
cache: new InMemoryCache({ addTypename: false }),
|
|
41
|
+
});
|
|
37
42
|
await app.init(); // Initialize the application
|
|
38
|
-
await app.listen(
|
|
43
|
+
await app.listen(configService.getPort());
|
|
39
44
|
|
|
40
|
-
//
|
|
41
|
-
|
|
42
|
-
|
|
45
|
+
// Check if the port is available
|
|
46
|
+
|
|
47
|
+
while (!app.getHttpServer().listening) {
|
|
48
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
49
|
+
}
|
|
50
|
+
}, 15000);
|
|
43
51
|
|
|
44
52
|
afterAll(async () => {
|
|
45
53
|
await app.close();
|
|
@@ -49,8 +57,10 @@ describe('End to End test for the application', () => {
|
|
|
49
57
|
query: string,
|
|
50
58
|
expectedResponse: unknown,
|
|
51
59
|
): Promise<void> {
|
|
52
|
-
const response = await request(
|
|
53
|
-
.
|
|
60
|
+
const response = await request(
|
|
61
|
+
`http://localhost:${configService.getPort()}`,
|
|
62
|
+
)
|
|
63
|
+
.post(configService.getApolloPath())
|
|
54
64
|
.send({ query });
|
|
55
65
|
expect(response.body).toEqual(expectedResponse);
|
|
56
66
|
}
|
|
@@ -1,43 +1,44 @@
|
|
|
1
1
|
import { describe, it, expect, jest } from '@jest/globals';
|
|
2
2
|
import { Test, TestingModule } from '@nestjs/testing';
|
|
3
|
-
import { ConfigService } from '@nestjs/config';
|
|
4
3
|
import FilesResolver from '../../src/files/files.resolver';
|
|
5
4
|
import LocalFilesService from '../../src/files/local/local-files.service';
|
|
6
5
|
import {
|
|
6
|
+
jestMockConfigService,
|
|
7
7
|
pathToTestDirectory,
|
|
8
8
|
pathToTestFileContent,
|
|
9
9
|
testDirectory,
|
|
10
10
|
testFileContent,
|
|
11
|
-
MockConfigService,
|
|
12
11
|
} from '../testUtil';
|
|
13
12
|
import GitFilesService from '../../src/files/git/git-files.service';
|
|
14
13
|
import { FILE_SERVICE } from '../../src/files/interfaces/files.service.interface';
|
|
15
14
|
import FilesServiceFactory from '../../src/files/files-service.factory';
|
|
15
|
+
import { CONFIG_SERVICE, IConfig } from 'src/config/config.interface';
|
|
16
16
|
|
|
17
17
|
describe('Integration tests for FilesResolver', () => {
|
|
18
18
|
let filesResolver: FilesResolver;
|
|
19
|
-
let mockConfigService:
|
|
19
|
+
let mockConfigService: IConfig;
|
|
20
20
|
|
|
21
21
|
beforeEach(async () => {
|
|
22
|
-
mockConfigService =
|
|
22
|
+
mockConfigService = jestMockConfigService();
|
|
23
|
+
|
|
23
24
|
const module: TestingModule = await Test.createTestingModule({
|
|
24
25
|
providers: [
|
|
25
26
|
FilesResolver,
|
|
26
27
|
{
|
|
27
28
|
provide: FILE_SERVICE,
|
|
28
29
|
useFactory: (
|
|
29
|
-
configService:
|
|
30
|
+
configService: IConfig,
|
|
30
31
|
localFilesService: LocalFilesService,
|
|
31
32
|
gitFilesService: GitFilesService,
|
|
32
33
|
) => {
|
|
33
34
|
const fileServices = [localFilesService, gitFilesService];
|
|
34
35
|
return FilesServiceFactory.create(configService, fileServices);
|
|
35
36
|
},
|
|
36
|
-
inject: [
|
|
37
|
+
inject: [CONFIG_SERVICE, LocalFilesService, GitFilesService],
|
|
37
38
|
},
|
|
38
39
|
LocalFilesService,
|
|
39
40
|
GitFilesService,
|
|
40
|
-
{ provide:
|
|
41
|
+
{ provide: CONFIG_SERVICE, useValue: mockConfigService },
|
|
41
42
|
],
|
|
42
43
|
}).compile();
|
|
43
44
|
|
|
@@ -50,12 +51,10 @@ describe('Integration tests for FilesResolver', () => {
|
|
|
50
51
|
|
|
51
52
|
const modes = ['local'];
|
|
52
53
|
|
|
53
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
54
54
|
for (const mode of modes) {
|
|
55
|
-
// eslint-disable-next-line no-loop-func
|
|
56
55
|
describe(`when MODE is ${mode}`, () => {
|
|
57
56
|
beforeEach(() => {
|
|
58
|
-
jest.spyOn(mockConfigService, '
|
|
57
|
+
jest.spyOn(mockConfigService, 'getMode').mockImplementation(() => mode);
|
|
59
58
|
});
|
|
60
59
|
|
|
61
60
|
it('should be defined', () => {
|
package/test/jest-e2e.json
CHANGED
package/test/testUtil.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { IConfig } from 'src/config/config.interface';
|
|
2
2
|
import { setTimeout } from 'timers/promises';
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import { jest } from '@jest/globals';
|
|
4
|
+
import { GitRepo } from 'src/config/config.model';
|
|
5
|
+
import { CONFIG_MODE } from 'src/enums/config-mode.enum';
|
|
5
6
|
|
|
6
7
|
// actual data for integration and e2e tests
|
|
7
8
|
export const readFileActualContent = ['content123'];
|
|
@@ -26,7 +27,10 @@ export const testDirectory = {
|
|
|
26
27
|
};
|
|
27
28
|
export const testFileName = 'README.md';
|
|
28
29
|
export const fstestFileContent = 'content123';
|
|
30
|
+
export const largeTestFileName = 'large_file.md';
|
|
31
|
+
export const largeFstestFileContent = 'a'.repeat(500 * 1000);
|
|
29
32
|
export const pathToTestFileContent = 'user2/tools/README.md';
|
|
33
|
+
export const pathToLargeTestFileContent = 'user2/tools/large_file.md';
|
|
30
34
|
export const testFileArray = [
|
|
31
35
|
'data',
|
|
32
36
|
'digital_twins',
|
|
@@ -54,26 +58,26 @@ export function sleep(ms) {
|
|
|
54
58
|
}
|
|
55
59
|
|
|
56
60
|
export class MockConfigService {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
case 'LOCAL_PATH':
|
|
61
|
-
return process.env.LOCAL_PATH;
|
|
62
|
-
case 'MODE':
|
|
63
|
-
if (process.env.MODE === 'local') {
|
|
64
|
-
return 'local';
|
|
65
|
-
}
|
|
66
|
-
if (process.env.MODE === 'git') {
|
|
67
|
-
return 'git';
|
|
68
|
-
}
|
|
69
|
-
return 'unknown';
|
|
61
|
+
getMode(): string {
|
|
62
|
+
return '';
|
|
63
|
+
}
|
|
70
64
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
65
|
+
getLocalPath(): string {
|
|
66
|
+
return 'test/data';
|
|
74
67
|
}
|
|
75
68
|
}
|
|
76
69
|
|
|
70
|
+
export const jestMockConfigService = (): IConfig => ({
|
|
71
|
+
getMode: jest.fn<() => string>().mockReturnValue(CONFIG_MODE.LOCAL),
|
|
72
|
+
getLocalPath: jest.fn<() => string>().mockReturnValue('test/data'),
|
|
73
|
+
getApolloPath: jest.fn<() => string>(),
|
|
74
|
+
getGitRepos: jest.fn<() => { [key: string]: GitRepo }[]>(),
|
|
75
|
+
getGraphqlPlayground: jest.fn<() => string>(),
|
|
76
|
+
getLogLevel: jest.fn<() => string>(),
|
|
77
|
+
getPort: jest.fn<() => number>(),
|
|
78
|
+
loadConfig: jest.fn<() => Promise<void>>(),
|
|
79
|
+
});
|
|
80
|
+
|
|
77
81
|
export const mockReadFileResponseData = {
|
|
78
82
|
project: {
|
|
79
83
|
__typename: 'Project',
|
|
@@ -1,51 +1,62 @@
|
|
|
1
1
|
// files-service.factory.spec.ts
|
|
2
2
|
import { describe, it, expect, jest } from '@jest/globals';
|
|
3
3
|
import { Test, TestingModule } from '@nestjs/testing';
|
|
4
|
-
import { ConfigService } from '@nestjs/config';
|
|
5
4
|
import FilesServiceFactory from '../../src/files/files-service.factory';
|
|
6
5
|
import LocalFilesService from '../../src/files/local/local-files.service';
|
|
7
6
|
import { IFilesService } from '../../src/files/interfaces/files.service.interface';
|
|
8
7
|
import GitFilesService from '../../src/files/git/git-files.service';
|
|
8
|
+
import { CONFIG_SERVICE, IConfig } from 'src/config/config.interface';
|
|
9
|
+
import { jestMockConfigService } from 'test/testUtil';
|
|
10
|
+
import { CONFIG_MODE } from 'src/enums/config-mode.enum';
|
|
9
11
|
|
|
10
12
|
describe('FilesServiceFactory', () => {
|
|
11
|
-
let configService:
|
|
13
|
+
let configService: IConfig;
|
|
12
14
|
let localFilesService: IFilesService;
|
|
13
15
|
let gitFilesService: IFilesService;
|
|
14
16
|
let fileServices: IFilesService[];
|
|
15
17
|
|
|
16
18
|
beforeEach(async () => {
|
|
19
|
+
configService = jestMockConfigService();
|
|
20
|
+
gitFilesService = {
|
|
21
|
+
getMode: jest.fn<() => CONFIG_MODE>().mockReturnValue(CONFIG_MODE.GIT),
|
|
22
|
+
init: jest.fn<() => Promise<void>>(),
|
|
23
|
+
} as unknown as IFilesService;
|
|
24
|
+
|
|
17
25
|
const module: TestingModule = await Test.createTestingModule({
|
|
18
26
|
providers: [
|
|
19
|
-
GitFilesService,
|
|
20
|
-
{
|
|
27
|
+
{ provide: GitFilesService, useValue: gitFilesService },
|
|
28
|
+
{
|
|
29
|
+
provide: CONFIG_SERVICE,
|
|
30
|
+
useValue: configService,
|
|
31
|
+
},
|
|
21
32
|
LocalFilesService,
|
|
22
33
|
],
|
|
23
34
|
}).compile();
|
|
24
35
|
|
|
25
|
-
configService = module.get<ConfigService>(ConfigService);
|
|
26
36
|
localFilesService = module.get<LocalFilesService>(LocalFilesService);
|
|
27
37
|
gitFilesService = module.get<GitFilesService>(GitFilesService);
|
|
28
38
|
fileServices = [gitFilesService, localFilesService];
|
|
29
39
|
});
|
|
30
40
|
|
|
31
41
|
it('should create a local files service when MODE is local', () => {
|
|
32
|
-
jest.spyOn(configService, '
|
|
42
|
+
jest.spyOn(configService, 'getMode').mockReturnValue('local');
|
|
33
43
|
expect(FilesServiceFactory.create(configService, fileServices)).toBe(
|
|
34
44
|
localFilesService,
|
|
35
45
|
);
|
|
36
46
|
});
|
|
37
47
|
|
|
38
48
|
it('should create a git files service when MODE is git', () => {
|
|
39
|
-
jest.spyOn(configService, '
|
|
49
|
+
jest.spyOn(configService, 'getMode').mockReturnValue(CONFIG_MODE.GIT);
|
|
40
50
|
expect(FilesServiceFactory.create(configService, fileServices)).toBe(
|
|
41
51
|
gitFilesService,
|
|
42
52
|
);
|
|
43
53
|
});
|
|
44
54
|
|
|
45
55
|
it('should throw an error when MODE is invalid', () => {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
56
|
+
const invalidMode = 'invalid';
|
|
57
|
+
jest.spyOn(configService, 'getMode').mockReturnValue(invalidMode);
|
|
58
|
+
expect(() => {
|
|
59
|
+
FilesServiceFactory.create(configService, fileServices);
|
|
60
|
+
}).toThrow(`Invalid MODE: ${invalidMode}`);
|
|
50
61
|
});
|
|
51
62
|
});
|
|
@@ -27,6 +27,7 @@ describe('Unit tests for FilesResolver', () => {
|
|
|
27
27
|
.fn<() => Promise<Project>>()
|
|
28
28
|
.mockImplementation(() => Promise.resolve(testFileContent)),
|
|
29
29
|
getMode: jest.fn<() => CONFIG_MODE>().mockReturnValue(CONFIG_MODE.LOCAL),
|
|
30
|
+
init: jest.fn<() => Promise<void>>(),
|
|
30
31
|
};
|
|
31
32
|
|
|
32
33
|
const module: TestingModule = await Test.createTestingModule({
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { describe, it, expect, jest } from '@jest/globals';
|
|
2
2
|
import { Test, TestingModule } from '@nestjs/testing';
|
|
3
|
-
import { ConfigService } from '@nestjs/config';
|
|
4
3
|
import LocalFileService from 'src/files/local/local-files.service';
|
|
5
4
|
import { Project } from 'src/types';
|
|
6
5
|
import {
|
|
7
|
-
|
|
6
|
+
jestMockConfigService,
|
|
8
7
|
testDirectory,
|
|
9
8
|
testFileContent,
|
|
10
9
|
} from 'test/testUtil';
|
|
11
10
|
import GitFilesService from 'src/files/git/git-files.service';
|
|
12
11
|
import { CONFIG_MODE } from 'src/enums/config-mode.enum';
|
|
13
12
|
import { IFilesService } from 'src/files/interfaces/files.service.interface';
|
|
13
|
+
import { CONFIG_SERVICE } from 'src/config/config.interface';
|
|
14
14
|
|
|
15
15
|
jest.mock('fs', () => ({
|
|
16
16
|
promises: {
|
|
@@ -22,7 +22,7 @@ jest.mock('fs', () => ({
|
|
|
22
22
|
|
|
23
23
|
describe('GitFilesService', () => {
|
|
24
24
|
let service: GitFilesService;
|
|
25
|
-
const mockConfigService =
|
|
25
|
+
const mockConfigService = jestMockConfigService();
|
|
26
26
|
const mockLocalFilesService: IFilesService = {
|
|
27
27
|
listDirectory: jest
|
|
28
28
|
.fn<() => Promise<Project>>()
|
|
@@ -31,13 +31,14 @@ describe('GitFilesService', () => {
|
|
|
31
31
|
.fn<() => Promise<Project>>()
|
|
32
32
|
.mockImplementation(() => Promise.resolve(testFileContent)),
|
|
33
33
|
getMode: jest.fn<() => CONFIG_MODE>().mockReturnValue(CONFIG_MODE.LOCAL),
|
|
34
|
+
init: jest.fn<() => Promise<void>>(),
|
|
34
35
|
};
|
|
35
36
|
|
|
36
37
|
beforeEach(async () => {
|
|
37
38
|
const module: TestingModule = await Test.createTestingModule({
|
|
38
39
|
providers: [
|
|
39
40
|
GitFilesService,
|
|
40
|
-
{ provide:
|
|
41
|
+
{ provide: CONFIG_SERVICE, useValue: mockConfigService },
|
|
41
42
|
{ provide: LocalFileService, useValue: mockLocalFilesService },
|
|
42
43
|
],
|
|
43
44
|
}).compile();
|
|
@@ -76,6 +77,6 @@ describe('GitFilesService', () => {
|
|
|
76
77
|
await service.readFile('/some/path/file.txt');
|
|
77
78
|
|
|
78
79
|
// Assert
|
|
79
|
-
expect(mockReadFile).
|
|
80
|
+
expect(mockReadFile).toHaveBeenCalledTimes(1);
|
|
80
81
|
});
|
|
81
82
|
});
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect, jest } from '@jest/globals';
|
|
2
2
|
import { Test, TestingModule } from '@nestjs/testing';
|
|
3
|
-
import { ConfigService } from '@nestjs/config';
|
|
4
3
|
import * as fs from 'fs';
|
|
5
4
|
import { join } from 'path';
|
|
6
5
|
import LocalFilesService from '../../src/files/local/local-files.service';
|
|
@@ -8,11 +7,15 @@ import {
|
|
|
8
7
|
fstestFileContent,
|
|
9
8
|
pathToTestDirectory,
|
|
10
9
|
pathToTestFileContent,
|
|
11
|
-
testFileArray,
|
|
12
|
-
MockConfigService,
|
|
13
10
|
testFileName,
|
|
11
|
+
pathToLargeTestFileContent,
|
|
12
|
+
largeFstestFileContent,
|
|
13
|
+
largeTestFileName,
|
|
14
|
+
jestMockConfigService,
|
|
15
|
+
testFileArray,
|
|
14
16
|
} from '../testUtil';
|
|
15
17
|
import { Dirent } from 'fs';
|
|
18
|
+
import { CONFIG_SERVICE } from 'src/config/config.interface';
|
|
16
19
|
|
|
17
20
|
jest.mock('fs', () => ({
|
|
18
21
|
promises: {
|
|
@@ -24,13 +27,14 @@ jest.mock('fs', () => ({
|
|
|
24
27
|
|
|
25
28
|
describe('LocalFilesService', () => {
|
|
26
29
|
let service: LocalFilesService;
|
|
27
|
-
|
|
30
|
+
let mockConfigService;
|
|
28
31
|
|
|
29
32
|
beforeEach(async () => {
|
|
33
|
+
mockConfigService = jestMockConfigService();
|
|
30
34
|
const module: TestingModule = await Test.createTestingModule({
|
|
31
35
|
providers: [
|
|
32
36
|
LocalFilesService,
|
|
33
|
-
{ provide:
|
|
37
|
+
{ provide: CONFIG_SERVICE, useValue: mockConfigService },
|
|
34
38
|
],
|
|
35
39
|
}).compile();
|
|
36
40
|
|
|
@@ -47,7 +51,7 @@ describe('LocalFilesService', () => {
|
|
|
47
51
|
|
|
48
52
|
it('should list directory', async () => {
|
|
49
53
|
const fullPath = join(
|
|
50
|
-
mockConfigService.
|
|
54
|
+
mockConfigService.getLocalPath(),
|
|
51
55
|
pathToTestDirectory,
|
|
52
56
|
);
|
|
53
57
|
|
|
@@ -83,28 +87,40 @@ describe('LocalFilesService', () => {
|
|
|
83
87
|
expect(fs.promises.lstat).toHaveBeenCalledTimes(testFileArray.length);
|
|
84
88
|
});
|
|
85
89
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
90
|
+
const readTestFile = [
|
|
91
|
+
{
|
|
92
|
+
name: largeTestFileName,
|
|
93
|
+
filePath: pathToLargeTestFileContent,
|
|
94
|
+
expectedContent: largeFstestFileContent,
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: testFileName,
|
|
98
|
+
filePath: pathToTestFileContent,
|
|
99
|
+
expectedContent: fstestFileContent,
|
|
100
|
+
},
|
|
101
|
+
];
|
|
91
102
|
|
|
92
|
-
|
|
103
|
+
readTestFile.forEach(({ name, filePath, expectedContent }) => {
|
|
104
|
+
it(`should read file ${name}`, async () => {
|
|
105
|
+
const fullPath = join(mockConfigService.getLocalPath(), filePath);
|
|
93
106
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
107
|
+
jest.spyOn(fs.promises, 'readFile').mockResolvedValue(expectedContent);
|
|
108
|
+
|
|
109
|
+
const result = await service.readFile(filePath);
|
|
110
|
+
expect(result).toEqual({
|
|
111
|
+
repository: {
|
|
112
|
+
blobs: {
|
|
113
|
+
nodes: [
|
|
114
|
+
{
|
|
115
|
+
name: name,
|
|
116
|
+
rawBlob: expectedContent,
|
|
117
|
+
rawTextBlob: expectedContent,
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
},
|
|
105
121
|
},
|
|
106
|
-
}
|
|
122
|
+
});
|
|
123
|
+
expect(fs.promises.readFile).toHaveBeenCalledWith(fullPath, 'utf8');
|
|
107
124
|
});
|
|
108
|
-
expect(fs.promises.readFile).toHaveBeenCalledWith(fullPath, 'utf8');
|
|
109
125
|
});
|
|
110
126
|
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as yaml from 'js-yaml';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
|
|
5
|
+
// Load environment variables
|
|
6
|
+
const env = process.env;
|
|
7
|
+
|
|
8
|
+
const yamlFilePath = path.join(process.env.LIBMS_CONFIG_PATH || 'test/libms.test.yaml');
|
|
9
|
+
const fileContents = fs.readFileSync(yamlFilePath, 'utf8');
|
|
10
|
+
const config = yaml.load(fileContents);
|
|
11
|
+
|
|
12
|
+
if (env.LIBMS_LOCAL_PATH) {
|
|
13
|
+
console.log('Updating local-path to '+ env.LIBMS_LOCAL_PATH);
|
|
14
|
+
config['local-path'] = env.LIBMS_LOCAL_PATH;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (env.LIBMS_PORT) {
|
|
18
|
+
console.log('Updating PORT to '+ env.LIBMS_PORT);
|
|
19
|
+
config['port'] = env.LIBMS_PORT;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const updatedYaml = yaml.dump(config);
|
|
23
|
+
fs.writeFileSync(yamlFilePath, updatedYaml, 'utf8');
|
|
24
|
+
|
|
25
|
+
console.log( yamlFilePath + ' updated successfully.');
|