@into-cps-association/libms 0.4.3 → 0.4.5
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 +6 -0
- package/DEVELOPER.md +34 -9
- package/HTTP.md +12 -0
- package/README.md +288 -10
- package/config/.env.default +1 -1
- package/coverage/clover.xml +162 -0
- package/coverage/cobertura-coverage.xml +306 -0
- package/coverage/coverage-final.json +8 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +176 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov-report/src/bootstrap.ts.html +196 -0
- package/coverage/lcov-report/src/cloudcmd/cloudcmd.ts.html +181 -0
- package/coverage/lcov-report/src/cloudcmd/index.html +116 -0
- package/coverage/lcov-report/src/files/files.module.ts.html +112 -0
- package/coverage/lcov-report/src/files/index.html +116 -0
- package/coverage/lcov-report/src/files/resolvers/files.resolver.ts.html +154 -0
- package/coverage/lcov-report/src/files/resolvers/index.html +116 -0
- package/coverage/lcov-report/src/files/services/files-service.factory.ts.html +151 -0
- package/coverage/lcov-report/src/files/services/index.html +131 -0
- package/coverage/lcov-report/src/files/services/local-files.service.ts.html +313 -0
- package/coverage/lcov-report/src/index.html +131 -0
- package/coverage/lcov-report/src/types.ts.html +361 -0
- package/coverage/lcov.info +237 -0
- package/dist/src/app.module.d.ts +1 -0
- package/dist/src/app.module.js +36 -0
- package/dist/src/app.module.js.map +1 -0
- package/dist/src/bootstrap.d.ts +7 -0
- package/dist/src/bootstrap.js +31 -0
- package/dist/src/bootstrap.js.map +1 -0
- package/dist/src/cloudcmd/cloudcmd.d.ts +7 -0
- package/dist/src/cloudcmd/cloudcmd.js +22 -0
- package/dist/src/cloudcmd/cloudcmd.js.map +1 -0
- package/dist/src/files/files.module.d.ts +1 -0
- package/dist/src/files/files.module.js +21 -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/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 +12 -0
- package/dist/src/files/services/files-service.factory.js +40 -0
- package/dist/src/files/services/files-service.factory.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/cloudcmd/cloudcmd.spec.d.ts +1 -0
- package/dist/test/cloudcmd/cloudcmd.spec.js +35 -0
- package/dist/test/cloudcmd/cloudcmd.spec.js.map +1 -0
- package/dist/test/e2e/app.e2e.spec.d.ts +1 -0
- package/dist/test/e2e/app.e2e.spec.js +53 -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 +51 -0
- package/dist/test/integration/files.service.integration.spec.js.map +1 -0
- package/dist/test/testUtil.d.ts +90 -0
- package/dist/test/testUtil.js +173 -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 +32 -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/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/inside.png +0 -0
- package/package.json +1 -1
- package/top-level.png +0 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const testing_1 = require("@nestjs/testing");
|
|
4
|
+
const request = require("supertest");
|
|
5
|
+
const cross_fetch_1 = require("cross-fetch");
|
|
6
|
+
const client_1 = require("@apollo/client");
|
|
7
|
+
const app_module_1 = require("../../src/app.module");
|
|
8
|
+
const testUtil_1 = require("../testUtil");
|
|
9
|
+
const client = new client_1.ApolloClient({
|
|
10
|
+
link: new client_1.HttpLink({
|
|
11
|
+
uri: `http://localhost:${process.env.PORT}${process.env.APOLLO_PATH}`,
|
|
12
|
+
fetch: cross_fetch_1.default,
|
|
13
|
+
}),
|
|
14
|
+
cache: new client_1.InMemoryCache({ addTypename: false }),
|
|
15
|
+
});
|
|
16
|
+
describe('End to End test for the application', () => {
|
|
17
|
+
let app;
|
|
18
|
+
beforeAll(async () => {
|
|
19
|
+
const moduleFixture = await testing_1.Test.createTestingModule({
|
|
20
|
+
imports: [app_module_1.default],
|
|
21
|
+
}).compile();
|
|
22
|
+
app = moduleFixture.createNestApplication();
|
|
23
|
+
await app.init();
|
|
24
|
+
await app.listen(process.env.PORT);
|
|
25
|
+
await new Promise((resolve) => setTimeout(resolve, 4000));
|
|
26
|
+
}, 10000);
|
|
27
|
+
afterAll(async () => {
|
|
28
|
+
await app.close();
|
|
29
|
+
}, 10000);
|
|
30
|
+
async function HTTPQuery(query, expectedResponse) {
|
|
31
|
+
const response = await request(`http://localhost:${process.env.PORT}`)
|
|
32
|
+
.post(process.env.APOLLO_PATH)
|
|
33
|
+
.send({ query });
|
|
34
|
+
expect(response.body).toEqual(expectedResponse);
|
|
35
|
+
}
|
|
36
|
+
async function GraphQLQuery(query, expectedResponse) {
|
|
37
|
+
const { data } = await client.query({ query });
|
|
38
|
+
expect({ data }).toEqual(expectedResponse);
|
|
39
|
+
}
|
|
40
|
+
it('should return the directory contents requested with HTTP POST query', async () => {
|
|
41
|
+
await HTTPQuery(testUtil_1.e2elistDirectory, testUtil_1.expectedListDirectoryResponse);
|
|
42
|
+
}, 10000);
|
|
43
|
+
it('should return the file content requested with HTTP POST query', async () => {
|
|
44
|
+
await HTTPQuery(testUtil_1.e2eReadFile, testUtil_1.expectedFileContentResponse);
|
|
45
|
+
}, 10000);
|
|
46
|
+
it('should return the directory contents requested with GraphQL query', async () => {
|
|
47
|
+
await GraphQLQuery((0, client_1.gql)(testUtil_1.e2elistDirectory), testUtil_1.expectedListDirectoryResponse);
|
|
48
|
+
}, 10000);
|
|
49
|
+
it('should return the file content requested with GraphQL query', async () => {
|
|
50
|
+
await GraphQLQuery((0, client_1.gql)(testUtil_1.e2eReadFile), testUtil_1.expectedFileContentResponse);
|
|
51
|
+
}, 10000);
|
|
52
|
+
});
|
|
53
|
+
//# sourceMappingURL=app.e2e.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.e2e.spec.js","sourceRoot":"","sources":["../../../test/e2e/app.e2e.spec.ts"],"names":[],"mappings":";;AAAA,6CAAsD;AAEtD,qCAAqC;AACrC,6CAAgC;AAChC,2CAMwB;AACxB,qDAA6C;AAC7C,0CAKqB;AAErB,MAAM,MAAM,GAAG,IAAI,qBAAY,CAAC;IAC9B,IAAI,EAAE,IAAI,iBAAQ,CAAC;QACjB,GAAG,EAAE,oBAAoB,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE;QACrE,KAAK,EAAL,qBAAK;KACN,CAAC;IACF,KAAK,EAAE,IAA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QAC/C,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC7C,CAAC;IACD,EAAE,CAAC,qEAAqE,EAAE,KAAK,IAAI,EAAE;QACnF,MAAM,SAAS,CAAC,2BAAgB,EAAE,wCAA6B,CAAC,CAAC;IACnE,CAAC,EAAE,KAAK,CAAC,CAAC;IAEV,EAAE,CAAC,+DAA+D,EAAE,KAAK,IAAI,EAAE;QAC7E,MAAM,SAAS,CAAC,sBAAW,EAAE,sCAA2B,CAAC,CAAC;IAC5D,CAAC,EAAE,KAAK,CAAC,CAAC;IAEV,EAAE,CAAC,mEAAmE,EAAE,KAAK,IAAI,EAAE;QACjF,MAAM,YAAY,CAAC,IAAA,YAAG,EAAC,2BAAgB,CAAC,EAAE,wCAA6B,CAAC,CAAC;IAC3E,CAAC,EAAE,KAAK,CAAC,CAAC;IAEV,EAAE,CAAC,6DAA6D,EAAE,KAAK,IAAI,EAAE;QAC3E,MAAM,YAAY,CAAC,IAAA,YAAG,EAAC,sBAAW,CAAC,EAAE,sCAA2B,CAAC,CAAC;IACpE,CAAC,EAAE,KAAK,CAAC,CAAC;AACZ,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const testing_1 = require("@nestjs/testing");
|
|
4
|
+
const config_1 = require("@nestjs/config");
|
|
5
|
+
const files_resolver_1 = require("../../src/files/resolvers/files.resolver");
|
|
6
|
+
const files_service_factory_1 = require("../../src/files/services/files-service.factory");
|
|
7
|
+
const local_files_service_1 = require("../../src/files/services/local-files.service");
|
|
8
|
+
const testUtil_1 = require("../testUtil");
|
|
9
|
+
describe('Integration tests for FilesResolver', () => {
|
|
10
|
+
let filesResolver;
|
|
11
|
+
let mockConfigService;
|
|
12
|
+
beforeEach(async () => {
|
|
13
|
+
mockConfigService = new testUtil_1.MockConfigService();
|
|
14
|
+
const module = await testing_1.Test.createTestingModule({
|
|
15
|
+
providers: [
|
|
16
|
+
files_resolver_1.default,
|
|
17
|
+
files_service_factory_1.default,
|
|
18
|
+
local_files_service_1.default,
|
|
19
|
+
{ provide: config_1.ConfigService, useClass: testUtil_1.MockConfigService },
|
|
20
|
+
],
|
|
21
|
+
}).compile();
|
|
22
|
+
filesResolver = module.get(files_resolver_1.default);
|
|
23
|
+
});
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
jest.clearAllMocks();
|
|
26
|
+
});
|
|
27
|
+
const modes = ['local'];
|
|
28
|
+
for (const mode of modes) {
|
|
29
|
+
describe(`when MODE is ${mode}`, () => {
|
|
30
|
+
beforeEach(() => {
|
|
31
|
+
jest.spyOn(mockConfigService, 'get').mockReturnValue(mode);
|
|
32
|
+
});
|
|
33
|
+
it('should be defined', () => {
|
|
34
|
+
expect(filesResolver).toBeDefined();
|
|
35
|
+
});
|
|
36
|
+
describe('listDirectory', () => {
|
|
37
|
+
it('should list files', async () => {
|
|
38
|
+
const files = await filesResolver.listDirectory(testUtil_1.pathToTestDirectory);
|
|
39
|
+
expect(files).toEqual(testUtil_1.testDirectory);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
describe('readFile', () => {
|
|
43
|
+
it('should read file', async () => {
|
|
44
|
+
const content = await filesResolver.readFile(testUtil_1.pathToTestFileContent);
|
|
45
|
+
expect(content).toEqual(testUtil_1.testFileContent);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
//# sourceMappingURL=files.service.integration.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.service.integration.spec.js","sourceRoot":"","sources":["../../../test/integration/files.service.integration.spec.ts"],"names":[],"mappings":";;AAAA,6CAAsD;AACtD,2CAA+C;AAC/C,6EAAqE;AACrE,0FAAiF;AACjF,sF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AK,CAAC,CAAC,OAAO,CAAC,wBAAa,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,gCAAqB,CAAC,CAAC;oBACpE,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,0BAAe,CAAC,CAAC;gBAC3C,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
export declare const readFileActualContent: string[];
|
|
2
|
+
export declare const pathToTestDirectory = 'user2';
|
|
3
|
+
export declare const testDirectory: {
|
|
4
|
+
repository: {
|
|
5
|
+
tree: {
|
|
6
|
+
blobs: {
|
|
7
|
+
edges: any[];
|
|
8
|
+
};
|
|
9
|
+
trees: {
|
|
10
|
+
edges: {
|
|
11
|
+
node: {
|
|
12
|
+
name: string;
|
|
13
|
+
type: string;
|
|
14
|
+
};
|
|
15
|
+
}[];
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export declare const testFileName = 'README.md';
|
|
21
|
+
export declare const fstestFileContent = 'content123';
|
|
22
|
+
export declare const pathToTestFileContent = 'user2/tools/README.md';
|
|
23
|
+
export declare const testFileArray: string[];
|
|
24
|
+
export declare const testFileContent: {
|
|
25
|
+
repository: {
|
|
26
|
+
blobs: {
|
|
27
|
+
nodes: {
|
|
28
|
+
name: string;
|
|
29
|
+
rawBlob: string;
|
|
30
|
+
rawTextBlob: string;
|
|
31
|
+
}[];
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
export declare function sleep(ms: any): void;
|
|
36
|
+
export declare class MockConfigService {
|
|
37
|
+
get(key: string): string;
|
|
38
|
+
}
|
|
39
|
+
export declare const mockReadFileResponseData: {
|
|
40
|
+
project: {
|
|
41
|
+
__typename: string;
|
|
42
|
+
repository: {
|
|
43
|
+
__typename: string;
|
|
44
|
+
blobs: {
|
|
45
|
+
nodes: {
|
|
46
|
+
__typename: string;
|
|
47
|
+
name: string;
|
|
48
|
+
rawBlob: string;
|
|
49
|
+
rawTextBlob: string;
|
|
50
|
+
}[];
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
export declare const expectedListDirectoryResponse: {
|
|
56
|
+
data: {
|
|
57
|
+
listDirectory: {
|
|
58
|
+
repository: {
|
|
59
|
+
tree: {
|
|
60
|
+
trees: {
|
|
61
|
+
edges: {
|
|
62
|
+
node: {
|
|
63
|
+
name: string;
|
|
64
|
+
};
|
|
65
|
+
}[];
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
export declare const expectedFileContentResponse: {
|
|
73
|
+
data: {
|
|
74
|
+
readFile: {
|
|
75
|
+
repository: {
|
|
76
|
+
blobs: {
|
|
77
|
+
nodes: {
|
|
78
|
+
name: string;
|
|
79
|
+
rawBlob: string;
|
|
80
|
+
rawTextBlob: string;
|
|
81
|
+
}[];
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
export declare const e2elistDirectory =
|
|
88
|
+
'query {\n listDirectory(path:"user2")\n {\n repository{\n tree{\n trees{\n edges{\n node{\n name\n \n }\n }\n }\n }\n }\n }\n}';
|
|
89
|
+
export declare const e2eReadFile =
|
|
90
|
+
'query {\n readFile(path:"user2/tools/README.md") {\n repository {\n blobs {\n nodes {\n name\n rawBlob\n rawTextBlob\n }\n }\n }\n }\n}';
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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");
|
|
6
|
+
dotenv.config({ path: '.env' });
|
|
7
|
+
exports.readFileActualContent = ['content123'];
|
|
8
|
+
exports.pathToTestDirectory = 'user2';
|
|
9
|
+
exports.testDirectory = {
|
|
10
|
+
repository: {
|
|
11
|
+
tree: {
|
|
12
|
+
blobs: { edges: [] },
|
|
13
|
+
trees: {
|
|
14
|
+
edges: [
|
|
15
|
+
{ node: { name: 'data', type: 'tree' } },
|
|
16
|
+
{ node: { name: 'digital_twins', type: 'tree' } },
|
|
17
|
+
{ node: { name: 'functions', type: 'tree' } },
|
|
18
|
+
{ node: { name: 'models', type: 'tree' } },
|
|
19
|
+
{ node: { name: 'tools', type: 'tree' } },
|
|
20
|
+
],
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
exports.testFileName = 'README.md';
|
|
26
|
+
exports.fstestFileContent = 'content123';
|
|
27
|
+
exports.pathToTestFileContent = 'user2/tools/README.md';
|
|
28
|
+
exports.testFileArray = [
|
|
29
|
+
'data',
|
|
30
|
+
'digital_twins',
|
|
31
|
+
'functions',
|
|
32
|
+
'models',
|
|
33
|
+
'tools',
|
|
34
|
+
];
|
|
35
|
+
exports.testFileContent = {
|
|
36
|
+
repository: {
|
|
37
|
+
blobs: {
|
|
38
|
+
nodes: [
|
|
39
|
+
{
|
|
40
|
+
name: 'README.md',
|
|
41
|
+
rawBlob: 'content123',
|
|
42
|
+
rawTextBlob: 'content123',
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
function sleep(ms) {
|
|
49
|
+
const timer = (0, promises_1.setTimeout)(ms);
|
|
50
|
+
Promise.resolve(timer);
|
|
51
|
+
}
|
|
52
|
+
exports.sleep = sleep;
|
|
53
|
+
class MockConfigService {
|
|
54
|
+
get(key) {
|
|
55
|
+
switch (key) {
|
|
56
|
+
case 'LOCAL_PATH':
|
|
57
|
+
return process.env.LOCAL_PATH;
|
|
58
|
+
case 'MODE':
|
|
59
|
+
if (process.env.MODE === 'local') {
|
|
60
|
+
return 'local';
|
|
61
|
+
}
|
|
62
|
+
return 'unknown';
|
|
63
|
+
default:
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.MockConfigService = MockConfigService;
|
|
69
|
+
exports.mockReadFileResponseData = {
|
|
70
|
+
project: {
|
|
71
|
+
__typename: 'Project',
|
|
72
|
+
repository: {
|
|
73
|
+
__typename: 'Repository',
|
|
74
|
+
blobs: {
|
|
75
|
+
nodes: [
|
|
76
|
+
{
|
|
77
|
+
__typename: 'Blob',
|
|
78
|
+
name: 'README.md',
|
|
79
|
+
rawBlob: 'content123',
|
|
80
|
+
rawTextBlob: 'content123',
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
exports.expectedListDirectoryResponse = {
|
|
88
|
+
data: {
|
|
89
|
+
listDirectory: {
|
|
90
|
+
repository: {
|
|
91
|
+
tree: {
|
|
92
|
+
trees: {
|
|
93
|
+
edges: [
|
|
94
|
+
{
|
|
95
|
+
node: {
|
|
96
|
+
name: 'data',
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
node: {
|
|
101
|
+
name: 'digital_twins',
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
node: {
|
|
106
|
+
name: 'functions',
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
node: {
|
|
111
|
+
name: 'models',
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
node: {
|
|
116
|
+
name: 'tools',
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
exports.expectedFileContentResponse = {
|
|
127
|
+
data: {
|
|
128
|
+
readFile: {
|
|
129
|
+
repository: {
|
|
130
|
+
blobs: {
|
|
131
|
+
nodes: [
|
|
132
|
+
{
|
|
133
|
+
name: 'README.md',
|
|
134
|
+
rawBlob: 'content123',
|
|
135
|
+
rawTextBlob: 'content123',
|
|
136
|
+
},
|
|
137
|
+
],
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
exports.e2elistDirectory = `query {
|
|
144
|
+
listDirectory(path:"user2")
|
|
145
|
+
{
|
|
146
|
+
repository{
|
|
147
|
+
tree{
|
|
148
|
+
trees{
|
|
149
|
+
edges{
|
|
150
|
+
node{
|
|
151
|
+
name
|
|
152
|
+
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}`;
|
|
160
|
+
exports.e2eReadFile = `query {
|
|
161
|
+
readFile(path:"user2/tools/README.md") {
|
|
162
|
+
repository {
|
|
163
|
+
blobs {
|
|
164
|
+
nodes {
|
|
165
|
+
name
|
|
166
|
+
rawBlob
|
|
167
|
+
rawTextBlob
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}`;
|
|
173
|
+
//# sourceMappingURL=testUtil.js.map
|
|
@@ -0,0 +1 @@
|
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,QAAQ;iCACf;6BACF;4BACD;gCACE,IAAI,EAAE;oCACJ,IAAI,EAAE,OAAO;iCACd;6BACF;yBACF;qBACF;iBACF;aACF;SACF;KACF;CACF,CAAC;AAEW,QAAA,2BAA2B,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;AAEW,QAAA,gBAAgB,GAAG;;;;;;;;;;;;;;;;EAgB9B,CAAC;AAEU,QAAA,WAAW,GAAG;;;;;;;;;;;;EAYzB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const testing_1 = require("@nestjs/testing");
|
|
4
|
+
const config_1 = require("@nestjs/config");
|
|
5
|
+
const files_service_factory_1 = require("../../src/files/services/files-service.factory");
|
|
6
|
+
const local_files_service_1 = require("../../src/files/services/local-files.service");
|
|
7
|
+
describe('FilesServiceFactory', () => {
|
|
8
|
+
let serviceFactory;
|
|
9
|
+
let configService;
|
|
10
|
+
let localFilesService;
|
|
11
|
+
beforeEach(async () => {
|
|
12
|
+
localFilesService = new local_files_service_1.default(configService);
|
|
13
|
+
const module = await testing_1.Test.createTestingModule({
|
|
14
|
+
providers: [
|
|
15
|
+
files_service_factory_1.default,
|
|
16
|
+
{ provide: config_1.ConfigService, useValue: { get: jest.fn() } },
|
|
17
|
+
{ provide: local_files_service_1.default, useValue: localFilesService },
|
|
18
|
+
],
|
|
19
|
+
}).compile();
|
|
20
|
+
serviceFactory = module.get(files_service_factory_1.default);
|
|
21
|
+
configService = module.get(config_1.ConfigService);
|
|
22
|
+
});
|
|
23
|
+
it('should create a local files service when MODE is local', () => {
|
|
24
|
+
jest.spyOn(configService, 'get').mockReturnValue('local');
|
|
25
|
+
expect(serviceFactory.create()).toBe(localFilesService);
|
|
26
|
+
});
|
|
27
|
+
it('should throw an error when MODE is invalid', () => {
|
|
28
|
+
jest.spyOn(configService, 'get').mockReturnValue('invalid');
|
|
29
|
+
expect(() => serviceFactory.create()).toThrowError(`Invalid MODE: invalid`);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
//# sourceMappingURL=files-service.factory.unit.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files-service.factory.unit.spec.js","sourceRoot":"","sources":["../../../test/unit/files-service.factory.unit.spec.ts"],"names":[],"mappings":";;AACA,6CAAsD;AACtD,2CAA+C;AAC/C,0FAAiF;AACjF,sFAA6E;AAG7E,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,IAAI,cAAmC,CAAC;IACxC,IAAI,aAA4B,CAAC;IACjC,IAAI,iBAAgC,CAAC;IAErC,UAAU,CAAC,KAAK,IAAI,EAAE;QACpB,iBAAiB,GAAG,IAAI,6BAAiB,CAAC,aAA8B,CAAC,CAAC;QAE1E,MAAM,MAAM,GAAkB,MAAM,cAAI,CAAC,mBAAmB,CAAC;YAC3D,SAAS,EAAE;gBACT,+BAAmB;gBACnB,EAAE,OAAO,EAAE,sBAAa,EAAE,QAAQ,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE,EAAE,EAAE;gBACxD,EAAE,OAAO,EAAE,6BAAiB,EAAE,QAAQ,EAAE,iBAAiB,EAAE;aAC5D;SACF,CAAC,CAAC,OAAO,EAAE,CAAC;QAEb,cAAc,GAAG,MAAM,CAAC,GAAG,CAAsB,+BAAmB,CAAC,CAAC;QACtE,aAAa,GAAG,MAAM,CAAC,GAAG,CAAgB,sBAAa,CAAC,CAAC;IAC3D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,wDAAwD,EAAE,GAAG,EAAE;QAChE,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;QAC1D,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,4CAA4C,EAAE,GAAG,EAAE;QACpD,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;QAC5D,MAAM,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,MAAM,EAAE,CAAC,CAAC,YAAY,CAAC,uBAAuB,CAAC,CAAC;IAC9E,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const testing_1 = require("@nestjs/testing");
|
|
4
|
+
const files_resolver_1 = require("../../src/files/resolvers/files.resolver");
|
|
5
|
+
const testUtil_1 = require("../testUtil");
|
|
6
|
+
const files_service_factory_1 = require("../../src/files/services/files-service.factory");
|
|
7
|
+
describe('Unit tests for FilesResolver', () => {
|
|
8
|
+
let filesResolver;
|
|
9
|
+
let filesService;
|
|
10
|
+
beforeEach(async () => {
|
|
11
|
+
const mockFilesService = {
|
|
12
|
+
listDirectory: jest.fn().mockImplementation(() => testUtil_1.testDirectory),
|
|
13
|
+
readFile: jest.fn().mockImplementation(() => testUtil_1.testFileContent),
|
|
14
|
+
};
|
|
15
|
+
const module = await testing_1.Test.createTestingModule({
|
|
16
|
+
providers: [
|
|
17
|
+
files_resolver_1.default,
|
|
18
|
+
files_service_factory_1.default,
|
|
19
|
+
{
|
|
20
|
+
provide: files_service_factory_1.default,
|
|
21
|
+
useValue: {
|
|
22
|
+
create: () => mockFilesService,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
}).compile();
|
|
27
|
+
filesResolver = module.get(files_resolver_1.default);
|
|
28
|
+
filesService = module
|
|
29
|
+
.get(files_service_factory_1.default)
|
|
30
|
+
.create();
|
|
31
|
+
});
|
|
32
|
+
it('should be defined', () => {
|
|
33
|
+
expect(filesResolver).toBeDefined();
|
|
34
|
+
});
|
|
35
|
+
describe('listDirectory', () => {
|
|
36
|
+
it('should be defined', () => {
|
|
37
|
+
expect(filesResolver.listDirectory).toBeDefined();
|
|
38
|
+
});
|
|
39
|
+
it('should list files in directory', async () => {
|
|
40
|
+
const result = await filesResolver.listDirectory(testUtil_1.pathToTestDirectory);
|
|
41
|
+
expect(result).toEqual(testUtil_1.testDirectory);
|
|
42
|
+
expect(filesService.listDirectory).toHaveBeenCalledWith(testUtil_1.pathToTestDirectory);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
describe('readFile', () => {
|
|
46
|
+
it('should be defined', () => {
|
|
47
|
+
expect(filesResolver.readFile).toBeDefined();
|
|
48
|
+
});
|
|
49
|
+
it('should read file', async () => {
|
|
50
|
+
const result = await filesResolver.readFile(testUtil_1.pathToTestFileContent);
|
|
51
|
+
expect(result).toEqual(testUtil_1.testFileContent);
|
|
52
|
+
expect(filesService.readFile).toHaveBeenCalledWith(testUtil_1.pathToTestFileContent);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
//# sourceMappingURL=files.resolver.unit.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.resolver.unit.spec.js","sourceRoot":"","sources":["../../../test/unit/files.resolver.unit.spec.ts"],"names":[],"mappings":";;AAAA,6CAAsD;AACtD,6EAAqE;AACrE,0CAKqB;AAErB,0FAAiF;AAEjF,QAAQ,CAAC,8BAA8B,EAAE,GAAG,EAAE;IAC5C,IAAI,aAA4B,CAAC;IACjC,IAAI,YAA2B,CAAC;I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,CAAC,oBAAoB,CACrD,8BAAmB,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,gCAAqB,CAAC,CAAC;YACnE,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,0BAAe,CAAC,CAAC;YACxC,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,oBAAoB,CAAC,gCAAqB,CAAC,CAAC;QAC5E,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const testing_1 = require("@nestjs/testing");
|
|
4
|
+
const config_1 = require("@nestjs/config");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const local_files_service_1 = require("../../src/files/services/local-files.service");
|
|
8
|
+
const testUtil_1 = require("../testUtil");
|
|
9
|
+
jest.mock('fs', () => ({
|
|
10
|
+
promises: {
|
|
11
|
+
readdir: jest.fn(),
|
|
12
|
+
lstat: jest.fn(),
|
|
13
|
+
readFile: jest.fn(),
|
|
14
|
+
},
|
|
15
|
+
}));
|
|
16
|
+
describe('LocalFilesService', () => {
|
|
17
|
+
let service;
|
|
18
|
+
const mockConfigService = new testUtil_1.MockConfigService();
|
|
19
|
+
beforeEach(async () => {
|
|
20
|
+
const module = await testing_1.Test.createTestingModule({
|
|
21
|
+
providers: [
|
|
22
|
+
local_files_service_1.default,
|
|
23
|
+
{ provide: config_1.ConfigService, useValue: mockConfigService },
|
|
24
|
+
],
|
|
25
|
+
}).compile();
|
|
26
|
+
service = module.get(local_files_service_1.default);
|
|
27
|
+
});
|
|
28
|
+
afterEach(() => {
|
|
29
|
+
jest.resetAllMocks();
|
|
30
|
+
});
|
|
31
|
+
it('should be defined', () => {
|
|
32
|
+
expect(service).toBeDefined();
|
|
33
|
+
});
|
|
34
|
+
it('should list directory', async () => {
|
|
35
|
+
const fullPath = (0, path_1.join)(mockConfigService.get('LOCAL_PATH'), testUtil_1.pathToTestDirectory);
|
|
36
|
+
const statsMock = {
|
|
37
|
+
isDirectory: () => true,
|
|
38
|
+
};
|
|
39
|
+
jest
|
|
40
|
+
.spyOn(fs.promises, 'readdir')
|
|
41
|
+
.mockResolvedValue(testUtil_1.testFileArray);
|
|
42
|
+
jest.spyOn(fs.promises, 'lstat').mockImplementation((pathToDirectory) => {
|
|
43
|
+
if (typeof pathToDirectory === 'string') {
|
|
44
|
+
return Promise.resolve(statsMock);
|
|
45
|
+
}
|
|
46
|
+
throw new Error(`Invalid argument: ${pathToDirectory}`);
|
|
47
|
+
});
|
|
48
|
+
const result = await service.listDirectory(testUtil_1.pathToTestDirectory);
|
|
49
|
+
expect(result).toEqual({
|
|
50
|
+
repository: {
|
|
51
|
+
tree: {
|
|
52
|
+
trees: {
|
|
53
|
+
edges: testUtil_1.testFileArray.map((file) => ({
|
|
54
|
+
node: { name: file, type: 'tree' },
|
|
55
|
+
})),
|
|
56
|
+
},
|
|
57
|
+
blobs: { edges: [] },
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
expect(fs.promises.readdir).toHaveBeenCalledWith(fullPath);
|
|
62
|
+
expect(fs.promises.lstat).toHaveBeenCalledTimes(testUtil_1.testFileArray.length);
|
|
63
|
+
});
|
|
64
|
+
it('should read file', async () => {
|
|
65
|
+
const fullPath = (0, path_1.join)(mockConfigService.get('LOCAL_PATH'), testUtil_1.pathToTestFileContent);
|
|
66
|
+
jest.spyOn(fs.promises, 'readFile').mockResolvedValue(testUtil_1.fstestFileContent);
|
|
67
|
+
const result = await service.readFile(testUtil_1.pathToTestFileContent);
|
|
68
|
+
expect(result).toEqual({
|
|
69
|
+
repository: {
|
|
70
|
+
blobs: {
|
|
71
|
+
nodes: [
|
|
72
|
+
{
|
|
73
|
+
name: testUtil_1.testFileName,
|
|
74
|
+
rawBlob: testUtil_1.fstestFileContent,
|
|
75
|
+
rawTextBlob: testUtil_1.fstestFileContent,
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
expect(fs.promises.readFile).toHaveBeenCalledWith(fullPath, 'utf8');
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
//# sourceMappingURL=local-files.service.unit.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-files.service.unit.spec.js","sourceRoot":"","sources":["../../../test/unit/local-files.service.unit.spec.ts"],"names":[],"mappings":";;AAAA,6CAAsD;AACtD,2CAA+C;AAC/C,yBAAyB;AACzB,+BAA4B;AAC5B,sFAA6E;AAC7E,0CAOqB;AAErB,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;IACrB,QAAQ,EAAE;QACR,OAAO,EAAE,IAAI,CAAC,EAAE,EAAE;QAClB,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE;QAChB,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE;KACpB;CACF,CAAC,CAAC,CAAC;AAEJ,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IACjC,IAAI,OAA0B,CAAC;IAC/B,MAAM,iBAAiB,GAAG,IAAI,4BAAiB,EAAE,CAAC;IAElD,UAAU,CAAC,KAAK,IAAI,EAAE;QACpB,MAAM,MAAM,GAAkB,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