Skip to content

Commit

Permalink
undo single quote prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
lindot11 committed Nov 25, 2023
1 parent d0d8ad0 commit 5264b71
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 131 deletions.
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
26 changes: 13 additions & 13 deletions servers/lib/test/unit/files-service.factory.unit.spec.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -29,18 +29,18 @@ describe('FilesServiceFactory', () => {
configService = module.get<ConfigService>(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`);
});
});
28 changes: 14 additions & 14 deletions servers/lib/test/unit/files.resolver.unit.spec.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 5264b71

Please sign in to comment.