@into-cps-association/libms 0.4.4 → 0.4.7
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/DEVELOPER.md +62 -0
- package/DOCKER.md +295 -0
- package/HTTP.md +12 -0
- package/README.md +1 -7
- package/compose.lib.dev.yml +9 -0
- package/compose.lib.yml +8 -0
- package/dist/src/app.module.js +14 -16
- package/dist/src/app.module.js.map +1 -1
- package/dist/src/bootstrap.js +10 -13
- package/dist/src/bootstrap.js.map +1 -1
- package/dist/src/cloudcmd/cloudcmd.js +15 -9
- package/dist/src/cloudcmd/cloudcmd.js.map +1 -1
- package/dist/src/enums/config-mode.enum.d.ts +4 -0
- package/dist/src/enums/config-mode.enum.js +6 -0
- package/dist/src/enums/config-mode.enum.js.map +1 -0
- package/dist/src/files/files-service.factory.d.ts +5 -0
- package/dist/src/files/files-service.factory.js +22 -0
- package/dist/src/files/files-service.factory.js.map +1 -0
- package/dist/src/files/files.module.js +23 -9
- package/dist/src/files/files.module.js.map +1 -1
- package/dist/src/files/{resolvers/files.resolver.d.ts → files.resolver.d.ts} +3 -3
- package/dist/src/files/{resolvers/files.resolver.js → files.resolver.js} +14 -14
- package/dist/src/files/files.resolver.js.map +1 -0
- package/dist/src/files/git/git-files.module.d.ts +2 -0
- package/dist/src/files/git/git-files.module.js +18 -0
- package/dist/src/files/git/git-files.module.js.map +1 -0
- package/dist/src/files/git/git-files.service.d.ts +9 -0
- package/dist/src/files/git/git-files.service.js +29 -0
- package/dist/src/files/git/git-files.service.js.map +1 -0
- package/dist/src/files/interfaces/files.service.interface.d.ts +4 -1
- package/dist/src/files/interfaces/files.service.interface.js +1 -2
- package/dist/src/files/interfaces/files.service.interface.js.map +1 -1
- package/dist/src/files/local/local-files.module.d.ts +2 -0
- package/dist/src/files/local/local-files.module.js +18 -0
- package/dist/src/files/local/local-files.module.js.map +1 -0
- package/dist/src/files/{services → local}/local-files.service.d.ts +5 -2
- package/dist/src/files/{services → local}/local-files.service.js +17 -15
- package/dist/src/files/local/local-files.service.js.map +1 -0
- package/dist/src/main.js +4 -6
- package/dist/src/main.js.map +1 -1
- package/dist/src/types.js +56 -59
- package/dist/src/types.js.map +1 -1
- package/dist/test/cloudcmd/cloudcmd.spec.js +14 -16
- package/dist/test/cloudcmd/cloudcmd.spec.js.map +1 -1
- package/dist/test/e2e/app.e2e.spec.js +18 -18
- package/dist/test/e2e/app.e2e.spec.js.map +1 -1
- package/dist/test/integration/files.service.integration.spec.js +28 -19
- package/dist/test/integration/files.service.integration.spec.js.map +1 -1
- package/dist/test/testUtil.js +18 -23
- package/dist/test/testUtil.js.map +1 -1
- package/dist/test/unit/files-service.factory.unit.spec.js +17 -16
- package/dist/test/unit/files-service.factory.unit.spec.js.map +1 -1
- package/dist/test/unit/files.resolver.unit.spec.js +26 -24
- package/dist/test/unit/files.resolver.unit.spec.js.map +1 -1
- package/dist/test/unit/local-files.service.unit.spec.js +23 -24
- package/dist/test/unit/local-files.service.unit.spec.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/eslint.config.js +60 -0
- package/jest.config.ts +47 -0
- package/package.json +54 -48
- package/src/app.module.ts +1 -1
- package/src/bootstrap.ts +3 -3
- package/src/cloudcmd/cloudcmd.ts +11 -3
- package/src/enums/config-mode.enum.ts +4 -0
- package/src/files/files-service.factory.ts +19 -0
- package/src/files/files.module.ts +24 -4
- package/src/files/{resolvers/files.resolver.ts → files.resolver.ts} +9 -8
- package/src/files/git/git-files.module.ts +8 -0
- package/src/files/git/git-files.service.ts +20 -0
- package/src/files/interfaces/files.service.interface.ts +4 -1
- package/src/files/local/local-files.module.ts +8 -0
- package/src/files/{services → local}/local-files.service.ts +15 -10
- package/src/main.ts +1 -1
- package/test/cloudcmd/cloudcmd.spec.ts +4 -6
- package/test/e2e/app.e2e.spec.ts +4 -3
- package/test/integration/files.service.integration.spec.ts +19 -4
- package/test/unit/files-service.factory.unit.spec.ts +18 -11
- package/test/unit/files.resolver.unit.spec.ts +19 -12
- package/test/unit/local-files.service.unit.spec.ts +4 -2
- package/tsconfig.json +10 -7
- package/.env +0 -6
- package/.eslintignore +0 -6
- package/.eslintrc +0 -53
- package/dist/src/files/resolvers/files.resolver.js.map +0 -1
- package/dist/src/files/services/files-service.factory.d.ts +0 -9
- package/dist/src/files/services/files-service.factory.js +0 -40
- package/dist/src/files/services/files-service.factory.js.map +0 -1
- package/dist/src/files/services/local-files.service.js.map +0 -1
- package/jest.config.json +0 -30
- package/src/files/services/files-service.factory.ts +0 -22
- /package/{pm2.config.js → pm2.config.cjs} +0 -0
|
@@ -1,34 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const promises_1 = require("fs/promises");
|
|
5
|
-
const dotenv_1 = require("dotenv");
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { unlink, writeFile } from 'fs/promises';
|
|
3
|
+
import { config } from 'dotenv';
|
|
6
4
|
describe('cloudcmd test for the application', () => {
|
|
7
5
|
beforeAll(async () => {
|
|
8
|
-
|
|
9
|
-
await
|
|
6
|
+
config();
|
|
7
|
+
await writeFile(`${process.env.LOCAL_PATH}/test.txt`, 'content12345');
|
|
10
8
|
await new Promise((resolve) => setTimeout(resolve, 8000));
|
|
11
9
|
}, 10000);
|
|
12
10
|
afterAll(async () => {
|
|
13
|
-
await
|
|
14
|
-
await
|
|
11
|
+
await unlink(`${process.env.LOCAL_PATH}/test.txt`);
|
|
12
|
+
await unlink(`${process.env.LOCAL_PATH}/uploadTest.txt`);
|
|
15
13
|
}, 10000);
|
|
16
14
|
it('should return the correct directory that is set as root', async () => {
|
|
17
|
-
const response = await
|
|
15
|
+
const response = await axios.get(`http://localhost:${process.env.PORT}${process.env.APOLLO_PATH}/files/api/v1/fs`, {
|
|
18
16
|
responseType: 'json',
|
|
19
17
|
});
|
|
20
|
-
console.log(response.data);
|
|
21
18
|
expect(response.data.path).toEqual('/');
|
|
22
|
-
|
|
23
|
-
expect(
|
|
24
|
-
expect(
|
|
19
|
+
const fileNames = response.data.files.map((file) => file.name);
|
|
20
|
+
expect(fileNames).toContain('common');
|
|
21
|
+
expect(fileNames).toContain('user1');
|
|
22
|
+
expect(fileNames).toContain('user2');
|
|
25
23
|
}, 10000);
|
|
26
24
|
it('should return the content of a file that is uplaoded to cloudcmd ', async () => {
|
|
27
|
-
const response = await
|
|
25
|
+
const response = await axios.get(`http://localhost:${process.env.PORT}${process.env.APOLLO_PATH}/files/api/v1/fs/test.txt`);
|
|
28
26
|
expect(response.data).toEqual('content12345');
|
|
29
27
|
}, 10000);
|
|
30
28
|
it('should upload a file to cloudcmd', async () => {
|
|
31
|
-
const response = await
|
|
29
|
+
const response = await axios.put(`http://localhost:${process.env.PORT}${process.env.APOLLO_PATH}/files/api/v1/fs/uploadTest.txt`, 'some content', { responseType: 'text' });
|
|
32
30
|
expect(response.data).toEqual('save: ok("uploadTest.txt")');
|
|
33
31
|
}, 10000);
|
|
34
32
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cloudcmd.spec.js","sourceRoot":"","sources":["../../../test/cloudcmd/cloudcmd.spec.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cloudcmd.spec.js","sourceRoot":"","sources":["../../../test/cloudcmd/cloudcmd.spec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,QAAQ,CAAC,mCAAmC,EAAE,GAAG,EAAE;IACjD,SAAS,CAAC,KAAK,IAAI,EAAE;QACnB,MAAM,EAAE,CAAC;QAET,MAAM,SAAS,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,WAAW,EAAE,cAAc,CAAC,CAAC;QAEtE,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UA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C,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;IAChD,CAAC,EAAE,KAAK,CAAC,CAAC;IAEV,EAAE,CAAC,kCAAkC,EAAE,KAAK,IAAI,EAAE;QAChD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAC9B,oBAAoB,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,iCAAiC,EAC/F,cAAc,EACd,EAAE,YAAY,EAAE,MAAM,EAAE,CACzB,CAAC;QAEF,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,4BAA4B,CAAC,CAAC;IAC9D,CAAC,EAAE,KAAK,CAAC,CAAC;AACZ,CAAC,CAAC,CAAC"}
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const client = new
|
|
10
|
-
link: new
|
|
1
|
+
import { describe, it, expect } from '@jest/globals';
|
|
2
|
+
import { Test } from '@nestjs/testing';
|
|
3
|
+
import request from 'supertest';
|
|
4
|
+
import fetch from 'cross-fetch';
|
|
5
|
+
import { ApolloClient, InMemoryCache, gql, } from '@apollo/client/core/core.cjs';
|
|
6
|
+
import { HttpLink } from '@apollo/client/link/http/http.cjs';
|
|
7
|
+
import AppModule from '../../src/app.module';
|
|
8
|
+
import { e2eReadFile, e2elistDirectory, expectedFileContentResponse, expectedListDirectoryResponse, } from '../testUtil';
|
|
9
|
+
const client = new ApolloClient({
|
|
10
|
+
link: new HttpLink({
|
|
11
11
|
uri: `http://localhost:${process.env.PORT}${process.env.APOLLO_PATH}`,
|
|
12
|
-
fetch
|
|
12
|
+
fetch,
|
|
13
13
|
}),
|
|
14
|
-
cache: new
|
|
14
|
+
cache: new InMemoryCache({ addTypename: false }),
|
|
15
15
|
});
|
|
16
16
|
describe('End to End test for the application', () => {
|
|
17
17
|
let app;
|
|
18
18
|
beforeAll(async () => {
|
|
19
|
-
const moduleFixture = await
|
|
20
|
-
imports: [
|
|
19
|
+
const moduleFixture = await Test.createTestingModule({
|
|
20
|
+
imports: [AppModule],
|
|
21
21
|
}).compile();
|
|
22
22
|
app = moduleFixture.createNestApplication();
|
|
23
23
|
await app.init();
|
|
@@ -38,16 +38,16 @@ describe('End to End test for the application', () => {
|
|
|
38
38
|
expect({ data }).toEqual(expectedResponse);
|
|
39
39
|
}
|
|
40
40
|
it('should return the directory contents requested with HTTP POST query', async () => {
|
|
41
|
-
await HTTPQuery(
|
|
41
|
+
await HTTPQuery(e2elistDirectory, expectedListDirectoryResponse);
|
|
42
42
|
}, 10000);
|
|
43
43
|
it('should return the file content requested with HTTP POST query', async () => {
|
|
44
|
-
await HTTPQuery(
|
|
44
|
+
await HTTPQuery(e2eReadFile, expectedFileContentResponse);
|
|
45
45
|
}, 10000);
|
|
46
46
|
it('should return the directory contents requested with GraphQL query', async () => {
|
|
47
|
-
await GraphQLQuery(
|
|
47
|
+
await GraphQLQuery(gql(e2elistDirectory), expectedListDirectoryResponse);
|
|
48
48
|
}, 10000);
|
|
49
49
|
it('should return the file content requested with GraphQL query', async () => {
|
|
50
|
-
await GraphQLQuery(
|
|
50
|
+
await GraphQLQuery(gql(e2eReadFile), expectedFileContentResponse);
|
|
51
51
|
}, 10000);
|
|
52
52
|
});
|
|
53
53
|
//# sourceMappingURL=app.e2e.spec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.e2e.spec.js","sourceRoot":"","sources":["../../../test/e2e/app.e2e.spec.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"app.e2e.spec.js","sourceRoot":"","sources":["../../../test/e2e/app.e2e.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,IAAI,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E,2BAA2B,CAAC,CAAC;IACpE,CAAC,EAAE,KAAK,CAAC,CAAC;AACZ,CAAC,CAAC,CAAC"}
|
|
@@ -1,25 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { describe, it, expect, jest } from '@jest/globals';
|
|
2
|
+
import { Test } from '@nestjs/testing';
|
|
3
|
+
import { ConfigService } from '@nestjs/config';
|
|
4
|
+
import FilesResolver from '../../src/files/files.resolver';
|
|
5
|
+
import LocalFilesService from '../../src/files/local/local-files.service';
|
|
6
|
+
import { pathToTestDirectory, pathToTestFileContent, testDirectory, testFileContent, MockConfigService, } from '../testUtil';
|
|
7
|
+
import GitFilesService from '../../src/files/git/git-files.service';
|
|
8
|
+
import { FILE_SERVICE } from '../../src/files/interfaces/files.service.interface';
|
|
9
|
+
import FilesServiceFactory from '../../src/files/files-service.factory';
|
|
9
10
|
describe('Integration tests for FilesResolver', () => {
|
|
10
11
|
let filesResolver;
|
|
11
12
|
let mockConfigService;
|
|
12
13
|
beforeEach(async () => {
|
|
13
|
-
mockConfigService = new
|
|
14
|
-
const module = await
|
|
14
|
+
mockConfigService = new MockConfigService();
|
|
15
|
+
const module = await Test.createTestingModule({
|
|
15
16
|
providers: [
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
FilesResolver,
|
|
18
|
+
{
|
|
19
|
+
provide: FILE_SERVICE,
|
|
20
|
+
useFactory: (configService, localFilesService, gitFilesService) => {
|
|
21
|
+
const fileServices = [localFilesService, gitFilesService];
|
|
22
|
+
return FilesServiceFactory.create(configService, fileServices);
|
|
23
|
+
},
|
|
24
|
+
inject: [ConfigService, LocalFilesService, GitFilesService],
|
|
25
|
+
},
|
|
26
|
+
LocalFilesService,
|
|
27
|
+
GitFilesService,
|
|
28
|
+
{ provide: ConfigService, useClass: MockConfigService },
|
|
20
29
|
],
|
|
21
30
|
}).compile();
|
|
22
|
-
filesResolver = module.get(
|
|
31
|
+
filesResolver = module.get(FilesResolver);
|
|
23
32
|
});
|
|
24
33
|
afterEach(() => {
|
|
25
34
|
jest.clearAllMocks();
|
|
@@ -35,14 +44,14 @@ describe('Integration tests for FilesResolver', () => {
|
|
|
35
44
|
});
|
|
36
45
|
describe('listDirectory', () => {
|
|
37
46
|
it('should list files', async () => {
|
|
38
|
-
const files = await filesResolver.listDirectory(
|
|
39
|
-
expect(files).toEqual(
|
|
47
|
+
const files = await filesResolver.listDirectory(pathToTestDirectory);
|
|
48
|
+
expect(files).toEqual(testDirectory);
|
|
40
49
|
});
|
|
41
50
|
});
|
|
42
51
|
describe('readFile', () => {
|
|
43
52
|
it('should read file', async () => {
|
|
44
|
-
const content = await filesResolver.readFile(
|
|
45
|
-
expect(content).toEqual(
|
|
53
|
+
const content = await filesResolver.readFile(pathToTestFileContent);
|
|
54
|
+
expect(content).toEqual(testFileContent);
|
|
46
55
|
});
|
|
47
56
|
});
|
|
48
57
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"files.service.integration.spec.js","sourceRoot":"","sources":["../../../test/integration/files.service.integration.spec.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"files.service.integration.spec.js","sourceRoot":"","sources":["../../../test/integration/files.service.integration.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAiB,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,aAAa,MAAM,gCAAgC,CAAC;AAC3D,OAAO,iBAAiB,MAAM,2CAA2C,CAAC;AAC1E,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,aAAa,EACb,eAAe,EACf,iBAAiB,GAClB,MAAM,aAAa,CAAC;A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,KAAK,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;YAC7D,CAAC,CAAC,CAAC;YAEH,EAAE,CAAC,mBAAmB,EAAE,GAAG,EAAE;gBAC3B,MAAM,CAAC,aAAa,CAAC,CAAC,WAAW,EAAE,CAAC;YACtC,CAAC,CAAC,CAAC;YAEH,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;gBAC7B,EAAE,CAAC,mBAAmB,EAAE,KAAK,IAAI,EAAE;oBACjC,MAAM,KAAK,GAAG,MAAM,aAAa,CAAC,aAAa,CAAC,mBAAmB,CAAC,CAAC;oBACrE,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;gBACvC,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;YAEH,QAAQ,CAAC,UAAU,EAAE,GAAG,EAAE;gBACxB,EAAE,CAAC,kBAAkB,EAAE,KAAK,IAAI,EAAE;oBAChC,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC,QAAQ,CAAC,qBAAqB,CAAC,CAAC;oBACpE,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;gBAC3C,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC,CAAC"}
|
package/dist/test/testUtil.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.e2eReadFile = exports.e2elistDirectory = exports.expectedFileContentResponse = exports.expectedListDirectoryResponse = exports.mockReadFileResponseData = exports.MockConfigService = exports.sleep = exports.testFileContent = exports.testFileArray = exports.pathToTestFileContent = exports.fstestFileContent = exports.testFileName = exports.testDirectory = exports.pathToTestDirectory = exports.readFileActualContent = void 0;
|
|
4
|
-
const dotenv = require("dotenv");
|
|
5
|
-
const promises_1 = require("timers/promises");
|
|
1
|
+
import * as dotenv from 'dotenv';
|
|
2
|
+
import { setTimeout } from 'timers/promises';
|
|
6
3
|
dotenv.config({ path: '.env' });
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
export const readFileActualContent = ['content123'];
|
|
5
|
+
export const pathToTestDirectory = 'user2';
|
|
6
|
+
export const testDirectory = {
|
|
10
7
|
repository: {
|
|
11
8
|
tree: {
|
|
12
9
|
blobs: { edges: [] },
|
|
@@ -22,17 +19,17 @@ exports.testDirectory = {
|
|
|
22
19
|
},
|
|
23
20
|
},
|
|
24
21
|
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
export const testFileName = 'README.md';
|
|
23
|
+
export const fstestFileContent = 'content123';
|
|
24
|
+
export const pathToTestFileContent = 'user2/tools/README.md';
|
|
25
|
+
export const testFileArray = [
|
|
29
26
|
'data',
|
|
30
27
|
'digital_twins',
|
|
31
28
|
'functions',
|
|
32
29
|
'models',
|
|
33
30
|
'tools',
|
|
34
31
|
];
|
|
35
|
-
|
|
32
|
+
export const testFileContent = {
|
|
36
33
|
repository: {
|
|
37
34
|
blobs: {
|
|
38
35
|
nodes: [
|
|
@@ -45,12 +42,11 @@ exports.testFileContent = {
|
|
|
45
42
|
},
|
|
46
43
|
},
|
|
47
44
|
};
|
|
48
|
-
function sleep(ms) {
|
|
49
|
-
const timer =
|
|
45
|
+
export function sleep(ms) {
|
|
46
|
+
const timer = setTimeout(ms);
|
|
50
47
|
Promise.resolve(timer);
|
|
51
48
|
}
|
|
52
|
-
|
|
53
|
-
class MockConfigService {
|
|
49
|
+
export class MockConfigService {
|
|
54
50
|
get(key) {
|
|
55
51
|
switch (key) {
|
|
56
52
|
case 'LOCAL_PATH':
|
|
@@ -65,8 +61,7 @@ class MockConfigService {
|
|
|
65
61
|
}
|
|
66
62
|
}
|
|
67
63
|
}
|
|
68
|
-
|
|
69
|
-
exports.mockReadFileResponseData = {
|
|
64
|
+
export const mockReadFileResponseData = {
|
|
70
65
|
project: {
|
|
71
66
|
__typename: 'Project',
|
|
72
67
|
repository: {
|
|
@@ -84,7 +79,7 @@ exports.mockReadFileResponseData = {
|
|
|
84
79
|
},
|
|
85
80
|
},
|
|
86
81
|
};
|
|
87
|
-
|
|
82
|
+
export const expectedListDirectoryResponse = {
|
|
88
83
|
data: {
|
|
89
84
|
listDirectory: {
|
|
90
85
|
repository: {
|
|
@@ -123,7 +118,7 @@ exports.expectedListDirectoryResponse = {
|
|
|
123
118
|
},
|
|
124
119
|
},
|
|
125
120
|
};
|
|
126
|
-
|
|
121
|
+
export const expectedFileContentResponse = {
|
|
127
122
|
data: {
|
|
128
123
|
readFile: {
|
|
129
124
|
repository: {
|
|
@@ -140,7 +135,7 @@ exports.expectedFileContentResponse = {
|
|
|
140
135
|
},
|
|
141
136
|
},
|
|
142
137
|
};
|
|
143
|
-
|
|
138
|
+
export const e2elistDirectory = `query {
|
|
144
139
|
listDirectory(path:"user2")
|
|
145
140
|
{
|
|
146
141
|
repository{
|
|
@@ -157,7 +152,7 @@ exports.e2elistDirectory = `query {
|
|
|
157
152
|
}
|
|
158
153
|
}
|
|
159
154
|
}`;
|
|
160
|
-
|
|
155
|
+
export const e2eReadFile = `query {
|
|
161
156
|
readFile(path:"user2/tools/README.md") {
|
|
162
157
|
repository {
|
|
163
158
|
blobs {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testUtil.js","sourceRoot":"","sources":["../../test/testUtil.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"testUtil.js","sourceRoot":"","sources":["../../test/testUtil.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;AAGhC,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,YAAY,CAAC,CAAC;A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AA2B,GAAG;IACzC,IAAI,EAAE;QACJ,QAAQ,EAAE;YACR,UAAU,EAAE;gBACV,KAAK,EAAE;oBACL,KAAK,EAAE;wBACL;4BACE,IAAI,EAAE,WAAW;4BACjB,OAAO,EAAE,YAAY;4BACrB,WAAW,EAAE,YAAY;yBAC1B;qBACF;iBACF;aACF;SACF;KACF;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG;;;;;;;;;;;;;;;;EAgB9B,CAAC;AAEH,MAAM,CAAC,MAAM,WAAW,GAAG;;;;;;;;;;;;EAYzB,CAAC"}
|
|
@@ -1,32 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { describe, it, expect, jest } from '@jest/globals';
|
|
2
|
+
import { Test } from '@nestjs/testing';
|
|
3
|
+
import { ConfigService } from '@nestjs/config';
|
|
4
|
+
import FilesServiceFactory from '../../src/files/files-service.factory';
|
|
5
|
+
import LocalFilesService from '../../src/files/local/local-files.service';
|
|
6
|
+
import GitFilesService from '../../src/files/git/git-files.service';
|
|
7
7
|
describe('FilesServiceFactory', () => {
|
|
8
|
-
let serviceFactory;
|
|
9
8
|
let configService;
|
|
10
9
|
let localFilesService;
|
|
10
|
+
let gitFilesService;
|
|
11
|
+
let fileServices;
|
|
11
12
|
beforeEach(async () => {
|
|
12
|
-
|
|
13
|
-
const module = await testing_1.Test.createTestingModule({
|
|
13
|
+
const module = await Test.createTestingModule({
|
|
14
14
|
providers: [
|
|
15
|
-
|
|
16
|
-
{ provide:
|
|
17
|
-
{ provide: local_files_service_1.default, useValue: localFilesService },
|
|
15
|
+
GitFilesService,
|
|
16
|
+
{ provide: ConfigService, useValue: { get: jest.fn() } },
|
|
18
17
|
],
|
|
19
18
|
}).compile();
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
configService = module.get(ConfigService);
|
|
20
|
+
localFilesService = new LocalFilesService(configService);
|
|
21
|
+
gitFilesService = module.get(GitFilesService);
|
|
22
|
+
fileServices = [gitFilesService, localFilesService];
|
|
22
23
|
});
|
|
23
24
|
it('should create a local files service when MODE is local', () => {
|
|
24
25
|
jest.spyOn(configService, 'get').mockReturnValue('local');
|
|
25
|
-
expect(
|
|
26
|
+
expect(FilesServiceFactory.create(configService, fileServices)).toBe(localFilesService);
|
|
26
27
|
});
|
|
27
28
|
it('should throw an error when MODE is invalid', () => {
|
|
28
29
|
jest.spyOn(configService, 'get').mockReturnValue('invalid');
|
|
29
|
-
expect(() =>
|
|
30
|
+
expect(() => FilesServiceFactory.create(configService, fileServices)).toThrow(`Invalid MODE: invalid`);
|
|
30
31
|
});
|
|
31
32
|
});
|
|
32
33
|
//# sourceMappingURL=files-service.factory.unit.spec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"files-service.factory.unit.spec.js","sourceRoot":"","sources":["../../../test/unit/files-service.factory.unit.spec.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"files-service.factory.unit.spec.js","sourceRoot":"","sources":["../../../test/unit/files-service.factory.unit.spec.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAiB,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,mBAAmB,MAAM,uCAAuC,CAAC;AACxE,OAAO,iBAAiB,MAAM,2CAA2C,CAAC;AAE1E,OAAO,eAAe,MAAM,uCAAuC,CAAC;AAEpE,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,IAAI,aAA4B,CAAC;IACjC,IAAI,iBAAgC,CAAC;IACrC,IAAI,eAA8B,CAAC;IACnC,IAAI,YAA6B,CAAC;IAElC,UAAU,CAAC,KAAK,IAAI,EAAE;QAEpB,MAAM,MAAM,GAAkB,MAAM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
|
+
import FilesResolver from '../../src/files/files.resolver';
|
|
4
|
+
import { testDirectory, pathToTestDirectory, pathToTestFileContent, testFileContent, } from '../testUtil';
|
|
5
|
+
import { FILE_SERVICE, } from '../../src/files/interfaces/files.service.interface';
|
|
6
|
+
import { CONFIG_MODE } from '../../src/enums/config-mode.enum';
|
|
7
7
|
describe('Unit tests for FilesResolver', () => {
|
|
8
8
|
let filesResolver;
|
|
9
9
|
let filesService;
|
|
10
10
|
beforeEach(async () => {
|
|
11
11
|
const mockFilesService = {
|
|
12
|
-
listDirectory: jest
|
|
13
|
-
|
|
12
|
+
listDirectory: jest
|
|
13
|
+
.fn()
|
|
14
|
+
.mockResolvedValue(testDirectory),
|
|
15
|
+
readFile: jest
|
|
16
|
+
.fn()
|
|
17
|
+
.mockImplementation(() => Promise.resolve(testFileContent)),
|
|
18
|
+
getMode: jest.fn().mockReturnValue(CONFIG_MODE.LOCAL),
|
|
14
19
|
};
|
|
15
|
-
const module = await
|
|
20
|
+
const module = await Test.createTestingModule({
|
|
16
21
|
providers: [
|
|
17
|
-
|
|
18
|
-
files_service_factory_1.default,
|
|
22
|
+
FilesResolver,
|
|
19
23
|
{
|
|
20
|
-
provide:
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
provide: FILE_SERVICE,
|
|
25
|
+
useFactory: () => {
|
|
26
|
+
return mockFilesService;
|
|
23
27
|
},
|
|
24
28
|
},
|
|
25
29
|
],
|
|
26
30
|
}).compile();
|
|
27
|
-
filesResolver = module.get(
|
|
28
|
-
filesService = module
|
|
29
|
-
.get(files_service_factory_1.default)
|
|
30
|
-
.create();
|
|
31
|
+
filesResolver = module.get(FilesResolver);
|
|
32
|
+
filesService = module.get(FILE_SERVICE);
|
|
31
33
|
});
|
|
32
34
|
it('should be defined', () => {
|
|
33
35
|
expect(filesResolver).toBeDefined();
|
|
@@ -37,9 +39,9 @@ describe('Unit tests for FilesResolver', () => {
|
|
|
37
39
|
expect(filesResolver.listDirectory).toBeDefined();
|
|
38
40
|
});
|
|
39
41
|
it('should list files in directory', async () => {
|
|
40
|
-
const result = await filesResolver.listDirectory(
|
|
41
|
-
expect(result).toEqual(
|
|
42
|
-
expect(filesService.listDirectory).toHaveBeenCalledWith(
|
|
42
|
+
const result = await filesResolver.listDirectory(pathToTestDirectory);
|
|
43
|
+
expect(result).toEqual(testDirectory);
|
|
44
|
+
expect(filesService.listDirectory).toHaveBeenCalledWith(pathToTestDirectory);
|
|
43
45
|
});
|
|
44
46
|
});
|
|
45
47
|
describe('readFile', () => {
|
|
@@ -47,9 +49,9 @@ describe('Unit tests for FilesResolver', () => {
|
|
|
47
49
|
expect(filesResolver.readFile).toBeDefined();
|
|
48
50
|
});
|
|
49
51
|
it('should read file', async () => {
|
|
50
|
-
const result = await filesResolver.readFile(
|
|
51
|
-
expect(result).toEqual(
|
|
52
|
-
expect(filesService.readFile).toHaveBeenCalledWith(
|
|
52
|
+
const result = await filesResolver.readFile(pathToTestFileContent);
|
|
53
|
+
expect(result).toEqual(testFileContent);
|
|
54
|
+
expect(filesService.readFile).toHaveBeenCalledWith(pathToTestFileContent);
|
|
53
55
|
});
|
|
54
56
|
});
|
|
55
57
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"files.resolver.unit.spec.js","sourceRoot":"","sources":["../../../test/unit/files.resolver.unit.spec.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"files.resolver.unit.spec.js","sourceRoot":"","sources":["../../../test/unit/files.resolver.unit.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAiB,MAAM,iBAAiB,CAAC;AACtD,OAAO,aAAa,MAAM,gCAAgC,CAAC;AAC3D,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,qBAAqB,EACrB,eAAe,GAChB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,YAAY,G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C;QAEH,EAAE,CAAC,gCAAgC,EAAE,KAAK,IAAI,EAAE;YAC9C,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,aAAa,CAAC,mBAAmB,CAAC,CAAC;YACtE,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;YACtC,MAAM,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC,oBAAoB,CACrD,mBAAmB,CACpB,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,UAAU,EAAE,GAAG,EAAE;QACxB,EAAE,CAAC,mBAAmB,EAAE,GAAG,EAAE;YAC3B,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC;QAC/C,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,kBAAkB,EAAE,KAAK,IAAI,EAAE;YAChC,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,QAAQ,CAAC,qBAAqB,CAAC,CAAC;YACnE,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;YACxC,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,oBAAoB,CAAC,qBAAqB,CAAC,CAAC;QAC5E,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const testUtil_1 = require("../testUtil");
|
|
1
|
+
import { describe, it, expect, jest } from '@jest/globals';
|
|
2
|
+
import { Test } from '@nestjs/testing';
|
|
3
|
+
import { ConfigService } from '@nestjs/config';
|
|
4
|
+
import * as fs from 'fs';
|
|
5
|
+
import { join } from 'path';
|
|
6
|
+
import LocalFilesService from '../../src/files/local/local-files.service';
|
|
7
|
+
import { fstestFileContent, pathToTestDirectory, pathToTestFileContent, testFileArray, MockConfigService, testFileName, } from '../testUtil';
|
|
9
8
|
jest.mock('fs', () => ({
|
|
10
9
|
promises: {
|
|
11
10
|
readdir: jest.fn(),
|
|
@@ -15,15 +14,15 @@ jest.mock('fs', () => ({
|
|
|
15
14
|
}));
|
|
16
15
|
describe('LocalFilesService', () => {
|
|
17
16
|
let service;
|
|
18
|
-
const mockConfigService = new
|
|
17
|
+
const mockConfigService = new MockConfigService();
|
|
19
18
|
beforeEach(async () => {
|
|
20
|
-
const module = await
|
|
19
|
+
const module = await Test.createTestingModule({
|
|
21
20
|
providers: [
|
|
22
|
-
|
|
23
|
-
{ provide:
|
|
21
|
+
LocalFilesService,
|
|
22
|
+
{ provide: ConfigService, useValue: mockConfigService },
|
|
24
23
|
],
|
|
25
24
|
}).compile();
|
|
26
|
-
service = module.get(
|
|
25
|
+
service = module.get(LocalFilesService);
|
|
27
26
|
});
|
|
28
27
|
afterEach(() => {
|
|
29
28
|
jest.resetAllMocks();
|
|
@@ -32,25 +31,25 @@ describe('LocalFilesService', () => {
|
|
|
32
31
|
expect(service).toBeDefined();
|
|
33
32
|
});
|
|
34
33
|
it('should list directory', async () => {
|
|
35
|
-
const fullPath =
|
|
34
|
+
const fullPath = join(mockConfigService.get('LOCAL_PATH'), pathToTestDirectory);
|
|
36
35
|
const statsMock = {
|
|
37
36
|
isDirectory: () => true,
|
|
38
37
|
};
|
|
39
38
|
jest
|
|
40
39
|
.spyOn(fs.promises, 'readdir')
|
|
41
|
-
.mockResolvedValue(
|
|
40
|
+
.mockResolvedValue(testFileArray);
|
|
42
41
|
jest.spyOn(fs.promises, 'lstat').mockImplementation((pathToDirectory) => {
|
|
43
42
|
if (typeof pathToDirectory === 'string') {
|
|
44
43
|
return Promise.resolve(statsMock);
|
|
45
44
|
}
|
|
46
45
|
throw new Error(`Invalid argument: ${pathToDirectory}`);
|
|
47
46
|
});
|
|
48
|
-
const result = await service.listDirectory(
|
|
47
|
+
const result = await service.listDirectory(pathToTestDirectory);
|
|
49
48
|
expect(result).toEqual({
|
|
50
49
|
repository: {
|
|
51
50
|
tree: {
|
|
52
51
|
trees: {
|
|
53
|
-
edges:
|
|
52
|
+
edges: testFileArray.map((file) => ({
|
|
54
53
|
node: { name: file, type: 'tree' },
|
|
55
54
|
})),
|
|
56
55
|
},
|
|
@@ -59,20 +58,20 @@ describe('LocalFilesService', () => {
|
|
|
59
58
|
},
|
|
60
59
|
});
|
|
61
60
|
expect(fs.promises.readdir).toHaveBeenCalledWith(fullPath);
|
|
62
|
-
expect(fs.promises.lstat).toHaveBeenCalledTimes(
|
|
61
|
+
expect(fs.promises.lstat).toHaveBeenCalledTimes(testFileArray.length);
|
|
63
62
|
});
|
|
64
63
|
it('should read file', async () => {
|
|
65
|
-
const fullPath =
|
|
66
|
-
jest.spyOn(fs.promises, 'readFile').mockResolvedValue(
|
|
67
|
-
const result = await service.readFile(
|
|
64
|
+
const fullPath = join(mockConfigService.get('LOCAL_PATH'), pathToTestFileContent);
|
|
65
|
+
jest.spyOn(fs.promises, 'readFile').mockResolvedValue(fstestFileContent);
|
|
66
|
+
const result = await service.readFile(pathToTestFileContent);
|
|
68
67
|
expect(result).toEqual({
|
|
69
68
|
repository: {
|
|
70
69
|
blobs: {
|
|
71
70
|
nodes: [
|
|
72
71
|
{
|
|
73
|
-
name:
|
|
74
|
-
rawBlob:
|
|
75
|
-
rawTextBlob:
|
|
72
|
+
name: testFileName,
|
|
73
|
+
rawBlob: fstestFileContent,
|
|
74
|
+
rawTextBlob: fstestFileContent,
|
|
76
75
|
},
|
|
77
76
|
],
|
|
78
77
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-files.service.unit.spec.js","sourceRoot":"","sources":["../../../test/unit/local-files.service.unit.spec.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"local-files.service.unit.spec.js","sourceRoot":"","sources":["../../../test/unit/local-files.service.unit.spec.ts"],"names":[],"mappings":"AAAA,OAAO,E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