@into-cps-association/libms 0.3.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/.env +9 -0
- package/.eslintignore +6 -0
- package/.eslintrc +53 -0
- package/.madgerc +18 -0
- package/.prettierrc +4 -0
- package/API.md +211 -0
- package/DEVELOPER.md +60 -0
- package/LICENSE.md +301 -0
- package/README.md +119 -0
- package/dist/src/app.module.d.ts +2 -0
- package/dist/src/app.module.js +36 -0
- package/dist/src/app.module.js.map +1 -0
- package/dist/src/bootstrap.d.ts +6 -0
- package/dist/src/bootstrap.js +27 -0
- package/dist/src/bootstrap.js.map +1 -0
- package/dist/src/files/files.module.d.ts +2 -0
- package/dist/src/files/files.module.js +27 -0
- package/dist/src/files/files.module.js.map +1 -0
- package/dist/src/files/interfaces/files.service.interface.d.ts +5 -0
- package/dist/src/files/interfaces/files.service.interface.js +3 -0
- package/dist/src/files/interfaces/files.service.interface.js.map +1 -0
- package/dist/src/files/queries.d.ts +2 -0
- package/dist/src/files/queries.js +47 -0
- package/dist/src/files/queries.js.map +1 -0
- package/dist/src/files/resolvers/files.resolver.d.ts +8 -0
- package/dist/src/files/resolvers/files.resolver.js +49 -0
- package/dist/src/files/resolvers/files.resolver.js.map +1 -0
- package/dist/src/files/services/files-service.factory.d.ts +11 -0
- package/dist/src/files/services/files-service.factory.js +48 -0
- package/dist/src/files/services/files-service.factory.js.map +1 -0
- package/dist/src/files/services/gitlab-files.service.d.ts +12 -0
- package/dist/src/files/services/gitlab-files.service.js +65 -0
- package/dist/src/files/services/gitlab-files.service.js.map +1 -0
- package/dist/src/files/services/local-files.service.d.ts +11 -0
- package/dist/src/files/services/local-files.service.js +77 -0
- package/dist/src/files/services/local-files.service.js.map +1 -0
- package/dist/src/main.d.ts +2 -0
- package/dist/src/main.js +20 -0
- package/dist/src/main.js.map +1 -0
- package/dist/src/types.d.ts +43 -0
- package/dist/src/types.js +181 -0
- package/dist/src/types.js.map +1 -0
- package/dist/test/e2e/app.e2e.spec.d.ts +1 -0
- package/dist/test/e2e/app.e2e.spec.js +36 -0
- package/dist/test/e2e/app.e2e.spec.js.map +1 -0
- package/dist/test/integration/files.service.integration.spec.d.ts +1 -0
- package/dist/test/integration/files.service.integration.spec.js +53 -0
- package/dist/test/integration/files.service.integration.spec.js.map +1 -0
- package/dist/test/testUtil.d.ts +88 -0
- package/dist/test/testUtil.js +182 -0
- package/dist/test/testUtil.js.map +1 -0
- package/dist/test/unit/files-service.factory.unit.spec.d.ts +1 -0
- package/dist/test/unit/files-service.factory.unit.spec.js +40 -0
- package/dist/test/unit/files-service.factory.unit.spec.js.map +1 -0
- package/dist/test/unit/files.resolver.unit.spec.d.ts +1 -0
- package/dist/test/unit/files.resolver.unit.spec.js +56 -0
- package/dist/test/unit/files.resolver.unit.spec.js.map +1 -0
- package/dist/test/unit/gitlab-files.service.unit.spec.d.ts +1 -0
- package/dist/test/unit/gitlab-files.service.unit.spec.js +37 -0
- package/dist/test/unit/gitlab-files.service.unit.spec.js.map +1 -0
- package/dist/test/unit/local-files.service.unit.spec.d.ts +1 -0
- package/dist/test/unit/local-files.service.unit.spec.js +84 -0
- package/dist/test/unit/local-files.service.unit.spec.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/jest.config.json +30 -0
- package/nest-cli.json +8 -0
- package/package.json +71 -0
- package/src/app.module.ts +24 -0
- package/src/bootstrap.ts +29 -0
- package/src/files/files.module.ts +15 -0
- package/src/files/interfaces/files.service.interface.ts +7 -0
- package/src/files/queries.ts +42 -0
- package/src/files/resolvers/files.resolver.ts +23 -0
- package/src/files/services/files-service.factory.ts +27 -0
- package/src/files/services/gitlab-files.service.ts +65 -0
- package/src/files/services/local-files.service.ts +76 -0
- package/src/main.ts +27 -0
- package/src/schema.gql +58 -0
- package/src/types.ts +92 -0
- package/test/README.md +33 -0
- package/test/coverage/clover.xml +40 -0
- package/test/coverage/coverage-final.json +2 -0
- package/test/coverage/lcov-report/base.css +224 -0
- package/test/coverage/lcov-report/block-navigation.js +87 -0
- package/test/coverage/lcov-report/favicon.png +0 -0
- package/test/coverage/lcov-report/index.html +116 -0
- package/test/coverage/lcov-report/prettify.css +1 -0
- package/test/coverage/lcov-report/prettify.js +2 -0
- package/test/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/test/coverage/lcov-report/sorter.js +196 -0
- package/test/coverage/lcov-report/testUtil.ts.html +655 -0
- package/test/coverage/lcov.info +52 -0
- package/test/data/user2/data/.gitkeep +0 -0
- package/test/data/user2/digital_twins/.gitkeep +0 -0
- package/test/data/user2/functions/.gitkeep +0 -0
- package/test/data/user2/models/.gitkeep +0 -0
- package/test/data/user2/tools/.gitkeep +0 -0
- package/test/data/user2/tools/README.md +1 -0
- package/test/e2e/app.e2e.spec.ts +79 -0
- package/test/integration/files.service.integration.spec.ts +67 -0
- package/test/jest-e2e.json +9 -0
- package/test/starttraefik.bash +11 -0
- package/test/stoptraefik.bash +9 -0
- package/test/testUtil.ts +190 -0
- package/test/unit/files-service.factory.unit.spec.ts +46 -0
- package/test/unit/files.resolver.unit.spec.ts +70 -0
- package/test/unit/gitlab-files.service.unit.spec.ts +46 -0
- package/test/unit/local-files.service.unit.spec.ts +108 -0
- package/tsconfig.json +31 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { Test, TestingModule } from '@nestjs/testing';
|
|
2
|
+
import { ConfigService } from '@nestjs/config';
|
|
3
|
+
import * as fs from 'fs';
|
|
4
|
+
import { join } from 'path';
|
|
5
|
+
import LocalFilesService from '../../src/files/services/local-files.service';
|
|
6
|
+
import {
|
|
7
|
+
fstestFileContent,
|
|
8
|
+
pathToTestDirectory,
|
|
9
|
+
pathToTestFileContent,
|
|
10
|
+
testFileArray,
|
|
11
|
+
MockConfigService,
|
|
12
|
+
testFileName,
|
|
13
|
+
} from '../testUtil';
|
|
14
|
+
|
|
15
|
+
jest.mock('fs', () => ({
|
|
16
|
+
promises: {
|
|
17
|
+
readdir: jest.fn(),
|
|
18
|
+
lstat: jest.fn(),
|
|
19
|
+
readFile: jest.fn(),
|
|
20
|
+
},
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
describe('LocalFilesService', () => {
|
|
24
|
+
let service: LocalFilesService;
|
|
25
|
+
const mockConfigService = new MockConfigService();
|
|
26
|
+
|
|
27
|
+
beforeEach(async () => {
|
|
28
|
+
const module: TestingModule = await Test.createTestingModule({
|
|
29
|
+
providers: [
|
|
30
|
+
LocalFilesService,
|
|
31
|
+
{ provide: ConfigService, useValue: mockConfigService },
|
|
32
|
+
],
|
|
33
|
+
}).compile();
|
|
34
|
+
|
|
35
|
+
service = module.get<LocalFilesService>(LocalFilesService);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
afterEach(() => {
|
|
39
|
+
jest.resetAllMocks();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should be defined', () => {
|
|
43
|
+
expect(service).toBeDefined();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('should list directory', async () => {
|
|
47
|
+
const fullPath = join(
|
|
48
|
+
mockConfigService.get('LOCAL_PATH'),
|
|
49
|
+
pathToTestDirectory,
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
// Mock Stats value for lstat
|
|
53
|
+
const statsMock: Partial<fs.Stats> = {
|
|
54
|
+
isDirectory: () => true, // change this to false when you need a file instead of a directory
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
jest
|
|
58
|
+
.spyOn(fs.promises, 'readdir')
|
|
59
|
+
.mockResolvedValue(testFileArray as unknown as Promise<[]>);
|
|
60
|
+
|
|
61
|
+
jest.spyOn(fs.promises, 'lstat').mockImplementation((pathToDirectory) => {
|
|
62
|
+
if (typeof pathToDirectory === 'string') {
|
|
63
|
+
return Promise.resolve(statsMock as fs.Stats);
|
|
64
|
+
}
|
|
65
|
+
throw new Error(`Invalid argument: ${pathToDirectory}`);
|
|
66
|
+
});
|
|
67
|
+
const result = await service.listDirectory(pathToTestDirectory);
|
|
68
|
+
expect(result).toEqual({
|
|
69
|
+
repository: {
|
|
70
|
+
tree: {
|
|
71
|
+
trees: {
|
|
72
|
+
edges: testFileArray.map((file) => ({
|
|
73
|
+
node: { name: file, type: 'tree' },
|
|
74
|
+
})),
|
|
75
|
+
},
|
|
76
|
+
blobs: { edges: [] },
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
expect(fs.promises.readdir).toHaveBeenCalledWith(fullPath);
|
|
81
|
+
expect(fs.promises.lstat).toHaveBeenCalledTimes(testFileArray.length);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('should read file', async () => {
|
|
85
|
+
const fullPath = join(
|
|
86
|
+
mockConfigService.get('LOCAL_PATH'),
|
|
87
|
+
pathToTestFileContent,
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
jest.spyOn(fs.promises, 'readFile').mockResolvedValue(fstestFileContent);
|
|
91
|
+
|
|
92
|
+
const result = await service.readFile(pathToTestFileContent);
|
|
93
|
+
expect(result).toEqual({
|
|
94
|
+
repository: {
|
|
95
|
+
blobs: {
|
|
96
|
+
nodes: [
|
|
97
|
+
{
|
|
98
|
+
name: testFileName,
|
|
99
|
+
rawBlob: fstestFileContent,
|
|
100
|
+
rawTextBlob: fstestFileContent,
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
expect(fs.promises.readFile).toHaveBeenCalledWith(fullPath, 'utf8');
|
|
107
|
+
});
|
|
108
|
+
});
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"allowSyntheticDefaultImports": true, //allow default imports from modules with no default export
|
|
4
|
+
"baseUrl": "./",
|
|
5
|
+
"declaration": true, //generate declaration '.d.ts' files
|
|
6
|
+
"emitDecoratorMetadata": true,
|
|
7
|
+
"experimentalDecorators": true, //allow experimental decorators for es7
|
|
8
|
+
"forceConsistentCasingInFileNames": false,
|
|
9
|
+
"incremental": true,
|
|
10
|
+
"module": "commonjs", //use node module system
|
|
11
|
+
"moduleResolution": "node", //use node module resolution strategy node
|
|
12
|
+
//"noImplicitAny": true, //raise error on any type
|
|
13
|
+
"noImplicitReturns": true, //raise error on implicit returns
|
|
14
|
+
"noUnusedLocals": true, //raise error on unused locals
|
|
15
|
+
"noUnusedParameters": true, //raise no error on unused parameters
|
|
16
|
+
"noFallthroughCasesInSwitch": false,
|
|
17
|
+
"outDir": "./dist",
|
|
18
|
+
"removeComments": true, //remove comments from build
|
|
19
|
+
"skipLibCheck": true,
|
|
20
|
+
"sourceMap": true, //generate .map files
|
|
21
|
+
"strictBindCallApply": false,
|
|
22
|
+
//"strictNullChecks": true,
|
|
23
|
+
//"strict": true, //enable all strict type-checking options
|
|
24
|
+
"target": "es2022",
|
|
25
|
+
"types": ["node", "jest"], //use node and jest types
|
|
26
|
+
"typeRoots": [
|
|
27
|
+
"node_modules/@types" //use node_modules/@types for type definitions
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
"exclude": ["**/node_modules/*", "./dist"]
|
|
31
|
+
}
|