diff --git a/servers/lib/src/app.module.ts b/servers/lib/src/app.module.ts index f4dd7531b..4a6893e3f 100644 --- a/servers/lib/src/app.module.ts +++ b/servers/lib/src/app.module.ts @@ -8,17 +8,17 @@ import FilesModule from './files/files.module'; @Module({ imports: [ ConfigModule.forRoot({ - isGlobal: true + isGlobal: true, }), GraphQLModule.forRootAsync({ driver: ApolloDriver, useFactory: (configService: ConfigService) => ({ autoSchemaFile: join(process.cwd(), 'src/schema.gql'), - path: configService.get('APOLLO_PATH') + path: configService.get('APOLLO_PATH'), }), - inject: [ConfigService] + inject: [ConfigService], }), FilesModule, - ] + ], }) export default class AppModule {} diff --git a/servers/lib/src/bootstrap.ts b/servers/lib/src/bootstrap.ts index 0be8defc7..3924622be 100644 --- a/servers/lib/src/bootstrap.ts +++ b/servers/lib/src/bootstrap.ts @@ -4,9 +4,9 @@ import * as dotenv from 'dotenv'; import AppModule from './app.module'; type BootstrapOptions = { - config?: string - runHelp?: CallableFunction -} + config?: string; + runHelp?: CallableFunction; +}; export default async function bootstrap(options?: BootstrapOptions) { const configFile = dotenv.config({ @@ -17,9 +17,9 @@ export default async function bootstrap(options?: BootstrapOptions) { // eslint-disable-next-line no-console console.error(configFile.error); if (options.runHelp) { - options.runHelp() + options.runHelp(); } else { - process.exit(1) + process.exit(1); } } const app = await NestFactory.create(AppModule); diff --git a/servers/lib/src/files/services/files-service.factory.ts b/servers/lib/src/files/services/files-service.factory.ts index 7c6569816..72147e8e6 100644 --- a/servers/lib/src/files/services/files-service.factory.ts +++ b/servers/lib/src/files/services/files-service.factory.ts @@ -10,7 +10,7 @@ export default class FilesServiceFactory { constructor( private configService: ConfigService, @Inject(GitlabFilesService) private gitlabFilesService: GitlabFilesService, - @Inject(LocalFilesService) private localFilesService: LocalFilesService + @Inject(LocalFilesService) private localFilesService: LocalFilesService, ) {} /* eslint-enable no-useless-constructor, no-empty-function */ diff --git a/servers/lib/src/files/services/gitlab-files.service.ts b/servers/lib/src/files/services/gitlab-files.service.ts index b30c83cb3..590889aa8 100644 --- a/servers/lib/src/files/services/gitlab-files.service.ts +++ b/servers/lib/src/files/services/gitlab-files.service.ts @@ -21,7 +21,7 @@ export default class GitlabFilesService implements IFilesService { } private async parseArguments( - path: string + path: string, ): Promise<{ domain: string; parsedPath: string }> { const gitlabGroup = this.configService.get('GITLAB_GROUP'); const pathParts: string[] = path.split('/'); @@ -56,7 +56,7 @@ export default class GitlabFilesService implements IFilesService { private async executeQuery( path: string, - getQuery: QueryFunction + getQuery: QueryFunction, ): Promise { const { domain, parsedPath } = await this.parseArguments(path); const query = getQuery(domain, parsedPath); diff --git a/servers/lib/test/e2e/app.e2e.spec.ts b/servers/lib/test/e2e/app.e2e.spec.ts index ce9c7c40e..75517c93f 100644 --- a/servers/lib/test/e2e/app.e2e.spec.ts +++ b/servers/lib/test/e2e/app.e2e.spec.ts @@ -1,16 +1,16 @@ -import { Test, TestingModule } from "@nestjs/testing"; -import { INestApplication } from "@nestjs/common"; -import * as request from "supertest"; +import { Test, TestingModule } from '@nestjs/testing'; +import { INestApplication } from '@nestjs/common'; +import * as request from 'supertest'; // import { execSync } from "child_process"; -import AppModule from "../../src/app.module"; +import AppModule from '../../src/app.module'; import { e2eReadFile, e2elistDirectory, expectedFileContentResponse, expectedListDirectoryResponse, -} from "../testUtil"; +} from '../testUtil'; -describe("End to End test for the application", () => { +describe('End to End test for the application', () => { let app: INestApplication; beforeAll(async () => { @@ -32,19 +32,19 @@ describe("End to End test for the application", () => { await app.close(); }, 10000); - it("should return the filename corresponding to the directory given in the query", async () => { + it('should return the filename corresponding to the directory given in the query', async () => { const query = e2elistDirectory; - const response = await request("http://localhost:4001") + const response = await request('http://localhost:4001') .post(process.env.APOLLO_PATH) .send({ query }); expect(response.body).toEqual(expectedListDirectoryResponse); }, 10000); - it("should return the content of a file given in the query ", async () => { + it('should return the content of a file given in the query ', async () => { const query = e2eReadFile; - const response = await request("http://localhost:4001") + const response = await request('http://localhost:4001') .post(process.env.APOLLO_PATH) .send({ query }); expect(response.body).toEqual(expectedFileContentResponse); diff --git a/servers/lib/test/integration/files.service.integration.spec.ts b/servers/lib/test/integration/files.service.integration.spec.ts index 82881ecac..d174eea19 100644 --- a/servers/lib/test/integration/files.service.integration.spec.ts +++ b/servers/lib/test/integration/files.service.integration.spec.ts @@ -1,18 +1,18 @@ -import { Test, TestingModule } from "@nestjs/testing"; -import { ConfigService } from "@nestjs/config"; -import FilesResolver from "../../src/files/resolvers/files.resolver"; -import FilesServiceFactory from "../../src/files/services/files-service.factory"; -import LocalFilesService from "../../src/files/services/local-files.service"; -import GitlabFilesService from "../../src/files/services/gitlab-files.service"; +import { Test, TestingModule } from '@nestjs/testing'; +import { ConfigService } from '@nestjs/config'; +import FilesResolver from '../../src/files/resolvers/files.resolver'; +import FilesServiceFactory from '../../src/files/services/files-service.factory'; +import LocalFilesService from '../../src/files/services/local-files.service'; +import GitlabFilesService from '../../src/files/services/gitlab-files.service'; import { pathToTestDirectory, pathToTestFileContent, testDirectory, testFileContent, MockConfigService, -} from "../testUtil"; +} from '../testUtil'; -describe("Integration tests for FilesResolver", () => { +describe('Integration tests for FilesResolver', () => { let filesResolver: FilesResolver; let mockConfigService: MockConfigService; @@ -35,29 +35,29 @@ describe("Integration tests for FilesResolver", () => { jest.clearAllMocks(); }); - const modes = ["local", "gitlab"]; + const modes = ['local', 'gitlab']; // eslint-disable-next-line no-restricted-syntax for (const mode of modes) { // eslint-disable-next-line no-loop-func describe(`when MODE is ${mode}`, () => { beforeEach(() => { - jest.spyOn(mockConfigService, "get").mockReturnValue(mode); + jest.spyOn(mockConfigService, 'get').mockReturnValue(mode); }); - it("should be defined", () => { + it('should be defined', () => { expect(filesResolver).toBeDefined(); }); - describe("listDirectory", () => { - it("should list files", async () => { + describe('listDirectory', () => { + it('should list files', async () => { const files = await filesResolver.listDirectory(pathToTestDirectory); expect(files).toEqual(testDirectory); }); }); - describe("readFile", () => { - it("should read file", async () => { + describe('readFile', () => { + it('should read file', async () => { const content = await filesResolver.readFile(pathToTestFileContent); expect(content).toEqual(testFileContent); }); diff --git a/servers/lib/test/testUtil.ts b/servers/lib/test/testUtil.ts index b3b65f305..4376f2aec 100644 --- a/servers/lib/test/testUtil.ts +++ b/servers/lib/test/testUtil.ts @@ -1,12 +1,12 @@ -import * as dotenv from "dotenv"; -import { setTimeout } from "timers/promises"; +import * as dotenv from 'dotenv'; +import { setTimeout } from 'timers/promises'; -dotenv.config({ path: ".env" }); +dotenv.config({ path: '.env' }); // actual data for integration and e2e tests -export const readFileActualContent = ["content123"]; +export const readFileActualContent = ['content123']; -export const pathToTestDirectory = "user2"; +export const pathToTestDirectory = 'user2'; export const testDirectory = { repository: { @@ -14,34 +14,34 @@ export const testDirectory = { blobs: { edges: [] }, trees: { edges: [ - { node: { name: "data", type: "tree" } }, - { node: { name: "digital_twins", type: "tree" } }, - { node: { name: "functions", type: "tree" } }, - { node: { name: "models", type: "tree" } }, - { node: { name: "tools", type: "tree" } }, + { node: { name: 'data', type: 'tree' } }, + { node: { name: 'digital_twins', type: 'tree' } }, + { node: { name: 'functions', type: 'tree' } }, + { node: { name: 'models', type: 'tree' } }, + { node: { name: 'tools', type: 'tree' } }, ], }, }, }, }; -export const testFileName = "README.md"; -export const fstestFileContent = "content123"; -export const pathToTestFileContent = "user2/tools/README.md"; +export const testFileName = 'README.md'; +export const fstestFileContent = 'content123'; +export const pathToTestFileContent = 'user2/tools/README.md'; export const testFileArray = [ - "data", - "digital_twins", - "functions", - "models", - "tools", + 'data', + 'digital_twins', + 'functions', + 'models', + 'tools', ]; export const testFileContent = { repository: { blobs: { nodes: [ { - name: "README.md", - rawBlob: "content123", - rawTextBlob: "content123", + name: 'README.md', + rawBlob: 'content123', + rawTextBlob: 'content123', }, ], }, @@ -57,22 +57,22 @@ export class MockConfigService { // eslint-disable-next-line class-methods-use-this get(key: string): string { switch (key) { - case "TOKEN": + case 'TOKEN': return process.env.TOKEN; - case "LOCAL_PATH": + case 'LOCAL_PATH': return process.env.TEST_PATH; - case "GITLAB_URL": + case 'GITLAB_URL': return process.env.GITLAB_URL; - case "GITLAB_GROUP": - return "dtaas"; - case "MODE": - if (process.env.MODE === "gitlab") { - return "gitlab"; + case 'GITLAB_GROUP': + return 'dtaas'; + case 'MODE': + if (process.env.MODE === 'gitlab') { + return 'gitlab'; } - if (process.env.MODE === "local") { - return "local"; + if (process.env.MODE === 'local') { + return 'local'; } - return "unknown"; + return 'unknown'; default: return undefined; @@ -82,16 +82,16 @@ export class MockConfigService { export const mockReadFileResponseData = { project: { - __typename: "Project", + __typename: 'Project', repository: { - __typename: "Repository", + __typename: 'Repository', blobs: { nodes: [ { - __typename: "Blob", - name: "README.md", - rawBlob: "content123", - rawTextBlob: "content123", + __typename: 'Blob', + name: 'README.md', + rawBlob: 'content123', + rawTextBlob: 'content123', }, ], }, @@ -108,27 +108,27 @@ export const expectedListDirectoryResponse = { edges: [ { node: { - name: "data", + name: 'data', }, }, { node: { - name: "digital_twins", + name: 'digital_twins', }, }, { node: { - name: "functions", + name: 'functions', }, }, { node: { - name: "models", + name: 'models', }, }, { node: { - name: "tools", + name: 'tools', }, }, ], @@ -146,9 +146,9 @@ export const expectedFileContentResponse = { blobs: { nodes: [ { - name: "README.md", - rawBlob: "content123", - rawTextBlob: "content123", + name: 'README.md', + rawBlob: 'content123', + rawTextBlob: 'content123', }, ], }, diff --git a/servers/lib/test/unit/files-service.factory.unit.spec.ts b/servers/lib/test/unit/files-service.factory.unit.spec.ts index a5751fdb7..7759f9818 100644 --- a/servers/lib/test/unit/files-service.factory.unit.spec.ts +++ b/servers/lib/test/unit/files-service.factory.unit.spec.ts @@ -1,12 +1,12 @@ // files-service.factory.spec.ts -import { Test, TestingModule } from "@nestjs/testing"; -import { ConfigService } from "@nestjs/config"; -import FilesServiceFactory from "../../src/files/services/files-service.factory"; -import LocalFilesService from "../../src/files/services/local-files.service"; -import GitlabFilesService from "../../src/files/services/gitlab-files.service"; -import { IFilesService } from "../../src/files/interfaces/files.service.interface"; +import { Test, TestingModule } from '@nestjs/testing'; +import { ConfigService } from '@nestjs/config'; +import FilesServiceFactory from '../../src/files/services/files-service.factory'; +import LocalFilesService from '../../src/files/services/local-files.service'; +import GitlabFilesService from '../../src/files/services/gitlab-files.service'; +import { IFilesService } from '../../src/files/interfaces/files.service.interface'; -describe("FilesServiceFactory", () => { +describe('FilesServiceFactory', () => { let serviceFactory: FilesServiceFactory; let configService: ConfigService; let localFilesService: IFilesService; @@ -29,18 +29,18 @@ describe("FilesServiceFactory", () => { configService = module.get(ConfigService); }); - it("should create a local files service when MODE is local", () => { - jest.spyOn(configService, "get").mockReturnValue("local"); + it('should create a local files service when MODE is local', () => { + jest.spyOn(configService, 'get').mockReturnValue('local'); expect(serviceFactory.create()).toBe(localFilesService); }); - it("should create a gitlab files service when MODE is gitlab", () => { - jest.spyOn(configService, "get").mockReturnValue("gitlab"); + it('should create a gitlab files service when MODE is gitlab', () => { + jest.spyOn(configService, 'get').mockReturnValue('gitlab'); expect(serviceFactory.create()).toBe(gitlabFilesService); }); - it("should throw an error when MODE is invalid", () => { - jest.spyOn(configService, "get").mockReturnValue("invalid"); + it('should throw an error when MODE is invalid', () => { + jest.spyOn(configService, 'get').mockReturnValue('invalid'); expect(() => serviceFactory.create()).toThrowError(`Invalid MODE: invalid`); }); }); diff --git a/servers/lib/test/unit/files.resolver.unit.spec.ts b/servers/lib/test/unit/files.resolver.unit.spec.ts index 62dcaab6d..850e50212 100644 --- a/servers/lib/test/unit/files.resolver.unit.spec.ts +++ b/servers/lib/test/unit/files.resolver.unit.spec.ts @@ -1,15 +1,15 @@ -import { Test, TestingModule } from "@nestjs/testing"; -import FilesResolver from "../../src/files/resolvers/files.resolver"; +import { Test, TestingModule } from '@nestjs/testing'; +import FilesResolver from '../../src/files/resolvers/files.resolver'; import { testDirectory, pathToTestDirectory, pathToTestFileContent, testFileContent, -} from "../testUtil"; -import { IFilesService } from "../../src/files/interfaces/files.service.interface"; -import FilesServiceFactory from "../../src/files/services/files-service.factory"; +} from '../testUtil'; +import { IFilesService } from '../../src/files/interfaces/files.service.interface'; +import FilesServiceFactory from '../../src/files/services/files-service.factory'; -describe("Unit tests for FilesResolver", () => { +describe('Unit tests for FilesResolver', () => { let filesResolver: FilesResolver; let filesService: IFilesService; @@ -38,30 +38,30 @@ describe("Unit tests for FilesResolver", () => { .create(); }); - it("should be defined", () => { + it('should be defined', () => { expect(filesResolver).toBeDefined(); }); - describe("listDirectory", () => { - it("should be defined", () => { + describe('listDirectory', () => { + it('should be defined', () => { expect(filesResolver.listDirectory).toBeDefined(); }); - it("should list files in directory", async () => { + it('should list files in directory', async () => { const result = await filesResolver.listDirectory(pathToTestDirectory); expect(result).toEqual(testDirectory); expect(filesService.listDirectory).toHaveBeenCalledWith( - pathToTestDirectory + pathToTestDirectory, ); }); }); - describe("readFile", () => { - it("should be defined", () => { + describe('readFile', () => { + it('should be defined', () => { expect(filesResolver.readFile).toBeDefined(); }); - it("should read file", async () => { + it('should read file', async () => { const result = await filesResolver.readFile(pathToTestFileContent); expect(result).toEqual(testFileContent); expect(filesService.readFile).toHaveBeenCalledWith(pathToTestFileContent); diff --git a/servers/lib/test/unit/gitlab-files.service.unit.spec.ts b/servers/lib/test/unit/gitlab-files.service.unit.spec.ts index 11f0fc416..f26a9712a 100644 --- a/servers/lib/test/unit/gitlab-files.service.unit.spec.ts +++ b/servers/lib/test/unit/gitlab-files.service.unit.spec.ts @@ -1,18 +1,18 @@ -import { Test, TestingModule } from "@nestjs/testing"; -import { ConfigService } from "@nestjs/config"; -import axios from "axios"; -import GitlabFilesService from "../../src/files/services/gitlab-files.service"; +import { Test, TestingModule } from '@nestjs/testing'; +import { ConfigService } from '@nestjs/config'; +import axios from 'axios'; +import GitlabFilesService from '../../src/files/services/gitlab-files.service'; import { pathToTestFileContent, testFileContent, MockConfigService, testDirectory, -} from "../testUtil"; +} from '../testUtil'; -describe("GitlabFilesService", () => { +describe('GitlabFilesService', () => { let filesService: GitlabFilesService; const mockConfigService = new MockConfigService(); - jest.mock("axios"); + jest.mock('axios'); beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ @@ -28,16 +28,16 @@ describe("GitlabFilesService", () => { filesService = module.get(GitlabFilesService); }); - it("should list directory", async () => { - jest.spyOn(axios, "post").mockResolvedValue({ data: testDirectory }); + it('should list directory', async () => { + jest.spyOn(axios, 'post').mockResolvedValue({ data: testDirectory }); - const result = await filesService.listDirectory("user2"); + const result = await filesService.listDirectory('user2'); expect(result).toEqual(testDirectory); }); - it("should read file", async () => { + it('should read file', async () => { jest - .spyOn(axios, "post") + .spyOn(axios, 'post') .mockResolvedValue({ data: { data: testFileContent } }); const result = await filesService.readFile(pathToTestFileContent); diff --git a/servers/lib/test/unit/local-files.service.unit.spec.ts b/servers/lib/test/unit/local-files.service.unit.spec.ts index a4fd0a497..72e4835be 100644 --- a/servers/lib/test/unit/local-files.service.unit.spec.ts +++ b/servers/lib/test/unit/local-files.service.unit.spec.ts @@ -1,8 +1,8 @@ -import { Test, TestingModule } from "@nestjs/testing"; -import { ConfigService } from "@nestjs/config"; -import * as fs from "fs"; -import { join } from "path"; -import LocalFilesService from "../../src/files/services/local-files.service"; +import { Test, TestingModule } from '@nestjs/testing'; +import { ConfigService } from '@nestjs/config'; +import * as fs from 'fs'; +import { join } from 'path'; +import LocalFilesService from '../../src/files/services/local-files.service'; import { fstestFileContent, pathToTestDirectory, @@ -10,9 +10,9 @@ import { testFileArray, MockConfigService, testFileName, -} from "../testUtil"; +} from '../testUtil'; -jest.mock("fs", () => ({ +jest.mock('fs', () => ({ promises: { readdir: jest.fn(), lstat: jest.fn(), @@ -20,7 +20,7 @@ jest.mock("fs", () => ({ }, })); -describe("LocalFilesService", () => { +describe('LocalFilesService', () => { let service: LocalFilesService; const mockConfigService = new MockConfigService(); @@ -39,14 +39,14 @@ describe("LocalFilesService", () => { jest.resetAllMocks(); }); - it("should be defined", () => { + it('should be defined', () => { expect(service).toBeDefined(); }); - it("should list directory", async () => { + it('should list directory', async () => { const fullPath = join( - mockConfigService.get("LOCAL_PATH"), - pathToTestDirectory + mockConfigService.get('LOCAL_PATH'), + pathToTestDirectory, ); // Mock Stats value for lstat @@ -55,11 +55,11 @@ describe("LocalFilesService", () => { }; jest - .spyOn(fs.promises, "readdir") + .spyOn(fs.promises, 'readdir') .mockResolvedValue(testFileArray as unknown as Promise<[]>); - jest.spyOn(fs.promises, "lstat").mockImplementation((pathToDirectory) => { - if (typeof pathToDirectory === "string") { + jest.spyOn(fs.promises, 'lstat').mockImplementation((pathToDirectory) => { + if (typeof pathToDirectory === 'string') { return Promise.resolve(statsMock as fs.Stats); } throw new Error(`Invalid argument: ${pathToDirectory}`); @@ -70,7 +70,7 @@ describe("LocalFilesService", () => { tree: { trees: { edges: testFileArray.map((file) => ({ - node: { name: file, type: "tree" }, + node: { name: file, type: 'tree' }, })), }, blobs: { edges: [] }, @@ -81,13 +81,13 @@ describe("LocalFilesService", () => { expect(fs.promises.lstat).toHaveBeenCalledTimes(testFileArray.length); }); - it("should read file", async () => { + it('should read file', async () => { const fullPath = join( - mockConfigService.get("LOCAL_PATH"), - pathToTestFileContent + mockConfigService.get('LOCAL_PATH'), + pathToTestFileContent, ); - jest.spyOn(fs.promises, "readFile").mockResolvedValue(fstestFileContent); + jest.spyOn(fs.promises, 'readFile').mockResolvedValue(fstestFileContent); const result = await service.readFile(pathToTestFileContent); expect(result).toEqual({ @@ -103,6 +103,6 @@ describe("LocalFilesService", () => { }, }, }); - expect(fs.promises.readFile).toHaveBeenCalledWith(fullPath, "utf8"); + expect(fs.promises.readFile).toHaveBeenCalledWith(fullPath, 'utf8'); }); });