Skip to content

Commit

Permalink
accept prettier lib improves codecov
Browse files Browse the repository at this point in the history
  • Loading branch information
lindot11 committed Nov 25, 2023
1 parent 6823b8d commit 9ceff6d
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 143 deletions.
8 changes: 4 additions & 4 deletions servers/lib/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>('APOLLO_PATH')
path: configService.get<string>('APOLLO_PATH'),
}),
inject: [ConfigService]
inject: [ConfigService],
}),
FilesModule,
]
],
})
export default class AppModule {}
10 changes: 5 additions & 5 deletions servers/lib/src/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion servers/lib/src/files/services/files-service.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down
4 changes: 2 additions & 2 deletions servers/lib/src/files/services/gitlab-files.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('/');
Expand Down Expand Up @@ -56,7 +56,7 @@ export default class GitlabFilesService implements IFilesService {

private async executeQuery(
path: string,
getQuery: QueryFunction
getQuery: QueryFunction,
): Promise<Project> {
const { domain, parsedPath } = await this.parseArguments(path);
const query = getQuery(domain, parsedPath);
Expand Down
20 changes: 10 additions & 10 deletions servers/lib/test/e2e/app.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand All @@ -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);
Expand Down
30 changes: 15 additions & 15 deletions servers/lib/test/integration/files.service.integration.spec.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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);
});
Expand Down
92 changes: 46 additions & 46 deletions servers/lib/test/testUtil.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
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: {
tree: {
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',
},
],
},
Expand All @@ -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;
Expand All @@ -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',
},
],
},
Expand All @@ -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',
},
},
],
Expand All @@ -146,9 +146,9 @@ export const expectedFileContentResponse = {
blobs: {
nodes: [
{
name: "README.md",
rawBlob: "content123",
rawTextBlob: "content123",
name: 'README.md',
rawBlob: 'content123',
rawTextBlob: 'content123',
},
],
},
Expand Down
Loading

0 comments on commit 9ceff6d

Please sign in to comment.